mirror of
https://github.com/kotaindah55/extended-markdown-syntax.git
synced 2026-07-22 05:38:06 +00:00
refactor: menuInvoker annotation be no longer needed
Tag menu will only be invoked through click event on the color button, command, or Formatter instance.
This commit is contained in:
parent
e2587b2be5
commit
a7bc51fed2
2 changed files with 5 additions and 21 deletions
|
|
@ -1,4 +0,0 @@
|
|||
import { Annotation } from "@codemirror/state";
|
||||
import { TagMenuSpec } from "src/types";
|
||||
|
||||
export let menuInvokerAnnot = Annotation.define<TagMenuSpec>();
|
||||
|
|
@ -3,17 +3,16 @@ import { DecorationBuilder } from "src/editor-mode/decorator/builder";
|
|||
import { builderField } from "src/editor-mode/state-fields";
|
||||
import { pluginFacet } from "src/editor-mode/facets";
|
||||
import ExtendedMarkdownSyntax from "main";
|
||||
import { menuInvokerAnnot } from "src/editor-mode/annotations";
|
||||
import { IndexCache, TagMenuSpec } from "src/types";
|
||||
import { ColorMenu } from "src/editor-mode/ui-components";
|
||||
import { Format } from "src/enums";
|
||||
import { IndexCache } from "src/types";
|
||||
|
||||
export class EditorPlugin implements PluginValue {
|
||||
builder: DecorationBuilder;
|
||||
mainPlugin: ExtendedMarkdownSyntax;
|
||||
root: DocumentOrShadowRoot;
|
||||
indexCache: Record<"colorMenuItem", IndexCache> = {
|
||||
colorMenuItem: { number: 0 }
|
||||
indexCache: Record<"colorMenuItem" | "spanTagMenuItem" | "divTagMenuItem", IndexCache> = {
|
||||
colorMenuItem: { number: 0 },
|
||||
spanTagMenuItem: { number: 0 },
|
||||
divTagMenuItem: { number: 0 }
|
||||
}
|
||||
constructor(view: EditorView) {
|
||||
let state = view.state;
|
||||
|
|
@ -27,13 +26,6 @@ export class EditorPlugin implements PluginValue {
|
|||
this.onRootChanged(update.view.root);
|
||||
}
|
||||
this.builder.onViewUpdate(update);
|
||||
let colorMenuSpec: undefined | TagMenuSpec;
|
||||
update.transactions.find(tr => colorMenuSpec = tr.annotation(menuInvokerAnnot));
|
||||
if (colorMenuSpec && colorMenuSpec.type == Format.HIGHLIGHT && !colorMenuSpec.accessed) {
|
||||
let showAtPos = update.state.selection.main.to;
|
||||
colorMenuSpec.accessed = true;
|
||||
this.invokeColorMenu(colorMenuSpec, update.view, showAtPos);
|
||||
}
|
||||
}
|
||||
destroy(): void {
|
||||
this.mainPlugin.colorsHandler.abandon(this.root);
|
||||
|
|
@ -46,8 +38,4 @@ export class EditorPlugin implements PluginValue {
|
|||
this.mainPlugin.opacityHandler.adopt(newRoot);
|
||||
this.root = newRoot;
|
||||
}
|
||||
invokeColorMenu(spec: TagMenuSpec, view: EditorView, showAtPos?: number) {
|
||||
let menu = ColorMenu.create(view, spec.openRange, spec.tagRange, spec.closeRange, spec.moveCursorAfterTag, this.indexCache.colorMenuItem);
|
||||
menu.showMenu(showAtPos);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue