Clean up code

This commit is contained in:
Gregory Schier
2024-08-26 15:10:29 -07:00
parent 55122b042b
commit 959ace8720

View File

@@ -68,7 +68,7 @@ function templateTags(
syntaxTree(view.state).iterate({ syntaxTree(view.state).iterate({
from, from,
to, to,
enter: (node) => { enter(node) {
if (node.name == 'Tag') { if (node.name == 'Tag') {
// Don't decorate if the cursor is inside the match // Don't decorate if the cursor is inside the match
for (const r of view.state.selection.ranges) { for (const r of view.state.selection.ranges) {
@@ -83,6 +83,7 @@ function templateTags(
const inner = rawTag.replace(/^\$\{\[\s*/, '').replace(/\s*]}$/, ''); const inner = rawTag.replace(/^\$\{\[\s*/, '').replace(/\s*]}$/, '');
const name = inner.match(/(\w+)[(]/)?.[1] ?? inner; const name = inner.match(/(\w+)[(]/)?.[1] ?? inner;
let option = options.find((v) => v.name === name); let option = options.find((v) => v.name === name);
if (option == null) { if (option == null) {
option = { option = {
invalid: true, invalid: true,
@@ -93,6 +94,7 @@ function templateTags(
onClick: () => onClickMissingVariable(name, rawTag, node.from), onClick: () => onClickMissingVariable(name, rawTag, node.from),
}; };
} }
const widget = new TemplateTagWidget(option, rawTag, node.from); const widget = new TemplateTagWidget(option, rawTag, node.from);
const deco = Decoration.replace({ widget, inclusive: true }); const deco = Decoration.replace({ widget, inclusive: true });
widgets.push(deco.range(node.from, node.to)); widgets.push(deco.range(node.from, node.to));
@@ -120,14 +122,16 @@ export function templateTagsPlugin(
} }
}, },
{ {
decorations: (v) => v.decorations, decorations(v) {
provide: (plugin) => return v.decorations;
EditorView.atomicRanges.of((view) => { },
provide(plugin) {
return EditorView.atomicRanges.of((view) => {
return view.plugin(plugin)?.decorations || Decoration.none; return view.plugin(plugin)?.decorations || Decoration.none;
}), });
},
eventHandlers: { eventHandlers: {
mousedown: (e) => { mousedown(e) {
const target = e.target as HTMLElement; const target = e.target as HTMLElement;
if (target.classList.contains('template-tag')) console.log('CLICKED TEMPLATE TAG'); if (target.classList.contains('template-tag')) console.log('CLICKED TEMPLATE TAG');
// return toggleBoolean(view, view.posAtDOM(target)); // return toggleBoolean(view, view.posAtDOM(target));