@lvce-editor/editor-worker 4.9.0 → 4.10.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.
- package/dist/editorWorkerMain.js +42 -8
- package/package.json +1 -1
package/dist/editorWorkerMain.js
CHANGED
|
@@ -144,6 +144,7 @@ const IndentMore = 'indentMore';
|
|
|
144
144
|
const InsertLineBreak = 'insertLineBreak';
|
|
145
145
|
const ReplaceAll$2 = 'replaceAll';
|
|
146
146
|
const ToggleBlockComment = 'toggleBlockComment';
|
|
147
|
+
const Rename$1 = 'rename';
|
|
147
148
|
|
|
148
149
|
const map$1 = Object.create(null);
|
|
149
150
|
const set$7 = (id, widget) => {
|
|
@@ -398,23 +399,27 @@ const offsetAt = (textDocument, positionRowIndex, positionColumnIndex) => {
|
|
|
398
399
|
return offset;
|
|
399
400
|
};
|
|
400
401
|
const positionAt = (textDocument, offset) => {
|
|
402
|
+
const {
|
|
403
|
+
lines
|
|
404
|
+
} = textDocument;
|
|
401
405
|
let rowIndex = 0;
|
|
402
406
|
let columnIndex = 0;
|
|
403
407
|
let currentOffset = 0;
|
|
404
|
-
while (rowIndex <
|
|
405
|
-
currentOffset +=
|
|
408
|
+
while (rowIndex < lines.length && currentOffset < offset) {
|
|
409
|
+
currentOffset += lines[rowIndex].length + 1;
|
|
406
410
|
rowIndex++;
|
|
407
411
|
}
|
|
408
412
|
if (currentOffset > offset) {
|
|
409
413
|
rowIndex--;
|
|
410
|
-
currentOffset -=
|
|
414
|
+
currentOffset -= lines[rowIndex].length + 1;
|
|
411
415
|
columnIndex = offset - currentOffset;
|
|
412
416
|
} else {
|
|
413
417
|
columnIndex = currentOffset - offset;
|
|
414
418
|
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
419
|
+
console.log({
|
|
420
|
+
rowIndex,
|
|
421
|
+
columnIndex
|
|
422
|
+
});
|
|
418
423
|
// TODO
|
|
419
424
|
return {
|
|
420
425
|
rowIndex,
|
|
@@ -3012,7 +3017,6 @@ const cutLine = async editor => {
|
|
|
3012
3017
|
return scheduleDocumentAndCursorsSelections(editor, changes, selectionChanges);
|
|
3013
3018
|
};
|
|
3014
3019
|
|
|
3015
|
-
// @ts-ignore
|
|
3016
3020
|
const cutSelectedText = async editor => {
|
|
3017
3021
|
const {
|
|
3018
3022
|
selections
|
|
@@ -8075,6 +8079,35 @@ const getRenameState = editor => {
|
|
|
8075
8079
|
return getWidgetState(editor, Rename);
|
|
8076
8080
|
};
|
|
8077
8081
|
|
|
8082
|
+
const getRenameChanges = (editor, result) => {
|
|
8083
|
+
if (!result || !result.edits) {
|
|
8084
|
+
return [];
|
|
8085
|
+
}
|
|
8086
|
+
const changes = [];
|
|
8087
|
+
console.log({
|
|
8088
|
+
result
|
|
8089
|
+
});
|
|
8090
|
+
for (const edit of result.edits) {
|
|
8091
|
+
const position = positionAt(editor, edit.offset);
|
|
8092
|
+
const start = position;
|
|
8093
|
+
const end = {
|
|
8094
|
+
...position,
|
|
8095
|
+
columnIndex: start.columnIndex + edit.deleted
|
|
8096
|
+
};
|
|
8097
|
+
const selection = {
|
|
8098
|
+
start,
|
|
8099
|
+
end
|
|
8100
|
+
};
|
|
8101
|
+
changes.push({
|
|
8102
|
+
start,
|
|
8103
|
+
end,
|
|
8104
|
+
inserted: [result.inserted],
|
|
8105
|
+
deleted: getSelectionText(editor, selection),
|
|
8106
|
+
origin: Rename$1
|
|
8107
|
+
});
|
|
8108
|
+
}
|
|
8109
|
+
return changes;
|
|
8110
|
+
};
|
|
8078
8111
|
const accept = async editor => {
|
|
8079
8112
|
const child = getRenameState(editor);
|
|
8080
8113
|
if (!child) {
|
|
@@ -8087,8 +8120,9 @@ const accept = async editor => {
|
|
|
8087
8120
|
// TODO
|
|
8088
8121
|
const offset = getOffsetAtCursor(editor);
|
|
8089
8122
|
const result = await executeRenameProvider(editor, offset, child.newValue);
|
|
8123
|
+
const changes = getRenameChanges(editor, result);
|
|
8090
8124
|
console.log({
|
|
8091
|
-
|
|
8125
|
+
changes
|
|
8092
8126
|
});
|
|
8093
8127
|
// 1. ask extension host for rename edits
|
|
8094
8128
|
// 2. apply rename edit across editor (and whole workspace)
|