@lvce-editor/editor-worker 19.72.10 → 19.73.1

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.
@@ -7048,6 +7048,445 @@ const disposeEditor = async editorUid => {
7048
7048
  return commands;
7049
7049
  };
7050
7050
 
7051
+ const getIndex = (widgets, id) => {
7052
+ for (const [i, widget] of widgets.entries()) {
7053
+ if (widget.id === id) {
7054
+ return i;
7055
+ }
7056
+ }
7057
+ return -1;
7058
+ };
7059
+ const removeEditorWidget = (widgets, id) => {
7060
+ const index = getIndex(widgets, id);
7061
+ const newWidgets = [...widgets.slice(0, index), ...widgets.slice(index + 1)];
7062
+ return newWidgets;
7063
+ };
7064
+
7065
+ const closeCompletion = editor => {
7066
+ const {
7067
+ widgets
7068
+ } = editor;
7069
+ const widgetRevision = next(editor.uid);
7070
+ if (widgets.every(widget => widget.id !== Completion)) {
7071
+ return editor;
7072
+ }
7073
+ return {
7074
+ ...editor,
7075
+ additionalFocus: 0,
7076
+ focused: true,
7077
+ widgetRevision,
7078
+ widgets: removeEditorWidget(widgets, Completion)
7079
+ };
7080
+ };
7081
+
7082
+ const hasWidget = (widgets, id) => {
7083
+ for (const widget of widgets) {
7084
+ if (widget.id === id) {
7085
+ return true;
7086
+ }
7087
+ }
7088
+ return false;
7089
+ };
7090
+
7091
+ const addWidgetToEditor = async (widgetId, focusKey, editor, factory, newStateGenerator, fullFocus) => {
7092
+ const {
7093
+ widgets = []
7094
+ } = editor;
7095
+ if (hasWidget(widgets, widgetId)) {
7096
+ return editor;
7097
+ }
7098
+ const widgetRevision = next(editor.uid);
7099
+ const widget = factory();
7100
+ // @ts-ignore
7101
+ widget.newState.editorUid = editor.uid;
7102
+ const newState = await newStateGenerator(widget.newState, editor.uid);
7103
+ if (!newState) {
7104
+ return editor;
7105
+ }
7106
+ if (get(editor.uid) !== widgetRevision) {
7107
+ return get$8(editor.uid)?.newState || editor;
7108
+ }
7109
+ // @ts-ignore
7110
+ newState.editorUid = editor.uid;
7111
+ const latestWidget = {
7112
+ ...widget,
7113
+ newState
7114
+ };
7115
+ const newWidgets = [...widgets, latestWidget];
7116
+ const newFocus = !fullFocus;
7117
+ const newEditor = {
7118
+ ...editor,
7119
+ additionalFocus: fullFocus ? 0 : focusKey,
7120
+ focus: fullFocus ? focusKey : FocusEditorText$1,
7121
+ focused: newFocus,
7122
+ widgetRevision,
7123
+ widgets: newWidgets
7124
+ };
7125
+ return newEditor;
7126
+ };
7127
+
7128
+ const state$5 = {
7129
+ configured: false,
7130
+ lastId: -1,
7131
+ nextId: 0
7132
+ };
7133
+ const configure = (start, end) => {
7134
+ const {
7135
+ configured
7136
+ } = state$5;
7137
+ if (configured) {
7138
+ throw new Error('Component id range is already configured');
7139
+ }
7140
+ if (!Number.isSafeInteger(start) || !Number.isSafeInteger(end) || start <= 0 || end < start) {
7141
+ throw new Error('Invalid component id range');
7142
+ }
7143
+ state$5.nextId = start;
7144
+ state$5.lastId = end;
7145
+ state$5.configured = true;
7146
+ };
7147
+ const create$8 = () => {
7148
+ const {
7149
+ configured,
7150
+ lastId,
7151
+ nextId
7152
+ } = state$5;
7153
+ if (!configured) {
7154
+ // Compatibility with renderer versions that do not assign worker id ranges.
7155
+ return Math.random();
7156
+ }
7157
+ if (nextId > lastId) {
7158
+ throw new Error('Component id range exhausted');
7159
+ }
7160
+ return state$5.nextId++;
7161
+ };
7162
+
7163
+ const create$7 = () => {
7164
+ const completionUid = create$8();
7165
+ const completionWidget = {
7166
+ id: Completion,
7167
+ newState: {
7168
+ commands: [],
7169
+ height: 0,
7170
+ uid: completionUid,
7171
+ width: 0,
7172
+ x: 0,
7173
+ y: 0
7174
+ },
7175
+ oldState: {
7176
+ commands: [],
7177
+ height: 0,
7178
+ uid: completionUid,
7179
+ width: 0,
7180
+ x: 0,
7181
+ y: 0
7182
+ }
7183
+ };
7184
+ return completionWidget;
7185
+ };
7186
+
7187
+ const {
7188
+ invoke: invoke$4,
7189
+ setFactory
7190
+ } = createLazyRpc(CompletionWorker);
7191
+
7192
+ // These commits preserve the document, selection, layout, widgets and lifecycle.
7193
+ const diagnosticFields = new Set(['decorations', 'diagnostics', 'lightBulbRowIndex', 'visualDecorations']);
7194
+ const isCurrent$1 = (snapshot, current) => {
7195
+ if (!current || current.lifecycle?.disposed) {
7196
+ return false;
7197
+ }
7198
+ if (snapshot === current) {
7199
+ return true;
7200
+ }
7201
+ const keys = new Set([...Object.keys(snapshot), ...Object.keys(current)]);
7202
+ for (const key of keys) {
7203
+ if (diagnosticFields.has(key)) {
7204
+ continue;
7205
+ }
7206
+ const field = key;
7207
+ if (Object.hasOwn(snapshot, field) !== Object.hasOwn(current, field) || snapshot[field] !== current[field]) {
7208
+ return false;
7209
+ }
7210
+ }
7211
+ return true;
7212
+ };
7213
+ const merge = (current, snapshot, result) => {
7214
+ if (!isCurrent$1(snapshot, current) || result === snapshot || result === current) {
7215
+ return current;
7216
+ }
7217
+ if (current === snapshot) {
7218
+ return result;
7219
+ }
7220
+ return {
7221
+ ...result,
7222
+ decorations: current.decorations,
7223
+ diagnostics: current.diagnostics,
7224
+ lightBulbRowIndex: current.lightBulbRowIndex,
7225
+ visualDecorations: current.visualDecorations
7226
+ };
7227
+ };
7228
+
7229
+ const updateWidget = (editor, widgetId, newState) => {
7230
+ // TODO avoid closure
7231
+ const isWidget = widget => {
7232
+ return widget.id === widgetId;
7233
+ };
7234
+ const childIndex = editor.widgets.findIndex(isWidget);
7235
+ if (childIndex === -1) {
7236
+ return editor;
7237
+ }
7238
+ // TODO scroll up/down if necessary
7239
+ const childWidget = editor.widgets[childIndex];
7240
+ const newWidget = {
7241
+ ...childWidget,
7242
+ newState,
7243
+ oldState: childWidget.newState
7244
+ };
7245
+ const newWidgets = [...editor.widgets.slice(0, childIndex), newWidget, ...editor.widgets.slice(childIndex + 1)];
7246
+ return {
7247
+ ...editor,
7248
+ widgets: newWidgets
7249
+ };
7250
+ };
7251
+
7252
+ const disposeCompletion = async uid => {
7253
+ try {
7254
+ await invoke$4('Completions.dispose', uid);
7255
+ } catch {
7256
+ // A completion worker may already have disposed this state during shutdown.
7257
+ }
7258
+ };
7259
+ const newStateGenerator$4 = async (state, parentUid, markCreated, automatic) => {
7260
+ const {
7261
+ height,
7262
+ uid,
7263
+ width,
7264
+ x,
7265
+ y
7266
+ } = state;
7267
+ const {
7268
+ newState
7269
+ } = get$8(parentUid);
7270
+ const {
7271
+ applicationId,
7272
+ languageId
7273
+ } = newState;
7274
+ await invoke$4('Completions.create', uid, x, y, width, height, parentUid, languageId, applicationId);
7275
+ markCreated();
7276
+ await invoke$4('Completions.loadContent', uid, automatic);
7277
+ if (automatic && !(await invoke$4('Completions.hasItems', uid))) {
7278
+ return undefined;
7279
+ }
7280
+ const diff = await invoke$4('Completions.diff2', uid);
7281
+ const commands = await invoke$4('Completions.render2', uid, diff);
7282
+ return {
7283
+ ...state,
7284
+ automatic,
7285
+ commands
7286
+ };
7287
+ };
7288
+ const openCompletion = async (editor, automatic = false) => {
7289
+ const widget = (editor.widgets || []).find(candidate => candidate.id === Completion);
7290
+ if (widget && (automatic || widget.newState.automatic)) {
7291
+ const {
7292
+ uid
7293
+ } = widget.newState;
7294
+ await invoke$4('Completions.loadContent', uid, automatic);
7295
+ if (!isCurrent$1(editor, get$8(editor.uid)?.newState)) {
7296
+ return get$8(editor.uid)?.newState || editor;
7297
+ }
7298
+ if (automatic && !(await invoke$4('Completions.hasItems', uid))) {
7299
+ return closeCompletion(editor);
7300
+ }
7301
+ const diff = await invoke$4('Completions.diff2', uid);
7302
+ const commands = await invoke$4('Completions.render2', uid, diff);
7303
+ return updateWidget(editor, Completion, {
7304
+ ...widget.newState,
7305
+ automatic,
7306
+ commands
7307
+ });
7308
+ }
7309
+ let completionUid = 0;
7310
+ let created = false;
7311
+ const generateState = async (state, parentUid) => {
7312
+ completionUid = state.uid;
7313
+ try {
7314
+ const result = await newStateGenerator$4(state, parentUid, () => {
7315
+ created = true;
7316
+ }, automatic);
7317
+ return result;
7318
+ } catch (error) {
7319
+ if (created) {
7320
+ await disposeCompletion(completionUid);
7321
+ }
7322
+ throw error;
7323
+ }
7324
+ };
7325
+ const fullFocus = false;
7326
+ const result = await addWidgetToEditor(Completion, EditorCompletion, editor, create$7, generateState, fullFocus);
7327
+ const wasAdded = (result?.widgets || []).some(widget => widget.id === Completion && widget.newState.uid === completionUid);
7328
+ const currentEditor = get$8(editor.uid)?.newState;
7329
+ if (created && (!wasAdded || !isCurrent$1(editor, currentEditor))) {
7330
+ await disposeCompletion(completionUid);
7331
+ }
7332
+ return result;
7333
+ };
7334
+
7335
+ const expressionKeywords = new Set(['return', 'throw', 'yield', 'await', 'typeof', 'void', 'delete', 'case', 'new', 'in', 'of']);
7336
+ const isIdentifier = character => /[\w$]/u.test(character);
7337
+
7338
+ // Scan the document prefix, retaining lexical state across lines and nested template expressions.
7339
+ const isTypeScriptCode = text => {
7340
+ const frames = [{
7341
+ context: 'code',
7342
+ depth: 0
7343
+ }];
7344
+ let expressionStart = true;
7345
+ let regexClass = false;
7346
+ scan: for (let index = 0; index < text.length; index++) {
7347
+ const frame = frames.at(-1);
7348
+ const character = text[index];
7349
+ const next = text[index + 1];
7350
+ switch (frame.context) {
7351
+ case 'blockComment':
7352
+ if (character === '*' && next === '/') {
7353
+ frames.pop();
7354
+ index++;
7355
+ }
7356
+ continue scan;
7357
+ case 'code':
7358
+ if (character === '/' && next === '/') {
7359
+ frames.push({
7360
+ context: 'lineComment',
7361
+ depth: 0
7362
+ });
7363
+ index++;
7364
+ } else if (character === '/' && next === '*') {
7365
+ frames.push({
7366
+ context: 'blockComment',
7367
+ depth: 0
7368
+ });
7369
+ index++;
7370
+ } else if (["'", '"', '`'].includes(character)) {
7371
+ frames.push({
7372
+ context: character === "'" ? 'single' : character === '"' ? 'double' : 'template',
7373
+ depth: 0
7374
+ });
7375
+ } else if (character === '/' && expressionStart) {
7376
+ frames.push({
7377
+ context: 'regex',
7378
+ depth: 0
7379
+ });
7380
+ regexClass = false;
7381
+ } else if (character === '{') {
7382
+ frame.depth++;
7383
+ expressionStart = true;
7384
+ } else if (character === '}') {
7385
+ frame.depth--;
7386
+ if (frame.depth === 0 && frames.length > 1) {
7387
+ frames.pop();
7388
+ }
7389
+ expressionStart = false;
7390
+ } else if (isIdentifier(character)) {
7391
+ const start = index;
7392
+ while (index + 1 < text.length && isIdentifier(text[index + 1])) {
7393
+ index++;
7394
+ }
7395
+ expressionStart = expressionKeywords.has(text.slice(start, index + 1));
7396
+ } else if (!/\s/u.test(character)) {
7397
+ expressionStart = '=(:,[!&|?;+-*%<>'.includes(character);
7398
+ }
7399
+ continue scan;
7400
+ case 'double':
7401
+ case 'single':
7402
+ if (character === '\\') {
7403
+ index++;
7404
+ } else if ([frame.context === 'single' ? "'" : '"', '\n', '\r'].includes(character)) {
7405
+ frames.pop();
7406
+ expressionStart = false;
7407
+ }
7408
+ continue scan;
7409
+ case 'lineComment':
7410
+ if (['\n', '\r'].includes(character)) {
7411
+ frames.pop();
7412
+ }
7413
+ continue scan;
7414
+ case 'regex':
7415
+ switch (character) {
7416
+ case '[':
7417
+ {
7418
+ regexClass = true;
7419
+ continue scan;
7420
+ }
7421
+ case ']':
7422
+ {
7423
+ regexClass = false;
7424
+ continue scan;
7425
+ }
7426
+ case '\\':
7427
+ {
7428
+ index++;
7429
+ continue scan;
7430
+ }
7431
+ default:
7432
+ if (character === '/' && !regexClass || ['\n', '\r'].includes(character)) {
7433
+ frames.pop();
7434
+ expressionStart = false;
7435
+ }
7436
+ }
7437
+ continue scan;
7438
+ case 'template':
7439
+ if (character === '\\') {
7440
+ index++;
7441
+ } else if (character === '`') {
7442
+ frames.pop();
7443
+ expressionStart = false;
7444
+ } else if (character === '$' && next === '{') {
7445
+ frames.push({
7446
+ context: 'code',
7447
+ depth: 1
7448
+ });
7449
+ expressionStart = true;
7450
+ index++;
7451
+ }
7452
+ continue scan;
7453
+ }
7454
+ }
7455
+ return frames.at(-1).context === 'code';
7456
+ };
7457
+
7458
+ const shouldOpenAutomaticCompletion = editor => {
7459
+ const {
7460
+ completionsOnType,
7461
+ isQuickSuggestionsEnabled,
7462
+ languageId,
7463
+ largeFile,
7464
+ lines,
7465
+ selections
7466
+ } = editor;
7467
+ if (largeFile || !(completionsOnType || languageId === 'typescript' && isQuickSuggestionsEnabled)) {
7468
+ return false;
7469
+ }
7470
+ if (languageId !== 'typescript') {
7471
+ return true;
7472
+ }
7473
+ const rowIndex = selections[0];
7474
+ const columnIndex = selections[1];
7475
+ const prefix = [...lines.slice(0, rowIndex), lines[rowIndex].slice(0, columnIndex)].join('\n');
7476
+ return /[\w$.]$/u.test(prefix) && isTypeScriptCode(prefix);
7477
+ };
7478
+
7479
+ const updateAutomaticCompletion = async editor => {
7480
+ const widget = (editor.widgets || []).find(candidate => candidate.id === Completion);
7481
+ if (widget && !widget.newState.automatic) {
7482
+ return editor;
7483
+ }
7484
+ if (!shouldOpenAutomaticCompletion(editor)) {
7485
+ return widget ? closeCompletion(editor) : editor;
7486
+ }
7487
+ return openCompletion(editor, true);
7488
+ };
7489
+
7051
7490
  const getAcceptedLines = (lines, conflict, action) => {
7052
7491
  const current = lines.slice(conflict.currentStartRowIndex, conflict.currentEndRowIndex);
7053
7492
  const incoming = lines.slice(conflict.incomingStartRowIndex, conflict.incomingEndRowIndex);
@@ -7542,55 +7981,6 @@ const isFormattingError = error => {
7542
7981
  return error && error instanceof Error && error.message.startsWith(expectedErrorMessage$1);
7543
7982
  };
7544
7983
 
7545
- const state$5 = {
7546
- configured: false,
7547
- lastId: -1,
7548
- nextId: 0
7549
- };
7550
- const configure = (start, end) => {
7551
- const {
7552
- configured
7553
- } = state$5;
7554
- if (configured) {
7555
- throw new Error('Component id range is already configured');
7556
- }
7557
- if (!Number.isSafeInteger(start) || !Number.isSafeInteger(end) || start <= 0 || end < start) {
7558
- throw new Error('Invalid component id range');
7559
- }
7560
- state$5.nextId = start;
7561
- state$5.lastId = end;
7562
- state$5.configured = true;
7563
- };
7564
- const create$8 = () => {
7565
- const {
7566
- configured,
7567
- lastId,
7568
- nextId
7569
- } = state$5;
7570
- if (!configured) {
7571
- // Compatibility with renderer versions that do not assign worker id ranges.
7572
- return Math.random();
7573
- }
7574
- if (nextId > lastId) {
7575
- throw new Error('Component id range exhausted');
7576
- }
7577
- return state$5.nextId++;
7578
- };
7579
-
7580
- const getIndex = (widgets, id) => {
7581
- for (const [i, widget] of widgets.entries()) {
7582
- if (widget.id === id) {
7583
- return i;
7584
- }
7585
- }
7586
- return -1;
7587
- };
7588
- const removeEditorWidget = (widgets, id) => {
7589
- const index = getIndex(widgets, id);
7590
- const newWidgets = [...widgets.slice(0, index), ...widgets.slice(index + 1)];
7591
- return newWidgets;
7592
- };
7593
-
7594
7984
  const Message = 9;
7595
7985
 
7596
7986
  const getAccurateColumnIndexAscii = async (line, guess, averageCharWidth, eventX, fontWeight, fontSize, fontFamily, letterSpacing, isMonospaceFont, charWidth) => {
@@ -7606,7 +7996,7 @@ const getAccurateColumnIndexAscii = async (line, guess, averageCharWidth, eventX
7606
7996
  const supported = () => {
7607
7997
  return 'Segmenter' in Intl;
7608
7998
  };
7609
- const create$7 = () => {
7999
+ const create$6 = () => {
7610
8000
  // @ts-ignore
7611
8001
  const segmenter = new Intl.Segmenter();
7612
8002
  return {
@@ -7641,7 +8031,7 @@ const create$7 = () => {
7641
8031
  };
7642
8032
 
7643
8033
  const getAccurateColumnIndexUnicode = async (line, guess, averageCharWidth, eventX, fontWeight, fontSize, fontFamily, letterSpacing) => {
7644
- const segmenter = create$7();
8034
+ const segmenter = create$6();
7645
8035
  const segments = segmenter.getSegments(line);
7646
8036
  const isMonospaceFont = false;
7647
8037
  const charWidth = 0;
@@ -8210,7 +8600,7 @@ const wrapFocusCommand$1 = (fn, returnState = true) => {
8210
8600
 
8211
8601
  // Optional provider work must not hold the editing queue while another worker responds.
8212
8602
  const wrapDeferredCommand$1 = (fn, returnState = true) => {
8213
- const apply = wrapCommand$1((editor, snapshot, result) => editor === snapshot ? result : editor, false, returnState);
8603
+ const apply = wrapCommand$1((editor, snapshot, result) => merge(editor, snapshot, result), false, returnState);
8214
8604
  return async (uid, ...args) => {
8215
8605
  const snapshot = await enqueue(uid, async () => get$8(uid)?.newState);
8216
8606
  if (!snapshot) {
@@ -8321,15 +8711,6 @@ const closeWidgetsMaybe = widgets => {
8321
8711
  return widgets.filter(widget => isPersistentWidget(widget.id));
8322
8712
  };
8323
8713
 
8324
- const hasWidget = (widgets, id) => {
8325
- for (const widget of widgets) {
8326
- if (widget.id === id) {
8327
- return true;
8328
- }
8329
- }
8330
- return false;
8331
- };
8332
-
8333
8714
  const handleBlur$1 = async editor => {
8334
8715
  if (!editor.focused) {
8335
8716
  return editor;
@@ -8745,23 +9126,6 @@ const closeCodeGenerator = editor => {
8745
9126
  };
8746
9127
  };
8747
9128
 
8748
- const closeCompletion = editor => {
8749
- const {
8750
- widgets
8751
- } = editor;
8752
- const widgetRevision = next(editor.uid);
8753
- if (widgets.every(widget => widget.id !== Completion)) {
8754
- return editor;
8755
- }
8756
- return {
8757
- ...editor,
8758
- additionalFocus: 0,
8759
- focused: true,
8760
- widgetRevision,
8761
- widgets: removeEditorWidget(widgets, Completion)
8762
- };
8763
- };
8764
-
8765
9129
  const isMatchingWidget$1 = widget => {
8766
9130
  return widget.id === Find;
8767
9131
  };
@@ -8831,44 +9195,7 @@ const closeSourceAction = editor => {
8831
9195
  };
8832
9196
  };
8833
9197
 
8834
- const addWidgetToEditor = async (widgetId, focusKey, editor, factory, newStateGenerator, fullFocus) => {
8835
- const {
8836
- widgets = []
8837
- } = editor;
8838
- if (hasWidget(widgets, widgetId)) {
8839
- return editor;
8840
- }
8841
- const widgetRevision = next(editor.uid);
8842
- const widget = factory();
8843
- // @ts-ignore
8844
- widget.newState.editorUid = editor.uid;
8845
- const newState = await newStateGenerator(widget.newState, editor.uid);
8846
- if (!newState) {
8847
- return editor;
8848
- }
8849
- if (get(editor.uid) !== widgetRevision) {
8850
- return get$8(editor.uid)?.newState || editor;
8851
- }
8852
- // @ts-ignore
8853
- newState.editorUid = editor.uid;
8854
- const latestWidget = {
8855
- ...widget,
8856
- newState
8857
- };
8858
- const newWidgets = [...widgets, latestWidget];
8859
- const newFocus = !fullFocus;
8860
- const newEditor = {
8861
- ...editor,
8862
- additionalFocus: fullFocus ? 0 : focusKey,
8863
- focus: fullFocus ? focusKey : FocusEditorText$1,
8864
- focused: newFocus,
8865
- widgetRevision,
8866
- widgets: newWidgets
8867
- };
8868
- return newEditor;
8869
- };
8870
-
8871
- const create$6 = (bounds, range, undoStackIndex) => {
9198
+ const create$5 = (bounds, range, undoStackIndex) => {
8872
9199
  const completionUid = create$8();
8873
9200
  const state = {
8874
9201
  ...bounds,
@@ -8922,7 +9249,7 @@ const getColorPickerBounds = editor => {
8922
9249
  };
8923
9250
  };
8924
9251
 
8925
- const newStateGenerator$4 = (state, parentUid) => {
9252
+ const newStateGenerator$3 = (state, parentUid) => {
8926
9253
  return loadContent$3(state, parentUid);
8927
9254
  };
8928
9255
  const openColorPicker = async editor => {
@@ -8932,8 +9259,8 @@ const openColorPicker = async editor => {
8932
9259
  getColorPickerRange
8933
9260
  } = await Promise.resolve().then(function () { return GetColorPickerRange; });
8934
9261
  const range = await getColorPickerRange(editor);
8935
- const createWidget = () => create$6(bounds, range, editor.undoStack.length);
8936
- return addWidgetToEditor(ColorPicker$2, ColorPicker, editor, createWidget, newStateGenerator$4, fullFocus);
9262
+ const createWidget = () => create$5(bounds, range, editor.undoStack.length);
9263
+ return addWidgetToEditor(ColorPicker$2, ColorPicker, editor, createWidget, newStateGenerator$3, fullFocus);
8937
9264
  };
8938
9265
  const closeColorPicker = editor => {
8939
9266
  const {
@@ -9247,7 +9574,7 @@ const characterLeft = (line, columnIndex) => {
9247
9574
  if (columnIndex > line.length) {
9248
9575
  return 1;
9249
9576
  }
9250
- const segmenter = create$7();
9577
+ const segmenter = create$6();
9251
9578
  const last = segmenter.at(line, columnIndex - 1);
9252
9579
  if (!last) {
9253
9580
  return 1;
@@ -9262,7 +9589,7 @@ const characterRight = (line, columnIndex) => {
9262
9589
  if (!supported()) {
9263
9590
  return 1;
9264
9591
  }
9265
- const segmenter = create$7();
9592
+ const segmenter = create$6();
9266
9593
  const next = segmenter.at(line, columnIndex);
9267
9594
  // @ts-ignore
9268
9595
  return next.segment.length;
@@ -11006,7 +11333,7 @@ const getDiagnosticHoverInfo = async (editor, diagnostic) => {
11006
11333
  };
11007
11334
  };
11008
11335
 
11009
- const create$5 = () => {
11336
+ const create$4 = () => {
11010
11337
  const uid = create$8();
11011
11338
  const widget = {
11012
11339
  id: Hover,
@@ -11225,29 +11552,6 @@ const loadHoverContent = async (state, position) => {
11225
11552
  };
11226
11553
  };
11227
11554
 
11228
- const updateWidget = (editor, widgetId, newState) => {
11229
- // TODO avoid closure
11230
- const isWidget = widget => {
11231
- return widget.id === widgetId;
11232
- };
11233
- const childIndex = editor.widgets.findIndex(isWidget);
11234
- if (childIndex === -1) {
11235
- return editor;
11236
- }
11237
- // TODO scroll up/down if necessary
11238
- const childWidget = editor.widgets[childIndex];
11239
- const newWidget = {
11240
- ...childWidget,
11241
- newState,
11242
- oldState: childWidget.newState
11243
- };
11244
- const newWidgets = [...editor.widgets.slice(0, childIndex), newWidget, ...editor.widgets.slice(childIndex + 1)];
11245
- return {
11246
- ...editor,
11247
- widgets: newWidgets
11248
- };
11249
- };
11250
-
11251
11555
  const getHoverWidgetIndex = widgets => {
11252
11556
  return widgets.findIndex(widget => widget.id === Hover);
11253
11557
  };
@@ -11257,7 +11561,7 @@ const applyHoverContent = async (editor, getNewState) => {
11257
11561
  } = editor;
11258
11562
  const widgetIndex = getHoverWidgetIndex(widgets);
11259
11563
  if (widgetIndex === -1) {
11260
- return addWidgetToEditor(Hover, FocusEditorHover, editor, create$5, getNewState);
11564
+ return addWidgetToEditor(Hover, FocusEditorHover, editor, create$4, getNewState);
11261
11565
  }
11262
11566
  const widgetRevision = next(editor.uid);
11263
11567
  const widget = widgets[widgetIndex];
@@ -12175,7 +12479,7 @@ const previousDiagnostic = editor => {
12175
12479
  const Script = 2;
12176
12480
  const Unknown$1 = 0;
12177
12481
 
12178
- const create$4 = () => {
12482
+ const create$3 = () => {
12179
12483
  const completionUid = create$8();
12180
12484
  const widget = {
12181
12485
  id: CodeGenerator,
@@ -12203,7 +12507,7 @@ const create$4 = () => {
12203
12507
  return widget;
12204
12508
  };
12205
12509
 
12206
- const newStateGenerator$3 = async state => {
12510
+ const newStateGenerator$2 = async state => {
12207
12511
  const latestState = {
12208
12512
  ...state,
12209
12513
  height: 45,
@@ -12215,65 +12519,7 @@ const newStateGenerator$3 = async state => {
12215
12519
  };
12216
12520
  const openCodeGenerator = async editor => {
12217
12521
  const fullFocus = true;
12218
- return addWidgetToEditor(CodeGenerator, FocusCodeGenerator, editor, create$4, newStateGenerator$3, fullFocus);
12219
- };
12220
-
12221
- const create$3 = () => {
12222
- const completionUid = create$8();
12223
- const completionWidget = {
12224
- id: Completion,
12225
- newState: {
12226
- commands: [],
12227
- height: 0,
12228
- uid: completionUid,
12229
- width: 0,
12230
- x: 0,
12231
- y: 0
12232
- },
12233
- oldState: {
12234
- commands: [],
12235
- height: 0,
12236
- uid: completionUid,
12237
- width: 0,
12238
- x: 0,
12239
- y: 0
12240
- }
12241
- };
12242
- return completionWidget;
12243
- };
12244
-
12245
- const {
12246
- invoke: invoke$4,
12247
- setFactory
12248
- } = createLazyRpc(CompletionWorker);
12249
-
12250
- const newStateGenerator$2 = async (state, parentUid) => {
12251
- const {
12252
- height,
12253
- uid,
12254
- width,
12255
- x,
12256
- y
12257
- } = state;
12258
- const {
12259
- newState
12260
- } = get$8(parentUid);
12261
- const {
12262
- applicationId,
12263
- languageId
12264
- } = newState;
12265
- await invoke$4('Completions.create', uid, x, y, width, height, parentUid, languageId, applicationId);
12266
- await invoke$4('Completions.loadContent', uid);
12267
- const diff = await invoke$4('Completions.diff2', uid);
12268
- const commands = await invoke$4('Completions.render2', uid, diff);
12269
- return {
12270
- ...state,
12271
- commands
12272
- };
12273
- };
12274
- const openCompletion = async editor => {
12275
- const fullFocus = false;
12276
- return addWidgetToEditor(Completion, EditorCompletion, editor, create$3, newStateGenerator$2, fullFocus);
12522
+ return addWidgetToEditor(CodeGenerator, FocusCodeGenerator, editor, create$3, newStateGenerator$2, fullFocus);
12277
12523
  };
12278
12524
 
12279
12525
  const isFunctional = widgetId => {
@@ -13808,7 +14054,7 @@ const showSignatureHelp = async editor => {
13808
14054
  const newStateGenerator = async state => {
13809
14055
  return loadSignatureHelpContent(state);
13810
14056
  };
13811
- return addWidgetToEditor(Hover, FocusEditorHover, editorWithoutHover, create$5, newStateGenerator);
14057
+ return addWidgetToEditor(Hover, FocusEditorHover, editorWithoutHover, create$4, newStateGenerator);
13812
14058
  };
13813
14059
 
13814
14060
  const create = () => {
@@ -14429,14 +14675,7 @@ const toggleCompletion = async editor => {
14429
14675
 
14430
14676
  const type = async (editor, text) => {
14431
14677
  const changes = editorReplaceSelections(editor, [text], EditorType);
14432
- const newEditor = await scheduleDocumentAndCursorsSelections(editor, changes);
14433
- if (newEditor.completionsOnType) {
14434
- // TODO if completion widget is already visible, advance
14435
- // TODO if character typed is space or tab or separator, close completions
14436
- const withCompletion = await openCompletion(newEditor);
14437
- return withCompletion;
14438
- }
14439
- return newEditor;
14678
+ return scheduleDocumentAndCursorsSelections(editor, changes);
14440
14679
  };
14441
14680
 
14442
14681
  const Slash = '/';
@@ -14815,6 +15054,15 @@ const add$7 = widget => {
14815
15054
  const remove$6 = widget => {
14816
15055
  return [];
14817
15056
  };
15057
+ const fns = createFns(['handleEditorType', 'handleEditorDeleteLeft'], 'Completions', Completion);
15058
+ const handleEditorType$1 = editor => {
15059
+ const widget = (editor.widgets || []).find(candidate => candidate.id === Completion);
15060
+ return widget?.newState.automatic ? editor : fns.handleEditorType(editor);
15061
+ };
15062
+ const handleEditorDeleteLeft$1 = editor => {
15063
+ const widget = (editor.widgets || []).find(candidate => candidate.id === Completion);
15064
+ return widget?.newState.automatic ? editor : fns.handleEditorDeleteLeft(editor);
15065
+ };
14818
15066
  const {
14819
15067
  close: close$3,
14820
15068
  closeDetails: closeDetails$1,
@@ -14825,8 +15073,6 @@ const {
14825
15073
  focusPrevious: focusPrevious$1,
14826
15074
  handleEditorBlur,
14827
15075
  handleEditorClick,
14828
- handleEditorDeleteLeft: handleEditorDeleteLeft$1,
14829
- handleEditorType: handleEditorType$1,
14830
15076
  handlePointerDown,
14831
15077
  handleWheel: handleWheel$1,
14832
15078
  openDetails,
@@ -18978,6 +19224,22 @@ const resize = async (editor, dimensions) => {
18978
19224
  const resizedEditor = resize$2(editor, dimensions, editor.columnWidth);
18979
19225
  return resize$1(resizedEditor, dimensions);
18980
19226
  };
19227
+ const openCompletionDeferred = wrapDeferredCommand(openCompletion);
19228
+ const updateAutomaticCompletionDeferred = wrapDeferredCommand(updateAutomaticCompletion);
19229
+ const wrapTypingCommand = (fn, shouldOpenCompletion) => {
19230
+ const command = wrapCommand(fn, true);
19231
+ return async (uid, ...args) => {
19232
+ await command(uid, ...args);
19233
+ const editor = get$8(uid)?.newState;
19234
+ if (editor && (shouldOpenCompletion(...args) && shouldOpenAutomaticCompletion(editor) || editor.widgets?.some(widget => widget.id === Completion && widget.newState.automatic))) {
19235
+ void updateAutomaticCompletionDeferred(uid).then(() => invoke$d('Editor.renderPending', uid)).catch(error => handleError$1(error, 'Failed to open completion widget: '));
19236
+ }
19237
+ };
19238
+ };
19239
+ const deleteLeftCommand = wrapTypingCommand(deleteCharacterLeft, () => false);
19240
+ const typeCommand = wrapTypingCommand(type, () => true);
19241
+ const typeWithAutoClosingCommand = wrapTypingCommand(typeWithAutoClosing, () => true);
19242
+ const handleBeforeInputCommand = wrapTypingCommand(handleBeforeInput, inputType => inputType === InsertText);
18981
19243
  const commandMap = {
18982
19244
  'ActivateByEvent.activateByEvent': activateByEvent,
18983
19245
  'CodeGenerator.accept': codeGeneratorAccept,
@@ -19031,10 +19293,10 @@ const commandMap = {
19031
19293
  'Editor.deleteAll': wrapCommand(deleteAll),
19032
19294
  'Editor.deleteAllLeft': wrapCommand(deleteAllLeft),
19033
19295
  'Editor.deleteAllRight': wrapCommand(deleteAllRight),
19034
- 'Editor.deleteCharacterLeft': wrapCommand(deleteCharacterLeft),
19296
+ 'Editor.deleteCharacterLeft': deleteLeftCommand,
19035
19297
  'Editor.deleteCharacterRight': wrapCommand(deleteCharacterRight),
19036
19298
  'Editor.deleteHorizontalRight': wrapCommand(editorDeleteHorizontalRight),
19037
- 'Editor.deleteLeft': wrapCommand(deleteCharacterLeft),
19299
+ 'Editor.deleteLeft': deleteLeftCommand,
19038
19300
  'Editor.deleteLine': wrapCommand(deleteLine$1),
19039
19301
  'Editor.deleteRight': wrapCommand(deleteCharacterRight),
19040
19302
  'Editor.deleteWordLeft': wrapCommand(deleteWordLeft),
@@ -19077,7 +19339,7 @@ const commandMap = {
19077
19339
  'Editor.goToBracket': wrapCommand(goToBracket$1),
19078
19340
  'Editor.goToDefinition': wrapCommand(goToDefinition),
19079
19341
  'Editor.goToTypeDefinition': wrapCommand(goToTypeDefinition),
19080
- 'Editor.handleBeforeInput': wrapCommand(handleBeforeInput, true),
19342
+ 'Editor.handleBeforeInput': handleBeforeInputCommand,
19081
19343
  'Editor.handleBeforeInputFromContentEditable': wrapCommand(handleBeforeInputFromContentEditable),
19082
19344
  'Editor.handleBlur': wrapCommand(handleBlur$1),
19083
19345
  'Editor.handleClickAtPosition': wrapCommand(handleClickAtPosition),
@@ -19130,7 +19392,7 @@ const commandMap = {
19130
19392
  'Editor.offsetAt': offsetAt,
19131
19393
  'Editor.openCodeGenerator': wrapCommand(openCodeGenerator),
19132
19394
  'Editor.openColorPicker': wrapCommand(openColorPicker),
19133
- 'Editor.openCompletion': wrapCommand(openCompletion),
19395
+ 'Editor.openCompletion': openCompletionDeferred,
19134
19396
  'Editor.openFind': wrapCommand(openFind),
19135
19397
  'Editor.openFind2': wrapCommand(openFind2),
19136
19398
  'Editor.openRename': wrapCommand(openRename),
@@ -19194,11 +19456,11 @@ const commandMap = {
19194
19456
  'Editor.toggleBlockComment': wrapCommand(toggleBlockComment),
19195
19457
  'Editor.toggleBreakpoint': wrapCommand(toggleBreakpoint),
19196
19458
  'Editor.toggleComment': wrapCommand(toggleComment),
19197
- 'Editor.toggleCompletion': wrapCommand(toggleCompletion),
19459
+ 'Editor.toggleCompletion': wrapDeferredCommand(toggleCompletion),
19198
19460
  'Editor.toggleLineComment': wrapCommand(editorToggleLineComment),
19199
19461
  'Editor.toggleMinimap': toggleMinimap,
19200
- 'Editor.type': wrapCommand(type, true),
19201
- 'Editor.typeWithAutoClosing': wrapCommand(typeWithAutoClosing, true),
19462
+ 'Editor.type': typeCommand,
19463
+ 'Editor.typeWithAutoClosing': typeWithAutoClosingCommand,
19202
19464
  'Editor.undo': wrapCommand(undo),
19203
19465
  'Editor.unfold': wrapCommand(unfold),
19204
19466
  'Editor.unIndent': wrapCommand(editorUnindent),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "19.72.10",
3
+ "version": "19.73.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"