Fixes #164: Rewrote all CM view plugins to statefields
This commit is contained in:
+22
-15
@@ -3,11 +3,12 @@
|
||||
// License: Apache License 2.0.
|
||||
import {
|
||||
Decoration,
|
||||
DecorationSet,
|
||||
EditorState,
|
||||
EditorView,
|
||||
foldedRanges,
|
||||
SyntaxNodeRef,
|
||||
syntaxTree,
|
||||
StateField,
|
||||
Transaction,
|
||||
WidgetType,
|
||||
} from "../deps.ts";
|
||||
|
||||
@@ -39,6 +40,25 @@ export class LinkWidget extends WidgetType {
|
||||
}
|
||||
}
|
||||
|
||||
export function decoratorStateField(
|
||||
stateToDecoratorMapper: (state: EditorState) => DecorationSet,
|
||||
) {
|
||||
return StateField.define<DecorationSet>({
|
||||
create(state: EditorState) {
|
||||
return stateToDecoratorMapper(state);
|
||||
},
|
||||
|
||||
update(value: DecorationSet, tr: Transaction) {
|
||||
// if (tr.docChanged || tr.selection) {
|
||||
return stateToDecoratorMapper(tr.state);
|
||||
// }
|
||||
// return value;
|
||||
},
|
||||
|
||||
provide: (f) => EditorView.decorations.from(f),
|
||||
});
|
||||
}
|
||||
|
||||
export class ButtonWidget extends WidgetType {
|
||||
constructor(
|
||||
readonly text: string,
|
||||
@@ -106,19 +126,6 @@ export function isCursorInRange(state: EditorState, range: [number, number]) {
|
||||
*/
|
||||
export const invisibleDecoration = Decoration.replace({});
|
||||
|
||||
export function iterateTreeInVisibleRanges(
|
||||
view: EditorView,
|
||||
iterateFns: {
|
||||
enter(node: SyntaxNodeRef): boolean | void;
|
||||
leave?(node: SyntaxNodeRef): void;
|
||||
},
|
||||
) {
|
||||
// for (const { from, to } of view.visibleRanges) {
|
||||
// syntaxTree(view.state).iterate({ ...iterateFns, from, to });
|
||||
// }
|
||||
syntaxTree(view.state).iterate(iterateFns);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the lines of the editor that are in the given range and not folded.
|
||||
* This function is of use when you need to get the lines of a particular
|
||||
|
||||
Reference in New Issue
Block a user