@bitbindle/prosemirror-view 0.0.0-stage → 1.44.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.tern-project +8 -0
- package/CHANGELOG.md +2639 -0
- package/CONTRIBUTING.md +104 -0
- package/FORK.md +67 -0
- package/LICENSE +19 -0
- package/README.md +27 -2
- package/dist/index.cjs +5668 -0
- package/dist/index.d.cts +921 -0
- package/dist/index.d.ts +921 -0
- package/dist/index.js +6135 -0
- package/package.json +56 -4
- package/src/README.md +38 -0
- package/src/browser.ts +18 -0
- package/src/capturekeys.ts +317 -0
- package/src/clipboard.ts +282 -0
- package/src/decoration.ts +834 -0
- package/src/dom.ts +174 -0
- package/src/domchange.ts +363 -0
- package/src/domcoords.ts +557 -0
- package/src/domobserver.ts +279 -0
- package/src/index.ts +800 -0
- package/src/input.ts +1001 -0
- package/src/selection.ts +460 -0
- package/src/viewdesc.ts +1518 -0
- package/style/prosemirror.css +54 -0
package/package.json
CHANGED
|
@@ -1,6 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bitbindle/prosemirror-view",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.44.2",
|
|
4
|
+
"description": "ProseMirror's view component (BitBindle fork)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.cjs",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.cjs"
|
|
13
|
+
},
|
|
14
|
+
"./style/prosemirror.css": "./style/prosemirror.css"
|
|
15
|
+
},
|
|
16
|
+
"sideEffects": [
|
|
17
|
+
"./style/prosemirror.css"
|
|
18
|
+
],
|
|
19
|
+
"style": "style/prosemirror.css",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"maintainers": [
|
|
22
|
+
{
|
|
23
|
+
"name": "Marijn Haverbeke",
|
|
24
|
+
"email": "marijn@haverbeke.berlin",
|
|
25
|
+
"web": "http://marijnhaverbeke.nl"
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/BitBindle/prosemirror-view.git"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public",
|
|
34
|
+
"provenance": true
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"prosemirror-model": "^1.25.12",
|
|
38
|
+
"prosemirror-state": "^1.0.0",
|
|
39
|
+
"prosemirror-transform": "^1.1.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@marijn/testtool": "0.1.3",
|
|
43
|
+
"@playwright/test": "1.65.1",
|
|
44
|
+
"@prosemirror/buildhelper": "0.1.8",
|
|
45
|
+
"ist": "1.1.7",
|
|
46
|
+
"prosemirror-test-builder": "1.1.1",
|
|
47
|
+
"prosemirror-view": "file:."
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"test": "node test/run-browser-tests.cjs",
|
|
51
|
+
"prepare": "pm-buildhelper src/index.ts"
|
|
52
|
+
},
|
|
53
|
+
"overrides": {
|
|
54
|
+
"mocha": {
|
|
55
|
+
"serialize-javascript": "7.1.4"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
package/src/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
ProseMirror's view module displays a given [editor
|
|
2
|
+
state](#state.EditorState) in the DOM, and handles user events.
|
|
3
|
+
|
|
4
|
+
Make sure you load `style/prosemirror.css` as a stylesheet when using
|
|
5
|
+
this module.
|
|
6
|
+
|
|
7
|
+
@EditorView
|
|
8
|
+
|
|
9
|
+
### Props
|
|
10
|
+
|
|
11
|
+
@EditorProps
|
|
12
|
+
|
|
13
|
+
@NodeViewConstructor
|
|
14
|
+
|
|
15
|
+
@MarkViewConstructor
|
|
16
|
+
|
|
17
|
+
@DirectEditorProps
|
|
18
|
+
|
|
19
|
+
@NodeView
|
|
20
|
+
|
|
21
|
+
@MarkView
|
|
22
|
+
|
|
23
|
+
@ViewMutationRecord
|
|
24
|
+
|
|
25
|
+
@DOMEventMap
|
|
26
|
+
|
|
27
|
+
### Decorations
|
|
28
|
+
|
|
29
|
+
Decorations make it possible to influence the way the document is
|
|
30
|
+
drawn, without actually changing the document.
|
|
31
|
+
|
|
32
|
+
@Decoration
|
|
33
|
+
|
|
34
|
+
@DecorationAttrs
|
|
35
|
+
|
|
36
|
+
@DecorationSet
|
|
37
|
+
|
|
38
|
+
@DecorationSource
|
package/src/browser.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const nav = typeof navigator != "undefined" ? navigator : null
|
|
2
|
+
const doc = typeof document != "undefined" ? document : null
|
|
3
|
+
const agent = (nav && nav.userAgent) || ""
|
|
4
|
+
|
|
5
|
+
export const gecko = /gecko\/(\d+)/i.test(agent) && !/edge?\//i.test(agent)
|
|
6
|
+
export const gecko_version = gecko && +(/Firefox\/(\d+)/.exec(agent) || [0, 0])[1]
|
|
7
|
+
|
|
8
|
+
const _chrome = /Chrome\/(\d+)/.exec(agent)
|
|
9
|
+
export const chrome = !!_chrome
|
|
10
|
+
export const chrome_version = _chrome ? +_chrome[1] : 0
|
|
11
|
+
export const safari = !!nav && /Apple Computer/.test(nav.vendor)
|
|
12
|
+
// Is true for both iOS and iPadOS for convenience
|
|
13
|
+
export const ios = safari && (/Mobile\/\w+/.test(agent) || !!nav && nav.maxTouchPoints > 2)
|
|
14
|
+
export const mac = ios || (nav ? /Mac/.test(nav.platform) : false)
|
|
15
|
+
export const windows = nav ? /Win/.test(nav.platform) : false
|
|
16
|
+
export const android = /Android \d/.test(agent)
|
|
17
|
+
export const webkit = !!doc && "webkitFontSmoothing" in doc.documentElement.style
|
|
18
|
+
export const webkit_version = webkit ? +(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent) || [0, 0])[1] : 0
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import {Selection, NodeSelection, TextSelection, AllSelection, EditorState} from "prosemirror-state"
|
|
2
|
+
import {EditorView} from "./index"
|
|
3
|
+
import * as browser from "./browser"
|
|
4
|
+
import {domIndex, selectionCollapsed, isElt, isText, nodeSize,
|
|
5
|
+
textNodeBefore, textNodeAfter} from "./dom"
|
|
6
|
+
|
|
7
|
+
function moveSelectionBlock(state: EditorState, dir: number) {
|
|
8
|
+
let {$anchor, $head} = state.selection
|
|
9
|
+
let $side = dir > 0 ? $anchor.max($head) : $anchor.min($head)
|
|
10
|
+
let $start = !$side.parent.inlineContent ? $side : $side.depth ? state.doc.resolve(dir > 0 ? $side.after() : $side.before()) : null
|
|
11
|
+
return $start && Selection.findFrom($start, dir)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function apply(view: EditorView, sel: Selection) {
|
|
15
|
+
view.dispatch(view.state.tr.setSelection(sel).scrollIntoView())
|
|
16
|
+
return true
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function selectHorizontally(view: EditorView, dir: number, mods: string) {
|
|
20
|
+
let sel = view.state.selection
|
|
21
|
+
if (sel instanceof TextSelection) {
|
|
22
|
+
if (mods.indexOf("s") > -1) {
|
|
23
|
+
let {$head} = sel, node = $head.textOffset ? null : dir < 0 ? $head.nodeBefore : $head.nodeAfter
|
|
24
|
+
if (!node || node.isText || !node.isLeaf) return false
|
|
25
|
+
let $newHead = view.state.doc.resolve($head.pos + node.nodeSize * (dir < 0 ? -1 : 1))
|
|
26
|
+
return apply(view, new TextSelection(sel.$anchor, $newHead))
|
|
27
|
+
} else if (!sel.empty) {
|
|
28
|
+
return false
|
|
29
|
+
} else if (view.endOfTextblock(dir > 0 ? "forward" : "backward")) {
|
|
30
|
+
let next = moveSelectionBlock(view.state, dir)
|
|
31
|
+
if (next && (next instanceof NodeSelection)) return apply(view, next)
|
|
32
|
+
return false
|
|
33
|
+
} else if (!browser.mac || mods.indexOf("m") < 0) {
|
|
34
|
+
let $head = sel.$head, node = $head.textOffset ? null : dir < 0 ? $head.nodeBefore : $head.nodeAfter, desc
|
|
35
|
+
if (!node || node.isText) return false
|
|
36
|
+
let nodePos = dir < 0 ? $head.pos - node.nodeSize : $head.pos
|
|
37
|
+
if (!(node.isAtom || (desc = view.docView.descAt(nodePos)) && !desc.contentDOM)) return false
|
|
38
|
+
if (NodeSelection.isSelectable(node)) {
|
|
39
|
+
return apply(view, new NodeSelection(dir < 0 ? view.state.doc.resolve($head.pos - node.nodeSize) : $head))
|
|
40
|
+
} else {
|
|
41
|
+
// Chrome and Safari will introduce extra pointless cursor
|
|
42
|
+
// positions around inline uneditable nodes (#937), and
|
|
43
|
+
// Firefox will sometimes just plain refuse to move across
|
|
44
|
+
// them (#1592), so in this situation we move the cursor
|
|
45
|
+
// ourselves.
|
|
46
|
+
return apply(view, new TextSelection(view.state.doc.resolve(dir < 0 ? nodePos : nodePos + node.nodeSize)))
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
} else if (sel instanceof NodeSelection && sel.node.isInline) {
|
|
50
|
+
return apply(view, new TextSelection(dir > 0 ? sel.$to : sel.$from))
|
|
51
|
+
} else {
|
|
52
|
+
let next = moveSelectionBlock(view.state, dir)
|
|
53
|
+
if (next) return apply(view, next)
|
|
54
|
+
return false
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function isIgnorable(dom: Node, dir: number) {
|
|
59
|
+
let desc = dom.pmViewDesc
|
|
60
|
+
return desc ? desc.size == 0 && (dir < 0 || dom.nextSibling || dom.nodeName != "BR")
|
|
61
|
+
: isElt(dom) && dom.contentEditable == "false"
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function skipIgnoredNodes(view: EditorView, dir: number) {
|
|
65
|
+
return dir < 0 ? skipIgnoredNodesBefore(view) : skipIgnoredNodesAfter(view)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Make sure the cursor isn't directly after one or more ignored
|
|
69
|
+
// nodes, which will confuse the browser's cursor motion logic.
|
|
70
|
+
function skipIgnoredNodesBefore(view: EditorView) {
|
|
71
|
+
let sel = view.domSel.readRange()
|
|
72
|
+
let node = sel.focusNode!, offset = sel.focusOffset
|
|
73
|
+
if (!node) return
|
|
74
|
+
let moveNode, moveOffset: number | undefined, force = false
|
|
75
|
+
// Gecko will do odd things when the selection is directly in front
|
|
76
|
+
// of a non-editable node, so in that case, move it into the next
|
|
77
|
+
// node if possible. Issue prosemirror/prosemirror#832.
|
|
78
|
+
if (browser.gecko && isElt(node) && offset < nodeSize(node) && isIgnorable(node.childNodes[offset], -1)) force = true
|
|
79
|
+
for (;;) {
|
|
80
|
+
if (offset > 0) {
|
|
81
|
+
if (!isElt(node)) break
|
|
82
|
+
let before = node.childNodes[offset - 1]
|
|
83
|
+
if (isIgnorable(before, -1)) {
|
|
84
|
+
moveNode = node
|
|
85
|
+
moveOffset = --offset
|
|
86
|
+
} else if (isText(before)) {
|
|
87
|
+
node = before
|
|
88
|
+
offset = node.nodeValue!.length
|
|
89
|
+
} else {
|
|
90
|
+
break
|
|
91
|
+
}
|
|
92
|
+
} else if (isBlockNode(node)) {
|
|
93
|
+
break
|
|
94
|
+
} else {
|
|
95
|
+
let prev = node.previousSibling
|
|
96
|
+
while (prev && isIgnorable(prev, -1)) {
|
|
97
|
+
moveNode = node.parentNode
|
|
98
|
+
moveOffset = domIndex(prev)
|
|
99
|
+
prev = prev.previousSibling
|
|
100
|
+
}
|
|
101
|
+
if (!prev) {
|
|
102
|
+
node = node.parentNode!
|
|
103
|
+
if (node == view.dom) break
|
|
104
|
+
offset = 0
|
|
105
|
+
} else {
|
|
106
|
+
node = prev
|
|
107
|
+
offset = nodeSize(node)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (force) setSelFocus(view, node, offset)
|
|
112
|
+
else if (moveNode) setSelFocus(view, moveNode, moveOffset!)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Make sure the cursor isn't directly before one or more ignored
|
|
116
|
+
// nodes.
|
|
117
|
+
function skipIgnoredNodesAfter(view: EditorView) {
|
|
118
|
+
let sel = view.domSel.readRange()
|
|
119
|
+
let node = sel.focusNode!, offset = sel.focusOffset
|
|
120
|
+
if (!node) return
|
|
121
|
+
let len = nodeSize(node)
|
|
122
|
+
let moveNode, moveOffset: number | undefined
|
|
123
|
+
for (;;) {
|
|
124
|
+
if (offset < len) {
|
|
125
|
+
if (!isElt(node)) break
|
|
126
|
+
let after = node.childNodes[offset]
|
|
127
|
+
if (isIgnorable(after, 1)) {
|
|
128
|
+
moveNode = node
|
|
129
|
+
moveOffset = ++offset
|
|
130
|
+
} else {
|
|
131
|
+
break
|
|
132
|
+
}
|
|
133
|
+
} else if (isBlockNode(node)) {
|
|
134
|
+
break
|
|
135
|
+
} else {
|
|
136
|
+
let next = node.nextSibling
|
|
137
|
+
while (next && isIgnorable(next, 1)) {
|
|
138
|
+
moveNode = next.parentNode
|
|
139
|
+
moveOffset = domIndex(next) + 1
|
|
140
|
+
next = next.nextSibling
|
|
141
|
+
}
|
|
142
|
+
if (!next) {
|
|
143
|
+
node = node.parentNode!
|
|
144
|
+
if (node == view.dom) break
|
|
145
|
+
offset = len = 0
|
|
146
|
+
} else {
|
|
147
|
+
node = next
|
|
148
|
+
offset = 0
|
|
149
|
+
len = nodeSize(node)
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (moveNode) setSelFocus(view, moveNode, moveOffset!)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function isBlockNode(dom: Node) {
|
|
157
|
+
for (let scan: Node | null = dom; scan; scan = scan.parentNode) {
|
|
158
|
+
let desc = scan.pmViewDesc
|
|
159
|
+
if (desc) return desc.node ? desc.node.isBlock : false
|
|
160
|
+
}
|
|
161
|
+
return false
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function setSelFocus(view: EditorView, node: Node, offset: number) {
|
|
165
|
+
if (!isText(node)) {
|
|
166
|
+
let before, after
|
|
167
|
+
if (after = textNodeAfter(node, offset)) {
|
|
168
|
+
node = after
|
|
169
|
+
offset = 0
|
|
170
|
+
} else if (before = textNodeBefore(node, offset)) {
|
|
171
|
+
node = before
|
|
172
|
+
offset = before.nodeValue!.length
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
let sel = view.domSelection(), range = view.domSel.readRange()
|
|
177
|
+
if (!sel) return
|
|
178
|
+
if (selectionCollapsed(range)) {
|
|
179
|
+
sel.collapse(node, offset)
|
|
180
|
+
} else if (sel.extend) {
|
|
181
|
+
sel.collapse(range.anchorNode, range.anchorOffset)
|
|
182
|
+
sel.extend(node, offset)
|
|
183
|
+
}
|
|
184
|
+
view.domSel.ignore()
|
|
185
|
+
let {state} = view
|
|
186
|
+
// If no state update ends up happening, reset the selection.
|
|
187
|
+
setTimeout(() => {
|
|
188
|
+
if (view.state == state) view.domSel.sync()
|
|
189
|
+
}, 50)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function findDirection(view: EditorView, pos: number): "rtl" | "ltr" {
|
|
193
|
+
let $pos = view.state.doc.resolve(pos)
|
|
194
|
+
if (!(browser.chrome || browser.windows) && $pos.parent.inlineContent) {
|
|
195
|
+
let coords = view.coordsAtPos(pos)
|
|
196
|
+
if (pos > $pos.start()) {
|
|
197
|
+
let before = view.coordsAtPos(pos - 1)
|
|
198
|
+
let mid = (before.top + before.bottom) / 2
|
|
199
|
+
if (mid > coords.top && mid < coords.bottom && Math.abs(before.left - coords.left) > 1)
|
|
200
|
+
return before.left < coords.left ? "ltr" : "rtl"
|
|
201
|
+
}
|
|
202
|
+
if (pos < $pos.end()) {
|
|
203
|
+
let after = view.coordsAtPos(pos + 1)
|
|
204
|
+
let mid = (after.top + after.bottom) / 2
|
|
205
|
+
if (mid > coords.top && mid < coords.bottom && Math.abs(after.left - coords.left) > 1)
|
|
206
|
+
return after.left > coords.left ? "ltr" : "rtl"
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
let block: Element = view.dom
|
|
210
|
+
for (let d = $pos.depth; d > 0; d--) if ($pos.node(d).isBlock) {
|
|
211
|
+
block = view.nodeDOM($pos.before(d)) as Element || block
|
|
212
|
+
break
|
|
213
|
+
}
|
|
214
|
+
let computed = getComputedStyle(block).direction
|
|
215
|
+
return computed == "rtl" ? "rtl" : "ltr"
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Check whether vertical selection motion would involve node
|
|
219
|
+
// selections. If so, apply it (if not, the result is left to the
|
|
220
|
+
// browser)
|
|
221
|
+
function selectVertically(view: EditorView, dir: number, mods: string) {
|
|
222
|
+
let sel = view.state.selection
|
|
223
|
+
if (sel instanceof TextSelection && !sel.empty || mods.indexOf("s") > -1) return false
|
|
224
|
+
if (browser.mac && mods.indexOf("m") > -1) return false
|
|
225
|
+
let {$from, $to} = sel
|
|
226
|
+
|
|
227
|
+
if (!$from.parent.inlineContent || view.endOfTextblock(dir < 0 ? "up" : "down")) {
|
|
228
|
+
let next = moveSelectionBlock(view.state, dir)
|
|
229
|
+
if (next && (next instanceof NodeSelection))
|
|
230
|
+
return apply(view, next)
|
|
231
|
+
}
|
|
232
|
+
if (!$from.parent.inlineContent) {
|
|
233
|
+
let side = dir < 0 ? $from : $to
|
|
234
|
+
let beyond = sel instanceof AllSelection ? Selection.near(side, dir) : Selection.findFrom(side, dir)
|
|
235
|
+
return beyond ? apply(view, beyond) : false
|
|
236
|
+
}
|
|
237
|
+
return false
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function stopNativeHorizontalDelete(view: EditorView, dir: number) {
|
|
241
|
+
if (!(view.state.selection instanceof TextSelection)) return true
|
|
242
|
+
let {$head, $anchor, empty} = view.state.selection
|
|
243
|
+
if (!$head.sameParent($anchor)) return true
|
|
244
|
+
if (!empty) return false
|
|
245
|
+
if (view.endOfTextblock(dir > 0 ? "forward" : "backward")) return true
|
|
246
|
+
let nextNode = !$head.textOffset && (dir < 0 ? $head.nodeBefore : $head.nodeAfter)
|
|
247
|
+
if (nextNode && !nextNode.isText) {
|
|
248
|
+
let tr = view.state.tr
|
|
249
|
+
if (dir < 0) tr.delete($head.pos - nextNode.nodeSize, $head.pos)
|
|
250
|
+
else tr.delete($head.pos, $head.pos + nextNode.nodeSize)
|
|
251
|
+
view.dispatch(tr)
|
|
252
|
+
return true
|
|
253
|
+
}
|
|
254
|
+
return false
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function switchEditable(view: EditorView, node: HTMLElement, state: string) {
|
|
258
|
+
view.domObserver.stopped(() => node.contentEditable = state)
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Issue #867 / #1090 / https://bugs.chromium.org/p/chromium/issues/detail?id=903821
|
|
262
|
+
// In which Safari (and at some point in the past, Chrome) does really
|
|
263
|
+
// wrong things when the down arrow is pressed when the cursor is
|
|
264
|
+
// directly at the start of a textblock and has an uneditable node
|
|
265
|
+
// after it
|
|
266
|
+
function safariDownArrowBug(view: EditorView) {
|
|
267
|
+
if (!browser.safari || view.state.selection.$head.parentOffset > 0) return false
|
|
268
|
+
let {focusNode, focusOffset} = view.domSel.readRange()
|
|
269
|
+
if (focusNode && isElt(focusNode) && focusOffset == 0 &&
|
|
270
|
+
focusNode.firstChild && isElt(focusNode.firstChild) && focusNode.firstChild.contentEditable == "false") {
|
|
271
|
+
let child = focusNode.firstChild
|
|
272
|
+
switchEditable(view, child, "true")
|
|
273
|
+
setTimeout(() => switchEditable(view, child, "false"), 20)
|
|
274
|
+
}
|
|
275
|
+
return false
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// A backdrop key mapping used to make sure we always suppress keys
|
|
279
|
+
// that have a dangerous default effect, even if the commands they are
|
|
280
|
+
// bound to return false, and to make sure that cursor-motion keys
|
|
281
|
+
// find a cursor (as opposed to a node selection) when pressed. For
|
|
282
|
+
// cursor-motion keys, the code in the handlers also takes care of
|
|
283
|
+
// block selections.
|
|
284
|
+
|
|
285
|
+
function getMods(event: KeyboardEvent) {
|
|
286
|
+
let result = ""
|
|
287
|
+
if (event.ctrlKey) result += "c"
|
|
288
|
+
if (event.metaKey) result += "m"
|
|
289
|
+
if (event.altKey) result += "a"
|
|
290
|
+
if (event.shiftKey) result += "s"
|
|
291
|
+
return result
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export function captureKeyDown(view: EditorView, event: KeyboardEvent) {
|
|
295
|
+
let code = event.keyCode, mods = getMods(event)
|
|
296
|
+
if (code == 8 || (browser.mac && code == 72 && mods == "c")) { // Backspace, Ctrl-h on Mac
|
|
297
|
+
return stopNativeHorizontalDelete(view, -1) || skipIgnoredNodes(view, -1)
|
|
298
|
+
} else if ((code == 46 && !event.shiftKey) || (browser.mac && code == 68 && mods == "c")) { // Delete, Ctrl-d on Mac
|
|
299
|
+
return stopNativeHorizontalDelete(view, 1) || skipIgnoredNodes(view, 1)
|
|
300
|
+
} else if (code == 13 || code == 27) { // Enter, Esc
|
|
301
|
+
return true
|
|
302
|
+
} else if (code == 37 || (browser.mac && code == 66 && mods == "c")) { // Left arrow, Ctrl-b on Mac
|
|
303
|
+
let dir = code == 37 ? (findDirection(view, view.state.selection.from) == "ltr" ? -1 : 1) : -1
|
|
304
|
+
return selectHorizontally(view, dir, mods) || skipIgnoredNodes(view, dir)
|
|
305
|
+
} else if (code == 39 || (browser.mac && code == 70 && mods == "c")) { // Right arrow, Ctrl-f on Mac
|
|
306
|
+
let dir = code == 39 ? (findDirection(view, view.state.selection.from) == "ltr" ? 1 : -1) : 1
|
|
307
|
+
return selectHorizontally(view, dir, mods) || skipIgnoredNodes(view, dir)
|
|
308
|
+
} else if (code == 38 || (browser.mac && code == 80 && mods == "c")) { // Up arrow, Ctrl-p on Mac
|
|
309
|
+
return selectVertically(view, -1, mods) || skipIgnoredNodes(view, -1)
|
|
310
|
+
} else if (code == 40 || (browser.mac && code == 78 && mods == "c")) { // Down arrow, Ctrl-n on Mac
|
|
311
|
+
return safariDownArrowBug(view) || selectVertically(view, 1, mods) || skipIgnoredNodes(view, 1)
|
|
312
|
+
} else if (mods == (browser.mac ? "m" : "c") &&
|
|
313
|
+
(code == 66 || code == 73 || code == 89 || code == 90)) { // Mod-[biyz]
|
|
314
|
+
return true
|
|
315
|
+
}
|
|
316
|
+
return false
|
|
317
|
+
}
|