@onereach/ui-components 4.10.0 → 4.10.1-beta.2921.0
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/dist/bundled/v2/components/OrCode/OrCode.js +4 -3792
- package/dist/bundled/v2/components/OrCode/index.js +4 -2
- package/dist/bundled/v2/components/OrCode/lang.js +24 -3
- package/dist/bundled/v2/components/OrCode/theme.js +1 -1
- package/dist/bundled/v2/components/OrCodeV3/OrCode.js +333 -0
- package/dist/bundled/v2/components/OrCodeV3/OrCode.vue.d.ts +169 -0
- package/dist/bundled/v2/components/OrCodeV3/index.d.ts +2 -0
- package/dist/bundled/v2/components/OrCodeV3/index.js +49 -0
- package/dist/bundled/v2/components/OrCodeV3/props.d.ts +8 -0
- package/dist/bundled/v2/components/OrCodeV3/props.js +11 -0
- package/dist/bundled/v2/components/OrCodeV3/styles.d.ts +2 -0
- package/dist/bundled/v2/components/OrCodeV3/styles.js +10 -0
- package/dist/bundled/v2/components/OrModalV3/OrModal.js +2 -2
- package/dist/bundled/v2/components/index.d.ts +1 -0
- package/dist/bundled/v2/components/index.js +8 -3
- package/dist/bundled/{v3/OrCode.vue_vue_type_script_lang-46846a36.js → v2/index-576b3dec.js} +3 -235
- package/dist/bundled/v2/{index-cf2c3c27.js → index-6a13fa4e.js} +1 -1
- package/dist/bundled/v2/{lang-0fb8f78b.js → index-eba9b646.js} +2 -22
- package/dist/bundled/v2/index.js +9 -4
- package/dist/bundled/v3/OrCode.vue_vue_type_script_lang-1812e6e4.js +237 -0
- package/dist/bundled/v3/OrCode.vue_vue_type_script_lang-84a512fb.js +200 -0
- package/dist/bundled/v3/components/OrCode/OrCode.js +7 -5
- package/dist/bundled/v3/components/OrCode/index.js +5 -3
- package/dist/bundled/v3/components/OrCode/lang.js +24 -3
- package/dist/bundled/v3/components/OrCode/theme.js +1 -1
- package/dist/bundled/v3/components/OrCodeV3/OrCode.js +142 -0
- package/dist/bundled/v3/components/OrCodeV3/OrCode.vue.d.ts +119 -0
- package/dist/bundled/v3/components/OrCodeV3/index.d.ts +2 -0
- package/dist/bundled/v3/components/OrCodeV3/index.js +60 -0
- package/dist/bundled/v3/components/OrCodeV3/props.d.ts +8 -0
- package/dist/bundled/v3/components/OrCodeV3/props.js +11 -0
- package/dist/bundled/v3/components/OrCodeV3/styles.d.ts +2 -0
- package/dist/bundled/v3/components/OrCodeV3/styles.js +10 -0
- package/dist/bundled/v3/components/index.d.ts +1 -0
- package/dist/bundled/v3/components/index.js +10 -4
- package/dist/bundled/v3/index-576b3dec.js +3794 -0
- package/dist/bundled/v3/{index-cf2c3c27.js → index-6a13fa4e.js} +1 -1
- package/dist/bundled/v3/{lang-0fb8f78b.js → index-eba9b646.js} +2 -22
- package/dist/bundled/v3/index.js +16 -10
- package/dist/esm/v2/OrCode-ad718022.js +327 -0
- package/dist/esm/v2/components/index.d.ts +1 -0
- package/dist/esm/v2/components/index.js +2 -1
- package/dist/esm/v2/components/or-code-v3/OrCode.vue.d.ts +169 -0
- package/dist/esm/v2/components/or-code-v3/index.d.ts +2 -0
- package/dist/esm/v2/components/or-code-v3/index.js +35 -0
- package/dist/esm/v2/components/or-code-v3/props.d.ts +8 -0
- package/dist/esm/v2/components/or-code-v3/styles.d.ts +2 -0
- package/dist/esm/v2/index.js +1 -0
- package/dist/esm/v3/OrCode-8ccd5dc7.js +301 -0
- package/dist/esm/v3/components/index.d.ts +1 -0
- package/dist/esm/v3/components/index.js +2 -1
- package/dist/esm/v3/components/or-code-v3/OrCode.vue.d.ts +119 -0
- package/dist/esm/v3/components/or-code-v3/index.d.ts +2 -0
- package/dist/esm/v3/components/or-code-v3/index.js +33 -0
- package/dist/esm/v3/components/or-code-v3/props.d.ts +8 -0
- package/dist/esm/v3/components/or-code-v3/styles.d.ts +2 -0
- package/dist/esm/v3/index.js +1 -0
- package/package.json +2 -3
- package/src/components/index.ts +1 -0
- package/src/components/or-code-v3/OrCode.vue +338 -0
- package/src/components/or-code-v3/index.ts +2 -0
- package/src/components/or-code-v3/props.ts +8 -0
- package/src/components/or-code-v3/styles.ts +12 -0
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { E as EditorView,
|
|
2
|
-
import {
|
|
1
|
+
import { E as EditorView, a as EditorState, k as keymap } from '../../index-6a13fa4e.js';
|
|
2
|
+
import { b as basicSetup, i as indentWithTab } from '../../index-576b3dec.js';
|
|
3
3
|
import { a as useElementHover } from '../../index-c92e2839.js';
|
|
4
4
|
import { defineComponent, ref } from 'vue-demi';
|
|
5
5
|
import __vue_component__$3 from '../OrTeleport/OrTeleport.js';
|
|
6
6
|
import { OrCodeLanguages } from './constants.js';
|
|
7
|
+
import languages from './lang.js';
|
|
7
8
|
import theme from './theme.js';
|
|
8
9
|
import __vue_component__$1 from '../OrIconButtonV2/OrIconButton.js';
|
|
9
10
|
import __vue_component__$2 from '../OrModal/OrModal.js';
|
|
@@ -12,6 +13,7 @@ import __vue_component__$5 from '../OrHint/OrHint.js';
|
|
|
12
13
|
import __vue_component__$6 from '../OrLabel/OrLabel.js';
|
|
13
14
|
import { s as styleInject } from '../../style-inject.es-4c6f2515.js';
|
|
14
15
|
import { n as normalizeComponent } from '../../normalize-component-6e8e3d80.js';
|
|
16
|
+
import '../../index-eba9b646.js';
|
|
15
17
|
import '../../index-ec92055d.js';
|
|
16
18
|
import 'vue';
|
|
17
19
|
import '../OrTeleport/constants.js';
|
|
@@ -36,3796 +38,6 @@ import '../OrLoader/constants.js';
|
|
|
36
38
|
import '../OrModal/constants.js';
|
|
37
39
|
import '../OrOverlay/OrOverlay.js';
|
|
38
40
|
|
|
39
|
-
/**
|
|
40
|
-
Comment or uncomment the current selection. Will use line comments
|
|
41
|
-
if available, otherwise falling back to block comments.
|
|
42
|
-
*/
|
|
43
|
-
const toggleComment = target => {
|
|
44
|
-
let {
|
|
45
|
-
state
|
|
46
|
-
} = target,
|
|
47
|
-
line = state.doc.lineAt(state.selection.main.from),
|
|
48
|
-
config = getConfig(target.state, line.from);
|
|
49
|
-
return config.line ? toggleLineComment(target) : config.block ? toggleBlockCommentByLine(target) : false;
|
|
50
|
-
};
|
|
51
|
-
function command(f, option) {
|
|
52
|
-
return _ref => {
|
|
53
|
-
let {
|
|
54
|
-
state,
|
|
55
|
-
dispatch
|
|
56
|
-
} = _ref;
|
|
57
|
-
if (state.readOnly) return false;
|
|
58
|
-
let tr = f(option, state);
|
|
59
|
-
if (!tr) return false;
|
|
60
|
-
dispatch(state.update(tr));
|
|
61
|
-
return true;
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
Comment or uncomment the current selection using line comments.
|
|
66
|
-
The line comment syntax is taken from the
|
|
67
|
-
[`commentTokens`](https://codemirror.net/6/docs/ref/#commands.CommentTokens) [language
|
|
68
|
-
data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt).
|
|
69
|
-
*/
|
|
70
|
-
const toggleLineComment = /*@__PURE__*/command(changeLineComment, 0 /* CommentOption.Toggle */);
|
|
71
|
-
/**
|
|
72
|
-
Comment or uncomment the current selection using block comments.
|
|
73
|
-
The block comment syntax is taken from the
|
|
74
|
-
[`commentTokens`](https://codemirror.net/6/docs/ref/#commands.CommentTokens) [language
|
|
75
|
-
data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt).
|
|
76
|
-
*/
|
|
77
|
-
const toggleBlockComment = /*@__PURE__*/command(changeBlockComment, 0 /* CommentOption.Toggle */);
|
|
78
|
-
/**
|
|
79
|
-
Comment or uncomment the lines around the current selection using
|
|
80
|
-
block comments.
|
|
81
|
-
*/
|
|
82
|
-
const toggleBlockCommentByLine = /*@__PURE__*/command((o, s) => changeBlockComment(o, s, selectedLineRanges(s)), 0 /* CommentOption.Toggle */);
|
|
83
|
-
function getConfig(state, pos) {
|
|
84
|
-
let data = state.languageDataAt("commentTokens", pos);
|
|
85
|
-
return data.length ? data[0] : {};
|
|
86
|
-
}
|
|
87
|
-
const SearchMargin = 50;
|
|
88
|
-
/**
|
|
89
|
-
Determines if the given range is block-commented in the given
|
|
90
|
-
state.
|
|
91
|
-
*/
|
|
92
|
-
function findBlockComment(state, _ref2, from, to) {
|
|
93
|
-
let {
|
|
94
|
-
open,
|
|
95
|
-
close
|
|
96
|
-
} = _ref2;
|
|
97
|
-
let textBefore = state.sliceDoc(from - SearchMargin, from);
|
|
98
|
-
let textAfter = state.sliceDoc(to, to + SearchMargin);
|
|
99
|
-
let spaceBefore = /\s*$/.exec(textBefore)[0].length,
|
|
100
|
-
spaceAfter = /^\s*/.exec(textAfter)[0].length;
|
|
101
|
-
let beforeOff = textBefore.length - spaceBefore;
|
|
102
|
-
if (textBefore.slice(beforeOff - open.length, beforeOff) == open && textAfter.slice(spaceAfter, spaceAfter + close.length) == close) {
|
|
103
|
-
return {
|
|
104
|
-
open: {
|
|
105
|
-
pos: from - spaceBefore,
|
|
106
|
-
margin: spaceBefore && 1
|
|
107
|
-
},
|
|
108
|
-
close: {
|
|
109
|
-
pos: to + spaceAfter,
|
|
110
|
-
margin: spaceAfter && 1
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
let startText, endText;
|
|
115
|
-
if (to - from <= 2 * SearchMargin) {
|
|
116
|
-
startText = endText = state.sliceDoc(from, to);
|
|
117
|
-
} else {
|
|
118
|
-
startText = state.sliceDoc(from, from + SearchMargin);
|
|
119
|
-
endText = state.sliceDoc(to - SearchMargin, to);
|
|
120
|
-
}
|
|
121
|
-
let startSpace = /^\s*/.exec(startText)[0].length,
|
|
122
|
-
endSpace = /\s*$/.exec(endText)[0].length;
|
|
123
|
-
let endOff = endText.length - endSpace - close.length;
|
|
124
|
-
if (startText.slice(startSpace, startSpace + open.length) == open && endText.slice(endOff, endOff + close.length) == close) {
|
|
125
|
-
return {
|
|
126
|
-
open: {
|
|
127
|
-
pos: from + startSpace + open.length,
|
|
128
|
-
margin: /\s/.test(startText.charAt(startSpace + open.length)) ? 1 : 0
|
|
129
|
-
},
|
|
130
|
-
close: {
|
|
131
|
-
pos: to - endSpace - close.length,
|
|
132
|
-
margin: /\s/.test(endText.charAt(endOff - 1)) ? 1 : 0
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
return null;
|
|
137
|
-
}
|
|
138
|
-
function selectedLineRanges(state) {
|
|
139
|
-
let ranges = [];
|
|
140
|
-
for (let r of state.selection.ranges) {
|
|
141
|
-
let fromLine = state.doc.lineAt(r.from);
|
|
142
|
-
let toLine = r.to <= fromLine.to ? fromLine : state.doc.lineAt(r.to);
|
|
143
|
-
let last = ranges.length - 1;
|
|
144
|
-
if (last >= 0 && ranges[last].to > fromLine.from) ranges[last].to = toLine.to;else ranges.push({
|
|
145
|
-
from: fromLine.from,
|
|
146
|
-
to: toLine.to
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
return ranges;
|
|
150
|
-
}
|
|
151
|
-
// Performs toggle, comment and uncomment of block comments in
|
|
152
|
-
// languages that support them.
|
|
153
|
-
function changeBlockComment(option, state) {
|
|
154
|
-
let ranges = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : state.selection.ranges;
|
|
155
|
-
let tokens = ranges.map(r => getConfig(state, r.from).block);
|
|
156
|
-
if (!tokens.every(c => c)) return null;
|
|
157
|
-
let comments = ranges.map((r, i) => findBlockComment(state, tokens[i], r.from, r.to));
|
|
158
|
-
if (option != 2 /* CommentOption.Uncomment */ && !comments.every(c => c)) {
|
|
159
|
-
return {
|
|
160
|
-
changes: state.changes(ranges.map((range, i) => {
|
|
161
|
-
if (comments[i]) return [];
|
|
162
|
-
return [{
|
|
163
|
-
from: range.from,
|
|
164
|
-
insert: tokens[i].open + " "
|
|
165
|
-
}, {
|
|
166
|
-
from: range.to,
|
|
167
|
-
insert: " " + tokens[i].close
|
|
168
|
-
}];
|
|
169
|
-
}))
|
|
170
|
-
};
|
|
171
|
-
} else if (option != 1 /* CommentOption.Comment */ && comments.some(c => c)) {
|
|
172
|
-
let changes = [];
|
|
173
|
-
for (let i = 0, comment; i < comments.length; i++) if (comment = comments[i]) {
|
|
174
|
-
let token = tokens[i],
|
|
175
|
-
{
|
|
176
|
-
open,
|
|
177
|
-
close
|
|
178
|
-
} = comment;
|
|
179
|
-
changes.push({
|
|
180
|
-
from: open.pos - token.open.length,
|
|
181
|
-
to: open.pos + open.margin
|
|
182
|
-
}, {
|
|
183
|
-
from: close.pos - close.margin,
|
|
184
|
-
to: close.pos + token.close.length
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
return {
|
|
188
|
-
changes
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
return null;
|
|
192
|
-
}
|
|
193
|
-
// Performs toggle, comment and uncomment of line comments.
|
|
194
|
-
function changeLineComment(option, state) {
|
|
195
|
-
let ranges = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : state.selection.ranges;
|
|
196
|
-
let lines = [];
|
|
197
|
-
let prevLine = -1;
|
|
198
|
-
for (let {
|
|
199
|
-
from,
|
|
200
|
-
to
|
|
201
|
-
} of ranges) {
|
|
202
|
-
let startI = lines.length,
|
|
203
|
-
minIndent = 1e9;
|
|
204
|
-
let token = getConfig(state, from).line;
|
|
205
|
-
if (!token) continue;
|
|
206
|
-
for (let pos = from; pos <= to;) {
|
|
207
|
-
let line = state.doc.lineAt(pos);
|
|
208
|
-
if (line.from > prevLine && (from == to || to > line.from)) {
|
|
209
|
-
prevLine = line.from;
|
|
210
|
-
let indent = /^\s*/.exec(line.text)[0].length;
|
|
211
|
-
let empty = indent == line.length;
|
|
212
|
-
let comment = line.text.slice(indent, indent + token.length) == token ? indent : -1;
|
|
213
|
-
if (indent < line.text.length && indent < minIndent) minIndent = indent;
|
|
214
|
-
lines.push({
|
|
215
|
-
line,
|
|
216
|
-
comment,
|
|
217
|
-
token,
|
|
218
|
-
indent,
|
|
219
|
-
empty,
|
|
220
|
-
single: false
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
pos = line.to + 1;
|
|
224
|
-
}
|
|
225
|
-
if (minIndent < 1e9) for (let i = startI; i < lines.length; i++) if (lines[i].indent < lines[i].line.text.length) lines[i].indent = minIndent;
|
|
226
|
-
if (lines.length == startI + 1) lines[startI].single = true;
|
|
227
|
-
}
|
|
228
|
-
if (option != 2 /* CommentOption.Uncomment */ && lines.some(l => l.comment < 0 && (!l.empty || l.single))) {
|
|
229
|
-
let changes = [];
|
|
230
|
-
for (let {
|
|
231
|
-
line,
|
|
232
|
-
token,
|
|
233
|
-
indent,
|
|
234
|
-
empty,
|
|
235
|
-
single
|
|
236
|
-
} of lines) if (single || !empty) changes.push({
|
|
237
|
-
from: line.from + indent,
|
|
238
|
-
insert: token + " "
|
|
239
|
-
});
|
|
240
|
-
let changeSet = state.changes(changes);
|
|
241
|
-
return {
|
|
242
|
-
changes: changeSet,
|
|
243
|
-
selection: state.selection.map(changeSet, 1)
|
|
244
|
-
};
|
|
245
|
-
} else if (option != 1 /* CommentOption.Comment */ && lines.some(l => l.comment >= 0)) {
|
|
246
|
-
let changes = [];
|
|
247
|
-
for (let {
|
|
248
|
-
line,
|
|
249
|
-
comment,
|
|
250
|
-
token
|
|
251
|
-
} of lines) if (comment >= 0) {
|
|
252
|
-
let from = line.from + comment,
|
|
253
|
-
to = from + token.length;
|
|
254
|
-
if (line.text[to - line.from] == " ") to++;
|
|
255
|
-
changes.push({
|
|
256
|
-
from,
|
|
257
|
-
to
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
return {
|
|
261
|
-
changes
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
return null;
|
|
265
|
-
}
|
|
266
|
-
const fromHistory = /*@__PURE__*/Annotation.define();
|
|
267
|
-
/**
|
|
268
|
-
Transaction annotation that will prevent that transaction from
|
|
269
|
-
being combined with other transactions in the undo history. Given
|
|
270
|
-
`"before"`, it'll prevent merging with previous transactions. With
|
|
271
|
-
`"after"`, subsequent transactions won't be combined with this
|
|
272
|
-
one. With `"full"`, the transaction is isolated on both sides.
|
|
273
|
-
*/
|
|
274
|
-
const isolateHistory = /*@__PURE__*/Annotation.define();
|
|
275
|
-
/**
|
|
276
|
-
This facet provides a way to register functions that, given a
|
|
277
|
-
transaction, provide a set of effects that the history should
|
|
278
|
-
store when inverting the transaction. This can be used to
|
|
279
|
-
integrate some kinds of effects in the history, so that they can
|
|
280
|
-
be undone (and redone again).
|
|
281
|
-
*/
|
|
282
|
-
const invertedEffects = /*@__PURE__*/Facet.define();
|
|
283
|
-
const historyConfig = /*@__PURE__*/Facet.define({
|
|
284
|
-
combine(configs) {
|
|
285
|
-
return combineConfig(configs, {
|
|
286
|
-
minDepth: 100,
|
|
287
|
-
newGroupDelay: 500,
|
|
288
|
-
joinToEvent: (_t, isAdjacent) => isAdjacent
|
|
289
|
-
}, {
|
|
290
|
-
minDepth: Math.max,
|
|
291
|
-
newGroupDelay: Math.min,
|
|
292
|
-
joinToEvent: (a, b) => (tr, adj) => a(tr, adj) || b(tr, adj)
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
});
|
|
296
|
-
function changeEnd(changes) {
|
|
297
|
-
let end = 0;
|
|
298
|
-
changes.iterChangedRanges((_, to) => end = to);
|
|
299
|
-
return end;
|
|
300
|
-
}
|
|
301
|
-
const historyField_ = /*@__PURE__*/StateField.define({
|
|
302
|
-
create() {
|
|
303
|
-
return HistoryState.empty;
|
|
304
|
-
},
|
|
305
|
-
update(state, tr) {
|
|
306
|
-
let config = tr.state.facet(historyConfig);
|
|
307
|
-
let fromHist = tr.annotation(fromHistory);
|
|
308
|
-
if (fromHist) {
|
|
309
|
-
let selection = tr.docChanged ? EditorSelection.single(changeEnd(tr.changes)) : undefined;
|
|
310
|
-
let item = HistEvent.fromTransaction(tr, selection),
|
|
311
|
-
from = fromHist.side;
|
|
312
|
-
let other = from == 0 /* BranchName.Done */ ? state.undone : state.done;
|
|
313
|
-
if (item) other = updateBranch(other, other.length, config.minDepth, item);else other = addSelection(other, tr.startState.selection);
|
|
314
|
-
return new HistoryState(from == 0 /* BranchName.Done */ ? fromHist.rest : other, from == 0 /* BranchName.Done */ ? other : fromHist.rest);
|
|
315
|
-
}
|
|
316
|
-
let isolate = tr.annotation(isolateHistory);
|
|
317
|
-
if (isolate == "full" || isolate == "before") state = state.isolate();
|
|
318
|
-
if (tr.annotation(Transaction.addToHistory) === false) return !tr.changes.empty ? state.addMapping(tr.changes.desc) : state;
|
|
319
|
-
let event = HistEvent.fromTransaction(tr);
|
|
320
|
-
let time = tr.annotation(Transaction.time),
|
|
321
|
-
userEvent = tr.annotation(Transaction.userEvent);
|
|
322
|
-
if (event) state = state.addChanges(event, time, userEvent, config, tr);else if (tr.selection) state = state.addSelection(tr.startState.selection, time, userEvent, config.newGroupDelay);
|
|
323
|
-
if (isolate == "full" || isolate == "after") state = state.isolate();
|
|
324
|
-
return state;
|
|
325
|
-
},
|
|
326
|
-
toJSON(value) {
|
|
327
|
-
return {
|
|
328
|
-
done: value.done.map(e => e.toJSON()),
|
|
329
|
-
undone: value.undone.map(e => e.toJSON())
|
|
330
|
-
};
|
|
331
|
-
},
|
|
332
|
-
fromJSON(json) {
|
|
333
|
-
return new HistoryState(json.done.map(HistEvent.fromJSON), json.undone.map(HistEvent.fromJSON));
|
|
334
|
-
}
|
|
335
|
-
});
|
|
336
|
-
/**
|
|
337
|
-
Create a history extension with the given configuration.
|
|
338
|
-
*/
|
|
339
|
-
function history() {
|
|
340
|
-
let config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
341
|
-
return [historyField_, historyConfig.of(config), EditorView.domEventHandlers({
|
|
342
|
-
beforeinput(e, view) {
|
|
343
|
-
let command = e.inputType == "historyUndo" ? undo : e.inputType == "historyRedo" ? redo : null;
|
|
344
|
-
if (!command) return false;
|
|
345
|
-
e.preventDefault();
|
|
346
|
-
return command(view);
|
|
347
|
-
}
|
|
348
|
-
})];
|
|
349
|
-
}
|
|
350
|
-
function cmd(side, selection) {
|
|
351
|
-
return function (_ref3) {
|
|
352
|
-
let {
|
|
353
|
-
state,
|
|
354
|
-
dispatch
|
|
355
|
-
} = _ref3;
|
|
356
|
-
if (!selection && state.readOnly) return false;
|
|
357
|
-
let historyState = state.field(historyField_, false);
|
|
358
|
-
if (!historyState) return false;
|
|
359
|
-
let tr = historyState.pop(side, state, selection);
|
|
360
|
-
if (!tr) return false;
|
|
361
|
-
dispatch(tr);
|
|
362
|
-
return true;
|
|
363
|
-
};
|
|
364
|
-
}
|
|
365
|
-
/**
|
|
366
|
-
Undo a single group of history events. Returns false if no group
|
|
367
|
-
was available.
|
|
368
|
-
*/
|
|
369
|
-
const undo = /*@__PURE__*/cmd(0 /* BranchName.Done */, false);
|
|
370
|
-
/**
|
|
371
|
-
Redo a group of history events. Returns false if no group was
|
|
372
|
-
available.
|
|
373
|
-
*/
|
|
374
|
-
const redo = /*@__PURE__*/cmd(1 /* BranchName.Undone */, false);
|
|
375
|
-
/**
|
|
376
|
-
Undo a change or selection change.
|
|
377
|
-
*/
|
|
378
|
-
const undoSelection = /*@__PURE__*/cmd(0 /* BranchName.Done */, true);
|
|
379
|
-
/**
|
|
380
|
-
Redo a change or selection change.
|
|
381
|
-
*/
|
|
382
|
-
const redoSelection = /*@__PURE__*/cmd(1 /* BranchName.Undone */, true);
|
|
383
|
-
// History events store groups of changes or effects that need to be
|
|
384
|
-
// undone/redone together.
|
|
385
|
-
class HistEvent {
|
|
386
|
-
constructor(
|
|
387
|
-
// The changes in this event. Normal events hold at least one
|
|
388
|
-
// change or effect. But it may be necessary to store selection
|
|
389
|
-
// events before the first change, in which case a special type of
|
|
390
|
-
// instance is created which doesn't hold any changes, with
|
|
391
|
-
// changes == startSelection == undefined
|
|
392
|
-
changes,
|
|
393
|
-
// The effects associated with this event
|
|
394
|
-
effects,
|
|
395
|
-
// Accumulated mapping (from addToHistory==false) that should be
|
|
396
|
-
// applied to events below this one.
|
|
397
|
-
mapped,
|
|
398
|
-
// The selection before this event
|
|
399
|
-
startSelection,
|
|
400
|
-
// Stores selection changes after this event, to be used for
|
|
401
|
-
// selection undo/redo.
|
|
402
|
-
selectionsAfter) {
|
|
403
|
-
this.changes = changes;
|
|
404
|
-
this.effects = effects;
|
|
405
|
-
this.mapped = mapped;
|
|
406
|
-
this.startSelection = startSelection;
|
|
407
|
-
this.selectionsAfter = selectionsAfter;
|
|
408
|
-
}
|
|
409
|
-
setSelAfter(after) {
|
|
410
|
-
return new HistEvent(this.changes, this.effects, this.mapped, this.startSelection, after);
|
|
411
|
-
}
|
|
412
|
-
toJSON() {
|
|
413
|
-
var _a, _b, _c;
|
|
414
|
-
return {
|
|
415
|
-
changes: (_a = this.changes) === null || _a === void 0 ? void 0 : _a.toJSON(),
|
|
416
|
-
mapped: (_b = this.mapped) === null || _b === void 0 ? void 0 : _b.toJSON(),
|
|
417
|
-
startSelection: (_c = this.startSelection) === null || _c === void 0 ? void 0 : _c.toJSON(),
|
|
418
|
-
selectionsAfter: this.selectionsAfter.map(s => s.toJSON())
|
|
419
|
-
};
|
|
420
|
-
}
|
|
421
|
-
static fromJSON(json) {
|
|
422
|
-
return new HistEvent(json.changes && ChangeSet.fromJSON(json.changes), [], json.mapped && ChangeDesc.fromJSON(json.mapped), json.startSelection && EditorSelection.fromJSON(json.startSelection), json.selectionsAfter.map(EditorSelection.fromJSON));
|
|
423
|
-
}
|
|
424
|
-
// This does not check `addToHistory` and such, it assumes the
|
|
425
|
-
// transaction needs to be converted to an item. Returns null when
|
|
426
|
-
// there are no changes or effects in the transaction.
|
|
427
|
-
static fromTransaction(tr, selection) {
|
|
428
|
-
let effects = none;
|
|
429
|
-
for (let invert of tr.startState.facet(invertedEffects)) {
|
|
430
|
-
let result = invert(tr);
|
|
431
|
-
if (result.length) effects = effects.concat(result);
|
|
432
|
-
}
|
|
433
|
-
if (!effects.length && tr.changes.empty) return null;
|
|
434
|
-
return new HistEvent(tr.changes.invert(tr.startState.doc), effects, undefined, selection || tr.startState.selection, none);
|
|
435
|
-
}
|
|
436
|
-
static selection(selections) {
|
|
437
|
-
return new HistEvent(undefined, none, undefined, undefined, selections);
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
function updateBranch(branch, to, maxLen, newEvent) {
|
|
441
|
-
let start = to + 1 > maxLen + 20 ? to - maxLen - 1 : 0;
|
|
442
|
-
let newBranch = branch.slice(start, to);
|
|
443
|
-
newBranch.push(newEvent);
|
|
444
|
-
return newBranch;
|
|
445
|
-
}
|
|
446
|
-
function isAdjacent(a, b) {
|
|
447
|
-
let ranges = [],
|
|
448
|
-
isAdjacent = false;
|
|
449
|
-
a.iterChangedRanges((f, t) => ranges.push(f, t));
|
|
450
|
-
b.iterChangedRanges((_f, _t, f, t) => {
|
|
451
|
-
for (let i = 0; i < ranges.length;) {
|
|
452
|
-
let from = ranges[i++],
|
|
453
|
-
to = ranges[i++];
|
|
454
|
-
if (t >= from && f <= to) isAdjacent = true;
|
|
455
|
-
}
|
|
456
|
-
});
|
|
457
|
-
return isAdjacent;
|
|
458
|
-
}
|
|
459
|
-
function eqSelectionShape(a, b) {
|
|
460
|
-
return a.ranges.length == b.ranges.length && a.ranges.filter((r, i) => r.empty != b.ranges[i].empty).length === 0;
|
|
461
|
-
}
|
|
462
|
-
function conc(a, b) {
|
|
463
|
-
return !a.length ? b : !b.length ? a : a.concat(b);
|
|
464
|
-
}
|
|
465
|
-
const none = [];
|
|
466
|
-
const MaxSelectionsPerEvent = 200;
|
|
467
|
-
function addSelection(branch, selection) {
|
|
468
|
-
if (!branch.length) {
|
|
469
|
-
return [HistEvent.selection([selection])];
|
|
470
|
-
} else {
|
|
471
|
-
let lastEvent = branch[branch.length - 1];
|
|
472
|
-
let sels = lastEvent.selectionsAfter.slice(Math.max(0, lastEvent.selectionsAfter.length - MaxSelectionsPerEvent));
|
|
473
|
-
if (sels.length && sels[sels.length - 1].eq(selection)) return branch;
|
|
474
|
-
sels.push(selection);
|
|
475
|
-
return updateBranch(branch, branch.length - 1, 1e9, lastEvent.setSelAfter(sels));
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
// Assumes the top item has one or more selectionAfter values
|
|
479
|
-
function popSelection(branch) {
|
|
480
|
-
let last = branch[branch.length - 1];
|
|
481
|
-
let newBranch = branch.slice();
|
|
482
|
-
newBranch[branch.length - 1] = last.setSelAfter(last.selectionsAfter.slice(0, last.selectionsAfter.length - 1));
|
|
483
|
-
return newBranch;
|
|
484
|
-
}
|
|
485
|
-
// Add a mapping to the top event in the given branch. If this maps
|
|
486
|
-
// away all the changes and effects in that item, drop it and
|
|
487
|
-
// propagate the mapping to the next item.
|
|
488
|
-
function addMappingToBranch(branch, mapping) {
|
|
489
|
-
if (!branch.length) return branch;
|
|
490
|
-
let length = branch.length,
|
|
491
|
-
selections = none;
|
|
492
|
-
while (length) {
|
|
493
|
-
let event = mapEvent(branch[length - 1], mapping, selections);
|
|
494
|
-
if (event.changes && !event.changes.empty || event.effects.length) {
|
|
495
|
-
// Event survived mapping
|
|
496
|
-
let result = branch.slice(0, length);
|
|
497
|
-
result[length - 1] = event;
|
|
498
|
-
return result;
|
|
499
|
-
} else {
|
|
500
|
-
// Drop this event, since there's no changes or effects left
|
|
501
|
-
mapping = event.mapped;
|
|
502
|
-
length--;
|
|
503
|
-
selections = event.selectionsAfter;
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
return selections.length ? [HistEvent.selection(selections)] : none;
|
|
507
|
-
}
|
|
508
|
-
function mapEvent(event, mapping, extraSelections) {
|
|
509
|
-
let selections = conc(event.selectionsAfter.length ? event.selectionsAfter.map(s => s.map(mapping)) : none, extraSelections);
|
|
510
|
-
// Change-less events don't store mappings (they are always the last event in a branch)
|
|
511
|
-
if (!event.changes) return HistEvent.selection(selections);
|
|
512
|
-
let mappedChanges = event.changes.map(mapping),
|
|
513
|
-
before = mapping.mapDesc(event.changes, true);
|
|
514
|
-
let fullMapping = event.mapped ? event.mapped.composeDesc(before) : before;
|
|
515
|
-
return new HistEvent(mappedChanges, StateEffect.mapEffects(event.effects, mapping), fullMapping, event.startSelection.map(before), selections);
|
|
516
|
-
}
|
|
517
|
-
const joinableUserEvent = /^(input\.type|delete)($|\.)/;
|
|
518
|
-
class HistoryState {
|
|
519
|
-
constructor(done, undone) {
|
|
520
|
-
let prevTime = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
521
|
-
let prevUserEvent = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : undefined;
|
|
522
|
-
this.done = done;
|
|
523
|
-
this.undone = undone;
|
|
524
|
-
this.prevTime = prevTime;
|
|
525
|
-
this.prevUserEvent = prevUserEvent;
|
|
526
|
-
}
|
|
527
|
-
isolate() {
|
|
528
|
-
return this.prevTime ? new HistoryState(this.done, this.undone) : this;
|
|
529
|
-
}
|
|
530
|
-
addChanges(event, time, userEvent, config, tr) {
|
|
531
|
-
let done = this.done,
|
|
532
|
-
lastEvent = done[done.length - 1];
|
|
533
|
-
if (lastEvent && lastEvent.changes && !lastEvent.changes.empty && event.changes && (!userEvent || joinableUserEvent.test(userEvent)) && (!lastEvent.selectionsAfter.length && time - this.prevTime < config.newGroupDelay && config.joinToEvent(tr, isAdjacent(lastEvent.changes, event.changes)) ||
|
|
534
|
-
// For compose (but not compose.start) events, always join with previous event
|
|
535
|
-
userEvent == "input.type.compose")) {
|
|
536
|
-
done = updateBranch(done, done.length - 1, config.minDepth, new HistEvent(event.changes.compose(lastEvent.changes), conc(event.effects, lastEvent.effects), lastEvent.mapped, lastEvent.startSelection, none));
|
|
537
|
-
} else {
|
|
538
|
-
done = updateBranch(done, done.length, config.minDepth, event);
|
|
539
|
-
}
|
|
540
|
-
return new HistoryState(done, none, time, userEvent);
|
|
541
|
-
}
|
|
542
|
-
addSelection(selection, time, userEvent, newGroupDelay) {
|
|
543
|
-
let last = this.done.length ? this.done[this.done.length - 1].selectionsAfter : none;
|
|
544
|
-
if (last.length > 0 && time - this.prevTime < newGroupDelay && userEvent == this.prevUserEvent && userEvent && /^select($|\.)/.test(userEvent) && eqSelectionShape(last[last.length - 1], selection)) return this;
|
|
545
|
-
return new HistoryState(addSelection(this.done, selection), this.undone, time, userEvent);
|
|
546
|
-
}
|
|
547
|
-
addMapping(mapping) {
|
|
548
|
-
return new HistoryState(addMappingToBranch(this.done, mapping), addMappingToBranch(this.undone, mapping), this.prevTime, this.prevUserEvent);
|
|
549
|
-
}
|
|
550
|
-
pop(side, state, selection) {
|
|
551
|
-
let branch = side == 0 /* BranchName.Done */ ? this.done : this.undone;
|
|
552
|
-
if (branch.length == 0) return null;
|
|
553
|
-
let event = branch[branch.length - 1];
|
|
554
|
-
if (selection && event.selectionsAfter.length) {
|
|
555
|
-
return state.update({
|
|
556
|
-
selection: event.selectionsAfter[event.selectionsAfter.length - 1],
|
|
557
|
-
annotations: fromHistory.of({
|
|
558
|
-
side,
|
|
559
|
-
rest: popSelection(branch)
|
|
560
|
-
}),
|
|
561
|
-
userEvent: side == 0 /* BranchName.Done */ ? "select.undo" : "select.redo",
|
|
562
|
-
scrollIntoView: true
|
|
563
|
-
});
|
|
564
|
-
} else if (!event.changes) {
|
|
565
|
-
return null;
|
|
566
|
-
} else {
|
|
567
|
-
let rest = branch.length == 1 ? none : branch.slice(0, branch.length - 1);
|
|
568
|
-
if (event.mapped) rest = addMappingToBranch(rest, event.mapped);
|
|
569
|
-
return state.update({
|
|
570
|
-
changes: event.changes,
|
|
571
|
-
selection: event.startSelection,
|
|
572
|
-
effects: event.effects,
|
|
573
|
-
annotations: fromHistory.of({
|
|
574
|
-
side,
|
|
575
|
-
rest
|
|
576
|
-
}),
|
|
577
|
-
filter: false,
|
|
578
|
-
userEvent: side == 0 /* BranchName.Done */ ? "undo" : "redo",
|
|
579
|
-
scrollIntoView: true
|
|
580
|
-
});
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
HistoryState.empty = /*@__PURE__*/new HistoryState(none, none);
|
|
585
|
-
/**
|
|
586
|
-
Default key bindings for the undo history.
|
|
587
|
-
|
|
588
|
-
- Mod-z: [`undo`](https://codemirror.net/6/docs/ref/#commands.undo).
|
|
589
|
-
- Mod-y (Mod-Shift-z on macOS) + Ctrl-Shift-z on Linux: [`redo`](https://codemirror.net/6/docs/ref/#commands.redo).
|
|
590
|
-
- Mod-u: [`undoSelection`](https://codemirror.net/6/docs/ref/#commands.undoSelection).
|
|
591
|
-
- Alt-u (Mod-Shift-u on macOS): [`redoSelection`](https://codemirror.net/6/docs/ref/#commands.redoSelection).
|
|
592
|
-
*/
|
|
593
|
-
const historyKeymap = [{
|
|
594
|
-
key: "Mod-z",
|
|
595
|
-
run: undo,
|
|
596
|
-
preventDefault: true
|
|
597
|
-
}, {
|
|
598
|
-
key: "Mod-y",
|
|
599
|
-
mac: "Mod-Shift-z",
|
|
600
|
-
run: redo,
|
|
601
|
-
preventDefault: true
|
|
602
|
-
}, {
|
|
603
|
-
linux: "Ctrl-Shift-z",
|
|
604
|
-
run: redo,
|
|
605
|
-
preventDefault: true
|
|
606
|
-
}, {
|
|
607
|
-
key: "Mod-u",
|
|
608
|
-
run: undoSelection,
|
|
609
|
-
preventDefault: true
|
|
610
|
-
}, {
|
|
611
|
-
key: "Alt-u",
|
|
612
|
-
mac: "Mod-Shift-u",
|
|
613
|
-
run: redoSelection,
|
|
614
|
-
preventDefault: true
|
|
615
|
-
}];
|
|
616
|
-
function updateSel(sel, by) {
|
|
617
|
-
return EditorSelection.create(sel.ranges.map(by), sel.mainIndex);
|
|
618
|
-
}
|
|
619
|
-
function setSel(state, selection) {
|
|
620
|
-
return state.update({
|
|
621
|
-
selection,
|
|
622
|
-
scrollIntoView: true,
|
|
623
|
-
userEvent: "select"
|
|
624
|
-
});
|
|
625
|
-
}
|
|
626
|
-
function moveSel(_ref4, how) {
|
|
627
|
-
let {
|
|
628
|
-
state,
|
|
629
|
-
dispatch
|
|
630
|
-
} = _ref4;
|
|
631
|
-
let selection = updateSel(state.selection, how);
|
|
632
|
-
if (selection.eq(state.selection)) return false;
|
|
633
|
-
dispatch(setSel(state, selection));
|
|
634
|
-
return true;
|
|
635
|
-
}
|
|
636
|
-
function rangeEnd(range, forward) {
|
|
637
|
-
return EditorSelection.cursor(forward ? range.to : range.from);
|
|
638
|
-
}
|
|
639
|
-
function cursorByChar(view, forward) {
|
|
640
|
-
return moveSel(view, range => range.empty ? view.moveByChar(range, forward) : rangeEnd(range, forward));
|
|
641
|
-
}
|
|
642
|
-
function ltrAtCursor(view) {
|
|
643
|
-
return view.textDirectionAt(view.state.selection.main.head) == Direction.LTR;
|
|
644
|
-
}
|
|
645
|
-
/**
|
|
646
|
-
Move the selection one character to the left (which is backward in
|
|
647
|
-
left-to-right text, forward in right-to-left text).
|
|
648
|
-
*/
|
|
649
|
-
const cursorCharLeft = view => cursorByChar(view, !ltrAtCursor(view));
|
|
650
|
-
/**
|
|
651
|
-
Move the selection one character to the right.
|
|
652
|
-
*/
|
|
653
|
-
const cursorCharRight = view => cursorByChar(view, ltrAtCursor(view));
|
|
654
|
-
function cursorByGroup(view, forward) {
|
|
655
|
-
return moveSel(view, range => range.empty ? view.moveByGroup(range, forward) : rangeEnd(range, forward));
|
|
656
|
-
}
|
|
657
|
-
/**
|
|
658
|
-
Move the selection to the left across one group of word or
|
|
659
|
-
non-word (but also non-space) characters.
|
|
660
|
-
*/
|
|
661
|
-
const cursorGroupLeft = view => cursorByGroup(view, !ltrAtCursor(view));
|
|
662
|
-
/**
|
|
663
|
-
Move the selection one group to the right.
|
|
664
|
-
*/
|
|
665
|
-
const cursorGroupRight = view => cursorByGroup(view, ltrAtCursor(view));
|
|
666
|
-
function interestingNode(state, node, bracketProp) {
|
|
667
|
-
if (node.type.prop(bracketProp)) return true;
|
|
668
|
-
let len = node.to - node.from;
|
|
669
|
-
return len && (len > 2 || /[^\s,.;:]/.test(state.sliceDoc(node.from, node.to))) || node.firstChild;
|
|
670
|
-
}
|
|
671
|
-
function moveBySyntax(state, start, forward) {
|
|
672
|
-
let pos = syntaxTree(state).resolveInner(start.head);
|
|
673
|
-
let bracketProp = forward ? NodeProp.closedBy : NodeProp.openedBy;
|
|
674
|
-
// Scan forward through child nodes to see if there's an interesting
|
|
675
|
-
// node ahead.
|
|
676
|
-
for (let at = start.head;;) {
|
|
677
|
-
let next = forward ? pos.childAfter(at) : pos.childBefore(at);
|
|
678
|
-
if (!next) break;
|
|
679
|
-
if (interestingNode(state, next, bracketProp)) pos = next;else at = forward ? next.to : next.from;
|
|
680
|
-
}
|
|
681
|
-
let bracket = pos.type.prop(bracketProp),
|
|
682
|
-
match,
|
|
683
|
-
newPos;
|
|
684
|
-
if (bracket && (match = forward ? matchBrackets(state, pos.from, 1) : matchBrackets(state, pos.to, -1)) && match.matched) newPos = forward ? match.end.to : match.end.from;else newPos = forward ? pos.to : pos.from;
|
|
685
|
-
return EditorSelection.cursor(newPos, forward ? -1 : 1);
|
|
686
|
-
}
|
|
687
|
-
/**
|
|
688
|
-
Move the cursor over the next syntactic element to the left.
|
|
689
|
-
*/
|
|
690
|
-
const cursorSyntaxLeft = view => moveSel(view, range => moveBySyntax(view.state, range, !ltrAtCursor(view)));
|
|
691
|
-
/**
|
|
692
|
-
Move the cursor over the next syntactic element to the right.
|
|
693
|
-
*/
|
|
694
|
-
const cursorSyntaxRight = view => moveSel(view, range => moveBySyntax(view.state, range, ltrAtCursor(view)));
|
|
695
|
-
function cursorByLine(view, forward) {
|
|
696
|
-
return moveSel(view, range => {
|
|
697
|
-
if (!range.empty) return rangeEnd(range, forward);
|
|
698
|
-
let moved = view.moveVertically(range, forward);
|
|
699
|
-
return moved.head != range.head ? moved : view.moveToLineBoundary(range, forward);
|
|
700
|
-
});
|
|
701
|
-
}
|
|
702
|
-
/**
|
|
703
|
-
Move the selection one line up.
|
|
704
|
-
*/
|
|
705
|
-
const cursorLineUp = view => cursorByLine(view, false);
|
|
706
|
-
/**
|
|
707
|
-
Move the selection one line down.
|
|
708
|
-
*/
|
|
709
|
-
const cursorLineDown = view => cursorByLine(view, true);
|
|
710
|
-
function pageInfo(view) {
|
|
711
|
-
let selfScroll = view.scrollDOM.clientHeight < view.scrollDOM.scrollHeight - 2;
|
|
712
|
-
let marginTop = 0,
|
|
713
|
-
marginBottom = 0,
|
|
714
|
-
height;
|
|
715
|
-
if (selfScroll) {
|
|
716
|
-
for (let source of view.state.facet(EditorView.scrollMargins)) {
|
|
717
|
-
let margins = source(view);
|
|
718
|
-
if (margins === null || margins === void 0 ? void 0 : margins.top) marginTop = Math.max(margins === null || margins === void 0 ? void 0 : margins.top, marginTop);
|
|
719
|
-
if (margins === null || margins === void 0 ? void 0 : margins.bottom) marginBottom = Math.max(margins === null || margins === void 0 ? void 0 : margins.bottom, marginBottom);
|
|
720
|
-
}
|
|
721
|
-
height = view.scrollDOM.clientHeight - marginTop - marginBottom;
|
|
722
|
-
} else {
|
|
723
|
-
height = (view.dom.ownerDocument.defaultView || window).innerHeight;
|
|
724
|
-
}
|
|
725
|
-
return {
|
|
726
|
-
marginTop,
|
|
727
|
-
marginBottom,
|
|
728
|
-
selfScroll,
|
|
729
|
-
height: Math.max(view.defaultLineHeight, height - 5)
|
|
730
|
-
};
|
|
731
|
-
}
|
|
732
|
-
function cursorByPage(view, forward) {
|
|
733
|
-
let page = pageInfo(view);
|
|
734
|
-
let {
|
|
735
|
-
state
|
|
736
|
-
} = view,
|
|
737
|
-
selection = updateSel(state.selection, range => {
|
|
738
|
-
return range.empty ? view.moveVertically(range, forward, page.height) : rangeEnd(range, forward);
|
|
739
|
-
});
|
|
740
|
-
if (selection.eq(state.selection)) return false;
|
|
741
|
-
let effect;
|
|
742
|
-
if (page.selfScroll) {
|
|
743
|
-
let startPos = view.coordsAtPos(state.selection.main.head);
|
|
744
|
-
let scrollRect = view.scrollDOM.getBoundingClientRect();
|
|
745
|
-
let scrollTop = scrollRect.top + page.marginTop,
|
|
746
|
-
scrollBottom = scrollRect.bottom - page.marginBottom;
|
|
747
|
-
if (startPos && startPos.top > scrollTop && startPos.bottom < scrollBottom) effect = EditorView.scrollIntoView(selection.main.head, {
|
|
748
|
-
y: "start",
|
|
749
|
-
yMargin: startPos.top - scrollTop
|
|
750
|
-
});
|
|
751
|
-
}
|
|
752
|
-
view.dispatch(setSel(state, selection), {
|
|
753
|
-
effects: effect
|
|
754
|
-
});
|
|
755
|
-
return true;
|
|
756
|
-
}
|
|
757
|
-
/**
|
|
758
|
-
Move the selection one page up.
|
|
759
|
-
*/
|
|
760
|
-
const cursorPageUp = view => cursorByPage(view, false);
|
|
761
|
-
/**
|
|
762
|
-
Move the selection one page down.
|
|
763
|
-
*/
|
|
764
|
-
const cursorPageDown = view => cursorByPage(view, true);
|
|
765
|
-
function moveByLineBoundary(view, start, forward) {
|
|
766
|
-
let line = view.lineBlockAt(start.head),
|
|
767
|
-
moved = view.moveToLineBoundary(start, forward);
|
|
768
|
-
if (moved.head == start.head && moved.head != (forward ? line.to : line.from)) moved = view.moveToLineBoundary(start, forward, false);
|
|
769
|
-
if (!forward && moved.head == line.from && line.length) {
|
|
770
|
-
let space = /^\s*/.exec(view.state.sliceDoc(line.from, Math.min(line.from + 100, line.to)))[0].length;
|
|
771
|
-
if (space && start.head != line.from + space) moved = EditorSelection.cursor(line.from + space);
|
|
772
|
-
}
|
|
773
|
-
return moved;
|
|
774
|
-
}
|
|
775
|
-
/**
|
|
776
|
-
Move the selection to the next line wrap point, or to the end of
|
|
777
|
-
the line if there isn't one left on this line.
|
|
778
|
-
*/
|
|
779
|
-
const cursorLineBoundaryForward = view => moveSel(view, range => moveByLineBoundary(view, range, true));
|
|
780
|
-
/**
|
|
781
|
-
Move the selection to previous line wrap point, or failing that to
|
|
782
|
-
the start of the line. If the line is indented, and the cursor
|
|
783
|
-
isn't already at the end of the indentation, this will move to the
|
|
784
|
-
end of the indentation instead of the start of the line.
|
|
785
|
-
*/
|
|
786
|
-
const cursorLineBoundaryBackward = view => moveSel(view, range => moveByLineBoundary(view, range, false));
|
|
787
|
-
/**
|
|
788
|
-
Move the selection one line wrap point to the left.
|
|
789
|
-
*/
|
|
790
|
-
const cursorLineBoundaryLeft = view => moveSel(view, range => moveByLineBoundary(view, range, !ltrAtCursor(view)));
|
|
791
|
-
/**
|
|
792
|
-
Move the selection one line wrap point to the right.
|
|
793
|
-
*/
|
|
794
|
-
const cursorLineBoundaryRight = view => moveSel(view, range => moveByLineBoundary(view, range, ltrAtCursor(view)));
|
|
795
|
-
/**
|
|
796
|
-
Move the selection to the start of the line.
|
|
797
|
-
*/
|
|
798
|
-
const cursorLineStart = view => moveSel(view, range => EditorSelection.cursor(view.lineBlockAt(range.head).from, 1));
|
|
799
|
-
/**
|
|
800
|
-
Move the selection to the end of the line.
|
|
801
|
-
*/
|
|
802
|
-
const cursorLineEnd = view => moveSel(view, range => EditorSelection.cursor(view.lineBlockAt(range.head).to, -1));
|
|
803
|
-
function toMatchingBracket(state, dispatch, extend) {
|
|
804
|
-
let found = false,
|
|
805
|
-
selection = updateSel(state.selection, range => {
|
|
806
|
-
let matching = matchBrackets(state, range.head, -1) || matchBrackets(state, range.head, 1) || range.head > 0 && matchBrackets(state, range.head - 1, 1) || range.head < state.doc.length && matchBrackets(state, range.head + 1, -1);
|
|
807
|
-
if (!matching || !matching.end) return range;
|
|
808
|
-
found = true;
|
|
809
|
-
let head = matching.start.from == range.head ? matching.end.to : matching.end.from;
|
|
810
|
-
return extend ? EditorSelection.range(range.anchor, head) : EditorSelection.cursor(head);
|
|
811
|
-
});
|
|
812
|
-
if (!found) return false;
|
|
813
|
-
dispatch(setSel(state, selection));
|
|
814
|
-
return true;
|
|
815
|
-
}
|
|
816
|
-
/**
|
|
817
|
-
Move the selection to the bracket matching the one it is currently
|
|
818
|
-
on, if any.
|
|
819
|
-
*/
|
|
820
|
-
const cursorMatchingBracket = _ref5 => {
|
|
821
|
-
let {
|
|
822
|
-
state,
|
|
823
|
-
dispatch
|
|
824
|
-
} = _ref5;
|
|
825
|
-
return toMatchingBracket(state, dispatch, false);
|
|
826
|
-
};
|
|
827
|
-
function extendSel(view, how) {
|
|
828
|
-
let selection = updateSel(view.state.selection, range => {
|
|
829
|
-
let head = how(range);
|
|
830
|
-
return EditorSelection.range(range.anchor, head.head, head.goalColumn, head.bidiLevel || undefined);
|
|
831
|
-
});
|
|
832
|
-
if (selection.eq(view.state.selection)) return false;
|
|
833
|
-
view.dispatch(setSel(view.state, selection));
|
|
834
|
-
return true;
|
|
835
|
-
}
|
|
836
|
-
function selectByChar(view, forward) {
|
|
837
|
-
return extendSel(view, range => view.moveByChar(range, forward));
|
|
838
|
-
}
|
|
839
|
-
/**
|
|
840
|
-
Move the selection head one character to the left, while leaving
|
|
841
|
-
the anchor in place.
|
|
842
|
-
*/
|
|
843
|
-
const selectCharLeft = view => selectByChar(view, !ltrAtCursor(view));
|
|
844
|
-
/**
|
|
845
|
-
Move the selection head one character to the right.
|
|
846
|
-
*/
|
|
847
|
-
const selectCharRight = view => selectByChar(view, ltrAtCursor(view));
|
|
848
|
-
function selectByGroup(view, forward) {
|
|
849
|
-
return extendSel(view, range => view.moveByGroup(range, forward));
|
|
850
|
-
}
|
|
851
|
-
/**
|
|
852
|
-
Move the selection head one [group](https://codemirror.net/6/docs/ref/#commands.cursorGroupLeft) to
|
|
853
|
-
the left.
|
|
854
|
-
*/
|
|
855
|
-
const selectGroupLeft = view => selectByGroup(view, !ltrAtCursor(view));
|
|
856
|
-
/**
|
|
857
|
-
Move the selection head one group to the right.
|
|
858
|
-
*/
|
|
859
|
-
const selectGroupRight = view => selectByGroup(view, ltrAtCursor(view));
|
|
860
|
-
/**
|
|
861
|
-
Move the selection head over the next syntactic element to the left.
|
|
862
|
-
*/
|
|
863
|
-
const selectSyntaxLeft = view => extendSel(view, range => moveBySyntax(view.state, range, !ltrAtCursor(view)));
|
|
864
|
-
/**
|
|
865
|
-
Move the selection head over the next syntactic element to the right.
|
|
866
|
-
*/
|
|
867
|
-
const selectSyntaxRight = view => extendSel(view, range => moveBySyntax(view.state, range, ltrAtCursor(view)));
|
|
868
|
-
function selectByLine(view, forward) {
|
|
869
|
-
return extendSel(view, range => view.moveVertically(range, forward));
|
|
870
|
-
}
|
|
871
|
-
/**
|
|
872
|
-
Move the selection head one line up.
|
|
873
|
-
*/
|
|
874
|
-
const selectLineUp = view => selectByLine(view, false);
|
|
875
|
-
/**
|
|
876
|
-
Move the selection head one line down.
|
|
877
|
-
*/
|
|
878
|
-
const selectLineDown = view => selectByLine(view, true);
|
|
879
|
-
function selectByPage(view, forward) {
|
|
880
|
-
return extendSel(view, range => view.moveVertically(range, forward, pageInfo(view).height));
|
|
881
|
-
}
|
|
882
|
-
/**
|
|
883
|
-
Move the selection head one page up.
|
|
884
|
-
*/
|
|
885
|
-
const selectPageUp = view => selectByPage(view, false);
|
|
886
|
-
/**
|
|
887
|
-
Move the selection head one page down.
|
|
888
|
-
*/
|
|
889
|
-
const selectPageDown = view => selectByPage(view, true);
|
|
890
|
-
/**
|
|
891
|
-
Move the selection head to the next line boundary.
|
|
892
|
-
*/
|
|
893
|
-
const selectLineBoundaryForward = view => extendSel(view, range => moveByLineBoundary(view, range, true));
|
|
894
|
-
/**
|
|
895
|
-
Move the selection head to the previous line boundary.
|
|
896
|
-
*/
|
|
897
|
-
const selectLineBoundaryBackward = view => extendSel(view, range => moveByLineBoundary(view, range, false));
|
|
898
|
-
/**
|
|
899
|
-
Move the selection head one line boundary to the left.
|
|
900
|
-
*/
|
|
901
|
-
const selectLineBoundaryLeft = view => extendSel(view, range => moveByLineBoundary(view, range, !ltrAtCursor(view)));
|
|
902
|
-
/**
|
|
903
|
-
Move the selection head one line boundary to the right.
|
|
904
|
-
*/
|
|
905
|
-
const selectLineBoundaryRight = view => extendSel(view, range => moveByLineBoundary(view, range, ltrAtCursor(view)));
|
|
906
|
-
/**
|
|
907
|
-
Move the selection head to the start of the line.
|
|
908
|
-
*/
|
|
909
|
-
const selectLineStart = view => extendSel(view, range => EditorSelection.cursor(view.lineBlockAt(range.head).from));
|
|
910
|
-
/**
|
|
911
|
-
Move the selection head to the end of the line.
|
|
912
|
-
*/
|
|
913
|
-
const selectLineEnd = view => extendSel(view, range => EditorSelection.cursor(view.lineBlockAt(range.head).to));
|
|
914
|
-
/**
|
|
915
|
-
Move the selection to the start of the document.
|
|
916
|
-
*/
|
|
917
|
-
const cursorDocStart = _ref7 => {
|
|
918
|
-
let {
|
|
919
|
-
state,
|
|
920
|
-
dispatch
|
|
921
|
-
} = _ref7;
|
|
922
|
-
dispatch(setSel(state, {
|
|
923
|
-
anchor: 0
|
|
924
|
-
}));
|
|
925
|
-
return true;
|
|
926
|
-
};
|
|
927
|
-
/**
|
|
928
|
-
Move the selection to the end of the document.
|
|
929
|
-
*/
|
|
930
|
-
const cursorDocEnd = _ref8 => {
|
|
931
|
-
let {
|
|
932
|
-
state,
|
|
933
|
-
dispatch
|
|
934
|
-
} = _ref8;
|
|
935
|
-
dispatch(setSel(state, {
|
|
936
|
-
anchor: state.doc.length
|
|
937
|
-
}));
|
|
938
|
-
return true;
|
|
939
|
-
};
|
|
940
|
-
/**
|
|
941
|
-
Move the selection head to the start of the document.
|
|
942
|
-
*/
|
|
943
|
-
const selectDocStart = _ref9 => {
|
|
944
|
-
let {
|
|
945
|
-
state,
|
|
946
|
-
dispatch
|
|
947
|
-
} = _ref9;
|
|
948
|
-
dispatch(setSel(state, {
|
|
949
|
-
anchor: state.selection.main.anchor,
|
|
950
|
-
head: 0
|
|
951
|
-
}));
|
|
952
|
-
return true;
|
|
953
|
-
};
|
|
954
|
-
/**
|
|
955
|
-
Move the selection head to the end of the document.
|
|
956
|
-
*/
|
|
957
|
-
const selectDocEnd = _ref10 => {
|
|
958
|
-
let {
|
|
959
|
-
state,
|
|
960
|
-
dispatch
|
|
961
|
-
} = _ref10;
|
|
962
|
-
dispatch(setSel(state, {
|
|
963
|
-
anchor: state.selection.main.anchor,
|
|
964
|
-
head: state.doc.length
|
|
965
|
-
}));
|
|
966
|
-
return true;
|
|
967
|
-
};
|
|
968
|
-
/**
|
|
969
|
-
Select the entire document.
|
|
970
|
-
*/
|
|
971
|
-
const selectAll = _ref11 => {
|
|
972
|
-
let {
|
|
973
|
-
state,
|
|
974
|
-
dispatch
|
|
975
|
-
} = _ref11;
|
|
976
|
-
dispatch(state.update({
|
|
977
|
-
selection: {
|
|
978
|
-
anchor: 0,
|
|
979
|
-
head: state.doc.length
|
|
980
|
-
},
|
|
981
|
-
userEvent: "select"
|
|
982
|
-
}));
|
|
983
|
-
return true;
|
|
984
|
-
};
|
|
985
|
-
/**
|
|
986
|
-
Expand the selection to cover entire lines.
|
|
987
|
-
*/
|
|
988
|
-
const selectLine = _ref12 => {
|
|
989
|
-
let {
|
|
990
|
-
state,
|
|
991
|
-
dispatch
|
|
992
|
-
} = _ref12;
|
|
993
|
-
let ranges = selectedLineBlocks(state).map(_ref13 => {
|
|
994
|
-
let {
|
|
995
|
-
from,
|
|
996
|
-
to
|
|
997
|
-
} = _ref13;
|
|
998
|
-
return EditorSelection.range(from, Math.min(to + 1, state.doc.length));
|
|
999
|
-
});
|
|
1000
|
-
dispatch(state.update({
|
|
1001
|
-
selection: EditorSelection.create(ranges),
|
|
1002
|
-
userEvent: "select"
|
|
1003
|
-
}));
|
|
1004
|
-
return true;
|
|
1005
|
-
};
|
|
1006
|
-
/**
|
|
1007
|
-
Select the next syntactic construct that is larger than the
|
|
1008
|
-
selection. Note that this will only work insofar as the language
|
|
1009
|
-
[provider](https://codemirror.net/6/docs/ref/#language.language) you use builds up a full
|
|
1010
|
-
syntax tree.
|
|
1011
|
-
*/
|
|
1012
|
-
const selectParentSyntax = _ref14 => {
|
|
1013
|
-
let {
|
|
1014
|
-
state,
|
|
1015
|
-
dispatch
|
|
1016
|
-
} = _ref14;
|
|
1017
|
-
let selection = updateSel(state.selection, range => {
|
|
1018
|
-
var _a;
|
|
1019
|
-
let context = syntaxTree(state).resolveInner(range.head, 1);
|
|
1020
|
-
while (!(context.from < range.from && context.to >= range.to || context.to > range.to && context.from <= range.from || !((_a = context.parent) === null || _a === void 0 ? void 0 : _a.parent))) context = context.parent;
|
|
1021
|
-
return EditorSelection.range(context.to, context.from);
|
|
1022
|
-
});
|
|
1023
|
-
dispatch(setSel(state, selection));
|
|
1024
|
-
return true;
|
|
1025
|
-
};
|
|
1026
|
-
/**
|
|
1027
|
-
Simplify the current selection. When multiple ranges are selected,
|
|
1028
|
-
reduce it to its main range. Otherwise, if the selection is
|
|
1029
|
-
non-empty, convert it to a cursor selection.
|
|
1030
|
-
*/
|
|
1031
|
-
const simplifySelection = _ref15 => {
|
|
1032
|
-
let {
|
|
1033
|
-
state,
|
|
1034
|
-
dispatch
|
|
1035
|
-
} = _ref15;
|
|
1036
|
-
let cur = state.selection,
|
|
1037
|
-
selection = null;
|
|
1038
|
-
if (cur.ranges.length > 1) selection = EditorSelection.create([cur.main]);else if (!cur.main.empty) selection = EditorSelection.create([EditorSelection.cursor(cur.main.head)]);
|
|
1039
|
-
if (!selection) return false;
|
|
1040
|
-
dispatch(setSel(state, selection));
|
|
1041
|
-
return true;
|
|
1042
|
-
};
|
|
1043
|
-
function deleteBy(target, by) {
|
|
1044
|
-
if (target.state.readOnly) return false;
|
|
1045
|
-
let event = "delete.selection",
|
|
1046
|
-
{
|
|
1047
|
-
state
|
|
1048
|
-
} = target;
|
|
1049
|
-
let changes = state.changeByRange(range => {
|
|
1050
|
-
let {
|
|
1051
|
-
from,
|
|
1052
|
-
to
|
|
1053
|
-
} = range;
|
|
1054
|
-
if (from == to) {
|
|
1055
|
-
let towards = by(from);
|
|
1056
|
-
if (towards < from) {
|
|
1057
|
-
event = "delete.backward";
|
|
1058
|
-
towards = skipAtomic(target, towards, false);
|
|
1059
|
-
} else if (towards > from) {
|
|
1060
|
-
event = "delete.forward";
|
|
1061
|
-
towards = skipAtomic(target, towards, true);
|
|
1062
|
-
}
|
|
1063
|
-
from = Math.min(from, towards);
|
|
1064
|
-
to = Math.max(to, towards);
|
|
1065
|
-
} else {
|
|
1066
|
-
from = skipAtomic(target, from, false);
|
|
1067
|
-
to = skipAtomic(target, to, true);
|
|
1068
|
-
}
|
|
1069
|
-
return from == to ? {
|
|
1070
|
-
range
|
|
1071
|
-
} : {
|
|
1072
|
-
changes: {
|
|
1073
|
-
from,
|
|
1074
|
-
to
|
|
1075
|
-
},
|
|
1076
|
-
range: EditorSelection.cursor(from)
|
|
1077
|
-
};
|
|
1078
|
-
});
|
|
1079
|
-
if (changes.changes.empty) return false;
|
|
1080
|
-
target.dispatch(state.update(changes, {
|
|
1081
|
-
scrollIntoView: true,
|
|
1082
|
-
userEvent: event,
|
|
1083
|
-
effects: event == "delete.selection" ? EditorView.announce.of(state.phrase("Selection deleted")) : undefined
|
|
1084
|
-
}));
|
|
1085
|
-
return true;
|
|
1086
|
-
}
|
|
1087
|
-
function skipAtomic(target, pos, forward) {
|
|
1088
|
-
if (target instanceof EditorView) for (let ranges of target.state.facet(EditorView.atomicRanges).map(f => f(target))) ranges.between(pos, pos, (from, to) => {
|
|
1089
|
-
if (from < pos && to > pos) pos = forward ? to : from;
|
|
1090
|
-
});
|
|
1091
|
-
return pos;
|
|
1092
|
-
}
|
|
1093
|
-
const deleteByChar = (target, forward) => deleteBy(target, pos => {
|
|
1094
|
-
let {
|
|
1095
|
-
state
|
|
1096
|
-
} = target,
|
|
1097
|
-
line = state.doc.lineAt(pos),
|
|
1098
|
-
before,
|
|
1099
|
-
targetPos;
|
|
1100
|
-
if (!forward && pos > line.from && pos < line.from + 200 && !/[^ \t]/.test(before = line.text.slice(0, pos - line.from))) {
|
|
1101
|
-
if (before[before.length - 1] == "\t") return pos - 1;
|
|
1102
|
-
let col = countColumn(before, state.tabSize),
|
|
1103
|
-
drop = col % getIndentUnit(state) || getIndentUnit(state);
|
|
1104
|
-
for (let i = 0; i < drop && before[before.length - 1 - i] == " "; i++) pos--;
|
|
1105
|
-
targetPos = pos;
|
|
1106
|
-
} else {
|
|
1107
|
-
targetPos = findClusterBreak(line.text, pos - line.from, forward, forward) + line.from;
|
|
1108
|
-
if (targetPos == pos && line.number != (forward ? state.doc.lines : 1)) targetPos += forward ? 1 : -1;
|
|
1109
|
-
}
|
|
1110
|
-
return targetPos;
|
|
1111
|
-
});
|
|
1112
|
-
/**
|
|
1113
|
-
Delete the selection, or, for cursor selections, the character
|
|
1114
|
-
before the cursor.
|
|
1115
|
-
*/
|
|
1116
|
-
const deleteCharBackward = view => deleteByChar(view, false);
|
|
1117
|
-
/**
|
|
1118
|
-
Delete the selection or the character after the cursor.
|
|
1119
|
-
*/
|
|
1120
|
-
const deleteCharForward = view => deleteByChar(view, true);
|
|
1121
|
-
const deleteByGroup = (target, forward) => deleteBy(target, start => {
|
|
1122
|
-
let pos = start,
|
|
1123
|
-
{
|
|
1124
|
-
state
|
|
1125
|
-
} = target,
|
|
1126
|
-
line = state.doc.lineAt(pos);
|
|
1127
|
-
let categorize = state.charCategorizer(pos);
|
|
1128
|
-
for (let cat = null;;) {
|
|
1129
|
-
if (pos == (forward ? line.to : line.from)) {
|
|
1130
|
-
if (pos == start && line.number != (forward ? state.doc.lines : 1)) pos += forward ? 1 : -1;
|
|
1131
|
-
break;
|
|
1132
|
-
}
|
|
1133
|
-
let next = findClusterBreak(line.text, pos - line.from, forward) + line.from;
|
|
1134
|
-
let nextChar = line.text.slice(Math.min(pos, next) - line.from, Math.max(pos, next) - line.from);
|
|
1135
|
-
let nextCat = categorize(nextChar);
|
|
1136
|
-
if (cat != null && nextCat != cat) break;
|
|
1137
|
-
if (nextChar != " " || pos != start) cat = nextCat;
|
|
1138
|
-
pos = next;
|
|
1139
|
-
}
|
|
1140
|
-
return pos;
|
|
1141
|
-
});
|
|
1142
|
-
/**
|
|
1143
|
-
Delete the selection or backward until the end of the next
|
|
1144
|
-
[group](https://codemirror.net/6/docs/ref/#view.EditorView.moveByGroup), only skipping groups of
|
|
1145
|
-
whitespace when they consist of a single space.
|
|
1146
|
-
*/
|
|
1147
|
-
const deleteGroupBackward = target => deleteByGroup(target, false);
|
|
1148
|
-
/**
|
|
1149
|
-
Delete the selection or forward until the end of the next group.
|
|
1150
|
-
*/
|
|
1151
|
-
const deleteGroupForward = target => deleteByGroup(target, true);
|
|
1152
|
-
/**
|
|
1153
|
-
Delete the selection, or, if it is a cursor selection, delete to
|
|
1154
|
-
the end of the line. If the cursor is directly at the end of the
|
|
1155
|
-
line, delete the line break after it.
|
|
1156
|
-
*/
|
|
1157
|
-
const deleteToLineEnd = view => deleteBy(view, pos => {
|
|
1158
|
-
let lineEnd = view.lineBlockAt(pos).to;
|
|
1159
|
-
return pos < lineEnd ? lineEnd : Math.min(view.state.doc.length, pos + 1);
|
|
1160
|
-
});
|
|
1161
|
-
/**
|
|
1162
|
-
Delete the selection, or, if it is a cursor selection, delete to
|
|
1163
|
-
the start of the line. If the cursor is directly at the start of the
|
|
1164
|
-
line, delete the line break before it.
|
|
1165
|
-
*/
|
|
1166
|
-
const deleteToLineStart = view => deleteBy(view, pos => {
|
|
1167
|
-
let lineStart = view.lineBlockAt(pos).from;
|
|
1168
|
-
return pos > lineStart ? lineStart : Math.max(0, pos - 1);
|
|
1169
|
-
});
|
|
1170
|
-
/**
|
|
1171
|
-
Replace each selection range with a line break, leaving the cursor
|
|
1172
|
-
on the line before the break.
|
|
1173
|
-
*/
|
|
1174
|
-
const splitLine = _ref17 => {
|
|
1175
|
-
let {
|
|
1176
|
-
state,
|
|
1177
|
-
dispatch
|
|
1178
|
-
} = _ref17;
|
|
1179
|
-
if (state.readOnly) return false;
|
|
1180
|
-
let changes = state.changeByRange(range => {
|
|
1181
|
-
return {
|
|
1182
|
-
changes: {
|
|
1183
|
-
from: range.from,
|
|
1184
|
-
to: range.to,
|
|
1185
|
-
insert: Text.of(["", ""])
|
|
1186
|
-
},
|
|
1187
|
-
range: EditorSelection.cursor(range.from)
|
|
1188
|
-
};
|
|
1189
|
-
});
|
|
1190
|
-
dispatch(state.update(changes, {
|
|
1191
|
-
scrollIntoView: true,
|
|
1192
|
-
userEvent: "input"
|
|
1193
|
-
}));
|
|
1194
|
-
return true;
|
|
1195
|
-
};
|
|
1196
|
-
/**
|
|
1197
|
-
Flip the characters before and after the cursor(s).
|
|
1198
|
-
*/
|
|
1199
|
-
const transposeChars = _ref18 => {
|
|
1200
|
-
let {
|
|
1201
|
-
state,
|
|
1202
|
-
dispatch
|
|
1203
|
-
} = _ref18;
|
|
1204
|
-
if (state.readOnly) return false;
|
|
1205
|
-
let changes = state.changeByRange(range => {
|
|
1206
|
-
if (!range.empty || range.from == 0 || range.from == state.doc.length) return {
|
|
1207
|
-
range
|
|
1208
|
-
};
|
|
1209
|
-
let pos = range.from,
|
|
1210
|
-
line = state.doc.lineAt(pos);
|
|
1211
|
-
let from = pos == line.from ? pos - 1 : findClusterBreak(line.text, pos - line.from, false) + line.from;
|
|
1212
|
-
let to = pos == line.to ? pos + 1 : findClusterBreak(line.text, pos - line.from, true) + line.from;
|
|
1213
|
-
return {
|
|
1214
|
-
changes: {
|
|
1215
|
-
from,
|
|
1216
|
-
to,
|
|
1217
|
-
insert: state.doc.slice(pos, to).append(state.doc.slice(from, pos))
|
|
1218
|
-
},
|
|
1219
|
-
range: EditorSelection.cursor(to)
|
|
1220
|
-
};
|
|
1221
|
-
});
|
|
1222
|
-
if (changes.changes.empty) return false;
|
|
1223
|
-
dispatch(state.update(changes, {
|
|
1224
|
-
scrollIntoView: true,
|
|
1225
|
-
userEvent: "move.character"
|
|
1226
|
-
}));
|
|
1227
|
-
return true;
|
|
1228
|
-
};
|
|
1229
|
-
function selectedLineBlocks(state) {
|
|
1230
|
-
let blocks = [],
|
|
1231
|
-
upto = -1;
|
|
1232
|
-
for (let range of state.selection.ranges) {
|
|
1233
|
-
let startLine = state.doc.lineAt(range.from),
|
|
1234
|
-
endLine = state.doc.lineAt(range.to);
|
|
1235
|
-
if (!range.empty && range.to == endLine.from) endLine = state.doc.lineAt(range.to - 1);
|
|
1236
|
-
if (upto >= startLine.number) {
|
|
1237
|
-
let prev = blocks[blocks.length - 1];
|
|
1238
|
-
prev.to = endLine.to;
|
|
1239
|
-
prev.ranges.push(range);
|
|
1240
|
-
} else {
|
|
1241
|
-
blocks.push({
|
|
1242
|
-
from: startLine.from,
|
|
1243
|
-
to: endLine.to,
|
|
1244
|
-
ranges: [range]
|
|
1245
|
-
});
|
|
1246
|
-
}
|
|
1247
|
-
upto = endLine.number + 1;
|
|
1248
|
-
}
|
|
1249
|
-
return blocks;
|
|
1250
|
-
}
|
|
1251
|
-
function moveLine(state, dispatch, forward) {
|
|
1252
|
-
if (state.readOnly) return false;
|
|
1253
|
-
let changes = [],
|
|
1254
|
-
ranges = [];
|
|
1255
|
-
for (let block of selectedLineBlocks(state)) {
|
|
1256
|
-
if (forward ? block.to == state.doc.length : block.from == 0) continue;
|
|
1257
|
-
let nextLine = state.doc.lineAt(forward ? block.to + 1 : block.from - 1);
|
|
1258
|
-
let size = nextLine.length + 1;
|
|
1259
|
-
if (forward) {
|
|
1260
|
-
changes.push({
|
|
1261
|
-
from: block.to,
|
|
1262
|
-
to: nextLine.to
|
|
1263
|
-
}, {
|
|
1264
|
-
from: block.from,
|
|
1265
|
-
insert: nextLine.text + state.lineBreak
|
|
1266
|
-
});
|
|
1267
|
-
for (let r of block.ranges) ranges.push(EditorSelection.range(Math.min(state.doc.length, r.anchor + size), Math.min(state.doc.length, r.head + size)));
|
|
1268
|
-
} else {
|
|
1269
|
-
changes.push({
|
|
1270
|
-
from: nextLine.from,
|
|
1271
|
-
to: block.from
|
|
1272
|
-
}, {
|
|
1273
|
-
from: block.to,
|
|
1274
|
-
insert: state.lineBreak + nextLine.text
|
|
1275
|
-
});
|
|
1276
|
-
for (let r of block.ranges) ranges.push(EditorSelection.range(r.anchor - size, r.head - size));
|
|
1277
|
-
}
|
|
1278
|
-
}
|
|
1279
|
-
if (!changes.length) return false;
|
|
1280
|
-
dispatch(state.update({
|
|
1281
|
-
changes,
|
|
1282
|
-
scrollIntoView: true,
|
|
1283
|
-
selection: EditorSelection.create(ranges, state.selection.mainIndex),
|
|
1284
|
-
userEvent: "move.line"
|
|
1285
|
-
}));
|
|
1286
|
-
return true;
|
|
1287
|
-
}
|
|
1288
|
-
/**
|
|
1289
|
-
Move the selected lines up one line.
|
|
1290
|
-
*/
|
|
1291
|
-
const moveLineUp = _ref19 => {
|
|
1292
|
-
let {
|
|
1293
|
-
state,
|
|
1294
|
-
dispatch
|
|
1295
|
-
} = _ref19;
|
|
1296
|
-
return moveLine(state, dispatch, false);
|
|
1297
|
-
};
|
|
1298
|
-
/**
|
|
1299
|
-
Move the selected lines down one line.
|
|
1300
|
-
*/
|
|
1301
|
-
const moveLineDown = _ref20 => {
|
|
1302
|
-
let {
|
|
1303
|
-
state,
|
|
1304
|
-
dispatch
|
|
1305
|
-
} = _ref20;
|
|
1306
|
-
return moveLine(state, dispatch, true);
|
|
1307
|
-
};
|
|
1308
|
-
function copyLine(state, dispatch, forward) {
|
|
1309
|
-
if (state.readOnly) return false;
|
|
1310
|
-
let changes = [];
|
|
1311
|
-
for (let block of selectedLineBlocks(state)) {
|
|
1312
|
-
if (forward) changes.push({
|
|
1313
|
-
from: block.from,
|
|
1314
|
-
insert: state.doc.slice(block.from, block.to) + state.lineBreak
|
|
1315
|
-
});else changes.push({
|
|
1316
|
-
from: block.to,
|
|
1317
|
-
insert: state.lineBreak + state.doc.slice(block.from, block.to)
|
|
1318
|
-
});
|
|
1319
|
-
}
|
|
1320
|
-
dispatch(state.update({
|
|
1321
|
-
changes,
|
|
1322
|
-
scrollIntoView: true,
|
|
1323
|
-
userEvent: "input.copyline"
|
|
1324
|
-
}));
|
|
1325
|
-
return true;
|
|
1326
|
-
}
|
|
1327
|
-
/**
|
|
1328
|
-
Create a copy of the selected lines. Keep the selection in the top copy.
|
|
1329
|
-
*/
|
|
1330
|
-
const copyLineUp = _ref21 => {
|
|
1331
|
-
let {
|
|
1332
|
-
state,
|
|
1333
|
-
dispatch
|
|
1334
|
-
} = _ref21;
|
|
1335
|
-
return copyLine(state, dispatch, false);
|
|
1336
|
-
};
|
|
1337
|
-
/**
|
|
1338
|
-
Create a copy of the selected lines. Keep the selection in the bottom copy.
|
|
1339
|
-
*/
|
|
1340
|
-
const copyLineDown = _ref22 => {
|
|
1341
|
-
let {
|
|
1342
|
-
state,
|
|
1343
|
-
dispatch
|
|
1344
|
-
} = _ref22;
|
|
1345
|
-
return copyLine(state, dispatch, true);
|
|
1346
|
-
};
|
|
1347
|
-
/**
|
|
1348
|
-
Delete selected lines.
|
|
1349
|
-
*/
|
|
1350
|
-
const deleteLine = view => {
|
|
1351
|
-
if (view.state.readOnly) return false;
|
|
1352
|
-
let {
|
|
1353
|
-
state
|
|
1354
|
-
} = view,
|
|
1355
|
-
changes = state.changes(selectedLineBlocks(state).map(_ref23 => {
|
|
1356
|
-
let {
|
|
1357
|
-
from,
|
|
1358
|
-
to
|
|
1359
|
-
} = _ref23;
|
|
1360
|
-
if (from > 0) from--;else if (to < state.doc.length) to++;
|
|
1361
|
-
return {
|
|
1362
|
-
from,
|
|
1363
|
-
to
|
|
1364
|
-
};
|
|
1365
|
-
}));
|
|
1366
|
-
let selection = updateSel(state.selection, range => view.moveVertically(range, true)).map(changes);
|
|
1367
|
-
view.dispatch({
|
|
1368
|
-
changes,
|
|
1369
|
-
selection,
|
|
1370
|
-
scrollIntoView: true,
|
|
1371
|
-
userEvent: "delete.line"
|
|
1372
|
-
});
|
|
1373
|
-
return true;
|
|
1374
|
-
};
|
|
1375
|
-
function isBetweenBrackets(state, pos) {
|
|
1376
|
-
if (/\(\)|\[\]|\{\}/.test(state.sliceDoc(pos - 1, pos + 1))) return {
|
|
1377
|
-
from: pos,
|
|
1378
|
-
to: pos
|
|
1379
|
-
};
|
|
1380
|
-
let context = syntaxTree(state).resolveInner(pos);
|
|
1381
|
-
let before = context.childBefore(pos),
|
|
1382
|
-
after = context.childAfter(pos),
|
|
1383
|
-
closedBy;
|
|
1384
|
-
if (before && after && before.to <= pos && after.from >= pos && (closedBy = before.type.prop(NodeProp.closedBy)) && closedBy.indexOf(after.name) > -1 && state.doc.lineAt(before.to).from == state.doc.lineAt(after.from).from) return {
|
|
1385
|
-
from: before.to,
|
|
1386
|
-
to: after.from
|
|
1387
|
-
};
|
|
1388
|
-
return null;
|
|
1389
|
-
}
|
|
1390
|
-
/**
|
|
1391
|
-
Replace the selection with a newline and indent the newly created
|
|
1392
|
-
line(s). If the current line consists only of whitespace, this
|
|
1393
|
-
will also delete that whitespace. When the cursor is between
|
|
1394
|
-
matching brackets, an additional newline will be inserted after
|
|
1395
|
-
the cursor.
|
|
1396
|
-
*/
|
|
1397
|
-
const insertNewlineAndIndent = /*@__PURE__*/newlineAndIndent(false);
|
|
1398
|
-
/**
|
|
1399
|
-
Create a blank, indented line below the current line.
|
|
1400
|
-
*/
|
|
1401
|
-
const insertBlankLine = /*@__PURE__*/newlineAndIndent(true);
|
|
1402
|
-
function newlineAndIndent(atEof) {
|
|
1403
|
-
return _ref25 => {
|
|
1404
|
-
let {
|
|
1405
|
-
state,
|
|
1406
|
-
dispatch
|
|
1407
|
-
} = _ref25;
|
|
1408
|
-
if (state.readOnly) return false;
|
|
1409
|
-
let changes = state.changeByRange(range => {
|
|
1410
|
-
let {
|
|
1411
|
-
from,
|
|
1412
|
-
to
|
|
1413
|
-
} = range,
|
|
1414
|
-
line = state.doc.lineAt(from);
|
|
1415
|
-
let explode = !atEof && from == to && isBetweenBrackets(state, from);
|
|
1416
|
-
if (atEof) from = to = (to <= line.to ? line : state.doc.lineAt(to)).to;
|
|
1417
|
-
let cx = new IndentContext(state, {
|
|
1418
|
-
simulateBreak: from,
|
|
1419
|
-
simulateDoubleBreak: !!explode
|
|
1420
|
-
});
|
|
1421
|
-
let indent = getIndentation(cx, from);
|
|
1422
|
-
if (indent == null) indent = /^\s*/.exec(state.doc.lineAt(from).text)[0].length;
|
|
1423
|
-
while (to < line.to && /\s/.test(line.text[to - line.from])) to++;
|
|
1424
|
-
if (explode) ({
|
|
1425
|
-
from,
|
|
1426
|
-
to
|
|
1427
|
-
} = explode);else if (from > line.from && from < line.from + 100 && !/\S/.test(line.text.slice(0, from))) from = line.from;
|
|
1428
|
-
let insert = ["", indentString(state, indent)];
|
|
1429
|
-
if (explode) insert.push(indentString(state, cx.lineIndent(line.from, -1)));
|
|
1430
|
-
return {
|
|
1431
|
-
changes: {
|
|
1432
|
-
from,
|
|
1433
|
-
to,
|
|
1434
|
-
insert: Text.of(insert)
|
|
1435
|
-
},
|
|
1436
|
-
range: EditorSelection.cursor(from + 1 + insert[1].length)
|
|
1437
|
-
};
|
|
1438
|
-
});
|
|
1439
|
-
dispatch(state.update(changes, {
|
|
1440
|
-
scrollIntoView: true,
|
|
1441
|
-
userEvent: "input"
|
|
1442
|
-
}));
|
|
1443
|
-
return true;
|
|
1444
|
-
};
|
|
1445
|
-
}
|
|
1446
|
-
function changeBySelectedLine(state, f) {
|
|
1447
|
-
let atLine = -1;
|
|
1448
|
-
return state.changeByRange(range => {
|
|
1449
|
-
let changes = [];
|
|
1450
|
-
for (let pos = range.from; pos <= range.to;) {
|
|
1451
|
-
let line = state.doc.lineAt(pos);
|
|
1452
|
-
if (line.number > atLine && (range.empty || range.to > line.from)) {
|
|
1453
|
-
f(line, changes, range);
|
|
1454
|
-
atLine = line.number;
|
|
1455
|
-
}
|
|
1456
|
-
pos = line.to + 1;
|
|
1457
|
-
}
|
|
1458
|
-
let changeSet = state.changes(changes);
|
|
1459
|
-
return {
|
|
1460
|
-
changes,
|
|
1461
|
-
range: EditorSelection.range(changeSet.mapPos(range.anchor, 1), changeSet.mapPos(range.head, 1))
|
|
1462
|
-
};
|
|
1463
|
-
});
|
|
1464
|
-
}
|
|
1465
|
-
/**
|
|
1466
|
-
Auto-indent the selected lines. This uses the [indentation service
|
|
1467
|
-
facet](https://codemirror.net/6/docs/ref/#language.indentService) as source for auto-indent
|
|
1468
|
-
information.
|
|
1469
|
-
*/
|
|
1470
|
-
const indentSelection = _ref26 => {
|
|
1471
|
-
let {
|
|
1472
|
-
state,
|
|
1473
|
-
dispatch
|
|
1474
|
-
} = _ref26;
|
|
1475
|
-
if (state.readOnly) return false;
|
|
1476
|
-
let updated = Object.create(null);
|
|
1477
|
-
let context = new IndentContext(state, {
|
|
1478
|
-
overrideIndentation: start => {
|
|
1479
|
-
let found = updated[start];
|
|
1480
|
-
return found == null ? -1 : found;
|
|
1481
|
-
}
|
|
1482
|
-
});
|
|
1483
|
-
let changes = changeBySelectedLine(state, (line, changes, range) => {
|
|
1484
|
-
let indent = getIndentation(context, line.from);
|
|
1485
|
-
if (indent == null) return;
|
|
1486
|
-
if (!/\S/.test(line.text)) indent = 0;
|
|
1487
|
-
let cur = /^\s*/.exec(line.text)[0];
|
|
1488
|
-
let norm = indentString(state, indent);
|
|
1489
|
-
if (cur != norm || range.from < line.from + cur.length) {
|
|
1490
|
-
updated[line.from] = indent;
|
|
1491
|
-
changes.push({
|
|
1492
|
-
from: line.from,
|
|
1493
|
-
to: line.from + cur.length,
|
|
1494
|
-
insert: norm
|
|
1495
|
-
});
|
|
1496
|
-
}
|
|
1497
|
-
});
|
|
1498
|
-
if (!changes.changes.empty) dispatch(state.update(changes, {
|
|
1499
|
-
userEvent: "indent"
|
|
1500
|
-
}));
|
|
1501
|
-
return true;
|
|
1502
|
-
};
|
|
1503
|
-
/**
|
|
1504
|
-
Add a [unit](https://codemirror.net/6/docs/ref/#language.indentUnit) of indentation to all selected
|
|
1505
|
-
lines.
|
|
1506
|
-
*/
|
|
1507
|
-
const indentMore = _ref27 => {
|
|
1508
|
-
let {
|
|
1509
|
-
state,
|
|
1510
|
-
dispatch
|
|
1511
|
-
} = _ref27;
|
|
1512
|
-
if (state.readOnly) return false;
|
|
1513
|
-
dispatch(state.update(changeBySelectedLine(state, (line, changes) => {
|
|
1514
|
-
changes.push({
|
|
1515
|
-
from: line.from,
|
|
1516
|
-
insert: state.facet(indentUnit)
|
|
1517
|
-
});
|
|
1518
|
-
}), {
|
|
1519
|
-
userEvent: "input.indent"
|
|
1520
|
-
}));
|
|
1521
|
-
return true;
|
|
1522
|
-
};
|
|
1523
|
-
/**
|
|
1524
|
-
Remove a [unit](https://codemirror.net/6/docs/ref/#language.indentUnit) of indentation from all
|
|
1525
|
-
selected lines.
|
|
1526
|
-
*/
|
|
1527
|
-
const indentLess = _ref28 => {
|
|
1528
|
-
let {
|
|
1529
|
-
state,
|
|
1530
|
-
dispatch
|
|
1531
|
-
} = _ref28;
|
|
1532
|
-
if (state.readOnly) return false;
|
|
1533
|
-
dispatch(state.update(changeBySelectedLine(state, (line, changes) => {
|
|
1534
|
-
let space = /^\s*/.exec(line.text)[0];
|
|
1535
|
-
if (!space) return;
|
|
1536
|
-
let col = countColumn(space, state.tabSize),
|
|
1537
|
-
keep = 0;
|
|
1538
|
-
let insert = indentString(state, Math.max(0, col - getIndentUnit(state)));
|
|
1539
|
-
while (keep < space.length && keep < insert.length && space.charCodeAt(keep) == insert.charCodeAt(keep)) keep++;
|
|
1540
|
-
changes.push({
|
|
1541
|
-
from: line.from + keep,
|
|
1542
|
-
to: line.from + space.length,
|
|
1543
|
-
insert: insert.slice(keep)
|
|
1544
|
-
});
|
|
1545
|
-
}), {
|
|
1546
|
-
userEvent: "delete.dedent"
|
|
1547
|
-
}));
|
|
1548
|
-
return true;
|
|
1549
|
-
};
|
|
1550
|
-
/**
|
|
1551
|
-
Array of key bindings containing the Emacs-style bindings that are
|
|
1552
|
-
available on macOS by default.
|
|
1553
|
-
|
|
1554
|
-
- Ctrl-b: [`cursorCharLeft`](https://codemirror.net/6/docs/ref/#commands.cursorCharLeft) ([`selectCharLeft`](https://codemirror.net/6/docs/ref/#commands.selectCharLeft) with Shift)
|
|
1555
|
-
- Ctrl-f: [`cursorCharRight`](https://codemirror.net/6/docs/ref/#commands.cursorCharRight) ([`selectCharRight`](https://codemirror.net/6/docs/ref/#commands.selectCharRight) with Shift)
|
|
1556
|
-
- Ctrl-p: [`cursorLineUp`](https://codemirror.net/6/docs/ref/#commands.cursorLineUp) ([`selectLineUp`](https://codemirror.net/6/docs/ref/#commands.selectLineUp) with Shift)
|
|
1557
|
-
- Ctrl-n: [`cursorLineDown`](https://codemirror.net/6/docs/ref/#commands.cursorLineDown) ([`selectLineDown`](https://codemirror.net/6/docs/ref/#commands.selectLineDown) with Shift)
|
|
1558
|
-
- Ctrl-a: [`cursorLineStart`](https://codemirror.net/6/docs/ref/#commands.cursorLineStart) ([`selectLineStart`](https://codemirror.net/6/docs/ref/#commands.selectLineStart) with Shift)
|
|
1559
|
-
- Ctrl-e: [`cursorLineEnd`](https://codemirror.net/6/docs/ref/#commands.cursorLineEnd) ([`selectLineEnd`](https://codemirror.net/6/docs/ref/#commands.selectLineEnd) with Shift)
|
|
1560
|
-
- Ctrl-d: [`deleteCharForward`](https://codemirror.net/6/docs/ref/#commands.deleteCharForward)
|
|
1561
|
-
- Ctrl-h: [`deleteCharBackward`](https://codemirror.net/6/docs/ref/#commands.deleteCharBackward)
|
|
1562
|
-
- Ctrl-k: [`deleteToLineEnd`](https://codemirror.net/6/docs/ref/#commands.deleteToLineEnd)
|
|
1563
|
-
- Ctrl-Alt-h: [`deleteGroupBackward`](https://codemirror.net/6/docs/ref/#commands.deleteGroupBackward)
|
|
1564
|
-
- Ctrl-o: [`splitLine`](https://codemirror.net/6/docs/ref/#commands.splitLine)
|
|
1565
|
-
- Ctrl-t: [`transposeChars`](https://codemirror.net/6/docs/ref/#commands.transposeChars)
|
|
1566
|
-
- Ctrl-v: [`cursorPageDown`](https://codemirror.net/6/docs/ref/#commands.cursorPageDown)
|
|
1567
|
-
- Alt-v: [`cursorPageUp`](https://codemirror.net/6/docs/ref/#commands.cursorPageUp)
|
|
1568
|
-
*/
|
|
1569
|
-
const emacsStyleKeymap = [{
|
|
1570
|
-
key: "Ctrl-b",
|
|
1571
|
-
run: cursorCharLeft,
|
|
1572
|
-
shift: selectCharLeft,
|
|
1573
|
-
preventDefault: true
|
|
1574
|
-
}, {
|
|
1575
|
-
key: "Ctrl-f",
|
|
1576
|
-
run: cursorCharRight,
|
|
1577
|
-
shift: selectCharRight
|
|
1578
|
-
}, {
|
|
1579
|
-
key: "Ctrl-p",
|
|
1580
|
-
run: cursorLineUp,
|
|
1581
|
-
shift: selectLineUp
|
|
1582
|
-
}, {
|
|
1583
|
-
key: "Ctrl-n",
|
|
1584
|
-
run: cursorLineDown,
|
|
1585
|
-
shift: selectLineDown
|
|
1586
|
-
}, {
|
|
1587
|
-
key: "Ctrl-a",
|
|
1588
|
-
run: cursorLineStart,
|
|
1589
|
-
shift: selectLineStart
|
|
1590
|
-
}, {
|
|
1591
|
-
key: "Ctrl-e",
|
|
1592
|
-
run: cursorLineEnd,
|
|
1593
|
-
shift: selectLineEnd
|
|
1594
|
-
}, {
|
|
1595
|
-
key: "Ctrl-d",
|
|
1596
|
-
run: deleteCharForward
|
|
1597
|
-
}, {
|
|
1598
|
-
key: "Ctrl-h",
|
|
1599
|
-
run: deleteCharBackward
|
|
1600
|
-
}, {
|
|
1601
|
-
key: "Ctrl-k",
|
|
1602
|
-
run: deleteToLineEnd
|
|
1603
|
-
}, {
|
|
1604
|
-
key: "Ctrl-Alt-h",
|
|
1605
|
-
run: deleteGroupBackward
|
|
1606
|
-
}, {
|
|
1607
|
-
key: "Ctrl-o",
|
|
1608
|
-
run: splitLine
|
|
1609
|
-
}, {
|
|
1610
|
-
key: "Ctrl-t",
|
|
1611
|
-
run: transposeChars
|
|
1612
|
-
}, {
|
|
1613
|
-
key: "Ctrl-v",
|
|
1614
|
-
run: cursorPageDown
|
|
1615
|
-
}];
|
|
1616
|
-
/**
|
|
1617
|
-
An array of key bindings closely sticking to platform-standard or
|
|
1618
|
-
widely used bindings. (This includes the bindings from
|
|
1619
|
-
[`emacsStyleKeymap`](https://codemirror.net/6/docs/ref/#commands.emacsStyleKeymap), with their `key`
|
|
1620
|
-
property changed to `mac`.)
|
|
1621
|
-
|
|
1622
|
-
- ArrowLeft: [`cursorCharLeft`](https://codemirror.net/6/docs/ref/#commands.cursorCharLeft) ([`selectCharLeft`](https://codemirror.net/6/docs/ref/#commands.selectCharLeft) with Shift)
|
|
1623
|
-
- ArrowRight: [`cursorCharRight`](https://codemirror.net/6/docs/ref/#commands.cursorCharRight) ([`selectCharRight`](https://codemirror.net/6/docs/ref/#commands.selectCharRight) with Shift)
|
|
1624
|
-
- Ctrl-ArrowLeft (Alt-ArrowLeft on macOS): [`cursorGroupLeft`](https://codemirror.net/6/docs/ref/#commands.cursorGroupLeft) ([`selectGroupLeft`](https://codemirror.net/6/docs/ref/#commands.selectGroupLeft) with Shift)
|
|
1625
|
-
- Ctrl-ArrowRight (Alt-ArrowRight on macOS): [`cursorGroupRight`](https://codemirror.net/6/docs/ref/#commands.cursorGroupRight) ([`selectGroupRight`](https://codemirror.net/6/docs/ref/#commands.selectGroupRight) with Shift)
|
|
1626
|
-
- Cmd-ArrowLeft (on macOS): [`cursorLineStart`](https://codemirror.net/6/docs/ref/#commands.cursorLineStart) ([`selectLineStart`](https://codemirror.net/6/docs/ref/#commands.selectLineStart) with Shift)
|
|
1627
|
-
- Cmd-ArrowRight (on macOS): [`cursorLineEnd`](https://codemirror.net/6/docs/ref/#commands.cursorLineEnd) ([`selectLineEnd`](https://codemirror.net/6/docs/ref/#commands.selectLineEnd) with Shift)
|
|
1628
|
-
- ArrowUp: [`cursorLineUp`](https://codemirror.net/6/docs/ref/#commands.cursorLineUp) ([`selectLineUp`](https://codemirror.net/6/docs/ref/#commands.selectLineUp) with Shift)
|
|
1629
|
-
- ArrowDown: [`cursorLineDown`](https://codemirror.net/6/docs/ref/#commands.cursorLineDown) ([`selectLineDown`](https://codemirror.net/6/docs/ref/#commands.selectLineDown) with Shift)
|
|
1630
|
-
- Cmd-ArrowUp (on macOS): [`cursorDocStart`](https://codemirror.net/6/docs/ref/#commands.cursorDocStart) ([`selectDocStart`](https://codemirror.net/6/docs/ref/#commands.selectDocStart) with Shift)
|
|
1631
|
-
- Cmd-ArrowDown (on macOS): [`cursorDocEnd`](https://codemirror.net/6/docs/ref/#commands.cursorDocEnd) ([`selectDocEnd`](https://codemirror.net/6/docs/ref/#commands.selectDocEnd) with Shift)
|
|
1632
|
-
- Ctrl-ArrowUp (on macOS): [`cursorPageUp`](https://codemirror.net/6/docs/ref/#commands.cursorPageUp) ([`selectPageUp`](https://codemirror.net/6/docs/ref/#commands.selectPageUp) with Shift)
|
|
1633
|
-
- Ctrl-ArrowDown (on macOS): [`cursorPageDown`](https://codemirror.net/6/docs/ref/#commands.cursorPageDown) ([`selectPageDown`](https://codemirror.net/6/docs/ref/#commands.selectPageDown) with Shift)
|
|
1634
|
-
- PageUp: [`cursorPageUp`](https://codemirror.net/6/docs/ref/#commands.cursorPageUp) ([`selectPageUp`](https://codemirror.net/6/docs/ref/#commands.selectPageUp) with Shift)
|
|
1635
|
-
- PageDown: [`cursorPageDown`](https://codemirror.net/6/docs/ref/#commands.cursorPageDown) ([`selectPageDown`](https://codemirror.net/6/docs/ref/#commands.selectPageDown) with Shift)
|
|
1636
|
-
- Home: [`cursorLineBoundaryBackward`](https://codemirror.net/6/docs/ref/#commands.cursorLineBoundaryBackward) ([`selectLineBoundaryBackward`](https://codemirror.net/6/docs/ref/#commands.selectLineBoundaryBackward) with Shift)
|
|
1637
|
-
- End: [`cursorLineBoundaryForward`](https://codemirror.net/6/docs/ref/#commands.cursorLineBoundaryForward) ([`selectLineBoundaryForward`](https://codemirror.net/6/docs/ref/#commands.selectLineBoundaryForward) with Shift)
|
|
1638
|
-
- Ctrl-Home (Cmd-Home on macOS): [`cursorDocStart`](https://codemirror.net/6/docs/ref/#commands.cursorDocStart) ([`selectDocStart`](https://codemirror.net/6/docs/ref/#commands.selectDocStart) with Shift)
|
|
1639
|
-
- Ctrl-End (Cmd-Home on macOS): [`cursorDocEnd`](https://codemirror.net/6/docs/ref/#commands.cursorDocEnd) ([`selectDocEnd`](https://codemirror.net/6/docs/ref/#commands.selectDocEnd) with Shift)
|
|
1640
|
-
- Enter: [`insertNewlineAndIndent`](https://codemirror.net/6/docs/ref/#commands.insertNewlineAndIndent)
|
|
1641
|
-
- Ctrl-a (Cmd-a on macOS): [`selectAll`](https://codemirror.net/6/docs/ref/#commands.selectAll)
|
|
1642
|
-
- Backspace: [`deleteCharBackward`](https://codemirror.net/6/docs/ref/#commands.deleteCharBackward)
|
|
1643
|
-
- Delete: [`deleteCharForward`](https://codemirror.net/6/docs/ref/#commands.deleteCharForward)
|
|
1644
|
-
- Ctrl-Backspace (Alt-Backspace on macOS): [`deleteGroupBackward`](https://codemirror.net/6/docs/ref/#commands.deleteGroupBackward)
|
|
1645
|
-
- Ctrl-Delete (Alt-Delete on macOS): [`deleteGroupForward`](https://codemirror.net/6/docs/ref/#commands.deleteGroupForward)
|
|
1646
|
-
- Cmd-Backspace (macOS): [`deleteToLineStart`](https://codemirror.net/6/docs/ref/#commands.deleteToLineStart).
|
|
1647
|
-
- Cmd-Delete (macOS): [`deleteToLineEnd`](https://codemirror.net/6/docs/ref/#commands.deleteToLineEnd).
|
|
1648
|
-
*/
|
|
1649
|
-
const standardKeymap = /*@__PURE__*/[{
|
|
1650
|
-
key: "ArrowLeft",
|
|
1651
|
-
run: cursorCharLeft,
|
|
1652
|
-
shift: selectCharLeft,
|
|
1653
|
-
preventDefault: true
|
|
1654
|
-
}, {
|
|
1655
|
-
key: "Mod-ArrowLeft",
|
|
1656
|
-
mac: "Alt-ArrowLeft",
|
|
1657
|
-
run: cursorGroupLeft,
|
|
1658
|
-
shift: selectGroupLeft,
|
|
1659
|
-
preventDefault: true
|
|
1660
|
-
}, {
|
|
1661
|
-
mac: "Cmd-ArrowLeft",
|
|
1662
|
-
run: cursorLineBoundaryLeft,
|
|
1663
|
-
shift: selectLineBoundaryLeft,
|
|
1664
|
-
preventDefault: true
|
|
1665
|
-
}, {
|
|
1666
|
-
key: "ArrowRight",
|
|
1667
|
-
run: cursorCharRight,
|
|
1668
|
-
shift: selectCharRight,
|
|
1669
|
-
preventDefault: true
|
|
1670
|
-
}, {
|
|
1671
|
-
key: "Mod-ArrowRight",
|
|
1672
|
-
mac: "Alt-ArrowRight",
|
|
1673
|
-
run: cursorGroupRight,
|
|
1674
|
-
shift: selectGroupRight,
|
|
1675
|
-
preventDefault: true
|
|
1676
|
-
}, {
|
|
1677
|
-
mac: "Cmd-ArrowRight",
|
|
1678
|
-
run: cursorLineBoundaryRight,
|
|
1679
|
-
shift: selectLineBoundaryRight,
|
|
1680
|
-
preventDefault: true
|
|
1681
|
-
}, {
|
|
1682
|
-
key: "ArrowUp",
|
|
1683
|
-
run: cursorLineUp,
|
|
1684
|
-
shift: selectLineUp,
|
|
1685
|
-
preventDefault: true
|
|
1686
|
-
}, {
|
|
1687
|
-
mac: "Cmd-ArrowUp",
|
|
1688
|
-
run: cursorDocStart,
|
|
1689
|
-
shift: selectDocStart
|
|
1690
|
-
}, {
|
|
1691
|
-
mac: "Ctrl-ArrowUp",
|
|
1692
|
-
run: cursorPageUp,
|
|
1693
|
-
shift: selectPageUp
|
|
1694
|
-
}, {
|
|
1695
|
-
key: "ArrowDown",
|
|
1696
|
-
run: cursorLineDown,
|
|
1697
|
-
shift: selectLineDown,
|
|
1698
|
-
preventDefault: true
|
|
1699
|
-
}, {
|
|
1700
|
-
mac: "Cmd-ArrowDown",
|
|
1701
|
-
run: cursorDocEnd,
|
|
1702
|
-
shift: selectDocEnd
|
|
1703
|
-
}, {
|
|
1704
|
-
mac: "Ctrl-ArrowDown",
|
|
1705
|
-
run: cursorPageDown,
|
|
1706
|
-
shift: selectPageDown
|
|
1707
|
-
}, {
|
|
1708
|
-
key: "PageUp",
|
|
1709
|
-
run: cursorPageUp,
|
|
1710
|
-
shift: selectPageUp
|
|
1711
|
-
}, {
|
|
1712
|
-
key: "PageDown",
|
|
1713
|
-
run: cursorPageDown,
|
|
1714
|
-
shift: selectPageDown
|
|
1715
|
-
}, {
|
|
1716
|
-
key: "Home",
|
|
1717
|
-
run: cursorLineBoundaryBackward,
|
|
1718
|
-
shift: selectLineBoundaryBackward,
|
|
1719
|
-
preventDefault: true
|
|
1720
|
-
}, {
|
|
1721
|
-
key: "Mod-Home",
|
|
1722
|
-
run: cursorDocStart,
|
|
1723
|
-
shift: selectDocStart
|
|
1724
|
-
}, {
|
|
1725
|
-
key: "End",
|
|
1726
|
-
run: cursorLineBoundaryForward,
|
|
1727
|
-
shift: selectLineBoundaryForward,
|
|
1728
|
-
preventDefault: true
|
|
1729
|
-
}, {
|
|
1730
|
-
key: "Mod-End",
|
|
1731
|
-
run: cursorDocEnd,
|
|
1732
|
-
shift: selectDocEnd
|
|
1733
|
-
}, {
|
|
1734
|
-
key: "Enter",
|
|
1735
|
-
run: insertNewlineAndIndent
|
|
1736
|
-
}, {
|
|
1737
|
-
key: "Mod-a",
|
|
1738
|
-
run: selectAll
|
|
1739
|
-
}, {
|
|
1740
|
-
key: "Backspace",
|
|
1741
|
-
run: deleteCharBackward,
|
|
1742
|
-
shift: deleteCharBackward
|
|
1743
|
-
}, {
|
|
1744
|
-
key: "Delete",
|
|
1745
|
-
run: deleteCharForward
|
|
1746
|
-
}, {
|
|
1747
|
-
key: "Mod-Backspace",
|
|
1748
|
-
mac: "Alt-Backspace",
|
|
1749
|
-
run: deleteGroupBackward
|
|
1750
|
-
}, {
|
|
1751
|
-
key: "Mod-Delete",
|
|
1752
|
-
mac: "Alt-Delete",
|
|
1753
|
-
run: deleteGroupForward
|
|
1754
|
-
}, {
|
|
1755
|
-
mac: "Mod-Backspace",
|
|
1756
|
-
run: deleteToLineStart
|
|
1757
|
-
}, {
|
|
1758
|
-
mac: "Mod-Delete",
|
|
1759
|
-
run: deleteToLineEnd
|
|
1760
|
-
}].concat( /*@__PURE__*/emacsStyleKeymap.map(b => ({
|
|
1761
|
-
mac: b.key,
|
|
1762
|
-
run: b.run,
|
|
1763
|
-
shift: b.shift
|
|
1764
|
-
})));
|
|
1765
|
-
/**
|
|
1766
|
-
The default keymap. Includes all bindings from
|
|
1767
|
-
[`standardKeymap`](https://codemirror.net/6/docs/ref/#commands.standardKeymap) plus the following:
|
|
1768
|
-
|
|
1769
|
-
- Alt-ArrowLeft (Ctrl-ArrowLeft on macOS): [`cursorSyntaxLeft`](https://codemirror.net/6/docs/ref/#commands.cursorSyntaxLeft) ([`selectSyntaxLeft`](https://codemirror.net/6/docs/ref/#commands.selectSyntaxLeft) with Shift)
|
|
1770
|
-
- Alt-ArrowRight (Ctrl-ArrowRight on macOS): [`cursorSyntaxRight`](https://codemirror.net/6/docs/ref/#commands.cursorSyntaxRight) ([`selectSyntaxRight`](https://codemirror.net/6/docs/ref/#commands.selectSyntaxRight) with Shift)
|
|
1771
|
-
- Alt-ArrowUp: [`moveLineUp`](https://codemirror.net/6/docs/ref/#commands.moveLineUp)
|
|
1772
|
-
- Alt-ArrowDown: [`moveLineDown`](https://codemirror.net/6/docs/ref/#commands.moveLineDown)
|
|
1773
|
-
- Shift-Alt-ArrowUp: [`copyLineUp`](https://codemirror.net/6/docs/ref/#commands.copyLineUp)
|
|
1774
|
-
- Shift-Alt-ArrowDown: [`copyLineDown`](https://codemirror.net/6/docs/ref/#commands.copyLineDown)
|
|
1775
|
-
- Escape: [`simplifySelection`](https://codemirror.net/6/docs/ref/#commands.simplifySelection)
|
|
1776
|
-
- Ctrl-Enter (Comd-Enter on macOS): [`insertBlankLine`](https://codemirror.net/6/docs/ref/#commands.insertBlankLine)
|
|
1777
|
-
- Alt-l (Ctrl-l on macOS): [`selectLine`](https://codemirror.net/6/docs/ref/#commands.selectLine)
|
|
1778
|
-
- Ctrl-i (Cmd-i on macOS): [`selectParentSyntax`](https://codemirror.net/6/docs/ref/#commands.selectParentSyntax)
|
|
1779
|
-
- Ctrl-[ (Cmd-[ on macOS): [`indentLess`](https://codemirror.net/6/docs/ref/#commands.indentLess)
|
|
1780
|
-
- Ctrl-] (Cmd-] on macOS): [`indentMore`](https://codemirror.net/6/docs/ref/#commands.indentMore)
|
|
1781
|
-
- Ctrl-Alt-\\ (Cmd-Alt-\\ on macOS): [`indentSelection`](https://codemirror.net/6/docs/ref/#commands.indentSelection)
|
|
1782
|
-
- Shift-Ctrl-k (Shift-Cmd-k on macOS): [`deleteLine`](https://codemirror.net/6/docs/ref/#commands.deleteLine)
|
|
1783
|
-
- Shift-Ctrl-\\ (Shift-Cmd-\\ on macOS): [`cursorMatchingBracket`](https://codemirror.net/6/docs/ref/#commands.cursorMatchingBracket)
|
|
1784
|
-
- Ctrl-/ (Cmd-/ on macOS): [`toggleComment`](https://codemirror.net/6/docs/ref/#commands.toggleComment).
|
|
1785
|
-
- Shift-Alt-a: [`toggleBlockComment`](https://codemirror.net/6/docs/ref/#commands.toggleBlockComment).
|
|
1786
|
-
*/
|
|
1787
|
-
const defaultKeymap = /*@__PURE__*/[{
|
|
1788
|
-
key: "Alt-ArrowLeft",
|
|
1789
|
-
mac: "Ctrl-ArrowLeft",
|
|
1790
|
-
run: cursorSyntaxLeft,
|
|
1791
|
-
shift: selectSyntaxLeft
|
|
1792
|
-
}, {
|
|
1793
|
-
key: "Alt-ArrowRight",
|
|
1794
|
-
mac: "Ctrl-ArrowRight",
|
|
1795
|
-
run: cursorSyntaxRight,
|
|
1796
|
-
shift: selectSyntaxRight
|
|
1797
|
-
}, {
|
|
1798
|
-
key: "Alt-ArrowUp",
|
|
1799
|
-
run: moveLineUp
|
|
1800
|
-
}, {
|
|
1801
|
-
key: "Shift-Alt-ArrowUp",
|
|
1802
|
-
run: copyLineUp
|
|
1803
|
-
}, {
|
|
1804
|
-
key: "Alt-ArrowDown",
|
|
1805
|
-
run: moveLineDown
|
|
1806
|
-
}, {
|
|
1807
|
-
key: "Shift-Alt-ArrowDown",
|
|
1808
|
-
run: copyLineDown
|
|
1809
|
-
}, {
|
|
1810
|
-
key: "Escape",
|
|
1811
|
-
run: simplifySelection
|
|
1812
|
-
}, {
|
|
1813
|
-
key: "Mod-Enter",
|
|
1814
|
-
run: insertBlankLine
|
|
1815
|
-
}, {
|
|
1816
|
-
key: "Alt-l",
|
|
1817
|
-
mac: "Ctrl-l",
|
|
1818
|
-
run: selectLine
|
|
1819
|
-
}, {
|
|
1820
|
-
key: "Mod-i",
|
|
1821
|
-
run: selectParentSyntax,
|
|
1822
|
-
preventDefault: true
|
|
1823
|
-
}, {
|
|
1824
|
-
key: "Mod-[",
|
|
1825
|
-
run: indentLess
|
|
1826
|
-
}, {
|
|
1827
|
-
key: "Mod-]",
|
|
1828
|
-
run: indentMore
|
|
1829
|
-
}, {
|
|
1830
|
-
key: "Mod-Alt-\\",
|
|
1831
|
-
run: indentSelection
|
|
1832
|
-
}, {
|
|
1833
|
-
key: "Shift-Mod-k",
|
|
1834
|
-
run: deleteLine
|
|
1835
|
-
}, {
|
|
1836
|
-
key: "Shift-Mod-\\",
|
|
1837
|
-
run: cursorMatchingBracket
|
|
1838
|
-
}, {
|
|
1839
|
-
key: "Mod-/",
|
|
1840
|
-
run: toggleComment
|
|
1841
|
-
}, {
|
|
1842
|
-
key: "Alt-A",
|
|
1843
|
-
run: toggleBlockComment
|
|
1844
|
-
}].concat(standardKeymap);
|
|
1845
|
-
/**
|
|
1846
|
-
A binding that binds Tab to [`indentMore`](https://codemirror.net/6/docs/ref/#commands.indentMore) and
|
|
1847
|
-
Shift-Tab to [`indentLess`](https://codemirror.net/6/docs/ref/#commands.indentLess).
|
|
1848
|
-
Please see the [Tab example](../../examples/tab/) before using
|
|
1849
|
-
this.
|
|
1850
|
-
*/
|
|
1851
|
-
const indentWithTab = {
|
|
1852
|
-
key: "Tab",
|
|
1853
|
-
run: indentMore,
|
|
1854
|
-
shift: indentLess
|
|
1855
|
-
};
|
|
1856
|
-
|
|
1857
|
-
function crelt() {
|
|
1858
|
-
var elt = arguments[0];
|
|
1859
|
-
if (typeof elt == "string") elt = document.createElement(elt);
|
|
1860
|
-
var i = 1,
|
|
1861
|
-
next = arguments[1];
|
|
1862
|
-
if (next && typeof next == "object" && next.nodeType == null && !Array.isArray(next)) {
|
|
1863
|
-
for (var name in next) if (Object.prototype.hasOwnProperty.call(next, name)) {
|
|
1864
|
-
var value = next[name];
|
|
1865
|
-
if (typeof value == "string") elt.setAttribute(name, value);else if (value != null) elt[name] = value;
|
|
1866
|
-
}
|
|
1867
|
-
i++;
|
|
1868
|
-
}
|
|
1869
|
-
for (; i < arguments.length; i++) add(elt, arguments[i]);
|
|
1870
|
-
return elt;
|
|
1871
|
-
}
|
|
1872
|
-
function add(elt, child) {
|
|
1873
|
-
if (typeof child == "string") {
|
|
1874
|
-
elt.appendChild(document.createTextNode(child));
|
|
1875
|
-
} else if (child == null) ; else if (child.nodeType != null) {
|
|
1876
|
-
elt.appendChild(child);
|
|
1877
|
-
} else if (Array.isArray(child)) {
|
|
1878
|
-
for (var i = 0; i < child.length; i++) add(elt, child[i]);
|
|
1879
|
-
} else {
|
|
1880
|
-
throw new RangeError("Unsupported child node: " + child);
|
|
1881
|
-
}
|
|
1882
|
-
}
|
|
1883
|
-
|
|
1884
|
-
const basicNormalize = typeof String.prototype.normalize == "function" ? x => x.normalize("NFKD") : x => x;
|
|
1885
|
-
/**
|
|
1886
|
-
A search cursor provides an iterator over text matches in a
|
|
1887
|
-
document.
|
|
1888
|
-
*/
|
|
1889
|
-
class SearchCursor {
|
|
1890
|
-
/**
|
|
1891
|
-
Create a text cursor. The query is the search string, `from` to
|
|
1892
|
-
`to` provides the region to search.
|
|
1893
|
-
|
|
1894
|
-
When `normalize` is given, it will be called, on both the query
|
|
1895
|
-
string and the content it is matched against, before comparing.
|
|
1896
|
-
You can, for example, create a case-insensitive search by
|
|
1897
|
-
passing `s => s.toLowerCase()`.
|
|
1898
|
-
|
|
1899
|
-
Text is always normalized with
|
|
1900
|
-
[`.normalize("NFKD")`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize)
|
|
1901
|
-
(when supported).
|
|
1902
|
-
*/
|
|
1903
|
-
constructor(text, query) {
|
|
1904
|
-
let from = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
1905
|
-
let to = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : text.length;
|
|
1906
|
-
let normalize = arguments.length > 4 ? arguments[4] : undefined;
|
|
1907
|
-
let test = arguments.length > 5 ? arguments[5] : undefined;
|
|
1908
|
-
this.test = test;
|
|
1909
|
-
/**
|
|
1910
|
-
The current match (only holds a meaningful value after
|
|
1911
|
-
[`next`](https://codemirror.net/6/docs/ref/#search.SearchCursor.next) has been called and when
|
|
1912
|
-
`done` is false).
|
|
1913
|
-
*/
|
|
1914
|
-
this.value = {
|
|
1915
|
-
from: 0,
|
|
1916
|
-
to: 0
|
|
1917
|
-
};
|
|
1918
|
-
/**
|
|
1919
|
-
Whether the end of the iterated region has been reached.
|
|
1920
|
-
*/
|
|
1921
|
-
this.done = false;
|
|
1922
|
-
this.matches = [];
|
|
1923
|
-
this.buffer = "";
|
|
1924
|
-
this.bufferPos = 0;
|
|
1925
|
-
this.iter = text.iterRange(from, to);
|
|
1926
|
-
this.bufferStart = from;
|
|
1927
|
-
this.normalize = normalize ? x => normalize(basicNormalize(x)) : basicNormalize;
|
|
1928
|
-
this.query = this.normalize(query);
|
|
1929
|
-
}
|
|
1930
|
-
peek() {
|
|
1931
|
-
if (this.bufferPos == this.buffer.length) {
|
|
1932
|
-
this.bufferStart += this.buffer.length;
|
|
1933
|
-
this.iter.next();
|
|
1934
|
-
if (this.iter.done) return -1;
|
|
1935
|
-
this.bufferPos = 0;
|
|
1936
|
-
this.buffer = this.iter.value;
|
|
1937
|
-
}
|
|
1938
|
-
return codePointAt(this.buffer, this.bufferPos);
|
|
1939
|
-
}
|
|
1940
|
-
/**
|
|
1941
|
-
Look for the next match. Updates the iterator's
|
|
1942
|
-
[`value`](https://codemirror.net/6/docs/ref/#search.SearchCursor.value) and
|
|
1943
|
-
[`done`](https://codemirror.net/6/docs/ref/#search.SearchCursor.done) properties. Should be called
|
|
1944
|
-
at least once before using the cursor.
|
|
1945
|
-
*/
|
|
1946
|
-
next() {
|
|
1947
|
-
while (this.matches.length) this.matches.pop();
|
|
1948
|
-
return this.nextOverlapping();
|
|
1949
|
-
}
|
|
1950
|
-
/**
|
|
1951
|
-
The `next` method will ignore matches that partially overlap a
|
|
1952
|
-
previous match. This method behaves like `next`, but includes
|
|
1953
|
-
such matches.
|
|
1954
|
-
*/
|
|
1955
|
-
nextOverlapping() {
|
|
1956
|
-
for (;;) {
|
|
1957
|
-
let next = this.peek();
|
|
1958
|
-
if (next < 0) {
|
|
1959
|
-
this.done = true;
|
|
1960
|
-
return this;
|
|
1961
|
-
}
|
|
1962
|
-
let str = fromCodePoint(next),
|
|
1963
|
-
start = this.bufferStart + this.bufferPos;
|
|
1964
|
-
this.bufferPos += codePointSize(next);
|
|
1965
|
-
let norm = this.normalize(str);
|
|
1966
|
-
for (let i = 0, pos = start;; i++) {
|
|
1967
|
-
let code = norm.charCodeAt(i);
|
|
1968
|
-
let match = this.match(code, pos);
|
|
1969
|
-
if (match) {
|
|
1970
|
-
this.value = match;
|
|
1971
|
-
return this;
|
|
1972
|
-
}
|
|
1973
|
-
if (i == norm.length - 1) break;
|
|
1974
|
-
if (pos == start && i < str.length && str.charCodeAt(i) == code) pos++;
|
|
1975
|
-
}
|
|
1976
|
-
}
|
|
1977
|
-
}
|
|
1978
|
-
match(code, pos) {
|
|
1979
|
-
let match = null;
|
|
1980
|
-
for (let i = 0; i < this.matches.length; i += 2) {
|
|
1981
|
-
let index = this.matches[i],
|
|
1982
|
-
keep = false;
|
|
1983
|
-
if (this.query.charCodeAt(index) == code) {
|
|
1984
|
-
if (index == this.query.length - 1) {
|
|
1985
|
-
match = {
|
|
1986
|
-
from: this.matches[i + 1],
|
|
1987
|
-
to: pos + 1
|
|
1988
|
-
};
|
|
1989
|
-
} else {
|
|
1990
|
-
this.matches[i]++;
|
|
1991
|
-
keep = true;
|
|
1992
|
-
}
|
|
1993
|
-
}
|
|
1994
|
-
if (!keep) {
|
|
1995
|
-
this.matches.splice(i, 2);
|
|
1996
|
-
i -= 2;
|
|
1997
|
-
}
|
|
1998
|
-
}
|
|
1999
|
-
if (this.query.charCodeAt(0) == code) {
|
|
2000
|
-
if (this.query.length == 1) match = {
|
|
2001
|
-
from: pos,
|
|
2002
|
-
to: pos + 1
|
|
2003
|
-
};else this.matches.push(1, pos);
|
|
2004
|
-
}
|
|
2005
|
-
if (match && this.test && !this.test(match.from, match.to, this.buffer, this.bufferPos)) match = null;
|
|
2006
|
-
return match;
|
|
2007
|
-
}
|
|
2008
|
-
}
|
|
2009
|
-
if (typeof Symbol != "undefined") SearchCursor.prototype[Symbol.iterator] = function () {
|
|
2010
|
-
return this;
|
|
2011
|
-
};
|
|
2012
|
-
const empty = {
|
|
2013
|
-
from: -1,
|
|
2014
|
-
to: -1,
|
|
2015
|
-
match: /*@__PURE__*/ /.*/.exec("")
|
|
2016
|
-
};
|
|
2017
|
-
const baseFlags = "gm" + (/x/.unicode == null ? "" : "u");
|
|
2018
|
-
/**
|
|
2019
|
-
This class is similar to [`SearchCursor`](https://codemirror.net/6/docs/ref/#search.SearchCursor)
|
|
2020
|
-
but searches for a regular expression pattern instead of a plain
|
|
2021
|
-
string.
|
|
2022
|
-
*/
|
|
2023
|
-
class RegExpCursor {
|
|
2024
|
-
/**
|
|
2025
|
-
Create a cursor that will search the given range in the given
|
|
2026
|
-
document. `query` should be the raw pattern (as you'd pass it to
|
|
2027
|
-
`new RegExp`).
|
|
2028
|
-
*/
|
|
2029
|
-
constructor(text, query, options) {
|
|
2030
|
-
let from = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
2031
|
-
let to = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : text.length;
|
|
2032
|
-
this.text = text;
|
|
2033
|
-
this.to = to;
|
|
2034
|
-
this.curLine = "";
|
|
2035
|
-
/**
|
|
2036
|
-
Set to `true` when the cursor has reached the end of the search
|
|
2037
|
-
range.
|
|
2038
|
-
*/
|
|
2039
|
-
this.done = false;
|
|
2040
|
-
/**
|
|
2041
|
-
Will contain an object with the extent of the match and the
|
|
2042
|
-
match object when [`next`](https://codemirror.net/6/docs/ref/#search.RegExpCursor.next)
|
|
2043
|
-
sucessfully finds a match.
|
|
2044
|
-
*/
|
|
2045
|
-
this.value = empty;
|
|
2046
|
-
if (/\\[sWDnr]|\n|\r|\[\^/.test(query)) return new MultilineRegExpCursor(text, query, options, from, to);
|
|
2047
|
-
this.re = new RegExp(query, baseFlags + ((options === null || options === void 0 ? void 0 : options.ignoreCase) ? "i" : ""));
|
|
2048
|
-
this.test = options === null || options === void 0 ? void 0 : options.test;
|
|
2049
|
-
this.iter = text.iter();
|
|
2050
|
-
let startLine = text.lineAt(from);
|
|
2051
|
-
this.curLineStart = startLine.from;
|
|
2052
|
-
this.matchPos = toCharEnd(text, from);
|
|
2053
|
-
this.getLine(this.curLineStart);
|
|
2054
|
-
}
|
|
2055
|
-
getLine(skip) {
|
|
2056
|
-
this.iter.next(skip);
|
|
2057
|
-
if (this.iter.lineBreak) {
|
|
2058
|
-
this.curLine = "";
|
|
2059
|
-
} else {
|
|
2060
|
-
this.curLine = this.iter.value;
|
|
2061
|
-
if (this.curLineStart + this.curLine.length > this.to) this.curLine = this.curLine.slice(0, this.to - this.curLineStart);
|
|
2062
|
-
this.iter.next();
|
|
2063
|
-
}
|
|
2064
|
-
}
|
|
2065
|
-
nextLine() {
|
|
2066
|
-
this.curLineStart = this.curLineStart + this.curLine.length + 1;
|
|
2067
|
-
if (this.curLineStart > this.to) this.curLine = "";else this.getLine(0);
|
|
2068
|
-
}
|
|
2069
|
-
/**
|
|
2070
|
-
Move to the next match, if there is one.
|
|
2071
|
-
*/
|
|
2072
|
-
next() {
|
|
2073
|
-
for (let off = this.matchPos - this.curLineStart;;) {
|
|
2074
|
-
this.re.lastIndex = off;
|
|
2075
|
-
let match = this.matchPos <= this.to && this.re.exec(this.curLine);
|
|
2076
|
-
if (match) {
|
|
2077
|
-
let from = this.curLineStart + match.index,
|
|
2078
|
-
to = from + match[0].length;
|
|
2079
|
-
this.matchPos = toCharEnd(this.text, to + (from == to ? 1 : 0));
|
|
2080
|
-
if (from == this.curLineStart + this.curLine.length) this.nextLine();
|
|
2081
|
-
if ((from < to || from > this.value.to) && (!this.test || this.test(from, to, match))) {
|
|
2082
|
-
this.value = {
|
|
2083
|
-
from,
|
|
2084
|
-
to,
|
|
2085
|
-
match
|
|
2086
|
-
};
|
|
2087
|
-
return this;
|
|
2088
|
-
}
|
|
2089
|
-
off = this.matchPos - this.curLineStart;
|
|
2090
|
-
} else if (this.curLineStart + this.curLine.length < this.to) {
|
|
2091
|
-
this.nextLine();
|
|
2092
|
-
off = 0;
|
|
2093
|
-
} else {
|
|
2094
|
-
this.done = true;
|
|
2095
|
-
return this;
|
|
2096
|
-
}
|
|
2097
|
-
}
|
|
2098
|
-
}
|
|
2099
|
-
}
|
|
2100
|
-
const flattened = /*@__PURE__*/new WeakMap();
|
|
2101
|
-
// Reusable (partially) flattened document strings
|
|
2102
|
-
class FlattenedDoc {
|
|
2103
|
-
constructor(from, text) {
|
|
2104
|
-
this.from = from;
|
|
2105
|
-
this.text = text;
|
|
2106
|
-
}
|
|
2107
|
-
get to() {
|
|
2108
|
-
return this.from + this.text.length;
|
|
2109
|
-
}
|
|
2110
|
-
static get(doc, from, to) {
|
|
2111
|
-
let cached = flattened.get(doc);
|
|
2112
|
-
if (!cached || cached.from >= to || cached.to <= from) {
|
|
2113
|
-
let flat = new FlattenedDoc(from, doc.sliceString(from, to));
|
|
2114
|
-
flattened.set(doc, flat);
|
|
2115
|
-
return flat;
|
|
2116
|
-
}
|
|
2117
|
-
if (cached.from == from && cached.to == to) return cached;
|
|
2118
|
-
let {
|
|
2119
|
-
text,
|
|
2120
|
-
from: cachedFrom
|
|
2121
|
-
} = cached;
|
|
2122
|
-
if (cachedFrom > from) {
|
|
2123
|
-
text = doc.sliceString(from, cachedFrom) + text;
|
|
2124
|
-
cachedFrom = from;
|
|
2125
|
-
}
|
|
2126
|
-
if (cached.to < to) text += doc.sliceString(cached.to, to);
|
|
2127
|
-
flattened.set(doc, new FlattenedDoc(cachedFrom, text));
|
|
2128
|
-
return new FlattenedDoc(from, text.slice(from - cachedFrom, to - cachedFrom));
|
|
2129
|
-
}
|
|
2130
|
-
}
|
|
2131
|
-
class MultilineRegExpCursor {
|
|
2132
|
-
constructor(text, query, options, from, to) {
|
|
2133
|
-
this.text = text;
|
|
2134
|
-
this.to = to;
|
|
2135
|
-
this.done = false;
|
|
2136
|
-
this.value = empty;
|
|
2137
|
-
this.matchPos = toCharEnd(text, from);
|
|
2138
|
-
this.re = new RegExp(query, baseFlags + ((options === null || options === void 0 ? void 0 : options.ignoreCase) ? "i" : ""));
|
|
2139
|
-
this.test = options === null || options === void 0 ? void 0 : options.test;
|
|
2140
|
-
this.flat = FlattenedDoc.get(text, from, this.chunkEnd(from + 5000 /* Chunk.Base */));
|
|
2141
|
-
}
|
|
2142
|
-
|
|
2143
|
-
chunkEnd(pos) {
|
|
2144
|
-
return pos >= this.to ? this.to : this.text.lineAt(pos).to;
|
|
2145
|
-
}
|
|
2146
|
-
next() {
|
|
2147
|
-
for (;;) {
|
|
2148
|
-
let off = this.re.lastIndex = this.matchPos - this.flat.from;
|
|
2149
|
-
let match = this.re.exec(this.flat.text);
|
|
2150
|
-
// Skip empty matches directly after the last match
|
|
2151
|
-
if (match && !match[0] && match.index == off) {
|
|
2152
|
-
this.re.lastIndex = off + 1;
|
|
2153
|
-
match = this.re.exec(this.flat.text);
|
|
2154
|
-
}
|
|
2155
|
-
if (match) {
|
|
2156
|
-
let from = this.flat.from + match.index,
|
|
2157
|
-
to = from + match[0].length;
|
|
2158
|
-
// If a match goes almost to the end of a noncomplete chunk, try
|
|
2159
|
-
// again, since it'll likely be able to match more
|
|
2160
|
-
if ((this.flat.to >= this.to || match.index + match[0].length <= this.flat.text.length - 10) && (!this.test || this.test(from, to, match))) {
|
|
2161
|
-
this.value = {
|
|
2162
|
-
from,
|
|
2163
|
-
to,
|
|
2164
|
-
match
|
|
2165
|
-
};
|
|
2166
|
-
this.matchPos = toCharEnd(this.text, to + (from == to ? 1 : 0));
|
|
2167
|
-
return this;
|
|
2168
|
-
}
|
|
2169
|
-
}
|
|
2170
|
-
if (this.flat.to == this.to) {
|
|
2171
|
-
this.done = true;
|
|
2172
|
-
return this;
|
|
2173
|
-
}
|
|
2174
|
-
// Grow the flattened doc
|
|
2175
|
-
this.flat = FlattenedDoc.get(this.text, this.flat.from, this.chunkEnd(this.flat.from + this.flat.text.length * 2));
|
|
2176
|
-
}
|
|
2177
|
-
}
|
|
2178
|
-
}
|
|
2179
|
-
if (typeof Symbol != "undefined") {
|
|
2180
|
-
RegExpCursor.prototype[Symbol.iterator] = MultilineRegExpCursor.prototype[Symbol.iterator] = function () {
|
|
2181
|
-
return this;
|
|
2182
|
-
};
|
|
2183
|
-
}
|
|
2184
|
-
function validRegExp(source) {
|
|
2185
|
-
try {
|
|
2186
|
-
new RegExp(source, baseFlags);
|
|
2187
|
-
return true;
|
|
2188
|
-
} catch (_a) {
|
|
2189
|
-
return false;
|
|
2190
|
-
}
|
|
2191
|
-
}
|
|
2192
|
-
function toCharEnd(text, pos) {
|
|
2193
|
-
if (pos >= text.length) return pos;
|
|
2194
|
-
let line = text.lineAt(pos),
|
|
2195
|
-
next;
|
|
2196
|
-
while (pos < line.to && (next = line.text.charCodeAt(pos - line.from)) >= 0xDC00 && next < 0xE000) pos++;
|
|
2197
|
-
return pos;
|
|
2198
|
-
}
|
|
2199
|
-
function createLineDialog(view) {
|
|
2200
|
-
let input = crelt("input", {
|
|
2201
|
-
class: "cm-textfield",
|
|
2202
|
-
name: "line"
|
|
2203
|
-
});
|
|
2204
|
-
let dom = crelt("form", {
|
|
2205
|
-
class: "cm-gotoLine",
|
|
2206
|
-
onkeydown: event => {
|
|
2207
|
-
if (event.keyCode == 27) {
|
|
2208
|
-
// Escape
|
|
2209
|
-
event.preventDefault();
|
|
2210
|
-
view.dispatch({
|
|
2211
|
-
effects: dialogEffect.of(false)
|
|
2212
|
-
});
|
|
2213
|
-
view.focus();
|
|
2214
|
-
} else if (event.keyCode == 13) {
|
|
2215
|
-
// Enter
|
|
2216
|
-
event.preventDefault();
|
|
2217
|
-
go();
|
|
2218
|
-
}
|
|
2219
|
-
},
|
|
2220
|
-
onsubmit: event => {
|
|
2221
|
-
event.preventDefault();
|
|
2222
|
-
go();
|
|
2223
|
-
}
|
|
2224
|
-
}, crelt("label", view.state.phrase("Go to line"), ": ", input), " ", crelt("button", {
|
|
2225
|
-
class: "cm-button",
|
|
2226
|
-
type: "submit"
|
|
2227
|
-
}, view.state.phrase("go")));
|
|
2228
|
-
function go() {
|
|
2229
|
-
let match = /^([+-])?(\d+)?(:\d+)?(%)?$/.exec(input.value);
|
|
2230
|
-
if (!match) return;
|
|
2231
|
-
let {
|
|
2232
|
-
state
|
|
2233
|
-
} = view,
|
|
2234
|
-
startLine = state.doc.lineAt(state.selection.main.head);
|
|
2235
|
-
let [, sign, ln, cl, percent] = match;
|
|
2236
|
-
let col = cl ? +cl.slice(1) : 0;
|
|
2237
|
-
let line = ln ? +ln : startLine.number;
|
|
2238
|
-
if (ln && percent) {
|
|
2239
|
-
let pc = line / 100;
|
|
2240
|
-
if (sign) pc = pc * (sign == "-" ? -1 : 1) + startLine.number / state.doc.lines;
|
|
2241
|
-
line = Math.round(state.doc.lines * pc);
|
|
2242
|
-
} else if (ln && sign) {
|
|
2243
|
-
line = line * (sign == "-" ? -1 : 1) + startLine.number;
|
|
2244
|
-
}
|
|
2245
|
-
let docLine = state.doc.line(Math.max(1, Math.min(state.doc.lines, line)));
|
|
2246
|
-
view.dispatch({
|
|
2247
|
-
effects: dialogEffect.of(false),
|
|
2248
|
-
selection: EditorSelection.cursor(docLine.from + Math.max(0, Math.min(col, docLine.length))),
|
|
2249
|
-
scrollIntoView: true
|
|
2250
|
-
});
|
|
2251
|
-
view.focus();
|
|
2252
|
-
}
|
|
2253
|
-
return {
|
|
2254
|
-
dom
|
|
2255
|
-
};
|
|
2256
|
-
}
|
|
2257
|
-
const dialogEffect = /*@__PURE__*/StateEffect.define();
|
|
2258
|
-
const dialogField = /*@__PURE__*/StateField.define({
|
|
2259
|
-
create() {
|
|
2260
|
-
return true;
|
|
2261
|
-
},
|
|
2262
|
-
update(value, tr) {
|
|
2263
|
-
for (let e of tr.effects) if (e.is(dialogEffect)) value = e.value;
|
|
2264
|
-
return value;
|
|
2265
|
-
},
|
|
2266
|
-
provide: f => showPanel.from(f, val => val ? createLineDialog : null)
|
|
2267
|
-
});
|
|
2268
|
-
/**
|
|
2269
|
-
Command that shows a dialog asking the user for a line number, and
|
|
2270
|
-
when a valid position is provided, moves the cursor to that line.
|
|
2271
|
-
|
|
2272
|
-
Supports line numbers, relative line offsets prefixed with `+` or
|
|
2273
|
-
`-`, document percentages suffixed with `%`, and an optional
|
|
2274
|
-
column position by adding `:` and a second number after the line
|
|
2275
|
-
number.
|
|
2276
|
-
*/
|
|
2277
|
-
const gotoLine = view => {
|
|
2278
|
-
let panel = getPanel(view, createLineDialog);
|
|
2279
|
-
if (!panel) {
|
|
2280
|
-
let effects = [dialogEffect.of(true)];
|
|
2281
|
-
if (view.state.field(dialogField, false) == null) effects.push(StateEffect.appendConfig.of([dialogField, baseTheme$1]));
|
|
2282
|
-
view.dispatch({
|
|
2283
|
-
effects
|
|
2284
|
-
});
|
|
2285
|
-
panel = getPanel(view, createLineDialog);
|
|
2286
|
-
}
|
|
2287
|
-
if (panel) panel.dom.querySelector("input").focus();
|
|
2288
|
-
return true;
|
|
2289
|
-
};
|
|
2290
|
-
const baseTheme$1 = /*@__PURE__*/EditorView.baseTheme({
|
|
2291
|
-
".cm-panel.cm-gotoLine": {
|
|
2292
|
-
padding: "2px 6px 4px",
|
|
2293
|
-
"& label": {
|
|
2294
|
-
fontSize: "80%"
|
|
2295
|
-
}
|
|
2296
|
-
}
|
|
2297
|
-
});
|
|
2298
|
-
const defaultHighlightOptions = {
|
|
2299
|
-
highlightWordAroundCursor: false,
|
|
2300
|
-
minSelectionLength: 1,
|
|
2301
|
-
maxMatches: 100,
|
|
2302
|
-
wholeWords: false
|
|
2303
|
-
};
|
|
2304
|
-
const highlightConfig = /*@__PURE__*/Facet.define({
|
|
2305
|
-
combine(options) {
|
|
2306
|
-
return combineConfig(options, defaultHighlightOptions, {
|
|
2307
|
-
highlightWordAroundCursor: (a, b) => a || b,
|
|
2308
|
-
minSelectionLength: Math.min,
|
|
2309
|
-
maxMatches: Math.min
|
|
2310
|
-
});
|
|
2311
|
-
}
|
|
2312
|
-
});
|
|
2313
|
-
/**
|
|
2314
|
-
This extension highlights text that matches the selection. It uses
|
|
2315
|
-
the `"cm-selectionMatch"` class for the highlighting. When
|
|
2316
|
-
`highlightWordAroundCursor` is enabled, the word at the cursor
|
|
2317
|
-
itself will be highlighted with `"cm-selectionMatch-main"`.
|
|
2318
|
-
*/
|
|
2319
|
-
function highlightSelectionMatches(options) {
|
|
2320
|
-
let ext = [defaultTheme, matchHighlighter];
|
|
2321
|
-
if (options) ext.push(highlightConfig.of(options));
|
|
2322
|
-
return ext;
|
|
2323
|
-
}
|
|
2324
|
-
const matchDeco = /*@__PURE__*/Decoration.mark({
|
|
2325
|
-
class: "cm-selectionMatch"
|
|
2326
|
-
});
|
|
2327
|
-
const mainMatchDeco = /*@__PURE__*/Decoration.mark({
|
|
2328
|
-
class: "cm-selectionMatch cm-selectionMatch-main"
|
|
2329
|
-
});
|
|
2330
|
-
// Whether the characters directly outside the given positions are non-word characters
|
|
2331
|
-
function insideWordBoundaries(check, state, from, to) {
|
|
2332
|
-
return (from == 0 || check(state.sliceDoc(from - 1, from)) != CharCategory.Word) && (to == state.doc.length || check(state.sliceDoc(to, to + 1)) != CharCategory.Word);
|
|
2333
|
-
}
|
|
2334
|
-
// Whether the characters directly at the given positions are word characters
|
|
2335
|
-
function insideWord(check, state, from, to) {
|
|
2336
|
-
return check(state.sliceDoc(from, from + 1)) == CharCategory.Word && check(state.sliceDoc(to - 1, to)) == CharCategory.Word;
|
|
2337
|
-
}
|
|
2338
|
-
const matchHighlighter = /*@__PURE__*/ViewPlugin.fromClass(class {
|
|
2339
|
-
constructor(view) {
|
|
2340
|
-
this.decorations = this.getDeco(view);
|
|
2341
|
-
}
|
|
2342
|
-
update(update) {
|
|
2343
|
-
if (update.selectionSet || update.docChanged || update.viewportChanged) this.decorations = this.getDeco(update.view);
|
|
2344
|
-
}
|
|
2345
|
-
getDeco(view) {
|
|
2346
|
-
let conf = view.state.facet(highlightConfig);
|
|
2347
|
-
let {
|
|
2348
|
-
state
|
|
2349
|
-
} = view,
|
|
2350
|
-
sel = state.selection;
|
|
2351
|
-
if (sel.ranges.length > 1) return Decoration.none;
|
|
2352
|
-
let range = sel.main,
|
|
2353
|
-
query,
|
|
2354
|
-
check = null;
|
|
2355
|
-
if (range.empty) {
|
|
2356
|
-
if (!conf.highlightWordAroundCursor) return Decoration.none;
|
|
2357
|
-
let word = state.wordAt(range.head);
|
|
2358
|
-
if (!word) return Decoration.none;
|
|
2359
|
-
check = state.charCategorizer(range.head);
|
|
2360
|
-
query = state.sliceDoc(word.from, word.to);
|
|
2361
|
-
} else {
|
|
2362
|
-
let len = range.to - range.from;
|
|
2363
|
-
if (len < conf.minSelectionLength || len > 200) return Decoration.none;
|
|
2364
|
-
if (conf.wholeWords) {
|
|
2365
|
-
query = state.sliceDoc(range.from, range.to); // TODO: allow and include leading/trailing space?
|
|
2366
|
-
check = state.charCategorizer(range.head);
|
|
2367
|
-
if (!(insideWordBoundaries(check, state, range.from, range.to) && insideWord(check, state, range.from, range.to))) return Decoration.none;
|
|
2368
|
-
} else {
|
|
2369
|
-
query = state.sliceDoc(range.from, range.to).trim();
|
|
2370
|
-
if (!query) return Decoration.none;
|
|
2371
|
-
}
|
|
2372
|
-
}
|
|
2373
|
-
let deco = [];
|
|
2374
|
-
for (let part of view.visibleRanges) {
|
|
2375
|
-
let cursor = new SearchCursor(state.doc, query, part.from, part.to);
|
|
2376
|
-
while (!cursor.next().done) {
|
|
2377
|
-
let {
|
|
2378
|
-
from,
|
|
2379
|
-
to
|
|
2380
|
-
} = cursor.value;
|
|
2381
|
-
if (!check || insideWordBoundaries(check, state, from, to)) {
|
|
2382
|
-
if (range.empty && from <= range.from && to >= range.to) deco.push(mainMatchDeco.range(from, to));else if (from >= range.to || to <= range.from) deco.push(matchDeco.range(from, to));
|
|
2383
|
-
if (deco.length > conf.maxMatches) return Decoration.none;
|
|
2384
|
-
}
|
|
2385
|
-
}
|
|
2386
|
-
}
|
|
2387
|
-
return Decoration.set(deco);
|
|
2388
|
-
}
|
|
2389
|
-
}, {
|
|
2390
|
-
decorations: v => v.decorations
|
|
2391
|
-
});
|
|
2392
|
-
const defaultTheme = /*@__PURE__*/EditorView.baseTheme({
|
|
2393
|
-
".cm-selectionMatch": {
|
|
2394
|
-
backgroundColor: "#99ff7780"
|
|
2395
|
-
},
|
|
2396
|
-
".cm-searchMatch .cm-selectionMatch": {
|
|
2397
|
-
backgroundColor: "transparent"
|
|
2398
|
-
}
|
|
2399
|
-
});
|
|
2400
|
-
// Select the words around the cursors.
|
|
2401
|
-
const selectWord = _ref => {
|
|
2402
|
-
let {
|
|
2403
|
-
state,
|
|
2404
|
-
dispatch
|
|
2405
|
-
} = _ref;
|
|
2406
|
-
let {
|
|
2407
|
-
selection
|
|
2408
|
-
} = state;
|
|
2409
|
-
let newSel = EditorSelection.create(selection.ranges.map(range => state.wordAt(range.head) || EditorSelection.cursor(range.head)), selection.mainIndex);
|
|
2410
|
-
if (newSel.eq(selection)) return false;
|
|
2411
|
-
dispatch(state.update({
|
|
2412
|
-
selection: newSel
|
|
2413
|
-
}));
|
|
2414
|
-
return true;
|
|
2415
|
-
};
|
|
2416
|
-
// Find next occurrence of query relative to last cursor. Wrap around
|
|
2417
|
-
// the document if there are no more matches.
|
|
2418
|
-
function findNextOccurrence(state, query) {
|
|
2419
|
-
let {
|
|
2420
|
-
main,
|
|
2421
|
-
ranges
|
|
2422
|
-
} = state.selection;
|
|
2423
|
-
let word = state.wordAt(main.head),
|
|
2424
|
-
fullWord = word && word.from == main.from && word.to == main.to;
|
|
2425
|
-
for (let cycled = false, cursor = new SearchCursor(state.doc, query, ranges[ranges.length - 1].to);;) {
|
|
2426
|
-
cursor.next();
|
|
2427
|
-
if (cursor.done) {
|
|
2428
|
-
if (cycled) return null;
|
|
2429
|
-
cursor = new SearchCursor(state.doc, query, 0, Math.max(0, ranges[ranges.length - 1].from - 1));
|
|
2430
|
-
cycled = true;
|
|
2431
|
-
} else {
|
|
2432
|
-
if (cycled && ranges.some(r => r.from == cursor.value.from)) continue;
|
|
2433
|
-
if (fullWord) {
|
|
2434
|
-
let word = state.wordAt(cursor.value.from);
|
|
2435
|
-
if (!word || word.from != cursor.value.from || word.to != cursor.value.to) continue;
|
|
2436
|
-
}
|
|
2437
|
-
return cursor.value;
|
|
2438
|
-
}
|
|
2439
|
-
}
|
|
2440
|
-
}
|
|
2441
|
-
/**
|
|
2442
|
-
Select next occurrence of the current selection. Expand selection
|
|
2443
|
-
to the surrounding word when the selection is empty.
|
|
2444
|
-
*/
|
|
2445
|
-
const selectNextOccurrence = _ref2 => {
|
|
2446
|
-
let {
|
|
2447
|
-
state,
|
|
2448
|
-
dispatch
|
|
2449
|
-
} = _ref2;
|
|
2450
|
-
let {
|
|
2451
|
-
ranges
|
|
2452
|
-
} = state.selection;
|
|
2453
|
-
if (ranges.some(sel => sel.from === sel.to)) return selectWord({
|
|
2454
|
-
state,
|
|
2455
|
-
dispatch
|
|
2456
|
-
});
|
|
2457
|
-
let searchedText = state.sliceDoc(ranges[0].from, ranges[0].to);
|
|
2458
|
-
if (state.selection.ranges.some(r => state.sliceDoc(r.from, r.to) != searchedText)) return false;
|
|
2459
|
-
let range = findNextOccurrence(state, searchedText);
|
|
2460
|
-
if (!range) return false;
|
|
2461
|
-
dispatch(state.update({
|
|
2462
|
-
selection: state.selection.addRange(EditorSelection.range(range.from, range.to), false),
|
|
2463
|
-
effects: EditorView.scrollIntoView(range.to)
|
|
2464
|
-
}));
|
|
2465
|
-
return true;
|
|
2466
|
-
};
|
|
2467
|
-
const searchConfigFacet = /*@__PURE__*/Facet.define({
|
|
2468
|
-
combine(configs) {
|
|
2469
|
-
return combineConfig(configs, {
|
|
2470
|
-
top: false,
|
|
2471
|
-
caseSensitive: false,
|
|
2472
|
-
literal: false,
|
|
2473
|
-
wholeWord: false,
|
|
2474
|
-
createPanel: view => new SearchPanel(view),
|
|
2475
|
-
scrollToMatch: range => EditorView.scrollIntoView(range)
|
|
2476
|
-
});
|
|
2477
|
-
}
|
|
2478
|
-
});
|
|
2479
|
-
/**
|
|
2480
|
-
A search query. Part of the editor's search state.
|
|
2481
|
-
*/
|
|
2482
|
-
class SearchQuery {
|
|
2483
|
-
/**
|
|
2484
|
-
Create a query object.
|
|
2485
|
-
*/
|
|
2486
|
-
constructor(config) {
|
|
2487
|
-
this.search = config.search;
|
|
2488
|
-
this.caseSensitive = !!config.caseSensitive;
|
|
2489
|
-
this.literal = !!config.literal;
|
|
2490
|
-
this.regexp = !!config.regexp;
|
|
2491
|
-
this.replace = config.replace || "";
|
|
2492
|
-
this.valid = !!this.search && (!this.regexp || validRegExp(this.search));
|
|
2493
|
-
this.unquoted = this.unquote(this.search);
|
|
2494
|
-
this.wholeWord = !!config.wholeWord;
|
|
2495
|
-
}
|
|
2496
|
-
/**
|
|
2497
|
-
@internal
|
|
2498
|
-
*/
|
|
2499
|
-
unquote(text) {
|
|
2500
|
-
return this.literal ? text : text.replace(/\\([nrt\\])/g, (_, ch) => ch == "n" ? "\n" : ch == "r" ? "\r" : ch == "t" ? "\t" : "\\");
|
|
2501
|
-
}
|
|
2502
|
-
/**
|
|
2503
|
-
Compare this query to another query.
|
|
2504
|
-
*/
|
|
2505
|
-
eq(other) {
|
|
2506
|
-
return this.search == other.search && this.replace == other.replace && this.caseSensitive == other.caseSensitive && this.regexp == other.regexp && this.wholeWord == other.wholeWord;
|
|
2507
|
-
}
|
|
2508
|
-
/**
|
|
2509
|
-
@internal
|
|
2510
|
-
*/
|
|
2511
|
-
create() {
|
|
2512
|
-
return this.regexp ? new RegExpQuery(this) : new StringQuery(this);
|
|
2513
|
-
}
|
|
2514
|
-
/**
|
|
2515
|
-
Get a search cursor for this query, searching through the given
|
|
2516
|
-
range in the given state.
|
|
2517
|
-
*/
|
|
2518
|
-
getCursor(state) {
|
|
2519
|
-
let from = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
2520
|
-
let to = arguments.length > 2 ? arguments[2] : undefined;
|
|
2521
|
-
let st = state.doc ? state : EditorState.create({
|
|
2522
|
-
doc: state
|
|
2523
|
-
});
|
|
2524
|
-
if (to == null) to = st.doc.length;
|
|
2525
|
-
return this.regexp ? regexpCursor(this, st, from, to) : stringCursor(this, st, from, to);
|
|
2526
|
-
}
|
|
2527
|
-
}
|
|
2528
|
-
class QueryType {
|
|
2529
|
-
constructor(spec) {
|
|
2530
|
-
this.spec = spec;
|
|
2531
|
-
}
|
|
2532
|
-
}
|
|
2533
|
-
function stringCursor(spec, state, from, to) {
|
|
2534
|
-
return new SearchCursor(state.doc, spec.unquoted, from, to, spec.caseSensitive ? undefined : x => x.toLowerCase(), spec.wholeWord ? stringWordTest(state.doc, state.charCategorizer(state.selection.main.head)) : undefined);
|
|
2535
|
-
}
|
|
2536
|
-
function stringWordTest(doc, categorizer) {
|
|
2537
|
-
return (from, to, buf, bufPos) => {
|
|
2538
|
-
if (bufPos > from || bufPos + buf.length < to) {
|
|
2539
|
-
bufPos = Math.max(0, from - 2);
|
|
2540
|
-
buf = doc.sliceString(bufPos, Math.min(doc.length, to + 2));
|
|
2541
|
-
}
|
|
2542
|
-
return (categorizer(charBefore(buf, from - bufPos)) != CharCategory.Word || categorizer(charAfter(buf, from - bufPos)) != CharCategory.Word) && (categorizer(charAfter(buf, to - bufPos)) != CharCategory.Word || categorizer(charBefore(buf, to - bufPos)) != CharCategory.Word);
|
|
2543
|
-
};
|
|
2544
|
-
}
|
|
2545
|
-
class StringQuery extends QueryType {
|
|
2546
|
-
constructor(spec) {
|
|
2547
|
-
super(spec);
|
|
2548
|
-
}
|
|
2549
|
-
nextMatch(state, curFrom, curTo) {
|
|
2550
|
-
let cursor = stringCursor(this.spec, state, curTo, state.doc.length).nextOverlapping();
|
|
2551
|
-
if (cursor.done) cursor = stringCursor(this.spec, state, 0, curFrom).nextOverlapping();
|
|
2552
|
-
return cursor.done ? null : cursor.value;
|
|
2553
|
-
}
|
|
2554
|
-
// Searching in reverse is, rather than implementing inverted search
|
|
2555
|
-
// cursor, done by scanning chunk after chunk forward.
|
|
2556
|
-
prevMatchInRange(state, from, to) {
|
|
2557
|
-
for (let pos = to;;) {
|
|
2558
|
-
let start = Math.max(from, pos - 10000 /* FindPrev.ChunkSize */ - this.spec.unquoted.length);
|
|
2559
|
-
let cursor = stringCursor(this.spec, state, start, pos),
|
|
2560
|
-
range = null;
|
|
2561
|
-
while (!cursor.nextOverlapping().done) range = cursor.value;
|
|
2562
|
-
if (range) return range;
|
|
2563
|
-
if (start == from) return null;
|
|
2564
|
-
pos -= 10000 /* FindPrev.ChunkSize */;
|
|
2565
|
-
}
|
|
2566
|
-
}
|
|
2567
|
-
|
|
2568
|
-
prevMatch(state, curFrom, curTo) {
|
|
2569
|
-
return this.prevMatchInRange(state, 0, curFrom) || this.prevMatchInRange(state, curTo, state.doc.length);
|
|
2570
|
-
}
|
|
2571
|
-
getReplacement(_result) {
|
|
2572
|
-
return this.spec.unquote(this.spec.replace);
|
|
2573
|
-
}
|
|
2574
|
-
matchAll(state, limit) {
|
|
2575
|
-
let cursor = stringCursor(this.spec, state, 0, state.doc.length),
|
|
2576
|
-
ranges = [];
|
|
2577
|
-
while (!cursor.next().done) {
|
|
2578
|
-
if (ranges.length >= limit) return null;
|
|
2579
|
-
ranges.push(cursor.value);
|
|
2580
|
-
}
|
|
2581
|
-
return ranges;
|
|
2582
|
-
}
|
|
2583
|
-
highlight(state, from, to, add) {
|
|
2584
|
-
let cursor = stringCursor(this.spec, state, Math.max(0, from - this.spec.unquoted.length), Math.min(to + this.spec.unquoted.length, state.doc.length));
|
|
2585
|
-
while (!cursor.next().done) add(cursor.value.from, cursor.value.to);
|
|
2586
|
-
}
|
|
2587
|
-
}
|
|
2588
|
-
function regexpCursor(spec, state, from, to) {
|
|
2589
|
-
return new RegExpCursor(state.doc, spec.search, {
|
|
2590
|
-
ignoreCase: !spec.caseSensitive,
|
|
2591
|
-
test: spec.wholeWord ? regexpWordTest(state.charCategorizer(state.selection.main.head)) : undefined
|
|
2592
|
-
}, from, to);
|
|
2593
|
-
}
|
|
2594
|
-
function charBefore(str, index) {
|
|
2595
|
-
return str.slice(findClusterBreak(str, index, false), index);
|
|
2596
|
-
}
|
|
2597
|
-
function charAfter(str, index) {
|
|
2598
|
-
return str.slice(index, findClusterBreak(str, index));
|
|
2599
|
-
}
|
|
2600
|
-
function regexpWordTest(categorizer) {
|
|
2601
|
-
return (_from, _to, match) => !match[0].length || (categorizer(charBefore(match.input, match.index)) != CharCategory.Word || categorizer(charAfter(match.input, match.index)) != CharCategory.Word) && (categorizer(charAfter(match.input, match.index + match[0].length)) != CharCategory.Word || categorizer(charBefore(match.input, match.index + match[0].length)) != CharCategory.Word);
|
|
2602
|
-
}
|
|
2603
|
-
class RegExpQuery extends QueryType {
|
|
2604
|
-
nextMatch(state, curFrom, curTo) {
|
|
2605
|
-
let cursor = regexpCursor(this.spec, state, curTo, state.doc.length).next();
|
|
2606
|
-
if (cursor.done) cursor = regexpCursor(this.spec, state, 0, curFrom).next();
|
|
2607
|
-
return cursor.done ? null : cursor.value;
|
|
2608
|
-
}
|
|
2609
|
-
prevMatchInRange(state, from, to) {
|
|
2610
|
-
for (let size = 1;; size++) {
|
|
2611
|
-
let start = Math.max(from, to - size * 10000 /* FindPrev.ChunkSize */);
|
|
2612
|
-
let cursor = regexpCursor(this.spec, state, start, to),
|
|
2613
|
-
range = null;
|
|
2614
|
-
while (!cursor.next().done) range = cursor.value;
|
|
2615
|
-
if (range && (start == from || range.from > start + 10)) return range;
|
|
2616
|
-
if (start == from) return null;
|
|
2617
|
-
}
|
|
2618
|
-
}
|
|
2619
|
-
prevMatch(state, curFrom, curTo) {
|
|
2620
|
-
return this.prevMatchInRange(state, 0, curFrom) || this.prevMatchInRange(state, curTo, state.doc.length);
|
|
2621
|
-
}
|
|
2622
|
-
getReplacement(result) {
|
|
2623
|
-
return this.spec.unquote(this.spec.replace.replace(/\$([$&\d+])/g, (m, i) => i == "$" ? "$" : i == "&" ? result.match[0] : i != "0" && +i < result.match.length ? result.match[i] : m));
|
|
2624
|
-
}
|
|
2625
|
-
matchAll(state, limit) {
|
|
2626
|
-
let cursor = regexpCursor(this.spec, state, 0, state.doc.length),
|
|
2627
|
-
ranges = [];
|
|
2628
|
-
while (!cursor.next().done) {
|
|
2629
|
-
if (ranges.length >= limit) return null;
|
|
2630
|
-
ranges.push(cursor.value);
|
|
2631
|
-
}
|
|
2632
|
-
return ranges;
|
|
2633
|
-
}
|
|
2634
|
-
highlight(state, from, to, add) {
|
|
2635
|
-
let cursor = regexpCursor(this.spec, state, Math.max(0, from - 250 /* RegExp.HighlightMargin */), Math.min(to + 250 /* RegExp.HighlightMargin */, state.doc.length));
|
|
2636
|
-
while (!cursor.next().done) add(cursor.value.from, cursor.value.to);
|
|
2637
|
-
}
|
|
2638
|
-
}
|
|
2639
|
-
/**
|
|
2640
|
-
A state effect that updates the current search query. Note that
|
|
2641
|
-
this only has an effect if the search state has been initialized
|
|
2642
|
-
(by including [`search`](https://codemirror.net/6/docs/ref/#search.search) in your configuration or
|
|
2643
|
-
by running [`openSearchPanel`](https://codemirror.net/6/docs/ref/#search.openSearchPanel) at least
|
|
2644
|
-
once).
|
|
2645
|
-
*/
|
|
2646
|
-
const setSearchQuery = /*@__PURE__*/StateEffect.define();
|
|
2647
|
-
const togglePanel$1 = /*@__PURE__*/StateEffect.define();
|
|
2648
|
-
const searchState = /*@__PURE__*/StateField.define({
|
|
2649
|
-
create(state) {
|
|
2650
|
-
return new SearchState(defaultQuery(state).create(), null);
|
|
2651
|
-
},
|
|
2652
|
-
update(value, tr) {
|
|
2653
|
-
for (let effect of tr.effects) {
|
|
2654
|
-
if (effect.is(setSearchQuery)) value = new SearchState(effect.value.create(), value.panel);else if (effect.is(togglePanel$1)) value = new SearchState(value.query, effect.value ? createSearchPanel : null);
|
|
2655
|
-
}
|
|
2656
|
-
return value;
|
|
2657
|
-
},
|
|
2658
|
-
provide: f => showPanel.from(f, val => val.panel)
|
|
2659
|
-
});
|
|
2660
|
-
class SearchState {
|
|
2661
|
-
constructor(query, panel) {
|
|
2662
|
-
this.query = query;
|
|
2663
|
-
this.panel = panel;
|
|
2664
|
-
}
|
|
2665
|
-
}
|
|
2666
|
-
const matchMark = /*@__PURE__*/Decoration.mark({
|
|
2667
|
-
class: "cm-searchMatch"
|
|
2668
|
-
}),
|
|
2669
|
-
selectedMatchMark = /*@__PURE__*/Decoration.mark({
|
|
2670
|
-
class: "cm-searchMatch cm-searchMatch-selected"
|
|
2671
|
-
});
|
|
2672
|
-
const searchHighlighter = /*@__PURE__*/ViewPlugin.fromClass(class {
|
|
2673
|
-
constructor(view) {
|
|
2674
|
-
this.view = view;
|
|
2675
|
-
this.decorations = this.highlight(view.state.field(searchState));
|
|
2676
|
-
}
|
|
2677
|
-
update(update) {
|
|
2678
|
-
let state = update.state.field(searchState);
|
|
2679
|
-
if (state != update.startState.field(searchState) || update.docChanged || update.selectionSet || update.viewportChanged) this.decorations = this.highlight(state);
|
|
2680
|
-
}
|
|
2681
|
-
highlight(_ref3) {
|
|
2682
|
-
let {
|
|
2683
|
-
query,
|
|
2684
|
-
panel
|
|
2685
|
-
} = _ref3;
|
|
2686
|
-
if (!panel || !query.spec.valid) return Decoration.none;
|
|
2687
|
-
let {
|
|
2688
|
-
view
|
|
2689
|
-
} = this;
|
|
2690
|
-
let builder = new RangeSetBuilder();
|
|
2691
|
-
for (let i = 0, ranges = view.visibleRanges, l = ranges.length; i < l; i++) {
|
|
2692
|
-
let {
|
|
2693
|
-
from,
|
|
2694
|
-
to
|
|
2695
|
-
} = ranges[i];
|
|
2696
|
-
while (i < l - 1 && to > ranges[i + 1].from - 2 * 250 /* RegExp.HighlightMargin */) to = ranges[++i].to;
|
|
2697
|
-
query.highlight(view.state, from, to, (from, to) => {
|
|
2698
|
-
let selected = view.state.selection.ranges.some(r => r.from == from && r.to == to);
|
|
2699
|
-
builder.add(from, to, selected ? selectedMatchMark : matchMark);
|
|
2700
|
-
});
|
|
2701
|
-
}
|
|
2702
|
-
return builder.finish();
|
|
2703
|
-
}
|
|
2704
|
-
}, {
|
|
2705
|
-
decorations: v => v.decorations
|
|
2706
|
-
});
|
|
2707
|
-
function searchCommand(f) {
|
|
2708
|
-
return view => {
|
|
2709
|
-
let state = view.state.field(searchState, false);
|
|
2710
|
-
return state && state.query.spec.valid ? f(view, state) : openSearchPanel(view);
|
|
2711
|
-
};
|
|
2712
|
-
}
|
|
2713
|
-
/**
|
|
2714
|
-
Open the search panel if it isn't already open, and move the
|
|
2715
|
-
selection to the first match after the current main selection.
|
|
2716
|
-
Will wrap around to the start of the document when it reaches the
|
|
2717
|
-
end.
|
|
2718
|
-
*/
|
|
2719
|
-
const findNext = /*@__PURE__*/searchCommand((view, _ref4) => {
|
|
2720
|
-
let {
|
|
2721
|
-
query
|
|
2722
|
-
} = _ref4;
|
|
2723
|
-
let {
|
|
2724
|
-
to
|
|
2725
|
-
} = view.state.selection.main;
|
|
2726
|
-
let next = query.nextMatch(view.state, to, to);
|
|
2727
|
-
if (!next) return false;
|
|
2728
|
-
let selection = EditorSelection.single(next.from, next.to);
|
|
2729
|
-
let config = view.state.facet(searchConfigFacet);
|
|
2730
|
-
view.dispatch({
|
|
2731
|
-
selection,
|
|
2732
|
-
effects: [announceMatch(view, next), config.scrollToMatch(selection.main)],
|
|
2733
|
-
userEvent: "select.search"
|
|
2734
|
-
});
|
|
2735
|
-
return true;
|
|
2736
|
-
});
|
|
2737
|
-
/**
|
|
2738
|
-
Move the selection to the previous instance of the search query,
|
|
2739
|
-
before the current main selection. Will wrap past the start
|
|
2740
|
-
of the document to start searching at the end again.
|
|
2741
|
-
*/
|
|
2742
|
-
const findPrevious = /*@__PURE__*/searchCommand((view, _ref5) => {
|
|
2743
|
-
let {
|
|
2744
|
-
query
|
|
2745
|
-
} = _ref5;
|
|
2746
|
-
let {
|
|
2747
|
-
state
|
|
2748
|
-
} = view,
|
|
2749
|
-
{
|
|
2750
|
-
from
|
|
2751
|
-
} = state.selection.main;
|
|
2752
|
-
let prev = query.prevMatch(state, from, from);
|
|
2753
|
-
if (!prev) return false;
|
|
2754
|
-
let selection = EditorSelection.single(prev.from, prev.to);
|
|
2755
|
-
let config = view.state.facet(searchConfigFacet);
|
|
2756
|
-
view.dispatch({
|
|
2757
|
-
selection,
|
|
2758
|
-
effects: [announceMatch(view, prev), config.scrollToMatch(selection.main)],
|
|
2759
|
-
userEvent: "select.search"
|
|
2760
|
-
});
|
|
2761
|
-
return true;
|
|
2762
|
-
});
|
|
2763
|
-
/**
|
|
2764
|
-
Select all instances of the search query.
|
|
2765
|
-
*/
|
|
2766
|
-
const selectMatches = /*@__PURE__*/searchCommand((view, _ref6) => {
|
|
2767
|
-
let {
|
|
2768
|
-
query
|
|
2769
|
-
} = _ref6;
|
|
2770
|
-
let ranges = query.matchAll(view.state, 1000);
|
|
2771
|
-
if (!ranges || !ranges.length) return false;
|
|
2772
|
-
view.dispatch({
|
|
2773
|
-
selection: EditorSelection.create(ranges.map(r => EditorSelection.range(r.from, r.to))),
|
|
2774
|
-
userEvent: "select.search.matches"
|
|
2775
|
-
});
|
|
2776
|
-
return true;
|
|
2777
|
-
});
|
|
2778
|
-
/**
|
|
2779
|
-
Select all instances of the currently selected text.
|
|
2780
|
-
*/
|
|
2781
|
-
const selectSelectionMatches = _ref7 => {
|
|
2782
|
-
let {
|
|
2783
|
-
state,
|
|
2784
|
-
dispatch
|
|
2785
|
-
} = _ref7;
|
|
2786
|
-
let sel = state.selection;
|
|
2787
|
-
if (sel.ranges.length > 1 || sel.main.empty) return false;
|
|
2788
|
-
let {
|
|
2789
|
-
from,
|
|
2790
|
-
to
|
|
2791
|
-
} = sel.main;
|
|
2792
|
-
let ranges = [],
|
|
2793
|
-
main = 0;
|
|
2794
|
-
for (let cur = new SearchCursor(state.doc, state.sliceDoc(from, to)); !cur.next().done;) {
|
|
2795
|
-
if (ranges.length > 1000) return false;
|
|
2796
|
-
if (cur.value.from == from) main = ranges.length;
|
|
2797
|
-
ranges.push(EditorSelection.range(cur.value.from, cur.value.to));
|
|
2798
|
-
}
|
|
2799
|
-
dispatch(state.update({
|
|
2800
|
-
selection: EditorSelection.create(ranges, main),
|
|
2801
|
-
userEvent: "select.search.matches"
|
|
2802
|
-
}));
|
|
2803
|
-
return true;
|
|
2804
|
-
};
|
|
2805
|
-
/**
|
|
2806
|
-
Replace the current match of the search query.
|
|
2807
|
-
*/
|
|
2808
|
-
const replaceNext = /*@__PURE__*/searchCommand((view, _ref8) => {
|
|
2809
|
-
let {
|
|
2810
|
-
query
|
|
2811
|
-
} = _ref8;
|
|
2812
|
-
let {
|
|
2813
|
-
state
|
|
2814
|
-
} = view,
|
|
2815
|
-
{
|
|
2816
|
-
from,
|
|
2817
|
-
to
|
|
2818
|
-
} = state.selection.main;
|
|
2819
|
-
if (state.readOnly) return false;
|
|
2820
|
-
let next = query.nextMatch(state, from, from);
|
|
2821
|
-
if (!next) return false;
|
|
2822
|
-
let changes = [],
|
|
2823
|
-
selection,
|
|
2824
|
-
replacement;
|
|
2825
|
-
let effects = [];
|
|
2826
|
-
if (next.from == from && next.to == to) {
|
|
2827
|
-
replacement = state.toText(query.getReplacement(next));
|
|
2828
|
-
changes.push({
|
|
2829
|
-
from: next.from,
|
|
2830
|
-
to: next.to,
|
|
2831
|
-
insert: replacement
|
|
2832
|
-
});
|
|
2833
|
-
next = query.nextMatch(state, next.from, next.to);
|
|
2834
|
-
effects.push(EditorView.announce.of(state.phrase("replaced match on line $", state.doc.lineAt(from).number) + "."));
|
|
2835
|
-
}
|
|
2836
|
-
if (next) {
|
|
2837
|
-
let off = changes.length == 0 || changes[0].from >= next.to ? 0 : next.to - next.from - replacement.length;
|
|
2838
|
-
selection = EditorSelection.single(next.from - off, next.to - off);
|
|
2839
|
-
effects.push(announceMatch(view, next));
|
|
2840
|
-
effects.push(state.facet(searchConfigFacet).scrollToMatch(selection.main));
|
|
2841
|
-
}
|
|
2842
|
-
view.dispatch({
|
|
2843
|
-
changes,
|
|
2844
|
-
selection,
|
|
2845
|
-
effects,
|
|
2846
|
-
userEvent: "input.replace"
|
|
2847
|
-
});
|
|
2848
|
-
return true;
|
|
2849
|
-
});
|
|
2850
|
-
/**
|
|
2851
|
-
Replace all instances of the search query with the given
|
|
2852
|
-
replacement.
|
|
2853
|
-
*/
|
|
2854
|
-
const replaceAll = /*@__PURE__*/searchCommand((view, _ref9) => {
|
|
2855
|
-
let {
|
|
2856
|
-
query
|
|
2857
|
-
} = _ref9;
|
|
2858
|
-
if (view.state.readOnly) return false;
|
|
2859
|
-
let changes = query.matchAll(view.state, 1e9).map(match => {
|
|
2860
|
-
let {
|
|
2861
|
-
from,
|
|
2862
|
-
to
|
|
2863
|
-
} = match;
|
|
2864
|
-
return {
|
|
2865
|
-
from,
|
|
2866
|
-
to,
|
|
2867
|
-
insert: query.getReplacement(match)
|
|
2868
|
-
};
|
|
2869
|
-
});
|
|
2870
|
-
if (!changes.length) return false;
|
|
2871
|
-
let announceText = view.state.phrase("replaced $ matches", changes.length) + ".";
|
|
2872
|
-
view.dispatch({
|
|
2873
|
-
changes,
|
|
2874
|
-
effects: EditorView.announce.of(announceText),
|
|
2875
|
-
userEvent: "input.replace.all"
|
|
2876
|
-
});
|
|
2877
|
-
return true;
|
|
2878
|
-
});
|
|
2879
|
-
function createSearchPanel(view) {
|
|
2880
|
-
return view.state.facet(searchConfigFacet).createPanel(view);
|
|
2881
|
-
}
|
|
2882
|
-
function defaultQuery(state, fallback) {
|
|
2883
|
-
var _a, _b, _c, _d;
|
|
2884
|
-
let sel = state.selection.main;
|
|
2885
|
-
let selText = sel.empty || sel.to > sel.from + 100 ? "" : state.sliceDoc(sel.from, sel.to);
|
|
2886
|
-
if (fallback && !selText) return fallback;
|
|
2887
|
-
let config = state.facet(searchConfigFacet);
|
|
2888
|
-
return new SearchQuery({
|
|
2889
|
-
search: ((_a = fallback === null || fallback === void 0 ? void 0 : fallback.literal) !== null && _a !== void 0 ? _a : config.literal) ? selText : selText.replace(/\n/g, "\\n"),
|
|
2890
|
-
caseSensitive: (_b = fallback === null || fallback === void 0 ? void 0 : fallback.caseSensitive) !== null && _b !== void 0 ? _b : config.caseSensitive,
|
|
2891
|
-
literal: (_c = fallback === null || fallback === void 0 ? void 0 : fallback.literal) !== null && _c !== void 0 ? _c : config.literal,
|
|
2892
|
-
wholeWord: (_d = fallback === null || fallback === void 0 ? void 0 : fallback.wholeWord) !== null && _d !== void 0 ? _d : config.wholeWord
|
|
2893
|
-
});
|
|
2894
|
-
}
|
|
2895
|
-
/**
|
|
2896
|
-
Make sure the search panel is open and focused.
|
|
2897
|
-
*/
|
|
2898
|
-
const openSearchPanel = view => {
|
|
2899
|
-
let state = view.state.field(searchState, false);
|
|
2900
|
-
if (state && state.panel) {
|
|
2901
|
-
let panel = getPanel(view, createSearchPanel);
|
|
2902
|
-
if (!panel) return false;
|
|
2903
|
-
let searchInput = panel.dom.querySelector("[main-field]");
|
|
2904
|
-
if (searchInput && searchInput != view.root.activeElement) {
|
|
2905
|
-
let query = defaultQuery(view.state, state.query.spec);
|
|
2906
|
-
if (query.valid) view.dispatch({
|
|
2907
|
-
effects: setSearchQuery.of(query)
|
|
2908
|
-
});
|
|
2909
|
-
searchInput.focus();
|
|
2910
|
-
searchInput.select();
|
|
2911
|
-
}
|
|
2912
|
-
} else {
|
|
2913
|
-
view.dispatch({
|
|
2914
|
-
effects: [togglePanel$1.of(true), state ? setSearchQuery.of(defaultQuery(view.state, state.query.spec)) : StateEffect.appendConfig.of(searchExtensions)]
|
|
2915
|
-
});
|
|
2916
|
-
}
|
|
2917
|
-
return true;
|
|
2918
|
-
};
|
|
2919
|
-
/**
|
|
2920
|
-
Close the search panel.
|
|
2921
|
-
*/
|
|
2922
|
-
const closeSearchPanel = view => {
|
|
2923
|
-
let state = view.state.field(searchState, false);
|
|
2924
|
-
if (!state || !state.panel) return false;
|
|
2925
|
-
let panel = getPanel(view, createSearchPanel);
|
|
2926
|
-
if (panel && panel.dom.contains(view.root.activeElement)) view.focus();
|
|
2927
|
-
view.dispatch({
|
|
2928
|
-
effects: togglePanel$1.of(false)
|
|
2929
|
-
});
|
|
2930
|
-
return true;
|
|
2931
|
-
};
|
|
2932
|
-
/**
|
|
2933
|
-
Default search-related key bindings.
|
|
2934
|
-
|
|
2935
|
-
- Mod-f: [`openSearchPanel`](https://codemirror.net/6/docs/ref/#search.openSearchPanel)
|
|
2936
|
-
- F3, Mod-g: [`findNext`](https://codemirror.net/6/docs/ref/#search.findNext)
|
|
2937
|
-
- Shift-F3, Shift-Mod-g: [`findPrevious`](https://codemirror.net/6/docs/ref/#search.findPrevious)
|
|
2938
|
-
- Alt-g: [`gotoLine`](https://codemirror.net/6/docs/ref/#search.gotoLine)
|
|
2939
|
-
- Mod-d: [`selectNextOccurrence`](https://codemirror.net/6/docs/ref/#search.selectNextOccurrence)
|
|
2940
|
-
*/
|
|
2941
|
-
const searchKeymap = [{
|
|
2942
|
-
key: "Mod-f",
|
|
2943
|
-
run: openSearchPanel,
|
|
2944
|
-
scope: "editor search-panel"
|
|
2945
|
-
}, {
|
|
2946
|
-
key: "F3",
|
|
2947
|
-
run: findNext,
|
|
2948
|
-
shift: findPrevious,
|
|
2949
|
-
scope: "editor search-panel",
|
|
2950
|
-
preventDefault: true
|
|
2951
|
-
}, {
|
|
2952
|
-
key: "Mod-g",
|
|
2953
|
-
run: findNext,
|
|
2954
|
-
shift: findPrevious,
|
|
2955
|
-
scope: "editor search-panel",
|
|
2956
|
-
preventDefault: true
|
|
2957
|
-
}, {
|
|
2958
|
-
key: "Escape",
|
|
2959
|
-
run: closeSearchPanel,
|
|
2960
|
-
scope: "editor search-panel"
|
|
2961
|
-
}, {
|
|
2962
|
-
key: "Mod-Shift-l",
|
|
2963
|
-
run: selectSelectionMatches
|
|
2964
|
-
}, {
|
|
2965
|
-
key: "Alt-g",
|
|
2966
|
-
run: gotoLine
|
|
2967
|
-
}, {
|
|
2968
|
-
key: "Mod-d",
|
|
2969
|
-
run: selectNextOccurrence,
|
|
2970
|
-
preventDefault: true
|
|
2971
|
-
}];
|
|
2972
|
-
class SearchPanel {
|
|
2973
|
-
constructor(view) {
|
|
2974
|
-
this.view = view;
|
|
2975
|
-
let query = this.query = view.state.field(searchState).query.spec;
|
|
2976
|
-
this.commit = this.commit.bind(this);
|
|
2977
|
-
this.searchField = crelt("input", {
|
|
2978
|
-
value: query.search,
|
|
2979
|
-
placeholder: phrase(view, "Find"),
|
|
2980
|
-
"aria-label": phrase(view, "Find"),
|
|
2981
|
-
class: "cm-textfield",
|
|
2982
|
-
name: "search",
|
|
2983
|
-
form: "",
|
|
2984
|
-
"main-field": "true",
|
|
2985
|
-
onchange: this.commit,
|
|
2986
|
-
onkeyup: this.commit
|
|
2987
|
-
});
|
|
2988
|
-
this.replaceField = crelt("input", {
|
|
2989
|
-
value: query.replace,
|
|
2990
|
-
placeholder: phrase(view, "Replace"),
|
|
2991
|
-
"aria-label": phrase(view, "Replace"),
|
|
2992
|
-
class: "cm-textfield",
|
|
2993
|
-
name: "replace",
|
|
2994
|
-
form: "",
|
|
2995
|
-
onchange: this.commit,
|
|
2996
|
-
onkeyup: this.commit
|
|
2997
|
-
});
|
|
2998
|
-
this.caseField = crelt("input", {
|
|
2999
|
-
type: "checkbox",
|
|
3000
|
-
name: "case",
|
|
3001
|
-
form: "",
|
|
3002
|
-
checked: query.caseSensitive,
|
|
3003
|
-
onchange: this.commit
|
|
3004
|
-
});
|
|
3005
|
-
this.reField = crelt("input", {
|
|
3006
|
-
type: "checkbox",
|
|
3007
|
-
name: "re",
|
|
3008
|
-
form: "",
|
|
3009
|
-
checked: query.regexp,
|
|
3010
|
-
onchange: this.commit
|
|
3011
|
-
});
|
|
3012
|
-
this.wordField = crelt("input", {
|
|
3013
|
-
type: "checkbox",
|
|
3014
|
-
name: "word",
|
|
3015
|
-
form: "",
|
|
3016
|
-
checked: query.wholeWord,
|
|
3017
|
-
onchange: this.commit
|
|
3018
|
-
});
|
|
3019
|
-
function button(name, onclick, content) {
|
|
3020
|
-
return crelt("button", {
|
|
3021
|
-
class: "cm-button",
|
|
3022
|
-
name,
|
|
3023
|
-
onclick,
|
|
3024
|
-
type: "button"
|
|
3025
|
-
}, content);
|
|
3026
|
-
}
|
|
3027
|
-
this.dom = crelt("div", {
|
|
3028
|
-
onkeydown: e => this.keydown(e),
|
|
3029
|
-
class: "cm-search"
|
|
3030
|
-
}, [this.searchField, button("next", () => findNext(view), [phrase(view, "next")]), button("prev", () => findPrevious(view), [phrase(view, "previous")]), button("select", () => selectMatches(view), [phrase(view, "all")]), crelt("label", null, [this.caseField, phrase(view, "match case")]), crelt("label", null, [this.reField, phrase(view, "regexp")]), crelt("label", null, [this.wordField, phrase(view, "by word")]), ...(view.state.readOnly ? [] : [crelt("br"), this.replaceField, button("replace", () => replaceNext(view), [phrase(view, "replace")]), button("replaceAll", () => replaceAll(view), [phrase(view, "replace all")])]), crelt("button", {
|
|
3031
|
-
name: "close",
|
|
3032
|
-
onclick: () => closeSearchPanel(view),
|
|
3033
|
-
"aria-label": phrase(view, "close"),
|
|
3034
|
-
type: "button"
|
|
3035
|
-
}, ["×"])]);
|
|
3036
|
-
}
|
|
3037
|
-
commit() {
|
|
3038
|
-
let query = new SearchQuery({
|
|
3039
|
-
search: this.searchField.value,
|
|
3040
|
-
caseSensitive: this.caseField.checked,
|
|
3041
|
-
regexp: this.reField.checked,
|
|
3042
|
-
wholeWord: this.wordField.checked,
|
|
3043
|
-
replace: this.replaceField.value
|
|
3044
|
-
});
|
|
3045
|
-
if (!query.eq(this.query)) {
|
|
3046
|
-
this.query = query;
|
|
3047
|
-
this.view.dispatch({
|
|
3048
|
-
effects: setSearchQuery.of(query)
|
|
3049
|
-
});
|
|
3050
|
-
}
|
|
3051
|
-
}
|
|
3052
|
-
keydown(e) {
|
|
3053
|
-
if (runScopeHandlers(this.view, e, "search-panel")) {
|
|
3054
|
-
e.preventDefault();
|
|
3055
|
-
} else if (e.keyCode == 13 && e.target == this.searchField) {
|
|
3056
|
-
e.preventDefault();
|
|
3057
|
-
(e.shiftKey ? findPrevious : findNext)(this.view);
|
|
3058
|
-
} else if (e.keyCode == 13 && e.target == this.replaceField) {
|
|
3059
|
-
e.preventDefault();
|
|
3060
|
-
replaceNext(this.view);
|
|
3061
|
-
}
|
|
3062
|
-
}
|
|
3063
|
-
update(update) {
|
|
3064
|
-
for (let tr of update.transactions) for (let effect of tr.effects) {
|
|
3065
|
-
if (effect.is(setSearchQuery) && !effect.value.eq(this.query)) this.setQuery(effect.value);
|
|
3066
|
-
}
|
|
3067
|
-
}
|
|
3068
|
-
setQuery(query) {
|
|
3069
|
-
this.query = query;
|
|
3070
|
-
this.searchField.value = query.search;
|
|
3071
|
-
this.replaceField.value = query.replace;
|
|
3072
|
-
this.caseField.checked = query.caseSensitive;
|
|
3073
|
-
this.reField.checked = query.regexp;
|
|
3074
|
-
this.wordField.checked = query.wholeWord;
|
|
3075
|
-
}
|
|
3076
|
-
mount() {
|
|
3077
|
-
this.searchField.select();
|
|
3078
|
-
}
|
|
3079
|
-
get pos() {
|
|
3080
|
-
return 80;
|
|
3081
|
-
}
|
|
3082
|
-
get top() {
|
|
3083
|
-
return this.view.state.facet(searchConfigFacet).top;
|
|
3084
|
-
}
|
|
3085
|
-
}
|
|
3086
|
-
function phrase(view, phrase) {
|
|
3087
|
-
return view.state.phrase(phrase);
|
|
3088
|
-
}
|
|
3089
|
-
const AnnounceMargin = 30;
|
|
3090
|
-
const Break = /[\s\.,:;?!]/;
|
|
3091
|
-
function announceMatch(view, _ref10) {
|
|
3092
|
-
let {
|
|
3093
|
-
from,
|
|
3094
|
-
to
|
|
3095
|
-
} = _ref10;
|
|
3096
|
-
let line = view.state.doc.lineAt(from),
|
|
3097
|
-
lineEnd = view.state.doc.lineAt(to).to;
|
|
3098
|
-
let start = Math.max(line.from, from - AnnounceMargin),
|
|
3099
|
-
end = Math.min(lineEnd, to + AnnounceMargin);
|
|
3100
|
-
let text = view.state.sliceDoc(start, end);
|
|
3101
|
-
if (start != line.from) {
|
|
3102
|
-
for (let i = 0; i < AnnounceMargin; i++) if (!Break.test(text[i + 1]) && Break.test(text[i])) {
|
|
3103
|
-
text = text.slice(i);
|
|
3104
|
-
break;
|
|
3105
|
-
}
|
|
3106
|
-
}
|
|
3107
|
-
if (end != lineEnd) {
|
|
3108
|
-
for (let i = text.length - 1; i > text.length - AnnounceMargin; i--) if (!Break.test(text[i - 1]) && Break.test(text[i])) {
|
|
3109
|
-
text = text.slice(0, i);
|
|
3110
|
-
break;
|
|
3111
|
-
}
|
|
3112
|
-
}
|
|
3113
|
-
return EditorView.announce.of(`${view.state.phrase("current match")}. ${text} ${view.state.phrase("on line")} ${line.number}.`);
|
|
3114
|
-
}
|
|
3115
|
-
const baseTheme$2 = /*@__PURE__*/EditorView.baseTheme({
|
|
3116
|
-
".cm-panel.cm-search": {
|
|
3117
|
-
padding: "2px 6px 4px",
|
|
3118
|
-
position: "relative",
|
|
3119
|
-
"& [name=close]": {
|
|
3120
|
-
position: "absolute",
|
|
3121
|
-
top: "0",
|
|
3122
|
-
right: "4px",
|
|
3123
|
-
backgroundColor: "inherit",
|
|
3124
|
-
border: "none",
|
|
3125
|
-
font: "inherit",
|
|
3126
|
-
padding: 0,
|
|
3127
|
-
margin: 0
|
|
3128
|
-
},
|
|
3129
|
-
"& input, & button, & label": {
|
|
3130
|
-
margin: ".2em .6em .2em 0"
|
|
3131
|
-
},
|
|
3132
|
-
"& input[type=checkbox]": {
|
|
3133
|
-
marginRight: ".2em"
|
|
3134
|
-
},
|
|
3135
|
-
"& label": {
|
|
3136
|
-
fontSize: "80%",
|
|
3137
|
-
whiteSpace: "pre"
|
|
3138
|
-
}
|
|
3139
|
-
},
|
|
3140
|
-
"&light .cm-searchMatch": {
|
|
3141
|
-
backgroundColor: "#ffff0054"
|
|
3142
|
-
},
|
|
3143
|
-
"&dark .cm-searchMatch": {
|
|
3144
|
-
backgroundColor: "#00ffff8a"
|
|
3145
|
-
},
|
|
3146
|
-
"&light .cm-searchMatch-selected": {
|
|
3147
|
-
backgroundColor: "#ff6a0054"
|
|
3148
|
-
},
|
|
3149
|
-
"&dark .cm-searchMatch-selected": {
|
|
3150
|
-
backgroundColor: "#ff00ff8a"
|
|
3151
|
-
}
|
|
3152
|
-
});
|
|
3153
|
-
const searchExtensions = [searchState, /*@__PURE__*/Prec.lowest(searchHighlighter), baseTheme$2];
|
|
3154
|
-
|
|
3155
|
-
class SelectedDiagnostic {
|
|
3156
|
-
constructor(from, to, diagnostic) {
|
|
3157
|
-
this.from = from;
|
|
3158
|
-
this.to = to;
|
|
3159
|
-
this.diagnostic = diagnostic;
|
|
3160
|
-
}
|
|
3161
|
-
}
|
|
3162
|
-
class LintState {
|
|
3163
|
-
constructor(diagnostics, panel, selected) {
|
|
3164
|
-
this.diagnostics = diagnostics;
|
|
3165
|
-
this.panel = panel;
|
|
3166
|
-
this.selected = selected;
|
|
3167
|
-
}
|
|
3168
|
-
static init(diagnostics, panel, state) {
|
|
3169
|
-
// Filter the list of diagnostics for which to create markers
|
|
3170
|
-
let markedDiagnostics = diagnostics;
|
|
3171
|
-
let diagnosticFilter = state.facet(lintConfig).markerFilter;
|
|
3172
|
-
if (diagnosticFilter) markedDiagnostics = diagnosticFilter(markedDiagnostics);
|
|
3173
|
-
let ranges = Decoration.set(markedDiagnostics.map(d => {
|
|
3174
|
-
// For zero-length ranges or ranges covering only a line break, create a widget
|
|
3175
|
-
return d.from == d.to || d.from == d.to - 1 && state.doc.lineAt(d.from).to == d.from ? Decoration.widget({
|
|
3176
|
-
widget: new DiagnosticWidget(d),
|
|
3177
|
-
diagnostic: d
|
|
3178
|
-
}).range(d.from) : Decoration.mark({
|
|
3179
|
-
attributes: {
|
|
3180
|
-
class: "cm-lintRange cm-lintRange-" + d.severity
|
|
3181
|
-
},
|
|
3182
|
-
diagnostic: d
|
|
3183
|
-
}).range(d.from, d.to);
|
|
3184
|
-
}), true);
|
|
3185
|
-
return new LintState(ranges, panel, findDiagnostic(ranges));
|
|
3186
|
-
}
|
|
3187
|
-
}
|
|
3188
|
-
function findDiagnostic(diagnostics) {
|
|
3189
|
-
let diagnostic = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
3190
|
-
let after = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
3191
|
-
let found = null;
|
|
3192
|
-
diagnostics.between(after, 1e9, (from, to, _ref) => {
|
|
3193
|
-
let {
|
|
3194
|
-
spec
|
|
3195
|
-
} = _ref;
|
|
3196
|
-
if (diagnostic && spec.diagnostic != diagnostic) return;
|
|
3197
|
-
found = new SelectedDiagnostic(from, to, spec.diagnostic);
|
|
3198
|
-
return false;
|
|
3199
|
-
});
|
|
3200
|
-
return found;
|
|
3201
|
-
}
|
|
3202
|
-
function hideTooltip(tr, tooltip) {
|
|
3203
|
-
return !!(tr.effects.some(e => e.is(setDiagnosticsEffect)) || tr.changes.touchesRange(tooltip.pos));
|
|
3204
|
-
}
|
|
3205
|
-
function maybeEnableLint(state, effects) {
|
|
3206
|
-
return state.field(lintState, false) ? effects : effects.concat(StateEffect.appendConfig.of([lintState, EditorView.decorations.compute([lintState], state => {
|
|
3207
|
-
let {
|
|
3208
|
-
selected,
|
|
3209
|
-
panel
|
|
3210
|
-
} = state.field(lintState);
|
|
3211
|
-
return !selected || !panel || selected.from == selected.to ? Decoration.none : Decoration.set([activeMark.range(selected.from, selected.to)]);
|
|
3212
|
-
}), hoverTooltip(lintTooltip, {
|
|
3213
|
-
hideOn: hideTooltip
|
|
3214
|
-
}), baseTheme]));
|
|
3215
|
-
}
|
|
3216
|
-
/**
|
|
3217
|
-
Returns a transaction spec which updates the current set of
|
|
3218
|
-
diagnostics, and enables the lint extension if if wasn't already
|
|
3219
|
-
active.
|
|
3220
|
-
*/
|
|
3221
|
-
function setDiagnostics(state, diagnostics) {
|
|
3222
|
-
return {
|
|
3223
|
-
effects: maybeEnableLint(state, [setDiagnosticsEffect.of(diagnostics)])
|
|
3224
|
-
};
|
|
3225
|
-
}
|
|
3226
|
-
/**
|
|
3227
|
-
The state effect that updates the set of active diagnostics. Can
|
|
3228
|
-
be useful when writing an extension that needs to track these.
|
|
3229
|
-
*/
|
|
3230
|
-
const setDiagnosticsEffect = /*@__PURE__*/StateEffect.define();
|
|
3231
|
-
const togglePanel = /*@__PURE__*/StateEffect.define();
|
|
3232
|
-
const movePanelSelection = /*@__PURE__*/StateEffect.define();
|
|
3233
|
-
const lintState = /*@__PURE__*/StateField.define({
|
|
3234
|
-
create() {
|
|
3235
|
-
return new LintState(Decoration.none, null, null);
|
|
3236
|
-
},
|
|
3237
|
-
update(value, tr) {
|
|
3238
|
-
if (tr.docChanged) {
|
|
3239
|
-
let mapped = value.diagnostics.map(tr.changes),
|
|
3240
|
-
selected = null;
|
|
3241
|
-
if (value.selected) {
|
|
3242
|
-
let selPos = tr.changes.mapPos(value.selected.from, 1);
|
|
3243
|
-
selected = findDiagnostic(mapped, value.selected.diagnostic, selPos) || findDiagnostic(mapped, null, selPos);
|
|
3244
|
-
}
|
|
3245
|
-
value = new LintState(mapped, value.panel, selected);
|
|
3246
|
-
}
|
|
3247
|
-
for (let effect of tr.effects) {
|
|
3248
|
-
if (effect.is(setDiagnosticsEffect)) {
|
|
3249
|
-
value = LintState.init(effect.value, value.panel, tr.state);
|
|
3250
|
-
} else if (effect.is(togglePanel)) {
|
|
3251
|
-
value = new LintState(value.diagnostics, effect.value ? LintPanel.open : null, value.selected);
|
|
3252
|
-
} else if (effect.is(movePanelSelection)) {
|
|
3253
|
-
value = new LintState(value.diagnostics, value.panel, effect.value);
|
|
3254
|
-
}
|
|
3255
|
-
}
|
|
3256
|
-
return value;
|
|
3257
|
-
},
|
|
3258
|
-
provide: f => [showPanel.from(f, val => val.panel), EditorView.decorations.from(f, s => s.diagnostics)]
|
|
3259
|
-
});
|
|
3260
|
-
const activeMark = /*@__PURE__*/Decoration.mark({
|
|
3261
|
-
class: "cm-lintRange cm-lintRange-active"
|
|
3262
|
-
});
|
|
3263
|
-
function lintTooltip(view, pos, side) {
|
|
3264
|
-
let {
|
|
3265
|
-
diagnostics
|
|
3266
|
-
} = view.state.field(lintState);
|
|
3267
|
-
let found = [],
|
|
3268
|
-
stackStart = 2e8,
|
|
3269
|
-
stackEnd = 0;
|
|
3270
|
-
diagnostics.between(pos - (side < 0 ? 1 : 0), pos + (side > 0 ? 1 : 0), (from, to, _ref2) => {
|
|
3271
|
-
let {
|
|
3272
|
-
spec
|
|
3273
|
-
} = _ref2;
|
|
3274
|
-
if (pos >= from && pos <= to && (from == to || (pos > from || side > 0) && (pos < to || side < 0))) {
|
|
3275
|
-
found.push(spec.diagnostic);
|
|
3276
|
-
stackStart = Math.min(from, stackStart);
|
|
3277
|
-
stackEnd = Math.max(to, stackEnd);
|
|
3278
|
-
}
|
|
3279
|
-
});
|
|
3280
|
-
let diagnosticFilter = view.state.facet(lintConfig).tooltipFilter;
|
|
3281
|
-
if (diagnosticFilter) found = diagnosticFilter(found);
|
|
3282
|
-
if (!found.length) return null;
|
|
3283
|
-
return {
|
|
3284
|
-
pos: stackStart,
|
|
3285
|
-
end: stackEnd,
|
|
3286
|
-
above: view.state.doc.lineAt(stackStart).to < stackEnd,
|
|
3287
|
-
create() {
|
|
3288
|
-
return {
|
|
3289
|
-
dom: diagnosticsTooltip(view, found)
|
|
3290
|
-
};
|
|
3291
|
-
}
|
|
3292
|
-
};
|
|
3293
|
-
}
|
|
3294
|
-
function diagnosticsTooltip(view, diagnostics) {
|
|
3295
|
-
return crelt("ul", {
|
|
3296
|
-
class: "cm-tooltip-lint"
|
|
3297
|
-
}, diagnostics.map(d => renderDiagnostic(view, d, false)));
|
|
3298
|
-
}
|
|
3299
|
-
/**
|
|
3300
|
-
Command to open and focus the lint panel.
|
|
3301
|
-
*/
|
|
3302
|
-
const openLintPanel = view => {
|
|
3303
|
-
let field = view.state.field(lintState, false);
|
|
3304
|
-
if (!field || !field.panel) view.dispatch({
|
|
3305
|
-
effects: maybeEnableLint(view.state, [togglePanel.of(true)])
|
|
3306
|
-
});
|
|
3307
|
-
let panel = getPanel(view, LintPanel.open);
|
|
3308
|
-
if (panel) panel.dom.querySelector(".cm-panel-lint ul").focus();
|
|
3309
|
-
return true;
|
|
3310
|
-
};
|
|
3311
|
-
/**
|
|
3312
|
-
Command to close the lint panel, when open.
|
|
3313
|
-
*/
|
|
3314
|
-
const closeLintPanel = view => {
|
|
3315
|
-
let field = view.state.field(lintState, false);
|
|
3316
|
-
if (!field || !field.panel) return false;
|
|
3317
|
-
view.dispatch({
|
|
3318
|
-
effects: togglePanel.of(false)
|
|
3319
|
-
});
|
|
3320
|
-
return true;
|
|
3321
|
-
};
|
|
3322
|
-
/**
|
|
3323
|
-
Move the selection to the next diagnostic.
|
|
3324
|
-
*/
|
|
3325
|
-
const nextDiagnostic = view => {
|
|
3326
|
-
let field = view.state.field(lintState, false);
|
|
3327
|
-
if (!field) return false;
|
|
3328
|
-
let sel = view.state.selection.main,
|
|
3329
|
-
next = field.diagnostics.iter(sel.to + 1);
|
|
3330
|
-
if (!next.value) {
|
|
3331
|
-
next = field.diagnostics.iter(0);
|
|
3332
|
-
if (!next.value || next.from == sel.from && next.to == sel.to) return false;
|
|
3333
|
-
}
|
|
3334
|
-
view.dispatch({
|
|
3335
|
-
selection: {
|
|
3336
|
-
anchor: next.from,
|
|
3337
|
-
head: next.to
|
|
3338
|
-
},
|
|
3339
|
-
scrollIntoView: true
|
|
3340
|
-
});
|
|
3341
|
-
return true;
|
|
3342
|
-
};
|
|
3343
|
-
/**
|
|
3344
|
-
A set of default key bindings for the lint functionality.
|
|
3345
|
-
|
|
3346
|
-
- Ctrl-Shift-m (Cmd-Shift-m on macOS): [`openLintPanel`](https://codemirror.net/6/docs/ref/#lint.openLintPanel)
|
|
3347
|
-
- F8: [`nextDiagnostic`](https://codemirror.net/6/docs/ref/#lint.nextDiagnostic)
|
|
3348
|
-
*/
|
|
3349
|
-
const lintKeymap = [{
|
|
3350
|
-
key: "Mod-Shift-m",
|
|
3351
|
-
run: openLintPanel,
|
|
3352
|
-
preventDefault: true
|
|
3353
|
-
}, {
|
|
3354
|
-
key: "F8",
|
|
3355
|
-
run: nextDiagnostic
|
|
3356
|
-
}];
|
|
3357
|
-
const lintPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
|
|
3358
|
-
constructor(view) {
|
|
3359
|
-
this.view = view;
|
|
3360
|
-
this.timeout = -1;
|
|
3361
|
-
this.set = true;
|
|
3362
|
-
let {
|
|
3363
|
-
delay
|
|
3364
|
-
} = view.state.facet(lintConfig);
|
|
3365
|
-
this.lintTime = Date.now() + delay;
|
|
3366
|
-
this.run = this.run.bind(this);
|
|
3367
|
-
this.timeout = setTimeout(this.run, delay);
|
|
3368
|
-
}
|
|
3369
|
-
run() {
|
|
3370
|
-
let now = Date.now();
|
|
3371
|
-
if (now < this.lintTime - 10) {
|
|
3372
|
-
setTimeout(this.run, this.lintTime - now);
|
|
3373
|
-
} else {
|
|
3374
|
-
this.set = false;
|
|
3375
|
-
let {
|
|
3376
|
-
state
|
|
3377
|
-
} = this.view,
|
|
3378
|
-
{
|
|
3379
|
-
sources
|
|
3380
|
-
} = state.facet(lintConfig);
|
|
3381
|
-
Promise.all(sources.map(source => Promise.resolve(source(this.view)))).then(annotations => {
|
|
3382
|
-
let all = annotations.reduce((a, b) => a.concat(b));
|
|
3383
|
-
if (this.view.state.doc == state.doc) this.view.dispatch(setDiagnostics(this.view.state, all));
|
|
3384
|
-
}, error => {
|
|
3385
|
-
logException(this.view.state, error);
|
|
3386
|
-
});
|
|
3387
|
-
}
|
|
3388
|
-
}
|
|
3389
|
-
update(update) {
|
|
3390
|
-
let config = update.state.facet(lintConfig);
|
|
3391
|
-
if (update.docChanged || config != update.startState.facet(lintConfig) || config.needsRefresh && config.needsRefresh(update)) {
|
|
3392
|
-
this.lintTime = Date.now() + config.delay;
|
|
3393
|
-
if (!this.set) {
|
|
3394
|
-
this.set = true;
|
|
3395
|
-
this.timeout = setTimeout(this.run, config.delay);
|
|
3396
|
-
}
|
|
3397
|
-
}
|
|
3398
|
-
}
|
|
3399
|
-
force() {
|
|
3400
|
-
if (this.set) {
|
|
3401
|
-
this.lintTime = Date.now();
|
|
3402
|
-
this.run();
|
|
3403
|
-
}
|
|
3404
|
-
}
|
|
3405
|
-
destroy() {
|
|
3406
|
-
clearTimeout(this.timeout);
|
|
3407
|
-
}
|
|
3408
|
-
});
|
|
3409
|
-
const lintConfig = /*@__PURE__*/Facet.define({
|
|
3410
|
-
combine(input) {
|
|
3411
|
-
return Object.assign({
|
|
3412
|
-
sources: input.map(i => i.source)
|
|
3413
|
-
}, combineConfig(input.map(i => i.config), {
|
|
3414
|
-
delay: 750,
|
|
3415
|
-
markerFilter: null,
|
|
3416
|
-
tooltipFilter: null,
|
|
3417
|
-
needsRefresh: null
|
|
3418
|
-
}, {
|
|
3419
|
-
needsRefresh: (a, b) => !a ? b : !b ? a : u => a(u) || b(u)
|
|
3420
|
-
}));
|
|
3421
|
-
},
|
|
3422
|
-
enables: lintPlugin
|
|
3423
|
-
});
|
|
3424
|
-
function assignKeys(actions) {
|
|
3425
|
-
let assigned = [];
|
|
3426
|
-
if (actions) actions: for (let {
|
|
3427
|
-
name
|
|
3428
|
-
} of actions) {
|
|
3429
|
-
for (let i = 0; i < name.length; i++) {
|
|
3430
|
-
let ch = name[i];
|
|
3431
|
-
if (/[a-zA-Z]/.test(ch) && !assigned.some(c => c.toLowerCase() == ch.toLowerCase())) {
|
|
3432
|
-
assigned.push(ch);
|
|
3433
|
-
continue actions;
|
|
3434
|
-
}
|
|
3435
|
-
}
|
|
3436
|
-
assigned.push("");
|
|
3437
|
-
}
|
|
3438
|
-
return assigned;
|
|
3439
|
-
}
|
|
3440
|
-
function renderDiagnostic(view, diagnostic, inPanel) {
|
|
3441
|
-
var _a;
|
|
3442
|
-
let keys = inPanel ? assignKeys(diagnostic.actions) : [];
|
|
3443
|
-
return crelt("li", {
|
|
3444
|
-
class: "cm-diagnostic cm-diagnostic-" + diagnostic.severity
|
|
3445
|
-
}, crelt("span", {
|
|
3446
|
-
class: "cm-diagnosticText"
|
|
3447
|
-
}, diagnostic.renderMessage ? diagnostic.renderMessage() : diagnostic.message), (_a = diagnostic.actions) === null || _a === void 0 ? void 0 : _a.map((action, i) => {
|
|
3448
|
-
let fired = false,
|
|
3449
|
-
click = e => {
|
|
3450
|
-
e.preventDefault();
|
|
3451
|
-
if (fired) return;
|
|
3452
|
-
fired = true;
|
|
3453
|
-
let found = findDiagnostic(view.state.field(lintState).diagnostics, diagnostic);
|
|
3454
|
-
if (found) action.apply(view, found.from, found.to);
|
|
3455
|
-
};
|
|
3456
|
-
let {
|
|
3457
|
-
name
|
|
3458
|
-
} = action,
|
|
3459
|
-
keyIndex = keys[i] ? name.indexOf(keys[i]) : -1;
|
|
3460
|
-
let nameElt = keyIndex < 0 ? name : [name.slice(0, keyIndex), crelt("u", name.slice(keyIndex, keyIndex + 1)), name.slice(keyIndex + 1)];
|
|
3461
|
-
return crelt("button", {
|
|
3462
|
-
type: "button",
|
|
3463
|
-
class: "cm-diagnosticAction",
|
|
3464
|
-
onclick: click,
|
|
3465
|
-
onmousedown: click,
|
|
3466
|
-
"aria-label": ` Action: ${name}${keyIndex < 0 ? "" : ` (access key "${keys[i]})"`}.`
|
|
3467
|
-
}, nameElt);
|
|
3468
|
-
}), diagnostic.source && crelt("div", {
|
|
3469
|
-
class: "cm-diagnosticSource"
|
|
3470
|
-
}, diagnostic.source));
|
|
3471
|
-
}
|
|
3472
|
-
class DiagnosticWidget extends WidgetType {
|
|
3473
|
-
constructor(diagnostic) {
|
|
3474
|
-
super();
|
|
3475
|
-
this.diagnostic = diagnostic;
|
|
3476
|
-
}
|
|
3477
|
-
eq(other) {
|
|
3478
|
-
return other.diagnostic == this.diagnostic;
|
|
3479
|
-
}
|
|
3480
|
-
toDOM() {
|
|
3481
|
-
return crelt("span", {
|
|
3482
|
-
class: "cm-lintPoint cm-lintPoint-" + this.diagnostic.severity
|
|
3483
|
-
});
|
|
3484
|
-
}
|
|
3485
|
-
}
|
|
3486
|
-
class PanelItem {
|
|
3487
|
-
constructor(view, diagnostic) {
|
|
3488
|
-
this.diagnostic = diagnostic;
|
|
3489
|
-
this.id = "item_" + Math.floor(Math.random() * 0xffffffff).toString(16);
|
|
3490
|
-
this.dom = renderDiagnostic(view, diagnostic, true);
|
|
3491
|
-
this.dom.id = this.id;
|
|
3492
|
-
this.dom.setAttribute("role", "option");
|
|
3493
|
-
}
|
|
3494
|
-
}
|
|
3495
|
-
class LintPanel {
|
|
3496
|
-
constructor(view) {
|
|
3497
|
-
this.view = view;
|
|
3498
|
-
this.items = [];
|
|
3499
|
-
let onkeydown = event => {
|
|
3500
|
-
if (event.keyCode == 27) {
|
|
3501
|
-
// Escape
|
|
3502
|
-
closeLintPanel(this.view);
|
|
3503
|
-
this.view.focus();
|
|
3504
|
-
} else if (event.keyCode == 38 || event.keyCode == 33) {
|
|
3505
|
-
// ArrowUp, PageUp
|
|
3506
|
-
this.moveSelection((this.selectedIndex - 1 + this.items.length) % this.items.length);
|
|
3507
|
-
} else if (event.keyCode == 40 || event.keyCode == 34) {
|
|
3508
|
-
// ArrowDown, PageDown
|
|
3509
|
-
this.moveSelection((this.selectedIndex + 1) % this.items.length);
|
|
3510
|
-
} else if (event.keyCode == 36) {
|
|
3511
|
-
// Home
|
|
3512
|
-
this.moveSelection(0);
|
|
3513
|
-
} else if (event.keyCode == 35) {
|
|
3514
|
-
// End
|
|
3515
|
-
this.moveSelection(this.items.length - 1);
|
|
3516
|
-
} else if (event.keyCode == 13) {
|
|
3517
|
-
// Enter
|
|
3518
|
-
this.view.focus();
|
|
3519
|
-
} else if (event.keyCode >= 65 && event.keyCode <= 90 && this.selectedIndex >= 0) {
|
|
3520
|
-
// A-Z
|
|
3521
|
-
let {
|
|
3522
|
-
diagnostic
|
|
3523
|
-
} = this.items[this.selectedIndex],
|
|
3524
|
-
keys = assignKeys(diagnostic.actions);
|
|
3525
|
-
for (let i = 0; i < keys.length; i++) if (keys[i].toUpperCase().charCodeAt(0) == event.keyCode) {
|
|
3526
|
-
let found = findDiagnostic(this.view.state.field(lintState).diagnostics, diagnostic);
|
|
3527
|
-
if (found) diagnostic.actions[i].apply(view, found.from, found.to);
|
|
3528
|
-
}
|
|
3529
|
-
} else {
|
|
3530
|
-
return;
|
|
3531
|
-
}
|
|
3532
|
-
event.preventDefault();
|
|
3533
|
-
};
|
|
3534
|
-
let onclick = event => {
|
|
3535
|
-
for (let i = 0; i < this.items.length; i++) {
|
|
3536
|
-
if (this.items[i].dom.contains(event.target)) this.moveSelection(i);
|
|
3537
|
-
}
|
|
3538
|
-
};
|
|
3539
|
-
this.list = crelt("ul", {
|
|
3540
|
-
tabIndex: 0,
|
|
3541
|
-
role: "listbox",
|
|
3542
|
-
"aria-label": this.view.state.phrase("Diagnostics"),
|
|
3543
|
-
onkeydown,
|
|
3544
|
-
onclick
|
|
3545
|
-
});
|
|
3546
|
-
this.dom = crelt("div", {
|
|
3547
|
-
class: "cm-panel-lint"
|
|
3548
|
-
}, this.list, crelt("button", {
|
|
3549
|
-
type: "button",
|
|
3550
|
-
name: "close",
|
|
3551
|
-
"aria-label": this.view.state.phrase("close"),
|
|
3552
|
-
onclick: () => closeLintPanel(this.view)
|
|
3553
|
-
}, "×"));
|
|
3554
|
-
this.update();
|
|
3555
|
-
}
|
|
3556
|
-
get selectedIndex() {
|
|
3557
|
-
let selected = this.view.state.field(lintState).selected;
|
|
3558
|
-
if (!selected) return -1;
|
|
3559
|
-
for (let i = 0; i < this.items.length; i++) if (this.items[i].diagnostic == selected.diagnostic) return i;
|
|
3560
|
-
return -1;
|
|
3561
|
-
}
|
|
3562
|
-
update() {
|
|
3563
|
-
let {
|
|
3564
|
-
diagnostics,
|
|
3565
|
-
selected
|
|
3566
|
-
} = this.view.state.field(lintState);
|
|
3567
|
-
let i = 0,
|
|
3568
|
-
needsSync = false,
|
|
3569
|
-
newSelectedItem = null;
|
|
3570
|
-
diagnostics.between(0, this.view.state.doc.length, (_start, _end, _ref3) => {
|
|
3571
|
-
let {
|
|
3572
|
-
spec
|
|
3573
|
-
} = _ref3;
|
|
3574
|
-
let found = -1,
|
|
3575
|
-
item;
|
|
3576
|
-
for (let j = i; j < this.items.length; j++) if (this.items[j].diagnostic == spec.diagnostic) {
|
|
3577
|
-
found = j;
|
|
3578
|
-
break;
|
|
3579
|
-
}
|
|
3580
|
-
if (found < 0) {
|
|
3581
|
-
item = new PanelItem(this.view, spec.diagnostic);
|
|
3582
|
-
this.items.splice(i, 0, item);
|
|
3583
|
-
needsSync = true;
|
|
3584
|
-
} else {
|
|
3585
|
-
item = this.items[found];
|
|
3586
|
-
if (found > i) {
|
|
3587
|
-
this.items.splice(i, found - i);
|
|
3588
|
-
needsSync = true;
|
|
3589
|
-
}
|
|
3590
|
-
}
|
|
3591
|
-
if (selected && item.diagnostic == selected.diagnostic) {
|
|
3592
|
-
if (!item.dom.hasAttribute("aria-selected")) {
|
|
3593
|
-
item.dom.setAttribute("aria-selected", "true");
|
|
3594
|
-
newSelectedItem = item;
|
|
3595
|
-
}
|
|
3596
|
-
} else if (item.dom.hasAttribute("aria-selected")) {
|
|
3597
|
-
item.dom.removeAttribute("aria-selected");
|
|
3598
|
-
}
|
|
3599
|
-
i++;
|
|
3600
|
-
});
|
|
3601
|
-
while (i < this.items.length && !(this.items.length == 1 && this.items[0].diagnostic.from < 0)) {
|
|
3602
|
-
needsSync = true;
|
|
3603
|
-
this.items.pop();
|
|
3604
|
-
}
|
|
3605
|
-
if (this.items.length == 0) {
|
|
3606
|
-
this.items.push(new PanelItem(this.view, {
|
|
3607
|
-
from: -1,
|
|
3608
|
-
to: -1,
|
|
3609
|
-
severity: "info",
|
|
3610
|
-
message: this.view.state.phrase("No diagnostics")
|
|
3611
|
-
}));
|
|
3612
|
-
needsSync = true;
|
|
3613
|
-
}
|
|
3614
|
-
if (newSelectedItem) {
|
|
3615
|
-
this.list.setAttribute("aria-activedescendant", newSelectedItem.id);
|
|
3616
|
-
this.view.requestMeasure({
|
|
3617
|
-
key: this,
|
|
3618
|
-
read: () => ({
|
|
3619
|
-
sel: newSelectedItem.dom.getBoundingClientRect(),
|
|
3620
|
-
panel: this.list.getBoundingClientRect()
|
|
3621
|
-
}),
|
|
3622
|
-
write: _ref4 => {
|
|
3623
|
-
let {
|
|
3624
|
-
sel,
|
|
3625
|
-
panel
|
|
3626
|
-
} = _ref4;
|
|
3627
|
-
if (sel.top < panel.top) this.list.scrollTop -= panel.top - sel.top;else if (sel.bottom > panel.bottom) this.list.scrollTop += sel.bottom - panel.bottom;
|
|
3628
|
-
}
|
|
3629
|
-
});
|
|
3630
|
-
} else if (this.selectedIndex < 0) {
|
|
3631
|
-
this.list.removeAttribute("aria-activedescendant");
|
|
3632
|
-
}
|
|
3633
|
-
if (needsSync) this.sync();
|
|
3634
|
-
}
|
|
3635
|
-
sync() {
|
|
3636
|
-
let domPos = this.list.firstChild;
|
|
3637
|
-
function rm() {
|
|
3638
|
-
let prev = domPos;
|
|
3639
|
-
domPos = prev.nextSibling;
|
|
3640
|
-
prev.remove();
|
|
3641
|
-
}
|
|
3642
|
-
for (let item of this.items) {
|
|
3643
|
-
if (item.dom.parentNode == this.list) {
|
|
3644
|
-
while (domPos != item.dom) rm();
|
|
3645
|
-
domPos = item.dom.nextSibling;
|
|
3646
|
-
} else {
|
|
3647
|
-
this.list.insertBefore(item.dom, domPos);
|
|
3648
|
-
}
|
|
3649
|
-
}
|
|
3650
|
-
while (domPos) rm();
|
|
3651
|
-
}
|
|
3652
|
-
moveSelection(selectedIndex) {
|
|
3653
|
-
if (this.selectedIndex < 0) return;
|
|
3654
|
-
let field = this.view.state.field(lintState);
|
|
3655
|
-
let selection = findDiagnostic(field.diagnostics, this.items[selectedIndex].diagnostic);
|
|
3656
|
-
if (!selection) return;
|
|
3657
|
-
this.view.dispatch({
|
|
3658
|
-
selection: {
|
|
3659
|
-
anchor: selection.from,
|
|
3660
|
-
head: selection.to
|
|
3661
|
-
},
|
|
3662
|
-
scrollIntoView: true,
|
|
3663
|
-
effects: movePanelSelection.of(selection)
|
|
3664
|
-
});
|
|
3665
|
-
}
|
|
3666
|
-
static open(view) {
|
|
3667
|
-
return new LintPanel(view);
|
|
3668
|
-
}
|
|
3669
|
-
}
|
|
3670
|
-
function svg(content) {
|
|
3671
|
-
let attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : `viewBox="0 0 40 40"`;
|
|
3672
|
-
return `url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${attrs}>${encodeURIComponent(content)}</svg>')`;
|
|
3673
|
-
}
|
|
3674
|
-
function underline(color) {
|
|
3675
|
-
return svg(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${color}" fill="none" stroke-width=".7"/>`, `width="6" height="3"`);
|
|
3676
|
-
}
|
|
3677
|
-
const baseTheme = /*@__PURE__*/EditorView.baseTheme({
|
|
3678
|
-
".cm-diagnostic": {
|
|
3679
|
-
padding: "3px 6px 3px 8px",
|
|
3680
|
-
marginLeft: "-1px",
|
|
3681
|
-
display: "block",
|
|
3682
|
-
whiteSpace: "pre-wrap"
|
|
3683
|
-
},
|
|
3684
|
-
".cm-diagnostic-error": {
|
|
3685
|
-
borderLeft: "5px solid #d11"
|
|
3686
|
-
},
|
|
3687
|
-
".cm-diagnostic-warning": {
|
|
3688
|
-
borderLeft: "5px solid orange"
|
|
3689
|
-
},
|
|
3690
|
-
".cm-diagnostic-info": {
|
|
3691
|
-
borderLeft: "5px solid #999"
|
|
3692
|
-
},
|
|
3693
|
-
".cm-diagnosticAction": {
|
|
3694
|
-
font: "inherit",
|
|
3695
|
-
border: "none",
|
|
3696
|
-
padding: "2px 4px",
|
|
3697
|
-
backgroundColor: "#444",
|
|
3698
|
-
color: "white",
|
|
3699
|
-
borderRadius: "3px",
|
|
3700
|
-
marginLeft: "8px",
|
|
3701
|
-
cursor: "pointer"
|
|
3702
|
-
},
|
|
3703
|
-
".cm-diagnosticSource": {
|
|
3704
|
-
fontSize: "70%",
|
|
3705
|
-
opacity: .7
|
|
3706
|
-
},
|
|
3707
|
-
".cm-lintRange": {
|
|
3708
|
-
backgroundPosition: "left bottom",
|
|
3709
|
-
backgroundRepeat: "repeat-x",
|
|
3710
|
-
paddingBottom: "0.7px"
|
|
3711
|
-
},
|
|
3712
|
-
".cm-lintRange-error": {
|
|
3713
|
-
backgroundImage: /*@__PURE__*/underline("#d11")
|
|
3714
|
-
},
|
|
3715
|
-
".cm-lintRange-warning": {
|
|
3716
|
-
backgroundImage: /*@__PURE__*/underline("orange")
|
|
3717
|
-
},
|
|
3718
|
-
".cm-lintRange-info": {
|
|
3719
|
-
backgroundImage: /*@__PURE__*/underline("#999")
|
|
3720
|
-
},
|
|
3721
|
-
".cm-lintRange-active": {
|
|
3722
|
-
backgroundColor: "#ffdd9980"
|
|
3723
|
-
},
|
|
3724
|
-
".cm-tooltip-lint": {
|
|
3725
|
-
padding: 0,
|
|
3726
|
-
margin: 0
|
|
3727
|
-
},
|
|
3728
|
-
".cm-lintPoint": {
|
|
3729
|
-
position: "relative",
|
|
3730
|
-
"&:after": {
|
|
3731
|
-
content: '""',
|
|
3732
|
-
position: "absolute",
|
|
3733
|
-
bottom: 0,
|
|
3734
|
-
left: "-2px",
|
|
3735
|
-
borderLeft: "3px solid transparent",
|
|
3736
|
-
borderRight: "3px solid transparent",
|
|
3737
|
-
borderBottom: "4px solid #d11"
|
|
3738
|
-
}
|
|
3739
|
-
},
|
|
3740
|
-
".cm-lintPoint-warning": {
|
|
3741
|
-
"&:after": {
|
|
3742
|
-
borderBottomColor: "orange"
|
|
3743
|
-
}
|
|
3744
|
-
},
|
|
3745
|
-
".cm-lintPoint-info": {
|
|
3746
|
-
"&:after": {
|
|
3747
|
-
borderBottomColor: "#999"
|
|
3748
|
-
}
|
|
3749
|
-
},
|
|
3750
|
-
".cm-panel.cm-panel-lint": {
|
|
3751
|
-
position: "relative",
|
|
3752
|
-
"& ul": {
|
|
3753
|
-
maxHeight: "100px",
|
|
3754
|
-
overflowY: "auto",
|
|
3755
|
-
"& [aria-selected]": {
|
|
3756
|
-
backgroundColor: "#ddd",
|
|
3757
|
-
"& u": {
|
|
3758
|
-
textDecoration: "underline"
|
|
3759
|
-
}
|
|
3760
|
-
},
|
|
3761
|
-
"&:focus [aria-selected]": {
|
|
3762
|
-
background_fallback: "#bdf",
|
|
3763
|
-
backgroundColor: "Highlight",
|
|
3764
|
-
color_fallback: "white",
|
|
3765
|
-
color: "HighlightText"
|
|
3766
|
-
},
|
|
3767
|
-
"& u": {
|
|
3768
|
-
textDecoration: "none"
|
|
3769
|
-
},
|
|
3770
|
-
padding: 0,
|
|
3771
|
-
margin: 0
|
|
3772
|
-
},
|
|
3773
|
-
"& [name=close]": {
|
|
3774
|
-
position: "absolute",
|
|
3775
|
-
top: "0",
|
|
3776
|
-
right: "2px",
|
|
3777
|
-
background: "inherit",
|
|
3778
|
-
border: "none",
|
|
3779
|
-
font: "inherit",
|
|
3780
|
-
padding: 0,
|
|
3781
|
-
margin: 0
|
|
3782
|
-
}
|
|
3783
|
-
}
|
|
3784
|
-
});
|
|
3785
|
-
|
|
3786
|
-
// (The superfluous function calls around the list of extensions work
|
|
3787
|
-
// around current limitations in tree-shaking software.)
|
|
3788
|
-
/**
|
|
3789
|
-
This is an extension value that just pulls together a number of
|
|
3790
|
-
extensions that you might want in a basic editor. It is meant as a
|
|
3791
|
-
convenient helper to quickly set up CodeMirror without installing
|
|
3792
|
-
and importing a lot of separate packages.
|
|
3793
|
-
|
|
3794
|
-
Specifically, it includes...
|
|
3795
|
-
|
|
3796
|
-
- [the default command bindings](https://codemirror.net/6/docs/ref/#commands.defaultKeymap)
|
|
3797
|
-
- [line numbers](https://codemirror.net/6/docs/ref/#view.lineNumbers)
|
|
3798
|
-
- [special character highlighting](https://codemirror.net/6/docs/ref/#view.highlightSpecialChars)
|
|
3799
|
-
- [the undo history](https://codemirror.net/6/docs/ref/#commands.history)
|
|
3800
|
-
- [a fold gutter](https://codemirror.net/6/docs/ref/#language.foldGutter)
|
|
3801
|
-
- [custom selection drawing](https://codemirror.net/6/docs/ref/#view.drawSelection)
|
|
3802
|
-
- [drop cursor](https://codemirror.net/6/docs/ref/#view.dropCursor)
|
|
3803
|
-
- [multiple selections](https://codemirror.net/6/docs/ref/#state.EditorState^allowMultipleSelections)
|
|
3804
|
-
- [reindentation on input](https://codemirror.net/6/docs/ref/#language.indentOnInput)
|
|
3805
|
-
- [the default highlight style](https://codemirror.net/6/docs/ref/#language.defaultHighlightStyle) (as fallback)
|
|
3806
|
-
- [bracket matching](https://codemirror.net/6/docs/ref/#language.bracketMatching)
|
|
3807
|
-
- [bracket closing](https://codemirror.net/6/docs/ref/#autocomplete.closeBrackets)
|
|
3808
|
-
- [autocompletion](https://codemirror.net/6/docs/ref/#autocomplete.autocompletion)
|
|
3809
|
-
- [rectangular selection](https://codemirror.net/6/docs/ref/#view.rectangularSelection) and [crosshair cursor](https://codemirror.net/6/docs/ref/#view.crosshairCursor)
|
|
3810
|
-
- [active line highlighting](https://codemirror.net/6/docs/ref/#view.highlightActiveLine)
|
|
3811
|
-
- [active line gutter highlighting](https://codemirror.net/6/docs/ref/#view.highlightActiveLineGutter)
|
|
3812
|
-
- [selection match highlighting](https://codemirror.net/6/docs/ref/#search.highlightSelectionMatches)
|
|
3813
|
-
- [search](https://codemirror.net/6/docs/ref/#search.searchKeymap)
|
|
3814
|
-
- [linting](https://codemirror.net/6/docs/ref/#lint.lintKeymap)
|
|
3815
|
-
|
|
3816
|
-
(You'll probably want to add some language package to your setup
|
|
3817
|
-
too.)
|
|
3818
|
-
|
|
3819
|
-
This extension does not allow customization. The idea is that,
|
|
3820
|
-
once you decide you want to configure your editor more precisely,
|
|
3821
|
-
you take this package's source (which is just a bunch of imports
|
|
3822
|
-
and an array literal), copy it into your own code, and adjust it
|
|
3823
|
-
as desired.
|
|
3824
|
-
*/
|
|
3825
|
-
const basicSetup = /*@__PURE__*/(() => [lineNumbers(), highlightActiveLineGutter(), highlightSpecialChars(), history(), foldGutter(), drawSelection(), dropCursor(), EditorState.allowMultipleSelections.of(true), indentOnInput(), syntaxHighlighting(defaultHighlightStyle, {
|
|
3826
|
-
fallback: true
|
|
3827
|
-
}), bracketMatching(), closeBrackets(), autocompletion(), rectangularSelection(), crosshairCursor(), highlightActiveLine(), highlightSelectionMatches(), keymap.of([...closeBracketsKeymap, ...defaultKeymap, ...searchKeymap, ...historyKeymap, ...foldKeymap, ...completionKeymap, ...lintKeymap])])();
|
|
3828
|
-
|
|
3829
41
|
//partially based on https://github.com/logue/vue-codemirror6/blob/master/src/components/CodeMirror.vue
|
|
3830
42
|
var script = defineComponent({
|
|
3831
43
|
name: 'OrCode',
|