-
Notifications
You must be signed in to change notification settings - Fork 0
/
field.ts
46 lines (42 loc) · 1.04 KB
/
field.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { syntaxTree } from "@codemirror/language";
import {
Extension,
RangeSetBuilder,
StateField,
Transaction,
} from "@codemirror/state";
import {
Decoration,
DecorationSet,
EditorView,
WidgetType,
} from "@codemirror/view";
import { ThumbnailWidget } from "./widget";
import MyPlugin from "./main";
export const emojiListField = StateField.define<DecorationSet>({
create(state): DecorationSet {
return Decoration.none;
},
update(oldState: DecorationSet, transaction: Transaction): DecorationSet {
const builder = new RangeSetBuilder<Decoration>();
/*syntaxTree(transaction.state).iterate({
enter(node) {
if (node.type.name === "hmd-internal-link") {
// Position of the '-' or the '*'.
const listCharFrom = node.from;
builder.add(
listCharFrom,
listCharFrom + 1,
Decoration.widget({
widget: new ThumbnailWidget(),
})
);
}
},
});*/
return builder.finish();
},
provide(field: StateField<DecorationSet>): Extension {
return EditorView.decorations.from(field);
},
});