@lvce-editor/editor-worker 19.63.1 → 19.65.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.
@@ -5,7 +5,7 @@ const noColorRange = {
5
5
  startOffset: -1,
6
6
  value: ''
7
7
  };
8
- const colorPattern = /#[\da-f]{3,8}\b|\b(?:hsla?|rgba?)\([^)]*\)/gi;
8
+ const colorPattern = /#[\da-f]{3,8}\b|(?<![\w$])0x[\da-f]{6}(?![\w$])|\b(?:hsla?|rgba?)\([^)]*\)/gi;
9
9
  const getColorPickerRange = async editor => {
10
10
  const {
11
11
  lines,
@@ -1762,6 +1762,25 @@ const codeGeneratorAccept = state => {
1762
1762
  return state;
1763
1763
  };
1764
1764
 
1765
+ const javascriptHexColorPattern = /^0x([\da-f]{6})$/i;
1766
+ const toColorPickerValue = value => {
1767
+ const match = javascriptHexColorPattern.exec(value);
1768
+ if (!match) {
1769
+ return value;
1770
+ }
1771
+ return `#${match[1]}`;
1772
+ };
1773
+ const toEditorValue = (value, originalValue) => {
1774
+ if (!javascriptHexColorPattern.test(originalValue)) {
1775
+ return value;
1776
+ }
1777
+ const match = /^#([\da-f]{6})$/i.exec(value);
1778
+ if (!match) {
1779
+ return value;
1780
+ }
1781
+ return `0x${match[1]}`;
1782
+ };
1783
+
1765
1784
  const editorStates = create$9();
1766
1785
  const {
1767
1786
  dispose: dispose$5,
@@ -4513,21 +4532,23 @@ const updateColorPickerValue$1 = async (editor, value) => {
4513
4532
  const {
4514
4533
  endOffset,
4515
4534
  startOffset,
4516
- undoStackIndex
4535
+ undoStackIndex,
4536
+ value: originalValue
4517
4537
  } = widget.newState;
4518
4538
  if (startOffset < 0 || endOffset < startOffset) {
4519
4539
  return editor;
4520
4540
  }
4541
+ const editorValue = toEditorValue(value, originalValue);
4521
4542
  const edits = getDocumentEdits(editor, [{
4522
4543
  endOffset,
4523
- inserted: value,
4544
+ inserted: editorValue,
4524
4545
  startOffset
4525
4546
  }]).map(edit => ({
4526
4547
  ...edit,
4527
4548
  origin: ColorPicker$1
4528
4549
  }));
4529
4550
  const updatedEditor = await scheduleDocumentAndCursorsSelections(editor, edits);
4530
- const newEndOffset = startOffset + value.length;
4551
+ const newEndOffset = startOffset + editorValue.length;
4531
4552
  const widgets = updatedEditor.widgets.map(candidate => {
4532
4553
  if (candidate.id !== ColorPicker$2) {
4533
4554
  return candidate;
@@ -4885,6 +4906,46 @@ const findBracketPair = (lines, rowIndex, columnIndex) => {
4885
4906
  };
4886
4907
 
4887
4908
  const getPositionKey = position => `${position.rowIndex}:${position.columnIndex}`;
4909
+ const bracketMatchCache = new WeakMap();
4910
+ const selectionsEqual$1 = (left, right) => {
4911
+ if (left.length !== right.length) {
4912
+ return false;
4913
+ }
4914
+ for (let i = 0; i < left.length; i++) {
4915
+ if (left[i] !== right[i]) {
4916
+ return false;
4917
+ }
4918
+ }
4919
+ return true;
4920
+ };
4921
+ const findBracketMatchPositions = (lines, selections) => {
4922
+ const cached = bracketMatchCache.get(lines);
4923
+ if (cached && selectionsEqual$1(cached.selections, selections)) {
4924
+ return cached.positions;
4925
+ }
4926
+ const positions = new Map();
4927
+ for (let i = 0; i < selections.length; i += 4) {
4928
+ const startRowIndex = selections[i];
4929
+ const startColumnIndex = selections[i + 1];
4930
+ const endRowIndex = selections[i + 2];
4931
+ const endColumnIndex = selections[i + 3];
4932
+ if (startRowIndex !== endRowIndex || startColumnIndex !== endColumnIndex) {
4933
+ continue;
4934
+ }
4935
+ const pair = findMatchingBracket(lines, endRowIndex, endColumnIndex);
4936
+ if (!pair) {
4937
+ continue;
4938
+ }
4939
+ positions.set(getPositionKey(pair.source), pair.source);
4940
+ positions.set(getPositionKey(pair.match), pair.match);
4941
+ }
4942
+ const entry = {
4943
+ positions: positions.values().toArray(),
4944
+ selections: new Uint32Array(selections)
4945
+ };
4946
+ bracketMatchCache.set(lines, entry);
4947
+ return entry.positions;
4948
+ };
4888
4949
  const getInfo = async (editor, position, visibleLineIndices, startVisualRow) => {
4889
4950
  if (!visibleLineIndices.includes(position.rowIndex)) {
4890
4951
  return undefined;
@@ -4932,23 +4993,8 @@ const getVisibleBracketMatches = async editor => {
4932
4993
  length: maxLineY - minLineY
4933
4994
  }, (_, index) => minLineY + index);
4934
4995
  const startVisualRow = itemHeight ? Math.floor(deltaY / itemHeight) : viewLineIndices ? getVisualRowForDocumentRow$1(minLineY, viewLineIndices) : getVisualRowForDocumentRow(minLineY, foldingRanges);
4935
- const positions = new Map();
4936
- for (let i = 0; i < selections.length; i += 4) {
4937
- const startRowIndex = selections[i];
4938
- const startColumnIndex = selections[i + 1];
4939
- const endRowIndex = selections[i + 2];
4940
- const endColumnIndex = selections[i + 3];
4941
- if (startRowIndex !== endRowIndex || startColumnIndex !== endColumnIndex) {
4942
- continue;
4943
- }
4944
- const pair = findMatchingBracket(lines, endRowIndex, endColumnIndex);
4945
- if (!pair) {
4946
- continue;
4947
- }
4948
- positions.set(getPositionKey(pair.source), pair.source);
4949
- positions.set(getPositionKey(pair.match), pair.match);
4950
- }
4951
- const infos = await Promise.all(Array.from(positions.values(), position => getInfo(editor, position, actualVisibleLineIndices, startVisualRow)));
4996
+ const positions = findBracketMatchPositions(lines, selections);
4997
+ const infos = await Promise.all(positions.map(position => getInfo(editor, position, actualVisibleLineIndices, startVisualRow)));
4952
4998
  return infos.filter(info => info !== undefined);
4953
4999
  };
4954
5000
 
@@ -5174,7 +5220,7 @@ const loadContent$3 = async (state, parentUid) => {
5174
5220
  y
5175
5221
  } = state;
5176
5222
  await invoke$7('ColorPicker.create', uid, x, y, width, height, parentUid);
5177
- await invoke$7('ColorPicker.loadContent', uid, value);
5223
+ await invoke$7('ColorPicker.loadContent', uid, toColorPickerValue(value));
5178
5224
  const diff = await invoke$7('ColorPicker.diff2', uid);
5179
5225
  const commands = await invoke$7('ColorPicker.render2', uid, diff);
5180
5226
  return {
@@ -7383,7 +7429,7 @@ const openColorPicker = async editor => {
7383
7429
  const bounds = getColorPickerBounds(editor);
7384
7430
  const {
7385
7431
  getColorPickerRange
7386
- } = await import('./GetColorPickerRange-B84IlfRJ.js');
7432
+ } = await import('./GetColorPickerRange-CsGZK202.js');
7387
7433
  const range = await getColorPickerRange(editor);
7388
7434
  const createWidget = () => create$6(bounds, range, editor.undoStack.length);
7389
7435
  return addWidgetToEditor(ColorPicker$2, ColorPicker, editor, createWidget, newStateGenerator$5, fullFocus);
@@ -10690,6 +10736,9 @@ const getLines = editorUid => {
10690
10736
  const getSelections$1 = editorUid => {
10691
10737
  return getEditor$1(editorUid).selections;
10692
10738
  };
10739
+ const getFindWidgetFontSize = async () => {
10740
+ return get$3('editor.findWidgetFontSize');
10741
+ };
10693
10742
  const setSelections$1 = async (editorUid, selections) => {
10694
10743
  const editor = getEditor$1(editorUid);
10695
10744
  const newEditor = setSelections$2(editor, selections);
@@ -10699,6 +10748,7 @@ const setSelections$1 = async (editorUid, selections) => {
10699
10748
  const getFindWidgetWorkerCommandMap = () => ({
10700
10749
  'Editor.applyDocumentEdits': applyDocumentEdits,
10701
10750
  'Editor.closeFind2': closeFind,
10751
+ 'Editor.getFindWidgetFontSize': getFindWidgetFontSize,
10702
10752
  'Editor.getLines2': getLines,
10703
10753
  'Editor.getSelections2': getSelections$1,
10704
10754
  'Editor.setSelections2': setSelections$1
@@ -10961,6 +11011,7 @@ const {
10961
11011
  handleInput: handleInput$1,
10962
11012
  handleReplaceFocus,
10963
11013
  handleReplaceInput,
11014
+ handleSettingsChanged: handleSettingsChanged$1,
10964
11015
  handleToggleReplaceFocus,
10965
11016
  replace,
10966
11017
  replaceAll,
@@ -10970,7 +11021,7 @@ const {
10970
11021
  togglePreserveCase,
10971
11022
  toggleReplace,
10972
11023
  toggleUseRegularExpression
10973
- } = createFns(['close', 'focusCloseButton', 'focusFind', 'focusNext', 'focusNextMatchButton', 'focusPrevious', 'focusPreviousMatchButton', 'focusReplace', 'focusReplaceAllButton', 'focusReplaceButton', 'focusToggleReplace', 'handleBlur', 'handleClickButton', 'handleFocus', 'handleInput', 'handleReplaceFocus', 'handleReplaceInput', 'handleToggleReplaceFocus', 'replace', 'replaceAll', 'resize', 'toggleMatchCase', 'toggleMatchWholeWord', 'toggleReplace', 'toggleUseRegularExpression', 'focusNextElement', 'focusPreviousElement', 'togglePreserveCase'], 'FindWidget', Find);
11024
+ } = createFns(['close', 'focusCloseButton', 'focusFind', 'focusNext', 'focusNextMatchButton', 'focusPrevious', 'focusPreviousMatchButton', 'focusReplace', 'focusReplaceAllButton', 'focusReplaceButton', 'focusToggleReplace', 'handleBlur', 'handleClickButton', 'handleFocus', 'handleInput', 'handleReplaceFocus', 'handleReplaceInput', 'handleSettingsChanged', 'handleToggleReplaceFocus', 'replace', 'replaceAll', 'resize', 'toggleMatchCase', 'toggleMatchWholeWord', 'toggleReplace', 'toggleUseRegularExpression', 'focusNextElement', 'focusPreviousElement', 'togglePreserveCase'], 'FindWidget', Find);
10974
11025
 
10975
11026
  const EditorFindWidget = {
10976
11027
  __proto__: null,
@@ -10995,6 +11046,7 @@ const EditorFindWidget = {
10995
11046
  handleInput: handleInput$1,
10996
11047
  handleReplaceFocus,
10997
11048
  handleReplaceInput,
11049
+ handleSettingsChanged: handleSettingsChanged$1,
10998
11050
  handleToggleReplaceFocus,
10999
11051
  remove: remove$7,
11000
11052
  render: render$c,
@@ -14558,6 +14610,22 @@ const getWorkspaceUri$1 = async applicationId => {
14558
14610
  return '';
14559
14611
  }
14560
14612
  };
14613
+ const updateFindWidget = async state => {
14614
+ const widget = (state.widgets || []).find(widget => widget.id === Find);
14615
+ if (!widget) {
14616
+ return state;
14617
+ }
14618
+ const {
14619
+ uid
14620
+ } = widget.newState;
14621
+ await invoke$4('FindWidget.handleSettingsChanged', uid);
14622
+ const diff = await invoke$4('FindWidget.diff2', uid);
14623
+ const commands = await invoke$4('FindWidget.render2', uid, diff);
14624
+ return updateWidget(state, Find, {
14625
+ ...widget.newState,
14626
+ commands
14627
+ });
14628
+ };
14561
14629
  const handleSettingsChanged = async state => {
14562
14630
  const editorPreferences = {
14563
14631
  ...(await getEditorPreferences()),
@@ -14602,9 +14670,10 @@ const handleSettingsChanged = async state => {
14602
14670
  documentSymbols,
14603
14671
  workspaceUri
14604
14672
  }, {}, charWidth);
14673
+ const editorWithUpdatedFindWidget = await updateFindWidget(resizedEditor);
14605
14674
  return {
14606
- ...resizedEditor,
14607
- gutterDecorations: await getEditorGutterDecorations(resizedEditor)
14675
+ ...editorWithUpdatedFindWidget,
14676
+ gutterDecorations: await getEditorGutterDecorations(editorWithUpdatedFindWidget)
14608
14677
  };
14609
14678
  };
14610
14679
 
@@ -14823,6 +14892,7 @@ const intialize = async (syntaxHighlightingEnabled, syncIncremental) => {
14823
14892
  await initializeSyntaxHighlighting(syntaxHighlightingEnabled, syncIncremental);
14824
14893
  };
14825
14894
 
14895
+ const largeFileContentLength = 10 * 1024 * 1024;
14826
14896
  const getWorkspaceUri = async applicationId => {
14827
14897
  try {
14828
14898
  return await invoke$9(applicationId, 'Workspace.getPath');
@@ -14966,7 +15036,7 @@ const loadContent = async (state, savedState, largeFile = false) => {
14966
15036
  };
14967
15037
  }
14968
15038
  const savedLargeFile = !!savedState && typeof savedState === 'object' && savedState.largeFile === true;
14969
- largeFile ||= state.largeFile === true || existingEditor?.largeFile === true || savedLargeFile || content.length > 50 * 1024 * 1024;
15039
+ largeFile ||= state.largeFile === true || existingEditor?.largeFile === true || savedLargeFile || content.length > largeFileContentLength;
14970
15040
  const effectiveEditor = {
14971
15041
  ...newEditor0,
14972
15042
  largeFile,
@@ -25,6 +25,16 @@
25
25
  "type": "string",
26
26
  "value": "Fira Code"
27
27
  },
28
+ {
29
+ "category": "text-editor",
30
+ "description": "The font size of the find widget",
31
+ "heading": "Find Widget Font Size",
32
+ "id": "editor.findWidgetFontSize",
33
+ "type": "number",
34
+ "value": 0,
35
+ "minimum": 0,
36
+ "maximum": 100
37
+ },
28
38
  {
29
39
  "category": "text-editor",
30
40
  "description": "Format a file when it is saved",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "19.63.1",
3
+ "version": "19.65.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"