@lvce-editor/editor-worker 19.78.11 → 19.78.12

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/diff-sdk.js CHANGED
@@ -21238,22 +21238,31 @@ const handleWheel$2 = (editor, deltaMode, eventDeltaX, eventDeltaY) => {
21238
21238
  return setDelta(editor, deltaMode, eventDeltaX, eventDeltaY);
21239
21239
  };
21240
21240
 
21241
- // @ts-ignore
21242
- const getChanges$2 = selections => {
21241
+ const getChanges$2 = editor => {
21242
+ const {
21243
+ lines,
21244
+ selections
21245
+ } = editor;
21243
21246
  const changes = [];
21244
- const rowsToIndentLess = [];
21247
+ const rowsToIndentLess = new Set();
21245
21248
  for (let i = 0; i < selections.length; i += 4) {
21246
21249
  const selectionStartRow = selections[i];
21247
21250
  const selectionEndRow = selections[i + 2];
21248
21251
  for (let i = selectionStartRow; i <= selectionEndRow; i++) {
21249
- rowsToIndentLess.push(i);
21252
+ rowsToIndentLess.add(i);
21250
21253
  }
21251
21254
  }
21252
21255
  for (const rowToIndent of rowsToIndentLess) {
21256
+ const line = lines[rowToIndent];
21257
+ const leadingWhitespace = line.match(/^[\t ]+/)?.[0] ?? '';
21258
+ const whitespaceToRemove = leadingWhitespace.startsWith('\t') ? '\t' : leadingWhitespace.slice(0, editor.tabSize || 2);
21259
+ if (!whitespaceToRemove) {
21260
+ continue;
21261
+ }
21253
21262
  changes.push({
21254
- deleted: [' '],
21263
+ deleted: [whitespaceToRemove],
21255
21264
  end: {
21256
- columnIndex: 2,
21265
+ columnIndex: whitespaceToRemove.length,
21257
21266
  rowIndex: rowToIndent
21258
21267
  },
21259
21268
  inserted: [''],
@@ -21269,10 +21278,7 @@ const getChanges$2 = selections => {
21269
21278
 
21270
21279
  // @ts-ignore
21271
21280
  const indentLess = editor => {
21272
- const {
21273
- selections
21274
- } = editor;
21275
- const changes = getChanges$2(selections);
21281
+ const changes = getChanges$2(editor);
21276
21282
  return scheduleDocumentAndCursorsSelections(editor, changes);
21277
21283
  };
21278
21284
 
@@ -28647,7 +28653,7 @@ const commandMap = {
28647
28653
  'Editor.hasCachedCharacterWidth': has$1,
28648
28654
  'Editor.hotReload': hotReload,
28649
28655
  'Editor.incrementSelection': wrapCommand(incrementSelection),
28650
- 'Editor.indendLess': wrapCommand(indentLess),
28656
+ 'Editor.indentLess': wrapCommand(indentLess),
28651
28657
  'Editor.indentMore': wrapCommand(indentMore),
28652
28658
  'Editor.insertLineBreak': wrapCommand(insertLineBreak),
28653
28659
  'Editor.loadContent': wrapCommand(loadContent),
@@ -21689,22 +21689,31 @@ const handleWheel$2 = (editor, deltaMode, eventDeltaX, eventDeltaY) => {
21689
21689
  return setDelta(editor, deltaMode, eventDeltaX, eventDeltaY);
21690
21690
  };
21691
21691
 
21692
- // @ts-ignore
21693
- const getChanges$2 = selections => {
21692
+ const getChanges$2 = editor => {
21693
+ const {
21694
+ lines,
21695
+ selections
21696
+ } = editor;
21694
21697
  const changes = [];
21695
- const rowsToIndentLess = [];
21698
+ const rowsToIndentLess = new Set();
21696
21699
  for (let i = 0; i < selections.length; i += 4) {
21697
21700
  const selectionStartRow = selections[i];
21698
21701
  const selectionEndRow = selections[i + 2];
21699
21702
  for (let i = selectionStartRow; i <= selectionEndRow; i++) {
21700
- rowsToIndentLess.push(i);
21703
+ rowsToIndentLess.add(i);
21701
21704
  }
21702
21705
  }
21703
21706
  for (const rowToIndent of rowsToIndentLess) {
21707
+ const line = lines[rowToIndent];
21708
+ const leadingWhitespace = line.match(/^[\t ]+/)?.[0] ?? '';
21709
+ const whitespaceToRemove = leadingWhitespace.startsWith('\t') ? '\t' : leadingWhitespace.slice(0, editor.tabSize || 2);
21710
+ if (!whitespaceToRemove) {
21711
+ continue;
21712
+ }
21704
21713
  changes.push({
21705
- deleted: [' '],
21714
+ deleted: [whitespaceToRemove],
21706
21715
  end: {
21707
- columnIndex: 2,
21716
+ columnIndex: whitespaceToRemove.length,
21708
21717
  rowIndex: rowToIndent
21709
21718
  },
21710
21719
  inserted: [''],
@@ -21720,10 +21729,7 @@ const getChanges$2 = selections => {
21720
21729
 
21721
21730
  // @ts-ignore
21722
21731
  const indentLess = editor => {
21723
- const {
21724
- selections
21725
- } = editor;
21726
- const changes = getChanges$2(selections);
21732
+ const changes = getChanges$2(editor);
21727
21733
  return scheduleDocumentAndCursorsSelections(editor, changes);
21728
21734
  };
21729
21735
 
@@ -29095,7 +29101,7 @@ const commandMap = {
29095
29101
  'Editor.hasCachedCharacterWidth': has$1,
29096
29102
  'Editor.hotReload': hotReload,
29097
29103
  'Editor.incrementSelection': wrapCommand(incrementSelection),
29098
- 'Editor.indendLess': wrapCommand(indentLess),
29104
+ 'Editor.indentLess': wrapCommand(indentLess),
29099
29105
  'Editor.indentMore': wrapCommand(indentMore),
29100
29106
  'Editor.insertLineBreak': wrapCommand(insertLineBreak),
29101
29107
  'Editor.loadContent': wrapCommand(loadContent),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "19.78.11",
3
+ "version": "19.78.12",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"