@lvce-editor/editor-worker 5.3.0 → 5.5.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 +51 -43
- package/package.json +1 -1
package/dist/editorWorkerMain.js
CHANGED
|
@@ -147,9 +147,10 @@ const Format = 'format';
|
|
|
147
147
|
const IndentLess = 'indentLess';
|
|
148
148
|
const IndentMore = 'indentMore';
|
|
149
149
|
const InsertLineBreak = 'insertLineBreak';
|
|
150
|
+
const LineComment = 'lineComment';
|
|
151
|
+
const Rename$1 = 'rename';
|
|
150
152
|
const ReplaceAll$2 = 'replaceAll';
|
|
151
153
|
const ToggleBlockComment = 'toggleBlockComment';
|
|
152
|
-
const Rename$1 = 'rename';
|
|
153
154
|
|
|
154
155
|
const map$1 = Object.create(null);
|
|
155
156
|
const set$7 = (id, widget) => {
|
|
@@ -483,6 +484,10 @@ const getTabCount = string => {
|
|
|
483
484
|
return count;
|
|
484
485
|
};
|
|
485
486
|
|
|
487
|
+
const measureTextWidthFast = (text, charWidth) => {
|
|
488
|
+
return text.length * charWidth;
|
|
489
|
+
};
|
|
490
|
+
|
|
486
491
|
const getFontString = (fontWeight, fontSize, fontFamily) => {
|
|
487
492
|
return `${fontWeight} ${fontSize}px ${fontFamily}`;
|
|
488
493
|
};
|
|
@@ -516,16 +521,15 @@ const getContext = () => {
|
|
|
516
521
|
return ctx;
|
|
517
522
|
};
|
|
518
523
|
|
|
519
|
-
|
|
524
|
+
// TODO for text editor, could dispose measuring canvas after editor has been initialized to free up offscreencanvas space
|
|
525
|
+
|
|
526
|
+
const measureTextWidthSlow = (text, fontWeight, fontSize, fontFamily, letterSpacing, isMonoSpaceFont, charWidth) => {
|
|
520
527
|
string(text);
|
|
521
528
|
number$1(fontWeight);
|
|
522
529
|
number$1(fontSize);
|
|
523
530
|
string(fontFamily);
|
|
524
531
|
boolean(isMonoSpaceFont);
|
|
525
532
|
number$1(charWidth);
|
|
526
|
-
if (isMonoSpaceFont) {
|
|
527
|
-
return text.length * charWidth;
|
|
528
|
-
}
|
|
529
533
|
if (typeof letterSpacing !== 'number') {
|
|
530
534
|
throw new TypeError('letterSpacing must be of type number');
|
|
531
535
|
}
|
|
@@ -539,6 +543,13 @@ const measureTextWidth = (text, fontWeight, fontSize, fontFamily, letterSpacing,
|
|
|
539
543
|
return width;
|
|
540
544
|
};
|
|
541
545
|
|
|
546
|
+
const measureTextWidth = (text, fontWeight, fontSize, fontFamily, letterSpacing, isMonoSpaceFont, charWidth) => {
|
|
547
|
+
if (isMonoSpaceFont) {
|
|
548
|
+
return measureTextWidthFast(text, charWidth);
|
|
549
|
+
}
|
|
550
|
+
return measureTextWidthSlow(text, fontWeight, fontSize, fontFamily, letterSpacing, isMonoSpaceFont, charWidth);
|
|
551
|
+
};
|
|
552
|
+
|
|
542
553
|
const normalizeText = (text, normalize, tabSize) => {
|
|
543
554
|
if (normalize) {
|
|
544
555
|
return text.replaceAll(Tab, Space$1.repeat(tabSize));
|
|
@@ -1833,21 +1844,21 @@ const getVisibleDiagnostics = (editor, diagnostics) => {
|
|
|
1833
1844
|
return visibleDiagnostics;
|
|
1834
1845
|
};
|
|
1835
1846
|
|
|
1836
|
-
const updateDiagnostics = async
|
|
1847
|
+
const updateDiagnostics = async newState => {
|
|
1837
1848
|
try {
|
|
1838
1849
|
// TODO handle error
|
|
1839
1850
|
// TODO handle race condition
|
|
1840
|
-
const {
|
|
1841
|
-
newState
|
|
1842
|
-
} = get$6(uid);
|
|
1843
1851
|
|
|
1844
1852
|
// TODO sync textdocument incrementally
|
|
1845
1853
|
// TODO sync and ask for diagnostics at the same time?
|
|
1846
1854
|
// TODO throttle diagnostics
|
|
1847
1855
|
const content = getText$1(newState);
|
|
1856
|
+
|
|
1857
|
+
// TODO don't really need text document sync response
|
|
1858
|
+
// could perhaps save a lot of messages by using send instead of invoke
|
|
1848
1859
|
await invoke$2(TextDocumentSyncFull, newState.uri, newState.id, newState.languageId, content);
|
|
1849
1860
|
const diagnostics = await executeDiagnosticProvider(newState);
|
|
1850
|
-
const latest = get$6(
|
|
1861
|
+
const latest = get$6(newState.id);
|
|
1851
1862
|
if (!latest) {
|
|
1852
1863
|
return;
|
|
1853
1864
|
}
|
|
@@ -1857,8 +1868,8 @@ const updateDiagnostics = async uid => {
|
|
|
1857
1868
|
diagnostics,
|
|
1858
1869
|
decorations
|
|
1859
1870
|
};
|
|
1860
|
-
set$6(
|
|
1861
|
-
await invoke$3('Editor.rerender',
|
|
1871
|
+
set$6(newState.id, latest.oldState, newEditor);
|
|
1872
|
+
await invoke$3('Editor.rerender', newState.id);
|
|
1862
1873
|
} catch (error) {
|
|
1863
1874
|
// @ts-ignore
|
|
1864
1875
|
if (error && error.message.includes('No diagnostic provider found')) {
|
|
@@ -1993,7 +2004,7 @@ const createEditor = async ({
|
|
|
1993
2004
|
set$6(id, emptyEditor, newEditor4);
|
|
1994
2005
|
await invoke$2(TextDocumentSyncFull, uri, id, languageId, content);
|
|
1995
2006
|
if (diagnosticsEnabled) {
|
|
1996
|
-
updateDiagnostics(
|
|
2007
|
+
updateDiagnostics(newEditor4);
|
|
1997
2008
|
}
|
|
1998
2009
|
};
|
|
1999
2010
|
|
|
@@ -7161,14 +7172,11 @@ const getBlockComment = async editor => {
|
|
|
7161
7172
|
|
|
7162
7173
|
const RE_WHITESPACE_AT_START$1 = /^\s+/;
|
|
7163
7174
|
const RE_WHITESPACE_AT_END = /\s+$/;
|
|
7164
|
-
|
|
7165
|
-
|
|
7166
|
-
|
|
7167
|
-
|
|
7168
|
-
|
|
7169
|
-
return editor;
|
|
7170
|
-
}
|
|
7171
|
-
const rowIndex = editor.selections[0];
|
|
7175
|
+
const getBlockCommentEdits = (editor, blockComment) => {
|
|
7176
|
+
const {
|
|
7177
|
+
selections
|
|
7178
|
+
} = editor;
|
|
7179
|
+
const [rowIndex] = selections;
|
|
7172
7180
|
const line = getLine(editor, rowIndex);
|
|
7173
7181
|
const numberOfLines = editor.lines.length;
|
|
7174
7182
|
let endRowIndex = rowIndex;
|
|
@@ -7222,18 +7230,7 @@ const toggleBlockComment = async editor => {
|
|
|
7222
7230
|
deleted: [blockCommentEnd],
|
|
7223
7231
|
origin: ToggleBlockComment
|
|
7224
7232
|
};
|
|
7225
|
-
// @ts-ignore
|
|
7226
7233
|
changes.push(change1, change2);
|
|
7227
|
-
// Editor.moveCursors(editor, (editor, cursor) => {
|
|
7228
|
-
// let newColumnIndex = cursor.columnIndex - blockComment[0].length
|
|
7229
|
-
// if (cursor.columnIndex === endColumnIndex + blockComment[1].length) {
|
|
7230
|
-
// newColumnIndex -= blockComment[1].length
|
|
7231
|
-
// }
|
|
7232
|
-
// return {
|
|
7233
|
-
// rowIndex: cursor.rowIndex,
|
|
7234
|
-
// columnIndex: newColumnIndex,
|
|
7235
|
-
// }
|
|
7236
|
-
// })
|
|
7237
7234
|
} else {
|
|
7238
7235
|
const change1 = {
|
|
7239
7236
|
start: {
|
|
@@ -7356,7 +7353,16 @@ const toggleBlockComment = async editor => {
|
|
|
7356
7353
|
// }
|
|
7357
7354
|
// RendererProcess.invoke(/* setLines */ 2135, /* lines */ lines)
|
|
7358
7355
|
|
|
7359
|
-
return
|
|
7356
|
+
return changes;
|
|
7357
|
+
};
|
|
7358
|
+
|
|
7359
|
+
const toggleBlockComment = async editor => {
|
|
7360
|
+
const blockComment = await getBlockComment(editor);
|
|
7361
|
+
if (!blockComment) {
|
|
7362
|
+
return editor;
|
|
7363
|
+
}
|
|
7364
|
+
const edits = getBlockCommentEdits(editor, blockComment);
|
|
7365
|
+
return scheduleDocument(editor, edits);
|
|
7360
7366
|
};
|
|
7361
7367
|
|
|
7362
7368
|
const getLineComment = async editor => {
|
|
@@ -7376,7 +7382,7 @@ const getLineCommentEdit = (rowIndex, line, lineComment) => {
|
|
|
7376
7382
|
if (line[index + lineComment.length] === ' ') {
|
|
7377
7383
|
return {
|
|
7378
7384
|
inserted: [''],
|
|
7379
|
-
deleted: [lineComment
|
|
7385
|
+
deleted: [lineComment + ' '],
|
|
7380
7386
|
start: {
|
|
7381
7387
|
rowIndex,
|
|
7382
7388
|
columnIndex: index
|
|
@@ -7385,7 +7391,7 @@ const getLineCommentEdit = (rowIndex, line, lineComment) => {
|
|
|
7385
7391
|
rowIndex,
|
|
7386
7392
|
columnIndex: index + lineComment.length + 1
|
|
7387
7393
|
},
|
|
7388
|
-
|
|
7394
|
+
origin: LineComment
|
|
7389
7395
|
};
|
|
7390
7396
|
}
|
|
7391
7397
|
return {
|
|
@@ -7399,7 +7405,7 @@ const getLineCommentEdit = (rowIndex, line, lineComment) => {
|
|
|
7399
7405
|
rowIndex,
|
|
7400
7406
|
columnIndex: index + lineComment.length
|
|
7401
7407
|
},
|
|
7402
|
-
|
|
7408
|
+
origin: LineComment
|
|
7403
7409
|
};
|
|
7404
7410
|
}
|
|
7405
7411
|
return {
|
|
@@ -7413,11 +7419,10 @@ const getLineCommentEdit = (rowIndex, line, lineComment) => {
|
|
|
7413
7419
|
rowIndex,
|
|
7414
7420
|
columnIndex: index
|
|
7415
7421
|
},
|
|
7416
|
-
|
|
7422
|
+
origin: LineComment
|
|
7417
7423
|
};
|
|
7418
7424
|
};
|
|
7419
7425
|
|
|
7420
|
-
// @ts-ignore
|
|
7421
7426
|
const editorToggleLineComment = async editor => {
|
|
7422
7427
|
const lineComment = await getLineComment(editor);
|
|
7423
7428
|
if (!lineComment) {
|
|
@@ -8013,7 +8018,7 @@ const handleSashPointerUp = (state, eventX, eventY) => {
|
|
|
8013
8018
|
return state;
|
|
8014
8019
|
};
|
|
8015
8020
|
|
|
8016
|
-
const CodeGeneratorInput = 'CodeGeneratorInput';
|
|
8021
|
+
const CodeGeneratorInput$1 = 'CodeGeneratorInput';
|
|
8017
8022
|
const CodeGeneratorMessage = 'CodeGeneratorMessage';
|
|
8018
8023
|
const CodeGeneratorWidget = 'CodeGeneratorWidget';
|
|
8019
8024
|
const ColoredMaskIcon = 'ColoredMaskIcon';
|
|
@@ -9363,7 +9368,7 @@ const editorDiagnosticEffect = {
|
|
|
9363
9368
|
},
|
|
9364
9369
|
// TODO set effects delay / diagnostic delay
|
|
9365
9370
|
async apply(editor) {
|
|
9366
|
-
await updateDiagnostics(editor
|
|
9371
|
+
await updateDiagnostics(editor);
|
|
9367
9372
|
}
|
|
9368
9373
|
};
|
|
9369
9374
|
|
|
@@ -10159,6 +10164,9 @@ const removeWidget = widget => {
|
|
|
10159
10164
|
return [['Viewlet.send', widget.newState.uid, 'dispose']];
|
|
10160
10165
|
};
|
|
10161
10166
|
|
|
10167
|
+
const CodeGeneratorInput = 'CodeGeneratorInput';
|
|
10168
|
+
const ToggleReplace$1 = 'ToggleReplace';
|
|
10169
|
+
|
|
10162
10170
|
const getCodeGeneratorVirtualDom = state => {
|
|
10163
10171
|
const escapeToClose$1 = escapeToClose();
|
|
10164
10172
|
const enterCode$1 = enterCode();
|
|
@@ -10168,10 +10176,10 @@ const getCodeGeneratorVirtualDom = state => {
|
|
|
10168
10176
|
childCount: 2
|
|
10169
10177
|
}, {
|
|
10170
10178
|
type: Input,
|
|
10171
|
-
className: mergeClassNames(CodeGeneratorInput, InputBox),
|
|
10179
|
+
className: mergeClassNames(CodeGeneratorInput$1, InputBox),
|
|
10172
10180
|
childCount: 0,
|
|
10173
10181
|
placeholder: enterCode$1,
|
|
10174
|
-
name:
|
|
10182
|
+
name: CodeGeneratorInput
|
|
10175
10183
|
}, {
|
|
10176
10184
|
type: Div,
|
|
10177
10185
|
className: CodeGeneratorMessage,
|
|
@@ -11096,7 +11104,7 @@ const getSearchToggleButtonVirtualDom = (replaceExpanded, onClick = '') => {
|
|
|
11096
11104
|
title: 'Toggle Replace',
|
|
11097
11105
|
ariaLabel: 'Toggle Replace',
|
|
11098
11106
|
ariaExpanded: replaceExpanded,
|
|
11099
|
-
name:
|
|
11107
|
+
name: ToggleReplace$1,
|
|
11100
11108
|
childCount: 1,
|
|
11101
11109
|
'data-command': 'toggleReplace',
|
|
11102
11110
|
onClick,
|