@lvce-editor/editor-worker 19.30.12 → 19.30.13
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 +260 -4
- package/package.json +1 -1
package/dist/editorWorkerMain.js
CHANGED
|
@@ -1393,6 +1393,7 @@ const KeyC = 31;
|
|
|
1393
1393
|
const KeyD = 32;
|
|
1394
1394
|
const KeyF = 34;
|
|
1395
1395
|
const KeyH = 36;
|
|
1396
|
+
const KeyI = 37;
|
|
1396
1397
|
const KeyJ = 38;
|
|
1397
1398
|
const KeyK = 39;
|
|
1398
1399
|
const KeyL = 40;
|
|
@@ -5160,7 +5161,7 @@ const disposeEditor = async editorUid => {
|
|
|
5160
5161
|
};
|
|
5161
5162
|
|
|
5162
5163
|
// @ts-ignore
|
|
5163
|
-
const getNewSelections$
|
|
5164
|
+
const getNewSelections$d = selections => {
|
|
5164
5165
|
const newSelections = [];
|
|
5165
5166
|
for (let i = 0; i < selections.length; i += 4) {
|
|
5166
5167
|
const startRowIndex = selections[i];
|
|
@@ -5180,7 +5181,7 @@ const addCursorAbove = editor => {
|
|
|
5180
5181
|
const {
|
|
5181
5182
|
selections
|
|
5182
5183
|
} = editor;
|
|
5183
|
-
const newSelections = getNewSelections$
|
|
5184
|
+
const newSelections = getNewSelections$d(selections);
|
|
5184
5185
|
return {
|
|
5185
5186
|
...editor,
|
|
5186
5187
|
selections: newSelections
|
|
@@ -5188,7 +5189,7 @@ const addCursorAbove = editor => {
|
|
|
5188
5189
|
};
|
|
5189
5190
|
|
|
5190
5191
|
// @ts-ignore
|
|
5191
|
-
const getNewSelections$
|
|
5192
|
+
const getNewSelections$c = (selections, linesLength) => {
|
|
5192
5193
|
const newSelections = [];
|
|
5193
5194
|
for (let i = 0; i < selections.length; i += 4) {
|
|
5194
5195
|
const startRowIndex = selections[i];
|
|
@@ -5209,7 +5210,7 @@ const addCursorBelow = editor => {
|
|
|
5209
5210
|
lines,
|
|
5210
5211
|
selections
|
|
5211
5212
|
} = editor;
|
|
5212
|
-
const newSelections = getNewSelections$
|
|
5213
|
+
const newSelections = getNewSelections$c(selections, lines.length);
|
|
5213
5214
|
return {
|
|
5214
5215
|
...editor,
|
|
5215
5216
|
selections: newSelections
|
|
@@ -5897,6 +5898,251 @@ const cancelSelection = editor => {
|
|
|
5897
5898
|
return scheduleSelections(editor, newSelections);
|
|
5898
5899
|
};
|
|
5899
5900
|
|
|
5901
|
+
const colorPattern$1 = /#[\dA-Fa-f]+/g;
|
|
5902
|
+
const numberPattern = /(?<![\w.#])[+-]?(?:(?:\d+(?:\.\d*)?)|(?:\.\d+))(?:[eE][+-]?\d+)?(?![\d.])/g;
|
|
5903
|
+
const validColorLengths = new Set([4, 5, 7, 9]);
|
|
5904
|
+
const isColor = value => {
|
|
5905
|
+
return validColorLengths.has(value.length) && /^#[\dA-Fa-f]+$/.test(value);
|
|
5906
|
+
};
|
|
5907
|
+
const isNumber = value => {
|
|
5908
|
+
return /^[+-]?(?:(?:\d+(?:\.\d*)?)|(?:\.\d+))(?:[eE][+-]?\d+)?$/.test(value);
|
|
5909
|
+
};
|
|
5910
|
+
const adjustNumber = (value, delta) => {
|
|
5911
|
+
const match = /^([+-]?)(?:(\d+)(?:\.(\d*))?|\.(\d+))([eE][+-]?\d+)?$/.exec(value);
|
|
5912
|
+
if (!match) {
|
|
5913
|
+
return value;
|
|
5914
|
+
}
|
|
5915
|
+
const [, originalSign, integerPart = '', fractionAfterInteger, fractionWithoutInteger, exponent = ''] = match;
|
|
5916
|
+
const fraction = fractionAfterInteger ?? fractionWithoutInteger ?? '';
|
|
5917
|
+
const mantissaEnd = exponent ? value.length - exponent.length : value.length;
|
|
5918
|
+
const hadDecimalPoint = value.slice(0, mantissaEnd).includes('.');
|
|
5919
|
+
const scale = fraction.length;
|
|
5920
|
+
const unsignedUnits = BigInt(`${integerPart || '0'}${fraction}`);
|
|
5921
|
+
const signedUnits = originalSign === '-' ? -unsignedUnits : unsignedUnits;
|
|
5922
|
+
const nextUnits = signedUnits + BigInt(delta);
|
|
5923
|
+
const isNegative = nextUnits < 0;
|
|
5924
|
+
const absoluteUnits = isNegative ? -nextUnits : nextUnits;
|
|
5925
|
+
const minimumIntegerLength = Math.max(integerPart.length, 1);
|
|
5926
|
+
const digits = absoluteUnits.toString().padStart(scale + minimumIntegerLength, '0');
|
|
5927
|
+
const resultInteger = scale === 0 ? digits : digits.slice(0, -scale);
|
|
5928
|
+
const resultFraction = scale === 0 ? '' : digits.slice(-scale);
|
|
5929
|
+
const omitLeadingZero = integerPart === '' && resultInteger === '0';
|
|
5930
|
+
const mantissa = `${omitLeadingZero ? '' : resultInteger}${hadDecimalPoint ? '.' : ''}${resultFraction}`;
|
|
5931
|
+
const sign = isNegative ? '-' : originalSign === '+' ? '+' : '';
|
|
5932
|
+
return `${sign}${mantissa}${exponent}`;
|
|
5933
|
+
};
|
|
5934
|
+
const adjustColorComponent = (digits, componentIndex, componentWidth, delta, uppercase) => {
|
|
5935
|
+
const start = componentIndex * componentWidth;
|
|
5936
|
+
const value = Number.parseInt(digits.slice(start, start + componentWidth), 16);
|
|
5937
|
+
const maximum = componentWidth === 1 ? 0xf : 0xff;
|
|
5938
|
+
const nextValue = Math.max(0, Math.min(maximum, value + delta));
|
|
5939
|
+
const replacement = nextValue.toString(16).padStart(componentWidth, '0');
|
|
5940
|
+
return `${digits.slice(0, start)}${uppercase ? replacement.toUpperCase() : replacement}${digits.slice(start + componentWidth)}`;
|
|
5941
|
+
};
|
|
5942
|
+
const adjustColor = (value, delta, activeOffset) => {
|
|
5943
|
+
const digits = value.slice(1);
|
|
5944
|
+
const componentWidth = digits.length <= 4 ? 1 : 2;
|
|
5945
|
+
const componentCount = digits.length / componentWidth;
|
|
5946
|
+
const uppercase = /[A-F]/.test(digits) && !/[a-f]/.test(digits);
|
|
5947
|
+
if (activeOffset !== undefined && activeOffset > 0) {
|
|
5948
|
+
const digitOffset = Math.min(activeOffset - 1, digits.length - 1);
|
|
5949
|
+
const componentIndex = Math.floor(digitOffset / componentWidth);
|
|
5950
|
+
return `#${adjustColorComponent(digits, componentIndex, componentWidth, delta, uppercase)}`;
|
|
5951
|
+
}
|
|
5952
|
+
let adjusted = digits;
|
|
5953
|
+
for (let componentIndex = 0; componentIndex < Math.min(componentCount, 3); componentIndex++) {
|
|
5954
|
+
adjusted = adjustColorComponent(adjusted, componentIndex, componentWidth, delta, uppercase);
|
|
5955
|
+
}
|
|
5956
|
+
return `#${adjusted}`;
|
|
5957
|
+
};
|
|
5958
|
+
const changeValue = (value, delta, activeOffset = undefined) => {
|
|
5959
|
+
if (isColor(value)) {
|
|
5960
|
+
return adjustColor(value, delta, activeOffset);
|
|
5961
|
+
}
|
|
5962
|
+
if (isNumber(value)) {
|
|
5963
|
+
return adjustNumber(value, delta);
|
|
5964
|
+
}
|
|
5965
|
+
return value;
|
|
5966
|
+
};
|
|
5967
|
+
const findMatchAt = (line, columnIndex, pattern, predicate) => {
|
|
5968
|
+
pattern.lastIndex = 0;
|
|
5969
|
+
for (const match of line.matchAll(pattern)) {
|
|
5970
|
+
const value = match[0];
|
|
5971
|
+
const start = match.index;
|
|
5972
|
+
const end = start + value.length;
|
|
5973
|
+
if (predicate(value) && columnIndex >= start && columnIndex <= end) {
|
|
5974
|
+
return {
|
|
5975
|
+
end,
|
|
5976
|
+
start,
|
|
5977
|
+
value
|
|
5978
|
+
};
|
|
5979
|
+
}
|
|
5980
|
+
}
|
|
5981
|
+
return undefined;
|
|
5982
|
+
};
|
|
5983
|
+
const findValueAt = (line, columnIndex) => {
|
|
5984
|
+
return findMatchAt(line, columnIndex, colorPattern$1, isColor) ?? findMatchAt(line, columnIndex, numberPattern, isNumber);
|
|
5985
|
+
};
|
|
5986
|
+
const getSelectionTarget = (editor, index) => {
|
|
5987
|
+
const selectionStartRow = editor.selections[index];
|
|
5988
|
+
const selectionStartColumn = editor.selections[index + 1];
|
|
5989
|
+
const selectionEndRow = editor.selections[index + 2];
|
|
5990
|
+
if (selectionStartRow !== selectionEndRow) {
|
|
5991
|
+
return undefined;
|
|
5992
|
+
}
|
|
5993
|
+
const selectionEndColumn = editor.selections[index + 3];
|
|
5994
|
+
const rowIndex = selectionStartRow;
|
|
5995
|
+
const line = editor.lines[rowIndex];
|
|
5996
|
+
const start = Math.min(selectionStartColumn, selectionEndColumn);
|
|
5997
|
+
const end = Math.max(selectionStartColumn, selectionEndColumn);
|
|
5998
|
+
if (start !== end) {
|
|
5999
|
+
const value = line.slice(start, end);
|
|
6000
|
+
if (!isColor(value) && !isNumber(value)) {
|
|
6001
|
+
return undefined;
|
|
6002
|
+
}
|
|
6003
|
+
return {
|
|
6004
|
+
activeOffset: undefined,
|
|
6005
|
+
end,
|
|
6006
|
+
index,
|
|
6007
|
+
rowIndex,
|
|
6008
|
+
selectionEnd: selectionEndColumn,
|
|
6009
|
+
selectionStart: selectionStartColumn,
|
|
6010
|
+
start,
|
|
6011
|
+
value
|
|
6012
|
+
};
|
|
6013
|
+
}
|
|
6014
|
+
const range = findValueAt(line, selectionEndColumn);
|
|
6015
|
+
if (!range) {
|
|
6016
|
+
return undefined;
|
|
6017
|
+
}
|
|
6018
|
+
return {
|
|
6019
|
+
...range,
|
|
6020
|
+
activeOffset: selectionEndColumn - range.start,
|
|
6021
|
+
index,
|
|
6022
|
+
rowIndex,
|
|
6023
|
+
selectionEnd: selectionEndColumn,
|
|
6024
|
+
selectionStart: selectionStartColumn
|
|
6025
|
+
};
|
|
6026
|
+
};
|
|
6027
|
+
const getTargets = editor => {
|
|
6028
|
+
const targets = [];
|
|
6029
|
+
for (let index = 0; index < editor.selections.length; index += 4) {
|
|
6030
|
+
const target = getSelectionTarget(editor, index);
|
|
6031
|
+
if (target) {
|
|
6032
|
+
targets.push(target);
|
|
6033
|
+
}
|
|
6034
|
+
}
|
|
6035
|
+
return targets;
|
|
6036
|
+
};
|
|
6037
|
+
const getUniqueTargets = targets => {
|
|
6038
|
+
const seen = new Set();
|
|
6039
|
+
return targets.filter(target => {
|
|
6040
|
+
const key = `${target.rowIndex}:${target.start}:${target.end}`;
|
|
6041
|
+
if (seen.has(key)) {
|
|
6042
|
+
return false;
|
|
6043
|
+
}
|
|
6044
|
+
seen.add(key);
|
|
6045
|
+
return true;
|
|
6046
|
+
}).toSorted((a, b) => a.rowIndex - b.rowIndex || a.start - b.start);
|
|
6047
|
+
};
|
|
6048
|
+
const getColumnDeltaBefore = (targets, replacements, rowIndex, column) => {
|
|
6049
|
+
let delta = 0;
|
|
6050
|
+
for (const target of targets) {
|
|
6051
|
+
if (target.rowIndex !== rowIndex || target.end > column) {
|
|
6052
|
+
continue;
|
|
6053
|
+
}
|
|
6054
|
+
delta += replacements.get(target).length - target.value.length;
|
|
6055
|
+
}
|
|
6056
|
+
return delta;
|
|
6057
|
+
};
|
|
6058
|
+
const mapColumn = (targets, replacements, rowIndex, column) => {
|
|
6059
|
+
for (const target of targets) {
|
|
6060
|
+
if (target.rowIndex === rowIndex && column > target.start && column < target.end) {
|
|
6061
|
+
const replacement = replacements.get(target);
|
|
6062
|
+
return target.start + getColumnDeltaBefore(targets, replacements, rowIndex, target.start) + Math.min(column - target.start, replacement.length);
|
|
6063
|
+
}
|
|
6064
|
+
}
|
|
6065
|
+
return column + getColumnDeltaBefore(targets, replacements, rowIndex, column);
|
|
6066
|
+
};
|
|
6067
|
+
const getNewSelections$b = (editor, targets, uniqueTargets, replacements) => {
|
|
6068
|
+
const newSelections = new Uint32Array(editor.selections);
|
|
6069
|
+
const targetByIndex = new Map(targets.map(target => [target.index, target]));
|
|
6070
|
+
for (let index = 0; index < editor.selections.length; index += 4) {
|
|
6071
|
+
const startRow = editor.selections[index];
|
|
6072
|
+
const startColumn = editor.selections[index + 1];
|
|
6073
|
+
const endRow = editor.selections[index + 2];
|
|
6074
|
+
const endColumn = editor.selections[index + 3];
|
|
6075
|
+
const target = targetByIndex.get(index);
|
|
6076
|
+
if (!target) {
|
|
6077
|
+
newSelections[index + 1] = mapColumn(uniqueTargets, replacements, startRow, startColumn);
|
|
6078
|
+
newSelections[index + 3] = mapColumn(uniqueTargets, replacements, endRow, endColumn);
|
|
6079
|
+
continue;
|
|
6080
|
+
}
|
|
6081
|
+
const matchingTarget = uniqueTargets.find(candidate => candidate.rowIndex === target.rowIndex && candidate.start === target.start && candidate.end === target.end);
|
|
6082
|
+
const replacement = replacements.get(matchingTarget);
|
|
6083
|
+
const newStart = target.start + getColumnDeltaBefore(uniqueTargets, replacements, target.rowIndex, target.start);
|
|
6084
|
+
const newEnd = newStart + replacement.length;
|
|
6085
|
+
if (target.selectionStart === target.selectionEnd) {
|
|
6086
|
+
const originalOffset = target.selectionEnd - target.start;
|
|
6087
|
+
const newOffset = originalOffset === target.value.length ? replacement.length : Math.min(originalOffset, replacement.length);
|
|
6088
|
+
newSelections[index + 1] = newStart + newOffset;
|
|
6089
|
+
newSelections[index + 3] = newStart + newOffset;
|
|
6090
|
+
} else if (target.selectionStart < target.selectionEnd) {
|
|
6091
|
+
newSelections[index + 1] = newStart;
|
|
6092
|
+
newSelections[index + 3] = newEnd;
|
|
6093
|
+
} else {
|
|
6094
|
+
newSelections[index + 1] = newEnd;
|
|
6095
|
+
newSelections[index + 3] = newStart;
|
|
6096
|
+
}
|
|
6097
|
+
}
|
|
6098
|
+
return newSelections;
|
|
6099
|
+
};
|
|
6100
|
+
const changeSelectedValue = async (editor, delta) => {
|
|
6101
|
+
const targets = getTargets(editor);
|
|
6102
|
+
const uniqueTargets = getUniqueTargets(targets);
|
|
6103
|
+
if (uniqueTargets.length === 0) {
|
|
6104
|
+
return editor;
|
|
6105
|
+
}
|
|
6106
|
+
const replacements = new Map(uniqueTargets.map(target => [target, changeValue(target.value, delta, targets.find(candidate => candidate === target)?.activeOffset)]));
|
|
6107
|
+
const changedTargets = uniqueTargets.filter(target => replacements.get(target) !== target.value);
|
|
6108
|
+
if (changedTargets.length === 0) {
|
|
6109
|
+
return editor;
|
|
6110
|
+
}
|
|
6111
|
+
const changedTargetKeys = new Set(changedTargets.map(target => `${target.rowIndex}:${target.start}:${target.end}`));
|
|
6112
|
+
const selectionTargetsWithChanges = targets.filter(target => changedTargetKeys.has(`${target.rowIndex}:${target.start}:${target.end}`));
|
|
6113
|
+
const changes = [];
|
|
6114
|
+
const rowDeltas = new Map();
|
|
6115
|
+
for (const target of changedTargets) {
|
|
6116
|
+
const columnDelta = rowDeltas.get(target.rowIndex) ?? 0;
|
|
6117
|
+
const startColumn = target.start + columnDelta;
|
|
6118
|
+
const endColumn = target.end + columnDelta;
|
|
6119
|
+
const replacement = replacements.get(target);
|
|
6120
|
+
changes.push({
|
|
6121
|
+
deleted: [target.value],
|
|
6122
|
+
end: {
|
|
6123
|
+
columnIndex: endColumn,
|
|
6124
|
+
rowIndex: target.rowIndex
|
|
6125
|
+
},
|
|
6126
|
+
inserted: [replacement],
|
|
6127
|
+
origin: 'changeSelectedValue',
|
|
6128
|
+
start: {
|
|
6129
|
+
columnIndex: startColumn,
|
|
6130
|
+
rowIndex: target.rowIndex
|
|
6131
|
+
}
|
|
6132
|
+
});
|
|
6133
|
+
rowDeltas.set(target.rowIndex, columnDelta + replacement.length - target.value.length);
|
|
6134
|
+
}
|
|
6135
|
+
const newSelections = getNewSelections$b(editor, selectionTargetsWithChanges, changedTargets, replacements);
|
|
6136
|
+
return scheduleDocumentAndCursorsSelections(editor, changes, newSelections);
|
|
6137
|
+
};
|
|
6138
|
+
|
|
6139
|
+
const decrementSelection = editor => {
|
|
6140
|
+
return changeSelectedValue(editor, -1);
|
|
6141
|
+
};
|
|
6142
|
+
const incrementSelection = editor => {
|
|
6143
|
+
return changeSelectedValue(editor, 1);
|
|
6144
|
+
};
|
|
6145
|
+
|
|
5900
6146
|
const isMatchingWidget$2 = widget => {
|
|
5901
6147
|
return widget.id === CodeGenerator;
|
|
5902
6148
|
};
|
|
@@ -11921,6 +12167,14 @@ const getKeyBindings = () => {
|
|
|
11921
12167
|
command: 'Editor.cursorDocumentStart',
|
|
11922
12168
|
key: CtrlCmd | Home,
|
|
11923
12169
|
when: FocusEditorText
|
|
12170
|
+
}, {
|
|
12171
|
+
command: 'Editor.incrementSelection',
|
|
12172
|
+
key: CtrlCmd | Alt$1 | KeyI,
|
|
12173
|
+
when: FocusEditorText
|
|
12174
|
+
}, {
|
|
12175
|
+
command: 'Editor.decrementSelection',
|
|
12176
|
+
key: CtrlCmd | Alt$1 | KeyD,
|
|
12177
|
+
when: FocusEditorText
|
|
11924
12178
|
}, {
|
|
11925
12179
|
command: 'Editor.deleteWordPartLeft',
|
|
11926
12180
|
key: Alt$1 | Backspace,
|
|
@@ -14265,6 +14519,7 @@ const commandMap = {
|
|
|
14265
14519
|
'Editor.cursorWordPartRight': wrapCommand(cursorWordPartRight),
|
|
14266
14520
|
'Editor.cursorWordRight': wrapCommand(cursorWordRight),
|
|
14267
14521
|
'Editor.cut': wrapCommand(cut$1),
|
|
14522
|
+
'Editor.decrementSelection': wrapCommand(decrementSelection),
|
|
14268
14523
|
'Editor.deleteAll': wrapCommand(deleteAll),
|
|
14269
14524
|
'Editor.deleteAllLeft': wrapCommand(deleteAllLeft),
|
|
14270
14525
|
'Editor.deleteAllRight': wrapCommand(deleteAllRight),
|
|
@@ -14344,6 +14599,7 @@ const commandMap = {
|
|
|
14344
14599
|
'Editor.handleUriChange': wrapCommand(handleUriChange),
|
|
14345
14600
|
'Editor.handleWheel': wrapCommand(handleWheel$2),
|
|
14346
14601
|
'Editor.hotReload': hotReload,
|
|
14602
|
+
'Editor.incrementSelection': wrapCommand(incrementSelection),
|
|
14347
14603
|
'Editor.indendLess': wrapCommand(indentLess),
|
|
14348
14604
|
'Editor.indentMore': wrapCommand(indentMore),
|
|
14349
14605
|
'Editor.insertLineBreak': wrapCommand(insertLineBreak),
|