@lvce-editor/editor-worker 19.44.0 → 19.46.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.
@@ -4361,6 +4361,44 @@ const updateColorPickerValue$1 = async (editor, value) => {
4361
4361
  };
4362
4362
  };
4363
4363
 
4364
+ const validTypes = new Set(['added', 'deleted', 'modified']);
4365
+ const isProviderDecoration$1 = value => {
4366
+ return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
4367
+ };
4368
+ const getProviderDecorations$1 = results => {
4369
+ if (!Array.isArray(results)) {
4370
+ return [];
4371
+ }
4372
+ const decorations = [];
4373
+ for (const result of results) {
4374
+ if (!Array.isArray(result)) {
4375
+ continue;
4376
+ }
4377
+ for (const decoration of result) {
4378
+ if (isProviderDecoration$1(decoration) && Number.isSafeInteger(decoration.rowIndex) && decoration.rowIndex >= 0 && typeof decoration.type === 'string' && validTypes.has(decoration.type)) {
4379
+ decorations.push({
4380
+ rowIndex: decoration.rowIndex,
4381
+ type: decoration.type
4382
+ });
4383
+ }
4384
+ }
4385
+ }
4386
+ return decorations;
4387
+ };
4388
+ const getEditorGutterDecorations = async editor => {
4389
+ const textDocument = {
4390
+ languageId: editor.languageId,
4391
+ text: getText$1(editor),
4392
+ uri: editor.uri
4393
+ };
4394
+ try {
4395
+ const results = await invoke$d('Extensions.executeProvidersByEvent', 'onEditorGutterDecoration', 'ExtensionApi.executeEditorGutterDecorationProvider', textDocument);
4396
+ return getProviderDecorations$1(results);
4397
+ } catch {
4398
+ return [];
4399
+ }
4400
+ };
4401
+
4364
4402
  const diagnosticContainsPosition = (diagnostic, rowIndex, columnIndex) => {
4365
4403
  const {
4366
4404
  columnIndex: startColumnIndex,
@@ -4838,6 +4876,12 @@ const updateDerivedState = async (oldState, newState) => {
4838
4876
  lightBulbRowIndex: await getLightBulbRowIndex(finalState)
4839
4877
  };
4840
4878
  }
4879
+ if (oldState.lines !== nextState.lines || oldState.uri !== nextState.uri) {
4880
+ finalState = {
4881
+ ...finalState,
4882
+ gutterDecorations: await getEditorGutterDecorations(finalState)
4883
+ };
4884
+ }
4841
4885
  if (!shouldUpdateSelectionData(oldState, nextState)) {
4842
4886
  return finalState;
4843
4887
  }
@@ -4977,6 +5021,7 @@ const createEditor2 = (id, uri, x, y, width, height, platform, assetDir) => {
4977
5021
  fontFamily: '',
4978
5022
  fontSize: 0,
4979
5023
  fontWeight: 0,
5024
+ gutterDecorations: [],
4980
5025
  gutterWidth: 0,
4981
5026
  handleOffset: 0,
4982
5027
  handleOffsetX: 0,
@@ -5067,6 +5112,7 @@ const emptyEditor = {
5067
5112
  endOfLineDecorations: [],
5068
5113
  focused: false,
5069
5114
  foldingRanges: [],
5115
+ gutterDecorations: [],
5070
5116
  hasListener: false,
5071
5117
  height: 0,
5072
5118
  highlightedLine: -1,
@@ -5261,6 +5307,7 @@ const createEditor = async ({
5261
5307
  fontFamily,
5262
5308
  fontSize,
5263
5309
  fontWeight,
5310
+ gutterDecorations: [],
5264
5311
  gutterWidth: 0,
5265
5312
  handleOffset: 0,
5266
5313
  handleOffsetX: 0,
@@ -5455,7 +5502,7 @@ const isEqual$3 = (oldState, newState) => {
5455
5502
  };
5456
5503
 
5457
5504
  const isEqual$2 = (oldState, newState) => {
5458
- return oldState.breadcrumbsEnabled === newState.breadcrumbsEnabled && oldState.breakPoints === newState.breakPoints && oldState.bracketMatchInfos === newState.bracketMatchInfos && oldState.cursorInfos === newState.cursorInfos && oldState.diagnostics === newState.diagnostics && oldState.documentSymbols === newState.documentSymbols && oldState.endOfLineDecorations === newState.endOfLineDecorations && oldState.highlightedLine === newState.highlightedLine && oldState.lineNumbers === newState.lineNumbers && oldState.loadError === newState.loadError && oldState.textInfos === newState.textInfos && oldState.differences === newState.differences && oldState.initial === newState.initial && oldState.selectionInfos === newState.selectionInfos && oldState.selections === newState.selections && oldState.workspaceUri === newState.workspaceUri;
5505
+ return oldState.breadcrumbsEnabled === newState.breadcrumbsEnabled && oldState.breakPoints === newState.breakPoints && oldState.bracketMatchInfos === newState.bracketMatchInfos && oldState.cursorInfos === newState.cursorInfos && oldState.diagnostics === newState.diagnostics && oldState.documentSymbols === newState.documentSymbols && oldState.endOfLineDecorations === newState.endOfLineDecorations && oldState.gutterDecorations === newState.gutterDecorations && oldState.highlightedLine === newState.highlightedLine && oldState.lineNumbers === newState.lineNumbers && oldState.loadError === newState.loadError && oldState.textInfos === newState.textInfos && oldState.differences === newState.differences && oldState.initial === newState.initial && oldState.selectionInfos === newState.selectionInfos && oldState.selections === newState.selections && oldState.workspaceUri === newState.workspaceUri;
5459
5506
  };
5460
5507
 
5461
5508
  const isEqual$1 = (oldState, newState) => {
@@ -13610,11 +13657,15 @@ const handleSettingsChanged = async state => {
13610
13657
  } else if (!state.breadcrumbsEnabled) {
13611
13658
  [documentSymbols, workspaceUri] = await Promise.all([getDocumentSymbols(editorWithUpdatedSettings), getWorkspaceUri$1()]);
13612
13659
  }
13613
- return resize({
13660
+ const resizedEditor = resize({
13614
13661
  ...editorWithUpdatedSettings,
13615
13662
  documentSymbols,
13616
13663
  workspaceUri
13617
13664
  }, {}, charWidth);
13665
+ return {
13666
+ ...resizedEditor,
13667
+ gutterDecorations: await getEditorGutterDecorations(resizedEditor)
13668
+ };
13618
13669
  };
13619
13670
 
13620
13671
  const applyTabCompletion = (editor, result) => {
@@ -14087,6 +14138,31 @@ const moveLineUp = editor => {
14087
14138
  return moveLines(editor, -1);
14088
14139
  };
14089
14140
 
14141
+ const refreshGutterDecorations = async editor => {
14142
+ const gutterDecorations = await getEditorGutterDecorations(editor);
14143
+ return {
14144
+ ...editor,
14145
+ gutterDecorations
14146
+ };
14147
+ };
14148
+ const refreshGutterDecorationsAll = async () => {
14149
+ for (const key of getKeys$2()) {
14150
+ const editor = get$8(Number(key))?.newState;
14151
+ if (editor) {
14152
+ const refreshedEditor = await refreshGutterDecorations(editor);
14153
+ const latest = get$8(editor.id);
14154
+ if (!latest) {
14155
+ continue;
14156
+ }
14157
+ set$8(editor.id, latest.oldState, {
14158
+ ...latest.newState,
14159
+ gutterDecorations: refreshedEditor.gutterDecorations
14160
+ });
14161
+ await invoke$a('Editor.renderPending', editor.id);
14162
+ }
14163
+ }
14164
+ };
14165
+
14090
14166
  /**
14091
14167
  * Register a listener for editor events
14092
14168
  * @param listenerType - The type of event to listen for (from ListenerType enum)
@@ -14124,6 +14200,28 @@ ${editorSelector} .EditorLineDecoration {
14124
14200
  margin-left: 2em;
14125
14201
  user-select: none;
14126
14202
  }
14203
+ ${editorSelector} .LineNumber {
14204
+ position: relative;
14205
+ }
14206
+ ${editorSelector} .EditorGutterDecoration {
14207
+ bottom: 0;
14208
+ left: 0;
14209
+ pointer-events: none;
14210
+ position: absolute;
14211
+ top: 0;
14212
+ width: 3px;
14213
+ }
14214
+ ${editorSelector} .EditorGutterDecorationAdded {
14215
+ background: var(--EditorGutterAddedBackground, #2ea043);
14216
+ }
14217
+ ${editorSelector} .EditorGutterDecorationModified {
14218
+ background: var(--EditorGutterModifiedBackground, #0078d4);
14219
+ }
14220
+ ${editorSelector} .EditorGutterDecorationDeleted {
14221
+ background: var(--EditorGutterDeletedBackground, #f85149);
14222
+ height: 3px;
14223
+ top: calc(50% - 1px);
14224
+ }
14127
14225
  ${editorSelector} .R{background-color:#add6ff40}
14128
14226
  ${editorSelector} .BracketMatch {
14129
14227
  position: absolute;
@@ -14809,11 +14907,19 @@ const getEditorContentVirtualDom = ({
14809
14907
  return [editorContentNode, ...getEditorInputVirtualDom(), ...getEditorLayersVirtualDom(selectionInfos, textInfos, differences, lineNumbers, highlightedLine, cursorInfos, diagnostics, visibleLineIndices, endOfLineDecorations, bracketMatchInfos), ...getEditorScrollBarDiagnosticsVirtualDom(scrollBarDiagnostics), ...getScrollBarVirtualDom()];
14810
14908
  };
14811
14909
 
14812
- const getGutterInfoVirtualDom = gutterInfo => {
14910
+ const getGutterInfoVirtualDom = (gutterInfo, activeLineNumber) => {
14813
14911
  const isBreakpoint = typeof gutterInfo === 'object' && gutterInfo.isBreakpoint;
14814
14912
  const isLightBulb = typeof gutterInfo === 'object' && gutterInfo.isLightBulb;
14815
14913
  const lineNumber = typeof gutterInfo === 'object' ? gutterInfo.lineNumber : gutterInfo;
14914
+ const gutterDecorations = typeof gutterInfo === 'object' ? gutterInfo.gutterDecorations || [] : [];
14915
+ const showLineNumber = typeof gutterInfo !== 'object' || gutterInfo.showLineNumber !== false;
14816
14916
  const label = isLightBulb ? `Show Code Actions on line ${lineNumber}` : `Breakpoint on line ${lineNumber}`;
14917
+ let className = lineNumber === activeLineNumber ? 'LineNumber LineNumberActive' : 'LineNumber';
14918
+ if (isLightBulb) {
14919
+ className += ' LineNumberLightBulb MaskIconLightBulb';
14920
+ } else if (isBreakpoint) {
14921
+ className += ' LineNumberBreakpoint';
14922
+ }
14817
14923
  return [{
14818
14924
  ...((isBreakpoint || isLightBulb) && {
14819
14925
  ariaLabel: label,
@@ -14822,22 +14928,28 @@ const getGutterInfoVirtualDom = gutterInfo => {
14822
14928
  ...(isBreakpoint && !isLightBulb && {
14823
14929
  style: 'color:var(--DebugIconBreakpointForeground,#e51400)'
14824
14930
  }),
14825
- childCount: 1,
14826
- className: isLightBulb ? 'LineNumber LineNumberLightBulb MaskIconLightBulb' : isBreakpoint ? 'LineNumber LineNumberBreakpoint' : 'LineNumber',
14931
+ childCount: gutterDecorations.length + 1,
14932
+ className,
14827
14933
  ...(isLightBulb && {
14828
14934
  onClick: HandleLightBulbClick,
14829
14935
  role: Button
14830
14936
  }),
14831
14937
  type: Span
14832
- }, text(isLightBulb ? '' : isBreakpoint ? '●' : lineNumber)];
14938
+ }, ...gutterDecorations.map(decoration => ({
14939
+ ariaLabel: `${decoration.type[0].toUpperCase()}${decoration.type.slice(1)} line ${lineNumber}`,
14940
+ childCount: 0,
14941
+ className: mergeClassNames('EditorGutterDecoration', `EditorGutterDecoration${decoration.type[0].toUpperCase()}${decoration.type.slice(1)}`),
14942
+ title: `${decoration.type[0].toUpperCase()}${decoration.type.slice(1)} line ${lineNumber}`,
14943
+ type: Span
14944
+ })), text(isLightBulb ? '' : isBreakpoint ? '●' : showLineNumber ? lineNumber : '')];
14833
14945
  };
14834
- const getEditorGutterVirtualDom$1 = gutterInfos => {
14835
- const dom = gutterInfos.flatMap(getGutterInfoVirtualDom);
14946
+ const getEditorGutterVirtualDom$1 = (gutterInfos, activeLineNumber = -1) => {
14947
+ const dom = gutterInfos.flatMap(gutterInfo => getGutterInfoVirtualDom(gutterInfo, activeLineNumber));
14836
14948
  return dom;
14837
14949
  };
14838
14950
 
14839
- const getEditorGutterVirtualDom = gutterInfos => {
14840
- const gutterDom = getEditorGutterVirtualDom$1([...gutterInfos]);
14951
+ const getEditorGutterVirtualDom = (gutterInfos, activeLineNumber = -1) => {
14952
+ const gutterDom = getEditorGutterVirtualDom$1([...gutterInfos], activeLineNumber);
14841
14953
  return [{
14842
14954
  childCount: gutterInfos.length,
14843
14955
  className: 'Gutter',
@@ -14845,7 +14957,7 @@ const getEditorGutterVirtualDom = gutterInfos => {
14845
14957
  }, ...gutterDom];
14846
14958
  };
14847
14959
 
14848
- const getGutterInfos = (minLineY, maxLineY, breakPoints, showLineNumbers = true, lineIndices, lightBulbRowIndex = -1) => {
14960
+ const getGutterInfos = (minLineY, maxLineY, breakPoints, showLineNumbers = true, lineIndices, lightBulbRowIndex = -1, gutterDecorations = []) => {
14849
14961
  const gutterInfos = [];
14850
14962
  const rows = lineIndices || Array.from({
14851
14963
  length: maxLineY - minLineY
@@ -14854,17 +14966,30 @@ const getGutterInfos = (minLineY, maxLineY, breakPoints, showLineNumbers = true,
14854
14966
  const lineNumber = rowIndex + 1;
14855
14967
  const isBreakpoint = breakPoints.includes(rowIndex);
14856
14968
  const isLightBulb = rowIndex === lightBulbRowIndex;
14969
+ const rowDecorations = gutterDecorations.filter(decoration => decoration.rowIndex === rowIndex);
14857
14970
  if (isLightBulb) {
14858
14971
  gutterInfos.push({
14972
+ ...(rowDecorations.length > 0 && {
14973
+ gutterDecorations: rowDecorations
14974
+ }),
14859
14975
  isBreakpoint,
14860
14976
  isLightBulb: true,
14861
14977
  lineNumber
14862
14978
  });
14863
14979
  } else if (isBreakpoint) {
14864
14980
  gutterInfos.push({
14981
+ ...(rowDecorations.length > 0 && {
14982
+ gutterDecorations: rowDecorations
14983
+ }),
14865
14984
  isBreakpoint: true,
14866
14985
  lineNumber
14867
14986
  });
14987
+ } else if (rowDecorations.length > 0) {
14988
+ gutterInfos.push({
14989
+ gutterDecorations: rowDecorations,
14990
+ lineNumber,
14991
+ showLineNumber: showLineNumbers
14992
+ });
14868
14993
  } else {
14869
14994
  gutterInfos.push(showLineNumbers ? lineNumber : '');
14870
14995
  }
@@ -14872,6 +14997,10 @@ const getGutterInfos = (minLineY, maxLineY, breakPoints, showLineNumbers = true,
14872
14997
  return gutterInfos;
14873
14998
  };
14874
14999
 
15000
+ const getPrimaryCursorRowIndex = (selections, primarySelectionIndex = 0) => {
15001
+ return selections?.[primarySelectionIndex + 2] ?? -1;
15002
+ };
15003
+
14875
15004
  const textEditorErrorIconNode = {
14876
15005
  childCount: 0,
14877
15006
  className: mergeClassNames('EditorTextIcon', 'EditorTextIconError', 'MaskIcon', 'MaskIconError'),
@@ -14904,6 +15033,7 @@ const getEditorVirtualDom = ({
14904
15033
  differences,
14905
15034
  documentSymbols = [],
14906
15035
  endOfLineDecorations = [],
15036
+ gutterDecorations = [],
14907
15037
  gutterInfos = [],
14908
15038
  highlightedLine = -1,
14909
15039
  lightBulbRowIndex = -1,
@@ -14933,9 +15063,10 @@ const getEditorVirtualDom = ({
14933
15063
  type: Div
14934
15064
  }, textEditorErrorIconNode, textEditorErrorMessageNode, text(loadError)];
14935
15065
  }
14936
- const visibleGutterInfos = breakPoints.length > 0 || visibleLineIndices ? getGutterInfos(minLineY, maxLineY, breakPoints, lineNumbers, visibleLineIndices, lightBulbRowIndex) : gutterInfos;
14937
- const showGutter = lineNumbers || breakPoints.length > 0 || lightBulbRowIndex >= 0;
14938
- const gutterDom = showGutter ? getEditorGutterVirtualDom(visibleGutterInfos) : [];
15066
+ const visibleGutterInfos = breakPoints.length > 0 || gutterDecorations.length > 0 || visibleLineIndices ? getGutterInfos(minLineY, maxLineY, breakPoints, lineNumbers, visibleLineIndices, lightBulbRowIndex, gutterDecorations) : gutterInfos;
15067
+ const showGutter = lineNumbers || breakPoints.length > 0 || lightBulbRowIndex >= 0 || gutterDecorations.length > 0;
15068
+ const primaryCursorRowIndex = getPrimaryCursorRowIndex(selections, primarySelectionIndex);
15069
+ const gutterDom = showGutter ? getEditorGutterVirtualDom(visibleGutterInfos, primaryCursorRowIndex + 1) : [];
14939
15070
  const minimapDom = getMinimapVirtualDom(minimapEnabled, minimapLines, minLineY);
14940
15071
  const breadcrumbsDom = breadcrumbsEnabled ? getEditorBreadcrumbsVirtualDom({
14941
15072
  breadcrumbsEnabled,
@@ -15199,20 +15330,24 @@ const renderGutterInfo = {
15199
15330
  apply(oldState, newState) {
15200
15331
  const {
15201
15332
  breakPoints,
15333
+ gutterDecorations,
15202
15334
  lightBulbRowIndex,
15203
15335
  lineNumbers,
15204
15336
  maxLineY,
15205
15337
  minLineY,
15338
+ primarySelectionIndex,
15339
+ selections,
15206
15340
  visibleLineIndices
15207
15341
  } = newState;
15208
- if (!lineNumbers && breakPoints.length === 0 && lightBulbRowIndex === -1) {
15342
+ if (!lineNumbers && breakPoints.length === 0 && lightBulbRowIndex === -1 && gutterDecorations.length === 0) {
15209
15343
  return ['renderGutter', []];
15210
15344
  }
15211
- const gutterInfos = getGutterInfos(minLineY, maxLineY, breakPoints, lineNumbers, visibleLineIndices, lightBulbRowIndex);
15212
- const dom = getEditorGutterVirtualDom$1(gutterInfos);
15345
+ const gutterInfos = getGutterInfos(minLineY, maxLineY, breakPoints, lineNumbers, visibleLineIndices, lightBulbRowIndex, gutterDecorations);
15346
+ const primaryCursorRowIndex = getPrimaryCursorRowIndex(selections, primarySelectionIndex);
15347
+ const dom = getEditorGutterVirtualDom$1(gutterInfos, primaryCursorRowIndex + 1);
15213
15348
  return ['renderGutter', dom];
15214
15349
  },
15215
- isEqual: (oldState, newState) => oldState.breakPoints === newState.breakPoints && oldState.lightBulbRowIndex === newState.lightBulbRowIndex && oldState.foldingRanges === newState.foldingRanges && oldState.lineNumbers === newState.lineNumbers && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY
15350
+ isEqual: (oldState, newState) => oldState.breakPoints === newState.breakPoints && oldState.gutterDecorations === newState.gutterDecorations && oldState.lightBulbRowIndex === newState.lightBulbRowIndex && oldState.foldingRanges === newState.foldingRanges && oldState.lineNumbers === newState.lineNumbers && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY && getPrimaryCursorRowIndex(oldState.selections, oldState.primarySelectionIndex) === getPrimaryCursorRowIndex(newState.selections, newState.primarySelectionIndex)
15216
15351
  };
15217
15352
  const renderWidgets = {
15218
15353
  apply: renderWidgets$1,
@@ -15810,6 +15945,8 @@ const commandMap = {
15810
15945
  'Editor.pasteText': wrapCommand(pasteText),
15811
15946
  'Editor.previousDiagnostic': wrapCommand(previousDiagnostic),
15812
15947
  'Editor.redo': wrapCommand(redo),
15948
+ 'Editor.refreshGutterDecorations': wrapCommand(refreshGutterDecorations),
15949
+ 'Editor.refreshGutterDecorationsAll': refreshGutterDecorationsAll,
15813
15950
  'Editor.render': renderEditor,
15814
15951
  'Editor.render2': render2,
15815
15952
  'Editor.renderEventListeners': renderEventListeners,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "19.44.0",
3
+ "version": "19.46.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"