1
0
silverbullet/web/cm_plugins/block.ts

39 lines
1000 B
TypeScript
Raw Normal View History

import { Decoration, EditorState, syntaxTree } from "../deps.ts";
import {
decoratorStateField,
invisibleDecoration,
isCursorInRange,
} from "./util.ts";
export function cleanBlockPlugin() {
return decoratorStateField(
(state: EditorState) => {
const widgets: any[] = [];
2022-11-18 15:20:00 +00:00
syntaxTree(state).iterate({
enter(node) {
if (
node.name === "HorizontalRule" &&
!isCursorInRange(state, [node.from, node.to])
) {
widgets.push(invisibleDecoration.range(node.from, node.to));
widgets.push(
Decoration.line({
class: "sb-line-hr",
}).range(node.from),
);
}
2023-12-21 18:04:54 +00:00
if (
node.name === "Image" &&
!isCursorInRange(state, [node.from, node.to])
) {
widgets.push(invisibleDecoration.range(node.from, node.to));
2023-12-21 18:04:54 +00:00
}
},
});
return Decoration.set(widgets, true);
},
);
}