Reduce vertical jump for other blocks

This commit is contained in:
Zef Hemel
2022-12-19 12:35:58 +01:00
parent d032672076
commit bb04f30470
6 changed files with 79 additions and 51 deletions
+3 -20
View File
@@ -3,12 +3,11 @@ import {
directiveStartRegex,
} from "../../plug-api/lib/query.ts";
import { Decoration, EditorState, syntaxTree } from "../deps.ts";
import type { Editor } from "../editor.tsx";
import { decoratorStateField, HtmlWidget, isCursorInRange } from "./util.ts";
// Does a few things: hides the directives when the cursor is not placed inside
// Adds a class to the start and end of the directive when the cursor is placed inside
export function directivePlugin(editor: Editor) {
export function directivePlugin() {
return decoratorStateField((state: EditorState) => {
const widgets: any[] = [];
@@ -35,20 +34,12 @@ export function directivePlugin(editor: Editor) {
console.error("Something went wrong with this directive");
return;
}
const [fullMatch, directiveName] = match;
const [_fullMatch, directiveName] = match;
widgets.push(
Decoration.widget({
widget: new HtmlWidget(
`#${directiveName}`,
"sb-directive-placeholder",
(e) => {
e.stopPropagation();
editor.editorView?.dispatch({
selection: {
anchor: from + fullMatch.indexOf(directiveName),
},
});
},
),
}).range(from),
);
@@ -76,20 +67,12 @@ export function directivePlugin(editor: Editor) {
console.error("Something went wrong with this directive");
return;
}
const [fullMatch, directiveName] = match;
const [_fullMatch, directiveName] = match;
widgets.push(
Decoration.widget({
widget: new HtmlWidget(
`/${directiveName}`,
"sb-directive-placeholder",
(e) => {
e.stopPropagation();
editor.editorView?.dispatch({
selection: {
anchor: from + fullMatch.indexOf(directiveName),
},
});
},
),
}).range(from),
);