MCPcopy Create free account
hub / github.com/editablejs/editable / marks

Function marks

packages/models/src/interfaces/editor.ts:86–128  ·  view source on GitHub ↗
(editor: SlateEditor)

Source from the content-addressed store, hash-verified

84}
85
86const marks = (editor: SlateEditor): EditorMarks | null => {
87 const { selection } = editor
88 if (!selection) return null
89 if (Range.isExpanded(selection)) {
90 const [match] = Editor.nodes(editor, { match: Text.isText })
91
92 if (match) {
93 const [node] = match as NodeEntry<Text>
94 const { text, ...rest } = node
95 return rest
96 } else {
97 return {}
98 }
99 }
100
101 const { anchor } = selection
102 const { path } = anchor
103 let [node] = Editor.leaf(editor, path)
104
105 if (anchor.offset === 0) {
106 const prev = Editor.previous(editor, { at: path, match: Text.isText })
107 const markedVoid = Editor.above(editor, {
108 match: n => Element.isElement(n) && Editor.isVoid(editor, n) && editor.markableVoid(n),
109 })
110 if (!markedVoid) {
111 const block = Editor.above(editor, {
112 match: n => Element.isElement(n) && Editor.isBlock(editor, n),
113 })
114
115 if (prev && block) {
116 const [prevNode, prevPath] = prev
117 const [, blockPath] = block
118
119 if (Path.isAncestor(blockPath, prevPath)) {
120 node = prevNode as Text
121 }
122 }
123 }
124 }
125
126 const { text, ...rest } = node
127 return rest
128}
129
130SlateEditor.marks = (editor: SlateEditor, at?: Location) => {
131 const caches = EDITOR_ACTIVE_MARKS.get(editor)

Callers 1

editor.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…