@lvce-editor/editor-worker 10.1.0 → 11.0.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.
@@ -1118,6 +1118,8 @@ const ExtensionHostWorker = 44;
1118
1118
  const MarkdownWorker = 300;
1119
1119
  const RendererWorker$1 = 1;
1120
1120
 
1121
+ const FocusEditorText$1 = 12;
1122
+
1121
1123
  const rpcs = Object.create(null);
1122
1124
  const set$c = (id, rpc) => {
1123
1125
  rpcs[id] = rpc;
@@ -1348,7 +1350,7 @@ const getIcons = async requests => {
1348
1350
  const activateByEvent$1 = event => {
1349
1351
  return invoke$b('ExtensionHostManagement.activateByEvent', event);
1350
1352
  };
1351
- const setAdditionalFocus$1 = focusKey => {
1353
+ const setAdditionalFocus = focusKey => {
1352
1354
  // @ts-ignore
1353
1355
  return invoke$b('Focus.setAdditionalFocus', focusKey);
1354
1356
  };
@@ -1530,7 +1532,7 @@ const RendererWorker = {
1530
1532
  sendMessagePortToSearchProcess,
1531
1533
  sendMessagePortToSyntaxHighlightingWorker: sendMessagePortToSyntaxHighlightingWorker$1,
1532
1534
  set: set$a,
1533
- setAdditionalFocus: setAdditionalFocus$1,
1535
+ setAdditionalFocus,
1534
1536
  setColorTheme,
1535
1537
  setExtensionsSearchValue,
1536
1538
  setFocus: setFocus$1,
@@ -3762,13 +3764,12 @@ const applyWorkspaceEdit = async (editor, changes) => {
3762
3764
  };
3763
3765
 
3764
3766
  const handleBlur$1 = editor => {
3765
- if (editor.focusKey !== Empty) {
3767
+ if (!editor.focused) {
3766
3768
  return editor;
3767
3769
  }
3768
3770
  const newEditor = {
3769
3771
  ...editor,
3770
- focused: false,
3771
- focusKey: Empty
3772
+ focused: false
3772
3773
  };
3773
3774
  return newEditor;
3774
3775
  };
@@ -4212,25 +4213,6 @@ const hasWidget = (widgets, id) => {
4212
4213
  return false;
4213
4214
  };
4214
4215
 
4215
- const setAdditionalFocus = async focusKey => {
4216
- // @ts-ignore
4217
- await invoke$9('Focus.setAdditionalFocus', focusKey);
4218
- };
4219
-
4220
- const setFocus = async focusKey => {
4221
- if (!focusKey) {
4222
- return;
4223
- }
4224
- await invoke$9('Focus.setFocus', focusKey);
4225
- };
4226
- const unsetAdditionalFocus = async focusKey => {
4227
- if (!focusKey) {
4228
- return;
4229
- }
4230
- // @ts-ignore
4231
- await invoke$9('Focus.removeAdditionalFocus', focusKey);
4232
- };
4233
-
4234
4216
  const addWidgetToEditor = async (widgetId, focusKey, editor, factory, newStateGenerator, fullFocus) => {
4235
4217
  const {
4236
4218
  widgets
@@ -4249,14 +4231,13 @@ const addWidgetToEditor = async (widgetId, focusKey, editor, factory, newStateGe
4249
4231
  newState
4250
4232
  };
4251
4233
  const newWidgets = [...widgets, latestWidget];
4252
- // TODO avoid side effect, apply focus shift during render
4253
- await (fullFocus ? setFocus(focusKey) : setAdditionalFocus(focusKey));
4254
4234
  const newFocus = !fullFocus;
4255
4235
  const newEditor = {
4256
4236
  ...editor,
4257
4237
  widgets: newWidgets,
4258
- focusKey,
4259
- focused: newFocus
4238
+ focused: newFocus,
4239
+ focus: fullFocus ? focusKey : FocusEditorText$1,
4240
+ additionalFocus: fullFocus ? 0 : focusKey
4260
4241
  };
4261
4242
  return newEditor;
4262
4243
  };
@@ -5368,6 +5349,25 @@ const goToTypeDefinition = async (editor, explicit = true) => {
5368
5349
  });
5369
5350
  };
5370
5351
 
5352
+ const isPersistentWidget = widgetId => {
5353
+ switch (widgetId) {
5354
+ case Find:
5355
+ return true;
5356
+ default:
5357
+ return false;
5358
+ }
5359
+ };
5360
+
5361
+ // TODO widgets should have a persistence property:
5362
+ // 1 = close by click (e.g. completion, hover, source-actions)
5363
+ // 2 = stay open on click (e.g. find)
5364
+ const closeWidgetsMaybe = widgets => {
5365
+ if (widgets.length === 0) {
5366
+ return widgets;
5367
+ }
5368
+ return widgets.filter(isPersistentWidget);
5369
+ };
5370
+
5371
5371
  const state$3 = {
5372
5372
  position: {
5373
5373
  rowIndex: 0,
@@ -5430,11 +5430,14 @@ const Ctrl = 1;
5430
5430
  const Alt = 2;
5431
5431
 
5432
5432
  const handleSingleClickDefault = (editor, position) => {
5433
+ // TODO avoid global variables, add them to editor state
5433
5434
  setPosition$1(position);
5435
+ const widgets = closeWidgetsMaybe(editor.widgets);
5434
5436
  return {
5435
5437
  ...editor,
5436
5438
  selections: new Uint32Array([position.rowIndex, position.columnIndex, position.rowIndex, position.columnIndex]),
5437
- focused: true
5439
+ focused: true,
5440
+ widgets
5438
5441
  };
5439
5442
  };
5440
5443
  const getClickHandler = modifier => {
@@ -5498,12 +5501,16 @@ const handleDoubleClick = (editor, modifier, x, y) => {
5498
5501
  return selectWord(editor, position.rowIndex, position.columnIndex);
5499
5502
  };
5500
5503
 
5501
- const WhenExpressionEditorText = 12;
5502
5504
  const handleFocus$1 = editor => {
5503
- // TODO make change events functional,
5504
- // when rendering, send focus changes to renderer worker
5505
- invoke$9('Focus.setFocus', WhenExpressionEditorText);
5506
- return editor;
5505
+ if (editor.focused && editor.focus === FocusEditorText$1) {
5506
+ return editor;
5507
+ }
5508
+ return {
5509
+ ...editor,
5510
+ focused: true,
5511
+ focus: FocusEditorText$1,
5512
+ additionalFocus: 0
5513
+ };
5507
5514
  };
5508
5515
 
5509
5516
  const Single = 1;
@@ -9213,6 +9220,17 @@ const getWordAtOffset = editor => {
9213
9220
  return '';
9214
9221
  };
9215
9222
 
9223
+ const setFocus = async focusKey => {
9224
+ await invoke$9('Focus.setFocus', focusKey);
9225
+ };
9226
+ const unsetAdditionalFocus = async focusKey => {
9227
+ if (!focusKey) {
9228
+ return;
9229
+ }
9230
+ // @ts-ignore
9231
+ await invoke$9('Focus.removeAdditionalFocus', focusKey);
9232
+ };
9233
+
9216
9234
  const FocusEditor = 12;
9217
9235
  const FocusEditorCompletions = 9;
9218
9236
  const FocusEditorRename = 11;
@@ -10302,14 +10320,28 @@ const renderFocus$1 = {
10302
10320
  return oldState.focused === newState.focused;
10303
10321
  },
10304
10322
  apply(oldState, newState) {
10305
- // TODO avoid side effect
10306
- if (newState.focused) {
10307
- const FocusEditorText = 12;
10308
- invoke$9('Focus.setFocus', FocusEditorText);
10309
- }
10310
10323
  return [/* method */'setFocused', newState.focused];
10311
10324
  }
10312
10325
  };
10326
+ const renderFocusContext = {
10327
+ isEqual(oldState, newState) {
10328
+ return oldState.focus === newState.focus;
10329
+ },
10330
+ apply(oldState, newState) {
10331
+ return ['Viewlet.setFocusContext', newState.uid, newState.focus];
10332
+ }
10333
+ };
10334
+ const renderAdditionalFocusContext = {
10335
+ isEqual(oldState, newState) {
10336
+ return newState.additionalFocus === newState.additionalFocus;
10337
+ },
10338
+ apply(oldState, newState) {
10339
+ if (newState.additionalFocus) {
10340
+ return ['Focus.setAdditionalFocus', newState.uid, newState.additionalFocus];
10341
+ }
10342
+ return ['Focus.unsetAdditionalFocus', newState.uid, newState.additionalFocus];
10343
+ }
10344
+ };
10313
10345
  const renderDecorations = {
10314
10346
  isEqual(oldState, newState) {
10315
10347
  return oldState.decorations === newState.decorations;
@@ -10391,11 +10423,12 @@ const renderWidgets = {
10391
10423
  }
10392
10424
  }
10393
10425
  const allCommands = [...addCommands, ...changeCommands, ...removeCommands];
10394
- return allCommands;
10426
+ const filteredCommands = allCommands.filter(item => item[0] !== 'Viewlet.setFocusContext');
10427
+ return filteredCommands;
10395
10428
  },
10396
10429
  multiple: true
10397
10430
  };
10398
- const render$6 = [renderLines, renderSelections, renderScrollBarX, renderScrollBarY, renderFocus$1, renderDecorations, renderGutterInfo, renderWidgets];
10431
+ const render$6 = [renderLines, renderSelections, renderScrollBarX, renderScrollBarY, renderFocus$1, renderDecorations, renderGutterInfo, renderWidgets, renderFocusContext, renderAdditionalFocusContext];
10399
10432
  const renderEditor = id => {
10400
10433
  const instance = get$4(id);
10401
10434
  if (!instance) {
@@ -10540,8 +10573,9 @@ const widgetCommands = {
10540
10573
  const effects = [editorDiagnosticEffect];
10541
10574
  const wrapCommand = fn => async (editorUid, ...args) => {
10542
10575
  const oldInstance = get$4(editorUid);
10543
- const newEditor = await fn(oldInstance.newState, ...args);
10544
- if (oldInstance.newState === newEditor) {
10576
+ const state = oldInstance.newState;
10577
+ const newEditor = await fn(state, ...args);
10578
+ if (state === newEditor) {
10545
10579
  return newEditor;
10546
10580
  }
10547
10581
  for (const effect of effects) {
@@ -10553,7 +10587,7 @@ const wrapCommand = fn => async (editorUid, ...args) => {
10553
10587
 
10554
10588
  // TODO combine neweditor with latest editor?
10555
10589
 
10556
- set$6(editorUid, oldInstance.newState, newEditor);
10590
+ set$6(editorUid, state, newEditor);
10557
10591
  const commands = renderEditor(editorUid);
10558
10592
  return {
10559
10593
  ...newEditor,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "10.1.0",
3
+ "version": "11.0.0",
4
4
  "license": "MIT",
5
5
  "author": "Lvce Editor",
6
6
  "type": "module",