mirror of
https://github.com/rivea0/obsidian-match-syntax.git
synced 2026-07-22 05:46:49 +00:00
fix: update highlights when there is a change in editor
This commit is contained in:
parent
b4940bd875
commit
126f1c9d0a
1 changed files with 16 additions and 1 deletions
17
src/main.ts
17
src/main.ts
|
|
@ -3,7 +3,7 @@ import { EditorView, ViewPlugin, Decoration } from '@codemirror/view';
|
|||
import { MatchTextModal } from './modal';
|
||||
import { getMatchRanges } from './utils';
|
||||
import MatchSyntaxString from './syntaxObj';
|
||||
import type { PluginValue, DecorationSet, PluginSpec } from '@codemirror/view';
|
||||
import type { PluginValue, DecorationSet, PluginSpec, ViewUpdate } from '@codemirror/view';
|
||||
import type { MatchSyntaxPluginSettings, IRange } from './types';
|
||||
|
||||
const DEFAULT_SETTINGS: MatchSyntaxPluginSettings = {
|
||||
|
|
@ -116,6 +116,17 @@ class HighlighterPlugin implements PluginValue {
|
|||
constructor(view: EditorView) {
|
||||
this.decorations = Decoration.none;
|
||||
}
|
||||
|
||||
update(viewUpdate: ViewUpdate) {
|
||||
if (viewUpdate.docChanged) {
|
||||
if (this.decorations !== Decoration.none) {
|
||||
const docEl = viewUpdate.view.state.doc;
|
||||
const ranges = getMatchRanges(docEl, SYNTAX.getValue());
|
||||
this.makeDeco(ranges);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
makeDeco(ranges: IRange[]) {
|
||||
const deco = [];
|
||||
const highlightDeco = Decoration.mark({
|
||||
|
|
@ -132,6 +143,10 @@ class HighlighterPlugin implements PluginValue {
|
|||
clearDeco() {
|
||||
this.decorations = Decoration.none;
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.clearDeco();
|
||||
}
|
||||
}
|
||||
|
||||
const pluginSpec: PluginSpec<HighlighterPlugin> = {
|
||||
|
|
|
|||
Loading…
Reference in a new issue