@onereach/ui-components 6.2.0-beta.3294.0 → 6.2.0-beta.3299.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 +2 -2
- package/dist/bundled/v2/components/OrCode/index.js +5 -5
- package/dist/bundled/v2/components/OrCode/lang.js +5 -5
- package/dist/bundled/v2/components/OrCode/libs.js +5 -5
- package/dist/bundled/v2/components/OrCode/theme.js +1 -1
- package/dist/bundled/v2/components/OrCodeV3/OrCode.js +8 -8
- package/dist/bundled/v2/components/OrCodeV3/index.js +3 -3
- package/dist/bundled/v2/components/OrCodeV3/libs.js +3 -3
- package/dist/bundled/v2/components/index.js +6 -6
- package/dist/bundled/v2/{index-0ad0f605.js → index-003e27c5.js} +1 -1
- package/dist/bundled/v2/{index-379ec85d.js → index-13e363a1.js} +14 -12
- package/dist/bundled/v2/{index-d02cdc81.js → index-264444b5.js} +50 -13
- package/dist/bundled/{v3/index-c661340a.js → v2/index-2ff1af8f.js} +3 -3
- package/dist/bundled/v2/{index-0789b976.js → index-3f523d8c.js} +27 -25
- package/dist/bundled/v2/{index-b261a47e.js → index-4b36988f.js} +35 -25
- package/dist/bundled/v2/{index-ea7a689d.js → index-7488c2bc.js} +4 -4
- package/dist/bundled/v2/{index-7211e1c5.js → index-786635cb.js} +2 -2
- package/dist/bundled/v2/{index-9e0bdde8.js → index-e058b0e3.js} +2 -2
- package/dist/bundled/{v3/index-540ed5cb.js → v2/index-e9029e60.js} +288 -268
- package/dist/bundled/v2/index.js +6 -6
- package/dist/bundled/v3/{OrCode.vue_vue_type_script_lang-ad985f8f.js → OrCode.vue_vue_type_script_lang-53f0dbcf.js} +8 -8
- package/dist/bundled/v3/{OrCode.vue_vue_type_script_lang-1df17839.js → OrCode.vue_vue_type_script_lang-76b17c75.js} +2 -2
- package/dist/bundled/v3/components/OrCode/OrCode.js +2 -2
- package/dist/bundled/v3/components/OrCode/index.js +6 -6
- package/dist/bundled/v3/components/OrCode/lang.js +5 -5
- package/dist/bundled/v3/components/OrCode/libs.js +5 -5
- package/dist/bundled/v3/components/OrCode/theme.js +1 -1
- package/dist/bundled/v3/components/OrCodeV3/OrCode.js +2 -2
- package/dist/bundled/v3/components/OrCodeV3/index.js +4 -4
- package/dist/bundled/v3/components/OrCodeV3/libs.js +3 -3
- package/dist/bundled/v3/components/index.js +8 -8
- package/dist/bundled/v3/{index-168d8a72.js → index-3957c5be.js} +1 -1
- package/dist/bundled/v3/{index-e0aaa8dc.js → index-4eb7137d.js} +27 -25
- package/dist/bundled/v3/{index-3074ab3c.js → index-6a637771.js} +14 -12
- package/dist/bundled/{v2/index-c321391a.js → v3/index-81622681.js} +288 -268
- package/dist/bundled/v3/{index-73699920.js → index-9fa743a3.js} +35 -25
- package/dist/bundled/v3/{index-ce11b31b.js → index-b1301e6b.js} +50 -13
- package/dist/bundled/v3/{index-fdffd536.js → index-b52e24e9.js} +4 -4
- package/dist/bundled/{v2/index-5e5d18d5.js → v3/index-c3a9da95.js} +3 -3
- package/dist/bundled/v3/{index-a59e89b4.js → index-eaeb4268.js} +2 -2
- package/dist/bundled/v3/{index-3de4069f.js → index-f41a6890.js} +2 -2
- package/dist/bundled/v3/index.js +8 -8
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { s as syntaxTree, E as EditorView, r as codePointSize, q as codePointAt, b as EditorSelection, u as CharCategory, P as Prec, k as keymap, F as Facet, c as combineConfig, D as Direction,
|
|
1
|
+
import { s as syntaxTree, E as EditorView, r as codePointSize, q as codePointAt, b as EditorSelection, u as CharCategory, P as Prec, k as keymap, F as Facet, c as combineConfig, D as Direction, S as StateField, a0 as showTooltip, aj as getTooltip, V as ViewPlugin, Z as logException, m as StateEffect, ak as MapMode, al as RangeValue, $ as RangeSet, v as fromCodePoint, f as Text, A as Annotation, h as indentUnit, p as Decoration, a1 as WidgetType } from './index-4b36988f.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
An instance of this is passed to completion source functions.
|
|
@@ -224,7 +224,7 @@ class FuzzyMatcher {
|
|
|
224
224
|
// The score is a number that is more negative the worse the match
|
|
225
225
|
// is. See `Penalty` above.
|
|
226
226
|
match(word) {
|
|
227
|
-
if (this.pattern.length == 0) return [-100 /*
|
|
227
|
+
if (this.pattern.length == 0) return [-100 /* NotFull */];
|
|
228
228
|
if (word.length < this.pattern.length) return null;
|
|
229
229
|
let {
|
|
230
230
|
chars,
|
|
@@ -238,12 +238,12 @@ class FuzzyMatcher {
|
|
|
238
238
|
if (chars.length == 1) {
|
|
239
239
|
let first = codePointAt(word, 0),
|
|
240
240
|
firstSize = codePointSize(first);
|
|
241
|
-
let score = firstSize == word.length ? 0 : -100 /*
|
|
242
|
-
if (first == chars[0]) ;else if (first == folded[0]) score += -200 /*
|
|
241
|
+
let score = firstSize == word.length ? 0 : -100 /* NotFull */;
|
|
242
|
+
if (first == chars[0]) ;else if (first == folded[0]) score += -200 /* CaseFold */;else return null;
|
|
243
243
|
return [score, 0, firstSize];
|
|
244
244
|
}
|
|
245
245
|
let direct = word.indexOf(this.pattern);
|
|
246
|
-
if (direct == 0) return [word.length == this.pattern.length ? 0 : -100 /*
|
|
246
|
+
if (direct == 0) return [word.length == this.pattern.length ? 0 : -100 /* NotFull */, 0, this.pattern.length];
|
|
247
247
|
let len = chars.length,
|
|
248
248
|
anyTo = 0;
|
|
249
249
|
if (direct < 0) {
|
|
@@ -270,7 +270,7 @@ class FuzzyMatcher {
|
|
|
270
270
|
let hasLower = /[a-z]/.test(word),
|
|
271
271
|
wordAdjacent = true;
|
|
272
272
|
// Go over the option's text, scanning for the various kinds of matches
|
|
273
|
-
for (let i = 0, e = Math.min(word.length, 200), prevType = 0 /*
|
|
273
|
+
for (let i = 0, e = Math.min(word.length, 200), prevType = 0 /* NonWord */; i < e && byWordTo < len;) {
|
|
274
274
|
let next = codePointAt(word, i);
|
|
275
275
|
if (direct < 0) {
|
|
276
276
|
if (preciseTo < len && next == chars[preciseTo]) precise[preciseTo++] = i;
|
|
@@ -285,19 +285,19 @@ class FuzzyMatcher {
|
|
|
285
285
|
}
|
|
286
286
|
}
|
|
287
287
|
let ch,
|
|
288
|
-
type = next < 0xff ? next >= 48 && next <= 57 || next >= 97 && next <= 122 ? 2 /*
|
|
289
|
-
if (!i || type == 1 /*
|
|
288
|
+
type = next < 0xff ? next >= 48 && next <= 57 || next >= 97 && next <= 122 ? 2 /* Lower */ : next >= 65 && next <= 90 ? 1 /* Upper */ : 0 /* NonWord */ : (ch = fromCodePoint(next)) != ch.toLowerCase() ? 1 /* Upper */ : ch != ch.toUpperCase() ? 2 /* Lower */ : 0 /* NonWord */;
|
|
289
|
+
if (!i || type == 1 /* Upper */ && hasLower || prevType == 0 /* NonWord */ && type != 0 /* NonWord */) {
|
|
290
290
|
if (chars[byWordTo] == next || folded[byWordTo] == next && (byWordFolded = true)) byWord[byWordTo++] = i;else if (byWord.length) wordAdjacent = false;
|
|
291
291
|
}
|
|
292
292
|
prevType = type;
|
|
293
293
|
i += codePointSize(next);
|
|
294
294
|
}
|
|
295
|
-
if (byWordTo == len && byWord[0] == 0 && wordAdjacent) return this.result(-100 /*
|
|
296
|
-
if (adjacentTo == len && adjacentStart == 0) return [-200 /*
|
|
297
|
-
if (direct > -1) return [-700 /*
|
|
298
|
-
if (adjacentTo == len) return [-200 /*
|
|
299
|
-
if (byWordTo == len) return this.result(-100 /*
|
|
300
|
-
return chars.length == 2 ? null : this.result((any[0] ? -700 /*
|
|
295
|
+
if (byWordTo == len && byWord[0] == 0 && wordAdjacent) return this.result(-100 /* ByWord */ + (byWordFolded ? -200 /* CaseFold */ : 0), byWord, word);
|
|
296
|
+
if (adjacentTo == len && adjacentStart == 0) return [-200 /* CaseFold */ - word.length + (adjacentEnd == word.length ? 0 : -100 /* NotFull */), 0, adjacentEnd];
|
|
297
|
+
if (direct > -1) return [-700 /* NotStart */ - word.length, direct, direct + this.pattern.length];
|
|
298
|
+
if (adjacentTo == len) return [-200 /* CaseFold */ + -700 /* NotStart */ - word.length, adjacentStart, adjacentEnd];
|
|
299
|
+
if (byWordTo == len) return this.result(-100 /* ByWord */ + (byWordFolded ? -200 /* CaseFold */ : 0) + -700 /* NotStart */ + (wordAdjacent ? 0 : -1100 /* Gap */), byWord, word);
|
|
300
|
+
return chars.length == 2 ? null : this.result((any[0] ? -700 /* NotStart */ : 0) + -200 /* CaseFold */ + -1100 /* Gap */, any, word);
|
|
301
301
|
}
|
|
302
302
|
result(score, positions, word) {
|
|
303
303
|
let result = [score - word.length],
|
|
@@ -356,10 +356,10 @@ function defaultPositionInfo(view, list, option, info, space) {
|
|
|
356
356
|
if (left && spaceLeft < Math.min(infoWidth, spaceRight)) left = false;else if (!left && spaceRight < Math.min(infoWidth, spaceLeft)) left = true;
|
|
357
357
|
if (infoWidth <= (left ? spaceLeft : spaceRight)) {
|
|
358
358
|
offset = Math.max(space.top, Math.min(option.top, space.bottom - infoHeight)) - list.top;
|
|
359
|
-
maxWidth = Math.min(400 /*
|
|
359
|
+
maxWidth = Math.min(400 /* Width */, left ? spaceLeft : spaceRight);
|
|
360
360
|
} else {
|
|
361
361
|
narrow = true;
|
|
362
|
-
maxWidth = Math.min(400 /*
|
|
362
|
+
maxWidth = Math.min(400 /* Width */, (rtl ? list.right : space.right - list.left) - 30 /* Margin */);
|
|
363
363
|
let spaceBelow = space.bottom - list.bottom;
|
|
364
364
|
if (spaceBelow >= infoHeight || spaceBelow > list.top) {
|
|
365
365
|
// Below the completion
|
|
@@ -375,223 +375,6 @@ function defaultPositionInfo(view, list, option, info, space) {
|
|
|
375
375
|
class: "cm-completionInfo-" + (narrow ? rtl ? "left-narrow" : "right-narrow" : left ? "left" : "right")
|
|
376
376
|
};
|
|
377
377
|
}
|
|
378
|
-
|
|
379
|
-
/**
|
|
380
|
-
Returns a command that moves the completion selection forward or
|
|
381
|
-
backward by the given amount.
|
|
382
|
-
*/
|
|
383
|
-
function moveCompletionSelection(forward) {
|
|
384
|
-
let by = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "option";
|
|
385
|
-
return view => {
|
|
386
|
-
let cState = view.state.field(completionState, false);
|
|
387
|
-
if (!cState || !cState.open || cState.open.disabled || Date.now() - cState.open.timestamp < view.state.facet(completionConfig).interactionDelay) return false;
|
|
388
|
-
let step = 1,
|
|
389
|
-
tooltip;
|
|
390
|
-
if (by == "page" && (tooltip = getTooltip(view, cState.open.tooltip))) step = Math.max(2, Math.floor(tooltip.dom.offsetHeight / tooltip.dom.querySelector("li").offsetHeight) - 1);
|
|
391
|
-
let {
|
|
392
|
-
length
|
|
393
|
-
} = cState.open.options;
|
|
394
|
-
let selected = cState.open.selected > -1 ? cState.open.selected + step * (forward ? 1 : -1) : forward ? 0 : length - 1;
|
|
395
|
-
if (selected < 0) selected = by == "page" ? 0 : length - 1;else if (selected >= length) selected = by == "page" ? length - 1 : 0;
|
|
396
|
-
view.dispatch({
|
|
397
|
-
effects: setSelectedEffect.of(selected)
|
|
398
|
-
});
|
|
399
|
-
return true;
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
/**
|
|
403
|
-
Accept the current completion.
|
|
404
|
-
*/
|
|
405
|
-
const acceptCompletion = view => {
|
|
406
|
-
let cState = view.state.field(completionState, false);
|
|
407
|
-
if (view.state.readOnly || !cState || !cState.open || cState.open.selected < 0 || Date.now() - cState.open.timestamp < view.state.facet(completionConfig).interactionDelay) return false;
|
|
408
|
-
if (!cState.open.disabled) return applyCompletion(view, cState.open.options[cState.open.selected]);
|
|
409
|
-
return true;
|
|
410
|
-
};
|
|
411
|
-
/**
|
|
412
|
-
Explicitly start autocompletion.
|
|
413
|
-
*/
|
|
414
|
-
const startCompletion = view => {
|
|
415
|
-
let cState = view.state.field(completionState, false);
|
|
416
|
-
if (!cState) return false;
|
|
417
|
-
view.dispatch({
|
|
418
|
-
effects: startCompletionEffect.of(true)
|
|
419
|
-
});
|
|
420
|
-
return true;
|
|
421
|
-
};
|
|
422
|
-
/**
|
|
423
|
-
Close the currently active completion.
|
|
424
|
-
*/
|
|
425
|
-
const closeCompletion = view => {
|
|
426
|
-
let cState = view.state.field(completionState, false);
|
|
427
|
-
if (!cState || !cState.active.some(a => a.state != 0 /* State.Inactive */)) return false;
|
|
428
|
-
view.dispatch({
|
|
429
|
-
effects: closeCompletionEffect.of(null)
|
|
430
|
-
});
|
|
431
|
-
return true;
|
|
432
|
-
};
|
|
433
|
-
class RunningQuery {
|
|
434
|
-
constructor(active, context) {
|
|
435
|
-
this.active = active;
|
|
436
|
-
this.context = context;
|
|
437
|
-
this.time = Date.now();
|
|
438
|
-
this.updates = [];
|
|
439
|
-
// Note that 'undefined' means 'not done yet', whereas 'null' means
|
|
440
|
-
// 'query returned null'.
|
|
441
|
-
this.done = undefined;
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
const DebounceTime = 50,
|
|
445
|
-
MaxUpdateCount = 50,
|
|
446
|
-
MinAbortTime = 1000;
|
|
447
|
-
const completionPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
|
|
448
|
-
constructor(view) {
|
|
449
|
-
this.view = view;
|
|
450
|
-
this.debounceUpdate = -1;
|
|
451
|
-
this.running = [];
|
|
452
|
-
this.debounceAccept = -1;
|
|
453
|
-
this.composing = 0 /* CompositionState.None */;
|
|
454
|
-
for (let active of view.state.field(completionState).active) if (active.state == 1 /* State.Pending */) this.startQuery(active);
|
|
455
|
-
}
|
|
456
|
-
update(update) {
|
|
457
|
-
let cState = update.state.field(completionState);
|
|
458
|
-
if (!update.selectionSet && !update.docChanged && update.startState.field(completionState) == cState) return;
|
|
459
|
-
let doesReset = update.transactions.some(tr => {
|
|
460
|
-
return (tr.selection || tr.docChanged) && !getUserEvent(tr);
|
|
461
|
-
});
|
|
462
|
-
for (let i = 0; i < this.running.length; i++) {
|
|
463
|
-
let query = this.running[i];
|
|
464
|
-
if (doesReset || query.updates.length + update.transactions.length > MaxUpdateCount && Date.now() - query.time > MinAbortTime) {
|
|
465
|
-
for (let handler of query.context.abortListeners) {
|
|
466
|
-
try {
|
|
467
|
-
handler();
|
|
468
|
-
} catch (e) {
|
|
469
|
-
logException(this.view.state, e);
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
query.context.abortListeners = null;
|
|
473
|
-
this.running.splice(i--, 1);
|
|
474
|
-
} else {
|
|
475
|
-
query.updates.push(...update.transactions);
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
if (this.debounceUpdate > -1) clearTimeout(this.debounceUpdate);
|
|
479
|
-
this.debounceUpdate = cState.active.some(a => a.state == 1 /* State.Pending */ && !this.running.some(q => q.active.source == a.source)) ? setTimeout(() => this.startUpdate(), DebounceTime) : -1;
|
|
480
|
-
if (this.composing != 0 /* CompositionState.None */) for (let tr of update.transactions) {
|
|
481
|
-
if (getUserEvent(tr) == "input") this.composing = 2 /* CompositionState.Changed */;else if (this.composing == 2 /* CompositionState.Changed */ && tr.selection) this.composing = 3 /* CompositionState.ChangedAndMoved */;
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
startUpdate() {
|
|
486
|
-
this.debounceUpdate = -1;
|
|
487
|
-
let {
|
|
488
|
-
state
|
|
489
|
-
} = this.view,
|
|
490
|
-
cState = state.field(completionState);
|
|
491
|
-
for (let active of cState.active) {
|
|
492
|
-
if (active.state == 1 /* State.Pending */ && !this.running.some(r => r.active.source == active.source)) this.startQuery(active);
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
startQuery(active) {
|
|
496
|
-
let {
|
|
497
|
-
state
|
|
498
|
-
} = this.view,
|
|
499
|
-
pos = cur(state);
|
|
500
|
-
let context = new CompletionContext(state, pos, active.explicitPos == pos);
|
|
501
|
-
let pending = new RunningQuery(active, context);
|
|
502
|
-
this.running.push(pending);
|
|
503
|
-
Promise.resolve(active.source(context)).then(result => {
|
|
504
|
-
if (!pending.context.aborted) {
|
|
505
|
-
pending.done = result || null;
|
|
506
|
-
this.scheduleAccept();
|
|
507
|
-
}
|
|
508
|
-
}, err => {
|
|
509
|
-
this.view.dispatch({
|
|
510
|
-
effects: closeCompletionEffect.of(null)
|
|
511
|
-
});
|
|
512
|
-
logException(this.view.state, err);
|
|
513
|
-
});
|
|
514
|
-
}
|
|
515
|
-
scheduleAccept() {
|
|
516
|
-
if (this.running.every(q => q.done !== undefined)) this.accept();else if (this.debounceAccept < 0) this.debounceAccept = setTimeout(() => this.accept(), DebounceTime);
|
|
517
|
-
}
|
|
518
|
-
// For each finished query in this.running, try to create a result
|
|
519
|
-
// or, if appropriate, restart the query.
|
|
520
|
-
accept() {
|
|
521
|
-
var _a;
|
|
522
|
-
if (this.debounceAccept > -1) clearTimeout(this.debounceAccept);
|
|
523
|
-
this.debounceAccept = -1;
|
|
524
|
-
let updated = [];
|
|
525
|
-
let conf = this.view.state.facet(completionConfig);
|
|
526
|
-
for (let i = 0; i < this.running.length; i++) {
|
|
527
|
-
let query = this.running[i];
|
|
528
|
-
if (query.done === undefined) continue;
|
|
529
|
-
this.running.splice(i--, 1);
|
|
530
|
-
if (query.done) {
|
|
531
|
-
let active = new ActiveResult(query.active.source, query.active.explicitPos, query.done, query.done.from, (_a = query.done.to) !== null && _a !== void 0 ? _a : cur(query.updates.length ? query.updates[0].startState : this.view.state));
|
|
532
|
-
// Replay the transactions that happened since the start of
|
|
533
|
-
// the request and see if that preserves the result
|
|
534
|
-
for (let tr of query.updates) active = active.update(tr, conf);
|
|
535
|
-
if (active.hasResult()) {
|
|
536
|
-
updated.push(active);
|
|
537
|
-
continue;
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
let current = this.view.state.field(completionState).active.find(a => a.source == query.active.source);
|
|
541
|
-
if (current && current.state == 1 /* State.Pending */) {
|
|
542
|
-
if (query.done == null) {
|
|
543
|
-
// Explicitly failed. Should clear the pending status if it
|
|
544
|
-
// hasn't been re-set in the meantime.
|
|
545
|
-
let active = new ActiveSource(query.active.source, 0 /* State.Inactive */);
|
|
546
|
-
for (let tr of query.updates) active = active.update(tr, conf);
|
|
547
|
-
if (active.state != 1 /* State.Pending */) updated.push(active);
|
|
548
|
-
} else {
|
|
549
|
-
// Cleared by subsequent transactions. Restart.
|
|
550
|
-
this.startQuery(current);
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
if (updated.length) this.view.dispatch({
|
|
555
|
-
effects: setActiveEffect.of(updated)
|
|
556
|
-
});
|
|
557
|
-
}
|
|
558
|
-
}, {
|
|
559
|
-
eventHandlers: {
|
|
560
|
-
blur(event) {
|
|
561
|
-
let state = this.view.state.field(completionState, false);
|
|
562
|
-
if (state && state.tooltip && this.view.state.facet(completionConfig).closeOnBlur) {
|
|
563
|
-
let dialog = state.open && getTooltip(this.view, state.open.tooltip);
|
|
564
|
-
if (!dialog || !dialog.dom.contains(event.relatedTarget)) this.view.dispatch({
|
|
565
|
-
effects: closeCompletionEffect.of(null)
|
|
566
|
-
});
|
|
567
|
-
}
|
|
568
|
-
},
|
|
569
|
-
compositionstart() {
|
|
570
|
-
this.composing = 1 /* CompositionState.Started */;
|
|
571
|
-
},
|
|
572
|
-
|
|
573
|
-
compositionend() {
|
|
574
|
-
if (this.composing == 3 /* CompositionState.ChangedAndMoved */) {
|
|
575
|
-
// Safari fires compositionend events synchronously, possibly
|
|
576
|
-
// from inside an update, so dispatch asynchronously to avoid reentrancy
|
|
577
|
-
setTimeout(() => this.view.dispatch({
|
|
578
|
-
effects: startCompletionEffect.of(false)
|
|
579
|
-
}), 20);
|
|
580
|
-
}
|
|
581
|
-
this.composing = 0 /* CompositionState.None */;
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
});
|
|
585
|
-
|
|
586
|
-
function applyCompletion(view, option) {
|
|
587
|
-
const apply = option.completion.apply || option.completion.label;
|
|
588
|
-
let result = view.state.field(completionState).active.find(a => a.source == option.source);
|
|
589
|
-
if (!(result instanceof ActiveResult)) return false;
|
|
590
|
-
if (typeof apply == "string") view.dispatch(Object.assign(Object.assign({}, insertCompletionText(view.state, apply, result.from, result.to)), {
|
|
591
|
-
annotations: pickedCompletion.of(option.completion)
|
|
592
|
-
}));else apply(view, option.completion, result.from, result.to);
|
|
593
|
-
return true;
|
|
594
|
-
}
|
|
595
378
|
function optionContent(config) {
|
|
596
379
|
let content = config.addToOptions.slice();
|
|
597
380
|
if (config.icons) content.push({
|
|
@@ -657,10 +440,12 @@ function rangeAroundSelected(total, selected, max) {
|
|
|
657
440
|
};
|
|
658
441
|
}
|
|
659
442
|
class CompletionTooltip {
|
|
660
|
-
constructor(view, stateField) {
|
|
443
|
+
constructor(view, stateField, applyCompletion) {
|
|
661
444
|
this.view = view;
|
|
662
445
|
this.stateField = stateField;
|
|
446
|
+
this.applyCompletion = applyCompletion;
|
|
663
447
|
this.info = null;
|
|
448
|
+
this.infoDestroy = null;
|
|
664
449
|
this.placeInfoReq = {
|
|
665
450
|
read: () => this.measureInfo(),
|
|
666
451
|
write: pos => this.placeInfo(pos),
|
|
@@ -684,7 +469,7 @@ class CompletionTooltip {
|
|
|
684
469
|
this.dom.addEventListener("mousedown", e => {
|
|
685
470
|
for (let dom = e.target, match; dom && dom != this.dom; dom = dom.parentNode) {
|
|
686
471
|
if (dom.nodeName == "LI" && (match = /-(\d+)$/.exec(dom.id)) && +match[1] < options.length) {
|
|
687
|
-
applyCompletion(view, options[+match[1]]);
|
|
472
|
+
this.applyCompletion(view, options[+match[1]]);
|
|
688
473
|
e.preventDefault();
|
|
689
474
|
return;
|
|
690
475
|
}
|
|
@@ -738,10 +523,7 @@ class CompletionTooltip {
|
|
|
738
523
|
});
|
|
739
524
|
}
|
|
740
525
|
if (this.updateSelectedOption(open.selected)) {
|
|
741
|
-
|
|
742
|
-
this.info.remove();
|
|
743
|
-
this.info = null;
|
|
744
|
-
}
|
|
526
|
+
this.destroyInfo();
|
|
745
527
|
let {
|
|
746
528
|
completion
|
|
747
529
|
} = open.options[open.selected];
|
|
@@ -749,22 +531,33 @@ class CompletionTooltip {
|
|
|
749
531
|
info
|
|
750
532
|
} = completion;
|
|
751
533
|
if (!info) return;
|
|
752
|
-
let infoResult = typeof info ===
|
|
534
|
+
let infoResult = typeof info === "string" ? document.createTextNode(info) : info(completion);
|
|
753
535
|
if (!infoResult) return;
|
|
754
|
-
if (
|
|
755
|
-
infoResult.then(
|
|
756
|
-
if (
|
|
536
|
+
if ("then" in infoResult) {
|
|
537
|
+
infoResult.then(obj => {
|
|
538
|
+
if (obj && this.view.state.field(this.stateField, false) == cState) this.addInfoPane(obj, completion);
|
|
757
539
|
}).catch(e => logException(this.view.state, e, "completion info"));
|
|
758
540
|
} else {
|
|
759
|
-
this.addInfoPane(infoResult);
|
|
541
|
+
this.addInfoPane(infoResult, completion);
|
|
760
542
|
}
|
|
761
543
|
}
|
|
762
544
|
}
|
|
763
|
-
addInfoPane(content) {
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
545
|
+
addInfoPane(content, completion) {
|
|
546
|
+
this.destroyInfo();
|
|
547
|
+
let wrap = this.info = document.createElement("div");
|
|
548
|
+
wrap.className = "cm-tooltip cm-completionInfo";
|
|
549
|
+
if (content.nodeType != null) {
|
|
550
|
+
wrap.appendChild(content);
|
|
551
|
+
this.infoDestroy = null;
|
|
552
|
+
} else {
|
|
553
|
+
let {
|
|
554
|
+
dom,
|
|
555
|
+
destroy
|
|
556
|
+
} = content;
|
|
557
|
+
wrap.appendChild(dom);
|
|
558
|
+
this.infoDestroy = destroy || null;
|
|
559
|
+
}
|
|
560
|
+
this.dom.appendChild(wrap);
|
|
768
561
|
this.view.requestMeasure(this.placeInfoReq);
|
|
769
562
|
}
|
|
770
563
|
updateSelectedOption(selected) {
|
|
@@ -854,11 +647,21 @@ class CompletionTooltip {
|
|
|
854
647
|
if (range.to < options.length) ul.classList.add("cm-completionListIncompleteBottom");
|
|
855
648
|
return ul;
|
|
856
649
|
}
|
|
650
|
+
destroyInfo() {
|
|
651
|
+
if (this.info) {
|
|
652
|
+
if (this.infoDestroy) this.infoDestroy();
|
|
653
|
+
this.info.remove();
|
|
654
|
+
this.info = null;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
destroy() {
|
|
658
|
+
this.destroyInfo();
|
|
659
|
+
}
|
|
857
660
|
}
|
|
858
661
|
// We allocate a new function instance every time the completion
|
|
859
662
|
// changes to force redrawing/repositioning of the tooltip
|
|
860
|
-
function completionTooltip(stateField) {
|
|
861
|
-
return view => new CompletionTooltip(view, stateField);
|
|
663
|
+
function completionTooltip(stateField, applyCompletion) {
|
|
664
|
+
return view => new CompletionTooltip(view, stateField, applyCompletion);
|
|
862
665
|
}
|
|
863
666
|
function scrollIntoView(container, element) {
|
|
864
667
|
let parent = container.getBoundingClientRect();
|
|
@@ -925,7 +728,8 @@ function sortOptions(active, state) {
|
|
|
925
728
|
prev = null;
|
|
926
729
|
let compare = state.facet(completionConfig).compareCompletions;
|
|
927
730
|
for (let opt of options.sort((a, b) => b.score - a.score || compare(a.completion, b.completion))) {
|
|
928
|
-
|
|
731
|
+
let cur = opt.completion;
|
|
732
|
+
if (!prev || prev.label != cur.label || prev.detail != cur.detail || prev.type != null && cur.type != null && prev.type != cur.type || prev.apply != cur.apply || prev.boost != cur.boost) result.push(opt);else if (score(opt.completion) > score(prev)) result[result.length - 1] = opt;
|
|
929
733
|
prev = opt.completion;
|
|
930
734
|
}
|
|
931
735
|
return result;
|
|
@@ -945,7 +749,7 @@ class CompletionDialog {
|
|
|
945
749
|
static build(active, state, id, prev, conf) {
|
|
946
750
|
let options = sortOptions(active, state);
|
|
947
751
|
if (!options.length) {
|
|
948
|
-
return prev && active.some(a => a.state == 1 /*
|
|
752
|
+
return prev && active.some(a => a.state == 1 /* Pending */) ? new CompletionDialog(prev.options, prev.attrs, prev.tooltip, prev.timestamp, prev.selected, true) : null;
|
|
949
753
|
}
|
|
950
754
|
let selected = state.facet(completionConfig).selectOnOpen ? 0 : -1;
|
|
951
755
|
if (prev && prev.selected != selected && prev.selected != -1) {
|
|
@@ -957,7 +761,7 @@ class CompletionDialog {
|
|
|
957
761
|
}
|
|
958
762
|
return new CompletionDialog(options, makeAttrs(id, selected), {
|
|
959
763
|
pos: active.reduce((a, b) => b.hasResult() ? Math.min(a, b.from) : a, 1e8),
|
|
960
|
-
create: completionTooltip(completionState),
|
|
764
|
+
create: completionTooltip(completionState, applyCompletion),
|
|
961
765
|
above: conf.aboveCursor
|
|
962
766
|
}, prev ? prev.timestamp : Date.now(), selected, false);
|
|
963
767
|
}
|
|
@@ -983,14 +787,14 @@ class CompletionState {
|
|
|
983
787
|
conf = state.facet(completionConfig);
|
|
984
788
|
let sources = conf.override || state.languageDataAt("autocomplete", cur(state)).map(asSource);
|
|
985
789
|
let active = sources.map(source => {
|
|
986
|
-
let value = this.active.find(s => s.source == source) || new ActiveSource(source, this.active.some(a => a.state != 0 /*
|
|
790
|
+
let value = this.active.find(s => s.source == source) || new ActiveSource(source, this.active.some(a => a.state != 0 /* Inactive */) ? 1 /* Pending */ : 0 /* Inactive */);
|
|
987
791
|
return value.update(tr, conf);
|
|
988
792
|
});
|
|
989
793
|
if (active.length == this.active.length && active.every((a, i) => a == this.active[i])) active = this.active;
|
|
990
794
|
let open = this.open;
|
|
991
795
|
if (open && tr.docChanged) open = open.map(tr.changes);
|
|
992
|
-
if (tr.selection || active.some(a => a.hasResult() && tr.changes.touchesRange(a.from, a.to)) || !sameResults(active, this.active)) open = CompletionDialog.build(active, state, this.id, open, conf);else if (open && open.disabled && !active.some(a => a.state == 1 /*
|
|
993
|
-
if (!open && active.every(a => a.state != 1 /*
|
|
796
|
+
if (tr.selection || active.some(a => a.hasResult() && tr.changes.touchesRange(a.from, a.to)) || !sameResults(active, this.active)) open = CompletionDialog.build(active, state, this.id, open, conf);else if (open && open.disabled && !active.some(a => a.state == 1 /* Pending */)) open = null;
|
|
797
|
+
if (!open && active.every(a => a.state != 1 /* Pending */) && active.some(a => a.hasResult())) active = active.map(a => a.hasResult() ? new ActiveSource(a.source, 0 /* Inactive */) : a);
|
|
994
798
|
for (let effect of tr.effects) if (effect.is(setSelectedEffect)) open = open && open.setSelected(effect.value, this.id);
|
|
995
799
|
return active == this.active && open == this.open ? this : new CompletionState(active, this.id, open);
|
|
996
800
|
}
|
|
@@ -1041,18 +845,18 @@ class ActiveSource {
|
|
|
1041
845
|
update(tr, conf) {
|
|
1042
846
|
let event = getUserEvent(tr),
|
|
1043
847
|
value = this;
|
|
1044
|
-
if (event) value = value.handleUserEvent(tr, event, conf);else if (tr.docChanged) value = value.handleChange(tr);else if (tr.selection && value.state != 0 /*
|
|
848
|
+
if (event) value = value.handleUserEvent(tr, event, conf);else if (tr.docChanged) value = value.handleChange(tr);else if (tr.selection && value.state != 0 /* Inactive */) value = new ActiveSource(value.source, 0 /* Inactive */);
|
|
1045
849
|
for (let effect of tr.effects) {
|
|
1046
|
-
if (effect.is(startCompletionEffect)) value = new ActiveSource(value.source, 1 /*
|
|
850
|
+
if (effect.is(startCompletionEffect)) value = new ActiveSource(value.source, 1 /* Pending */, effect.value ? cur(tr.state) : -1);else if (effect.is(closeCompletionEffect)) value = new ActiveSource(value.source, 0 /* Inactive */);else if (effect.is(setActiveEffect)) for (let active of effect.value) if (active.source == value.source) value = active;
|
|
1047
851
|
}
|
|
1048
852
|
return value;
|
|
1049
853
|
}
|
|
1050
854
|
handleUserEvent(tr, type, conf) {
|
|
1051
|
-
return type == "delete" || !conf.activateOnTyping ? this.map(tr.changes) : new ActiveSource(this.source, 1 /*
|
|
855
|
+
return type == "delete" || !conf.activateOnTyping ? this.map(tr.changes) : new ActiveSource(this.source, 1 /* Pending */);
|
|
1052
856
|
}
|
|
1053
857
|
|
|
1054
858
|
handleChange(tr) {
|
|
1055
|
-
return tr.changes.touchesRange(cur(tr.startState)) ? new ActiveSource(this.source, 0 /*
|
|
859
|
+
return tr.changes.touchesRange(cur(tr.startState)) ? new ActiveSource(this.source, 0 /* Inactive */) : this.map(tr.changes);
|
|
1056
860
|
}
|
|
1057
861
|
map(changes) {
|
|
1058
862
|
return changes.empty || this.explicitPos < 0 ? this : new ActiveSource(this.source, this.state, changes.mapPos(this.explicitPos));
|
|
@@ -1060,7 +864,7 @@ class ActiveSource {
|
|
|
1060
864
|
}
|
|
1061
865
|
class ActiveResult extends ActiveSource {
|
|
1062
866
|
constructor(source, explicitPos, result, from, to) {
|
|
1063
|
-
super(source, 2 /*
|
|
867
|
+
super(source, 2 /* Result */, explicitPos);
|
|
1064
868
|
this.result = result;
|
|
1065
869
|
this.from = from;
|
|
1066
870
|
this.to = to;
|
|
@@ -1073,15 +877,15 @@ class ActiveResult extends ActiveSource {
|
|
|
1073
877
|
let from = tr.changes.mapPos(this.from),
|
|
1074
878
|
to = tr.changes.mapPos(this.to, 1);
|
|
1075
879
|
let pos = cur(tr.state);
|
|
1076
|
-
if ((this.explicitPos < 0 ? pos <= from : pos < this.from) || pos > to || type == "delete" && cur(tr.startState) == this.from) return new ActiveSource(this.source, type == "input" && conf.activateOnTyping ? 1 /*
|
|
880
|
+
if ((this.explicitPos < 0 ? pos <= from : pos < this.from) || pos > to || type == "delete" && cur(tr.startState) == this.from) return new ActiveSource(this.source, type == "input" && conf.activateOnTyping ? 1 /* Pending */ : 0 /* Inactive */);
|
|
1077
881
|
let explicitPos = this.explicitPos < 0 ? -1 : tr.changes.mapPos(this.explicitPos),
|
|
1078
882
|
updated;
|
|
1079
883
|
if (checkValid(this.result.validFor, tr.state, from, to)) return new ActiveResult(this.source, explicitPos, this.result, from, to);
|
|
1080
884
|
if (this.result.update && (updated = this.result.update(this.result, from, to, new CompletionContext(tr.state, pos, explicitPos >= 0)))) return new ActiveResult(this.source, explicitPos, updated, updated.from, (_a = updated.to) !== null && _a !== void 0 ? _a : cur(tr.state));
|
|
1081
|
-
return new ActiveSource(this.source, 1 /*
|
|
885
|
+
return new ActiveSource(this.source, 1 /* Pending */, explicitPos);
|
|
1082
886
|
}
|
|
1083
887
|
handleChange(tr) {
|
|
1084
|
-
return tr.changes.touchesRange(this.from, this.to) ? new ActiveSource(this.source, 0 /*
|
|
888
|
+
return tr.changes.touchesRange(this.from, this.to) ? new ActiveSource(this.source, 0 /* Inactive */) : this.map(tr.changes);
|
|
1085
889
|
}
|
|
1086
890
|
map(mapping) {
|
|
1087
891
|
return mapping.empty ? this : new ActiveResult(this.source, this.explicitPos < 0 ? -1 : mapping.mapPos(this.explicitPos), this.result, mapping.mapPos(this.from), mapping.mapPos(this.to, 1));
|
|
@@ -1107,6 +911,222 @@ const completionState = /*@__PURE__*/StateField.define({
|
|
|
1107
911
|
},
|
|
1108
912
|
provide: f => [showTooltip.from(f, val => val.tooltip), EditorView.contentAttributes.from(f, state => state.attrs)]
|
|
1109
913
|
});
|
|
914
|
+
function applyCompletion(view, option) {
|
|
915
|
+
const apply = option.completion.apply || option.completion.label;
|
|
916
|
+
let result = view.state.field(completionState).active.find(a => a.source == option.source);
|
|
917
|
+
if (!(result instanceof ActiveResult)) return false;
|
|
918
|
+
if (typeof apply == "string") view.dispatch(Object.assign(Object.assign({}, insertCompletionText(view.state, apply, result.from, result.to)), {
|
|
919
|
+
annotations: pickedCompletion.of(option.completion)
|
|
920
|
+
}));else apply(view, option.completion, result.from, result.to);
|
|
921
|
+
return true;
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
/**
|
|
925
|
+
Returns a command that moves the completion selection forward or
|
|
926
|
+
backward by the given amount.
|
|
927
|
+
*/
|
|
928
|
+
function moveCompletionSelection(forward) {
|
|
929
|
+
let by = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "option";
|
|
930
|
+
return view => {
|
|
931
|
+
let cState = view.state.field(completionState, false);
|
|
932
|
+
if (!cState || !cState.open || cState.open.disabled || Date.now() - cState.open.timestamp < view.state.facet(completionConfig).interactionDelay) return false;
|
|
933
|
+
let step = 1,
|
|
934
|
+
tooltip;
|
|
935
|
+
if (by == "page" && (tooltip = getTooltip(view, cState.open.tooltip))) step = Math.max(2, Math.floor(tooltip.dom.offsetHeight / tooltip.dom.querySelector("li").offsetHeight) - 1);
|
|
936
|
+
let {
|
|
937
|
+
length
|
|
938
|
+
} = cState.open.options;
|
|
939
|
+
let selected = cState.open.selected > -1 ? cState.open.selected + step * (forward ? 1 : -1) : forward ? 0 : length - 1;
|
|
940
|
+
if (selected < 0) selected = by == "page" ? 0 : length - 1;else if (selected >= length) selected = by == "page" ? length - 1 : 0;
|
|
941
|
+
view.dispatch({
|
|
942
|
+
effects: setSelectedEffect.of(selected)
|
|
943
|
+
});
|
|
944
|
+
return true;
|
|
945
|
+
};
|
|
946
|
+
}
|
|
947
|
+
/**
|
|
948
|
+
Accept the current completion.
|
|
949
|
+
*/
|
|
950
|
+
const acceptCompletion = view => {
|
|
951
|
+
let cState = view.state.field(completionState, false);
|
|
952
|
+
if (view.state.readOnly || !cState || !cState.open || cState.open.selected < 0 || cState.open.disabled || Date.now() - cState.open.timestamp < view.state.facet(completionConfig).interactionDelay) return false;
|
|
953
|
+
return applyCompletion(view, cState.open.options[cState.open.selected]);
|
|
954
|
+
};
|
|
955
|
+
/**
|
|
956
|
+
Explicitly start autocompletion.
|
|
957
|
+
*/
|
|
958
|
+
const startCompletion = view => {
|
|
959
|
+
let cState = view.state.field(completionState, false);
|
|
960
|
+
if (!cState) return false;
|
|
961
|
+
view.dispatch({
|
|
962
|
+
effects: startCompletionEffect.of(true)
|
|
963
|
+
});
|
|
964
|
+
return true;
|
|
965
|
+
};
|
|
966
|
+
/**
|
|
967
|
+
Close the currently active completion.
|
|
968
|
+
*/
|
|
969
|
+
const closeCompletion = view => {
|
|
970
|
+
let cState = view.state.field(completionState, false);
|
|
971
|
+
if (!cState || !cState.active.some(a => a.state != 0 /* Inactive */)) return false;
|
|
972
|
+
view.dispatch({
|
|
973
|
+
effects: closeCompletionEffect.of(null)
|
|
974
|
+
});
|
|
975
|
+
return true;
|
|
976
|
+
};
|
|
977
|
+
class RunningQuery {
|
|
978
|
+
constructor(active, context) {
|
|
979
|
+
this.active = active;
|
|
980
|
+
this.context = context;
|
|
981
|
+
this.time = Date.now();
|
|
982
|
+
this.updates = [];
|
|
983
|
+
// Note that 'undefined' means 'not done yet', whereas 'null' means
|
|
984
|
+
// 'query returned null'.
|
|
985
|
+
this.done = undefined;
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
const DebounceTime = 50,
|
|
989
|
+
MaxUpdateCount = 50,
|
|
990
|
+
MinAbortTime = 1000;
|
|
991
|
+
const completionPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
|
|
992
|
+
constructor(view) {
|
|
993
|
+
this.view = view;
|
|
994
|
+
this.debounceUpdate = -1;
|
|
995
|
+
this.running = [];
|
|
996
|
+
this.debounceAccept = -1;
|
|
997
|
+
this.composing = 0 /* None */;
|
|
998
|
+
for (let active of view.state.field(completionState).active) if (active.state == 1 /* Pending */) this.startQuery(active);
|
|
999
|
+
}
|
|
1000
|
+
update(update) {
|
|
1001
|
+
let cState = update.state.field(completionState);
|
|
1002
|
+
if (!update.selectionSet && !update.docChanged && update.startState.field(completionState) == cState) return;
|
|
1003
|
+
let doesReset = update.transactions.some(tr => {
|
|
1004
|
+
return (tr.selection || tr.docChanged) && !getUserEvent(tr);
|
|
1005
|
+
});
|
|
1006
|
+
for (let i = 0; i < this.running.length; i++) {
|
|
1007
|
+
let query = this.running[i];
|
|
1008
|
+
if (doesReset || query.updates.length + update.transactions.length > MaxUpdateCount && Date.now() - query.time > MinAbortTime) {
|
|
1009
|
+
for (let handler of query.context.abortListeners) {
|
|
1010
|
+
try {
|
|
1011
|
+
handler();
|
|
1012
|
+
} catch (e) {
|
|
1013
|
+
logException(this.view.state, e);
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
query.context.abortListeners = null;
|
|
1017
|
+
this.running.splice(i--, 1);
|
|
1018
|
+
} else {
|
|
1019
|
+
query.updates.push(...update.transactions);
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
if (this.debounceUpdate > -1) clearTimeout(this.debounceUpdate);
|
|
1023
|
+
this.debounceUpdate = cState.active.some(a => a.state == 1 /* Pending */ && !this.running.some(q => q.active.source == a.source)) ? setTimeout(() => this.startUpdate(), DebounceTime) : -1;
|
|
1024
|
+
if (this.composing != 0 /* None */) for (let tr of update.transactions) {
|
|
1025
|
+
if (getUserEvent(tr) == "input") this.composing = 2 /* Changed */;else if (this.composing == 2 /* Changed */ && tr.selection) this.composing = 3 /* ChangedAndMoved */;
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
startUpdate() {
|
|
1030
|
+
this.debounceUpdate = -1;
|
|
1031
|
+
let {
|
|
1032
|
+
state
|
|
1033
|
+
} = this.view,
|
|
1034
|
+
cState = state.field(completionState);
|
|
1035
|
+
for (let active of cState.active) {
|
|
1036
|
+
if (active.state == 1 /* Pending */ && !this.running.some(r => r.active.source == active.source)) this.startQuery(active);
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
startQuery(active) {
|
|
1040
|
+
let {
|
|
1041
|
+
state
|
|
1042
|
+
} = this.view,
|
|
1043
|
+
pos = cur(state);
|
|
1044
|
+
let context = new CompletionContext(state, pos, active.explicitPos == pos);
|
|
1045
|
+
let pending = new RunningQuery(active, context);
|
|
1046
|
+
this.running.push(pending);
|
|
1047
|
+
Promise.resolve(active.source(context)).then(result => {
|
|
1048
|
+
if (!pending.context.aborted) {
|
|
1049
|
+
pending.done = result || null;
|
|
1050
|
+
this.scheduleAccept();
|
|
1051
|
+
}
|
|
1052
|
+
}, err => {
|
|
1053
|
+
this.view.dispatch({
|
|
1054
|
+
effects: closeCompletionEffect.of(null)
|
|
1055
|
+
});
|
|
1056
|
+
logException(this.view.state, err);
|
|
1057
|
+
});
|
|
1058
|
+
}
|
|
1059
|
+
scheduleAccept() {
|
|
1060
|
+
if (this.running.every(q => q.done !== undefined)) this.accept();else if (this.debounceAccept < 0) this.debounceAccept = setTimeout(() => this.accept(), DebounceTime);
|
|
1061
|
+
}
|
|
1062
|
+
// For each finished query in this.running, try to create a result
|
|
1063
|
+
// or, if appropriate, restart the query.
|
|
1064
|
+
accept() {
|
|
1065
|
+
var _a;
|
|
1066
|
+
if (this.debounceAccept > -1) clearTimeout(this.debounceAccept);
|
|
1067
|
+
this.debounceAccept = -1;
|
|
1068
|
+
let updated = [];
|
|
1069
|
+
let conf = this.view.state.facet(completionConfig);
|
|
1070
|
+
for (let i = 0; i < this.running.length; i++) {
|
|
1071
|
+
let query = this.running[i];
|
|
1072
|
+
if (query.done === undefined) continue;
|
|
1073
|
+
this.running.splice(i--, 1);
|
|
1074
|
+
if (query.done) {
|
|
1075
|
+
let active = new ActiveResult(query.active.source, query.active.explicitPos, query.done, query.done.from, (_a = query.done.to) !== null && _a !== void 0 ? _a : cur(query.updates.length ? query.updates[0].startState : this.view.state));
|
|
1076
|
+
// Replay the transactions that happened since the start of
|
|
1077
|
+
// the request and see if that preserves the result
|
|
1078
|
+
for (let tr of query.updates) active = active.update(tr, conf);
|
|
1079
|
+
if (active.hasResult()) {
|
|
1080
|
+
updated.push(active);
|
|
1081
|
+
continue;
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
let current = this.view.state.field(completionState).active.find(a => a.source == query.active.source);
|
|
1085
|
+
if (current && current.state == 1 /* Pending */) {
|
|
1086
|
+
if (query.done == null) {
|
|
1087
|
+
// Explicitly failed. Should clear the pending status if it
|
|
1088
|
+
// hasn't been re-set in the meantime.
|
|
1089
|
+
let active = new ActiveSource(query.active.source, 0 /* Inactive */);
|
|
1090
|
+
for (let tr of query.updates) active = active.update(tr, conf);
|
|
1091
|
+
if (active.state != 1 /* Pending */) updated.push(active);
|
|
1092
|
+
} else {
|
|
1093
|
+
// Cleared by subsequent transactions. Restart.
|
|
1094
|
+
this.startQuery(current);
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
if (updated.length) this.view.dispatch({
|
|
1099
|
+
effects: setActiveEffect.of(updated)
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
1102
|
+
}, {
|
|
1103
|
+
eventHandlers: {
|
|
1104
|
+
blur(event) {
|
|
1105
|
+
let state = this.view.state.field(completionState, false);
|
|
1106
|
+
if (state && state.tooltip && this.view.state.facet(completionConfig).closeOnBlur) {
|
|
1107
|
+
let dialog = state.open && getTooltip(this.view, state.open.tooltip);
|
|
1108
|
+
if (!dialog || !dialog.dom.contains(event.relatedTarget)) this.view.dispatch({
|
|
1109
|
+
effects: closeCompletionEffect.of(null)
|
|
1110
|
+
});
|
|
1111
|
+
}
|
|
1112
|
+
},
|
|
1113
|
+
compositionstart() {
|
|
1114
|
+
this.composing = 1 /* Started */;
|
|
1115
|
+
},
|
|
1116
|
+
|
|
1117
|
+
compositionend() {
|
|
1118
|
+
if (this.composing == 3 /* ChangedAndMoved */) {
|
|
1119
|
+
// Safari fires compositionend events synchronously, possibly
|
|
1120
|
+
// from inside an update, so dispatch asynchronously to avoid reentrancy
|
|
1121
|
+
setTimeout(() => this.view.dispatch({
|
|
1122
|
+
effects: startCompletionEffect.of(false)
|
|
1123
|
+
}), 20);
|
|
1124
|
+
}
|
|
1125
|
+
this.composing = 0 /* None */;
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
});
|
|
1129
|
+
|
|
1110
1130
|
const baseTheme = /*@__PURE__*/EditorView.baseTheme({
|
|
1111
1131
|
".cm-tooltip.cm-tooltip-autocomplete": {
|
|
1112
1132
|
"& > ul": {
|
|
@@ -1162,7 +1182,7 @@ const baseTheme = /*@__PURE__*/EditorView.baseTheme({
|
|
|
1162
1182
|
position: "absolute",
|
|
1163
1183
|
padding: "3px 9px",
|
|
1164
1184
|
width: "max-content",
|
|
1165
|
-
maxWidth: `${400 /*
|
|
1185
|
+
maxWidth: `${400 /* Width */}px`,
|
|
1166
1186
|
boxSizing: "border-box"
|
|
1167
1187
|
},
|
|
1168
1188
|
".cm-completionInfo.cm-completionInfo-left": {
|
|
@@ -1172,10 +1192,10 @@ const baseTheme = /*@__PURE__*/EditorView.baseTheme({
|
|
|
1172
1192
|
left: "100%"
|
|
1173
1193
|
},
|
|
1174
1194
|
".cm-completionInfo.cm-completionInfo-left-narrow": {
|
|
1175
|
-
right: `${30 /*
|
|
1195
|
+
right: `${30 /* Margin */}px`
|
|
1176
1196
|
},
|
|
1177
1197
|
".cm-completionInfo.cm-completionInfo-right-narrow": {
|
|
1178
|
-
left: `${30 /*
|
|
1198
|
+
left: `${30 /* Margin */}px`
|
|
1179
1199
|
},
|
|
1180
1200
|
"&light .cm-snippetField": {
|
|
1181
1201
|
backgroundColor: "#00000022"
|