@lvce-editor/editor-worker 19.60.1 → 19.60.3

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.
@@ -1855,6 +1855,13 @@ const clamp = (num, min, max) => {
1855
1855
  return Math.min(Math.max(num, min), max);
1856
1856
  };
1857
1857
 
1858
+ const getScrollOffset = (deltaY, rowHeight) => {
1859
+ return rowHeight > 0 ? deltaY % rowHeight : 0;
1860
+ };
1861
+ const getRenderedLineCount = (height, rowHeight, deltaY) => {
1862
+ return height > 0 && rowHeight > 0 ? Math.ceil((height + getScrollOffset(deltaY, rowHeight)) / rowHeight) : 0;
1863
+ };
1864
+
1858
1865
  const toMergeConflictActionsRow = rowIndex => ~rowIndex;
1859
1866
  const isMergeConflictActionsRow = viewRow => viewRow < 0;
1860
1867
  const getMergeConflictRowIndex = viewRow => ~viewRow;
@@ -2080,10 +2087,11 @@ const updateLayout = (editor, foldingRanges) => {
2080
2087
  const viewLineIndices = hasMergeConflictRows ? getViewLineIndices(lines.length, rowIndex => isRowHidden(rowIndex, foldingRanges), mergeConflicts) : [];
2081
2088
  const visibleLineCount = hasMergeConflictRows ? viewLineIndices.length : getVisibleLineCount(lines.length, foldingRanges);
2082
2089
  const finalY = Math.max(visibleLineCount - numberOfVisibleLines, 0);
2083
- const finalDeltaY = finalY * itemHeight;
2090
+ const finalDeltaY = Math.max(visibleLineCount * itemHeight - height, 0);
2084
2091
  const deltaY = clamp(editor.deltaY, 0, finalDeltaY);
2085
2092
  const startVisualRow = Math.floor(deltaY / itemHeight);
2086
- const visibleViewLineIndices = hasMergeConflictRows ? getVisibleViewLineIndices(viewLineIndices, startVisualRow, numberOfVisibleLines) : getViewportLineIndices(lines.length, foldingRanges, startVisualRow, numberOfVisibleLines);
2093
+ const renderedLineCount = getRenderedLineCount(height, itemHeight, deltaY);
2094
+ const visibleViewLineIndices = hasMergeConflictRows ? getVisibleViewLineIndices(viewLineIndices, startVisualRow, renderedLineCount) : getViewportLineIndices(lines.length, foldingRanges, startVisualRow, renderedLineCount);
2087
2095
  const visibleLineIndices = hasMergeConflictRows ? getVisibleLineIndices(visibleViewLineIndices) : visibleViewLineIndices;
2088
2096
  const minLineY = visibleLineIndices[0] ?? 0;
2089
2097
  const maxLineY = visibleLineIndices.length === 0 ? 0 : visibleLineIndices.at(-1) + 1;
@@ -3214,7 +3222,7 @@ const getVisible$1 = async (editor, syncIncremental) => {
3214
3222
  width
3215
3223
  } = editor;
3216
3224
  const visibleLineIndices = editor.visibleLineIndices || Array.from({
3217
- length: Math.min(editor.numberOfVisibleLines, lines.length - editor.minLineY)
3225
+ length: Math.min(editor.maxLineY ?? editor.minLineY + editor.numberOfVisibleLines, lines.length) - editor.minLineY
3218
3226
  }, (_, index) => editor.minLineY + index);
3219
3227
  if (visibleLineIndices.length === 0) {
3220
3228
  return {
@@ -3272,7 +3280,6 @@ const setDeltaY$1 = async (state, value) => {
3272
3280
  finalDeltaY,
3273
3281
  height,
3274
3282
  itemHeight,
3275
- numberOfVisibleLines,
3276
3283
  scrollBarHeight
3277
3284
  } = state;
3278
3285
  const newDeltaY = clamp(value, 0, finalDeltaY);
@@ -3280,8 +3287,9 @@ const setDeltaY$1 = async (state, value) => {
3280
3287
  return state;
3281
3288
  }
3282
3289
  const startVisualRow = Math.floor(newDeltaY / itemHeight);
3290
+ const renderedLineCount = getRenderedLineCount(height, itemHeight, newDeltaY);
3283
3291
  const hasMergeConflictRows = state.viewLineIndices?.length > 0;
3284
- const visibleViewLineIndices = hasMergeConflictRows ? getVisibleViewLineIndices(state.viewLineIndices, startVisualRow, numberOfVisibleLines) : getViewportLineIndices(state.lines.length, state.foldingRanges || [], startVisualRow, numberOfVisibleLines);
3292
+ const visibleViewLineIndices = hasMergeConflictRows ? getVisibleViewLineIndices(state.viewLineIndices, startVisualRow, renderedLineCount) : getViewportLineIndices(state.lines.length, state.foldingRanges || [], startVisualRow, renderedLineCount);
3285
3293
  const visibleLineIndices = hasMergeConflictRows ? getVisibleLineIndices(visibleViewLineIndices) : visibleViewLineIndices;
3286
3294
  const minLineY = visibleLineIndices[0] ?? 0;
3287
3295
  const maxLineY = visibleLineIndices.length === 0 ? 0 : visibleLineIndices.at(-1) + 1;
@@ -3666,10 +3674,10 @@ const resize = (state, dimensions, columnWidth = state.columnWidth) => {
3666
3674
  if (!('foldingRanges' in state)) {
3667
3675
  const total = state.lines.length;
3668
3676
  const finalY = Math.max(total - numberOfVisibleLines, 0);
3669
- const finalDeltaY = finalY * state.itemHeight;
3677
+ const finalDeltaY = Math.max(total * state.itemHeight - height, 0);
3670
3678
  const deltaY = Math.min(state.deltaY, finalDeltaY);
3671
3679
  const minLineY = Math.floor(deltaY / state.itemHeight);
3672
- const maxLineY = Math.min(minLineY + numberOfVisibleLines, total);
3680
+ const maxLineY = Math.min(minLineY + getRenderedLineCount(height, state.itemHeight, deltaY), total);
3673
3681
  const contentHeight = total * state.rowHeight;
3674
3682
  const scrollBarHeight = getScrollBarSize(height, contentHeight, state.minimumSliderSize);
3675
3683
  return {
@@ -12223,25 +12231,6 @@ const getBlockCommentEdits = (editor, blockComment) => {
12223
12231
  return changes;
12224
12232
  };
12225
12233
 
12226
- const toggleBlockComment = async editor => {
12227
- const offset = getOffsetAtCursor$1(editor);
12228
- const blockComment = await getBlockComment(editor, offset);
12229
- if (!blockComment) {
12230
- return editor;
12231
- }
12232
- const edits = getBlockCommentEdits(editor, blockComment);
12233
- return scheduleDocument(editor, edits);
12234
- };
12235
-
12236
- const toggleBreakpoint = editor => {
12237
- const [rowIndex] = editor.selections;
12238
- const breakPoints = editor.breakPoints.includes(rowIndex) ? editor.breakPoints.filter(breakPoint => breakPoint !== rowIndex) : [...editor.breakPoints, rowIndex];
12239
- return {
12240
- ...editor,
12241
- breakPoints
12242
- };
12243
- };
12244
-
12245
12234
  const getLineComment = async editor => {
12246
12235
  const languageConfiguration = await getLanguageConfiguration(editor);
12247
12236
  if (!languageConfiguration?.comments?.lineComment) {
@@ -12300,6 +12289,72 @@ const getLineCommentEdit = (rowIndex, line, lineComment) => {
12300
12289
  };
12301
12290
  };
12302
12291
 
12292
+ const getSelectedLineCommentEdits = (editor, lineComment) => {
12293
+ const {
12294
+ lines,
12295
+ selections
12296
+ } = editor;
12297
+ const selectedRows = new Set();
12298
+ for (let i = 0; i < selections.length; i += 4) {
12299
+ const startRow = Math.min(selections[i], selections[i + 2]);
12300
+ let endRow = Math.max(selections[i], selections[i + 2]);
12301
+ const endColumn = selections[i + (selections[i] > selections[i + 2] ? 1 : 3)];
12302
+ if (endRow > startRow && endColumn === 0) {
12303
+ endRow--;
12304
+ }
12305
+ for (let row = startRow; row <= endRow; row++) {
12306
+ if (lines[row].trim()) {
12307
+ selectedRows.add(row);
12308
+ }
12309
+ }
12310
+ }
12311
+ const rows = [...selectedRows].toSorted((a, b) => a - b);
12312
+ const remove = rows.every(row => lines[row].trimStart().startsWith(lineComment));
12313
+ return rows.map(rowIndex => {
12314
+ const line = lines[rowIndex];
12315
+ if (remove) {
12316
+ return getLineCommentEdit(rowIndex, line, lineComment);
12317
+ }
12318
+ const columnIndex = line.length - line.trimStart().length;
12319
+ return {
12320
+ deleted: [''],
12321
+ end: {
12322
+ columnIndex,
12323
+ rowIndex
12324
+ },
12325
+ inserted: [`${lineComment} `],
12326
+ origin: ToggleBlockComment$1,
12327
+ start: {
12328
+ columnIndex,
12329
+ rowIndex
12330
+ }
12331
+ };
12332
+ });
12333
+ };
12334
+
12335
+ const toggleBlockComment = async editor => {
12336
+ const offset = getOffsetAtCursor$1(editor);
12337
+ const blockComment = await getBlockComment(editor, offset);
12338
+ if (!blockComment) {
12339
+ const lineComment = await getLineComment(editor);
12340
+ if (!lineComment) {
12341
+ return editor;
12342
+ }
12343
+ return scheduleDocumentAndCursorsSelections(editor, getSelectedLineCommentEdits(editor, lineComment));
12344
+ }
12345
+ const edits = getBlockCommentEdits(editor, blockComment);
12346
+ return scheduleDocument(editor, edits);
12347
+ };
12348
+
12349
+ const toggleBreakpoint = editor => {
12350
+ const [rowIndex] = editor.selections;
12351
+ const breakPoints = editor.breakPoints.includes(rowIndex) ? editor.breakPoints.filter(breakPoint => breakPoint !== rowIndex) : [...editor.breakPoints, rowIndex];
12352
+ return {
12353
+ ...editor,
12354
+ breakPoints
12355
+ };
12356
+ };
12357
+
12303
12358
  const editorToggleLineComment = async editor => {
12304
12359
  const lineComment = await getLineComment(editor);
12305
12360
  if (!lineComment) {
@@ -14873,8 +14928,10 @@ const renderAdditionalFocusContext$1 = (oldState, newState) => {
14873
14928
  return ['Viewlet.unsetAdditionalFocus', newState.uid, oldState.additionalFocus];
14874
14929
  };
14875
14930
 
14876
- const getCss = (uid, rowHeight, scrollBarHeight, scrollBarTop, scrollBarWidth, scrollBarLeft) => {
14931
+ const getCss = (uid, rowHeight, scrollBarHeight, scrollBarTop, scrollBarWidth, scrollBarLeft, deltaY = 0) => {
14877
14932
  const editorSelector = `.Editor[data-uid="${uid}"]`;
14933
+ const scrollOffset = getScrollOffset(deltaY, rowHeight);
14934
+ const translate = scrollOffset === 0 ? 'none' : `0px -${scrollOffset}px`;
14878
14935
  return `${editorSelector} {
14879
14936
  --EditorRowHeight: ${rowHeight}px;
14880
14937
  --ScrollBarHeight: ${scrollBarHeight}px;
@@ -14882,13 +14939,33 @@ const getCss = (uid, rowHeight, scrollBarHeight, scrollBarTop, scrollBarWidth, s
14882
14939
  --ScrollBarWidth: ${scrollBarWidth}px;
14883
14940
  --ScrollBarLeft: ${scrollBarLeft}px;
14884
14941
  }
14942
+ ${editorSelector} .EditorLayers {
14943
+ height: calc(100% + var(--EditorRowHeight));
14944
+ translate: ${translate};
14945
+ }
14946
+ ${editorSelector} .GutterRows {
14947
+ flex: none;
14948
+ width: 100%;
14949
+ translate: ${translate};
14950
+ }
14951
+ ${editorSelector} .EditorRows,
14952
+ ${editorSelector} .GutterRows {
14953
+ display: flex;
14954
+ flex-direction: column;
14955
+ }
14956
+ ${editorSelector} .EditorRow,
14957
+ ${editorSelector} .LineNumber {
14958
+ flex: none;
14959
+ }
14885
14960
  ${editorSelector} .EditorRow {
14961
+ contain: size style;
14886
14962
  height: var(--EditorRowHeight);
14887
14963
  line-height: var(--EditorRowHeight);
14888
14964
  }
14889
14965
  ${editorSelector} .MergeConflictActions,
14890
14966
  ${editorSelector} .MergeConflictActionsGutter {
14891
14967
  box-sizing: border-box;
14968
+ flex: none;
14892
14969
  height: var(--EditorRowHeight);
14893
14970
  line-height: var(--EditorRowHeight);
14894
14971
  }
@@ -14926,6 +15003,7 @@ ${editorSelector} .EditorLineDecoration {
14926
15003
  user-select: none;
14927
15004
  }
14928
15005
  ${editorSelector} .LineNumber {
15006
+ contain: content;
14929
15007
  position: relative;
14930
15008
  }
14931
15009
  ${editorSelector} .EditorGutterDecoration {
@@ -14989,7 +15067,7 @@ const renderCss$1 = (oldState, newState) => {
14989
15067
  const scrollBarTop = getScrollBarY(deltaY, finalDeltaY, height, scrollBarHeight);
14990
15068
  const scrollBarWidth = getScrollBarSize(width, longestLineWidth, minimumSliderSize);
14991
15069
  const scrollBarLeft = getScrollBarLeft(deltaX, longestLineWidth, width);
14992
- const css = getCss(uid, rowHeight, scrollBarHeight, scrollBarTop, scrollBarWidth, scrollBarLeft);
15070
+ const css = getCss(uid, rowHeight, scrollBarHeight, scrollBarTop, scrollBarWidth, scrollBarLeft, deltaY);
14993
15071
  return [SetCss$1, uid, css];
14994
15072
  };
14995
15073
 
@@ -15457,13 +15535,20 @@ const getGutterInfoVirtualDom = (gutterInfo, activeLineNumber) => {
15457
15535
  };
15458
15536
  const getEditorGutterVirtualDom$1 = (gutterInfos, activeLineNumber = -1) => {
15459
15537
  const dom = gutterInfos.flatMap(gutterInfo => getGutterInfoVirtualDom(gutterInfo, activeLineNumber));
15460
- return dom;
15538
+ if (gutterInfos.length === 0) {
15539
+ return [];
15540
+ }
15541
+ return [{
15542
+ childCount: gutterInfos.length,
15543
+ className: 'GutterRows',
15544
+ type: Div
15545
+ }, ...dom];
15461
15546
  };
15462
15547
 
15463
15548
  const getEditorGutterVirtualDom = (gutterInfos, activeLineNumber = -1) => {
15464
15549
  const gutterDom = getEditorGutterVirtualDom$1([...gutterInfos], activeLineNumber);
15465
15550
  return [{
15466
- childCount: gutterInfos.length,
15551
+ childCount: gutterInfos.length === 0 ? 0 : 1,
15467
15552
  className: 'Gutter',
15468
15553
  type: Div
15469
15554
  }, ...gutterDom];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "19.60.1",
3
+ "version": "19.60.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"