@lvce-editor/editor-worker 19.29.9 → 19.29.11

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.
@@ -7689,35 +7689,35 @@ const tokenizeCodeBlock = async (codeBlock, languageId, tokenizerPath) => {
7689
7689
  return lineInfos;
7690
7690
  };
7691
7691
 
7692
- const getHoverPosition = (position, selections) => {
7693
- if (position) {
7694
- return position;
7692
+ const containsPosition = (diagnostic, rowIndex, columnIndex) => {
7693
+ const {
7694
+ columnIndex: startColumnIndex,
7695
+ endColumnIndex,
7696
+ endRowIndex,
7697
+ rowIndex: startRowIndex
7698
+ } = diagnostic;
7699
+ if (rowIndex < startRowIndex || rowIndex > endRowIndex) {
7700
+ return false;
7695
7701
  }
7696
- const rowIndex = selections[0];
7697
- const columnIndex = selections[1];
7698
- return {
7699
- columnIndex,
7700
- rowIndex
7701
- };
7702
+ if (rowIndex === startRowIndex && columnIndex < startColumnIndex) {
7703
+ return false;
7704
+ }
7705
+ if (rowIndex === endRowIndex && columnIndex >= endColumnIndex) {
7706
+ return false;
7707
+ }
7708
+ return true;
7702
7709
  };
7703
7710
  const getMatchingDiagnostics = (diagnostics, rowIndex, columnIndex) => {
7704
7711
  const matching = [];
7705
7712
  for (const diagnostic of diagnostics) {
7706
- if (diagnostic.rowIndex === rowIndex) {
7713
+ if (containsPosition(diagnostic, rowIndex, columnIndex)) {
7707
7714
  matching.push(diagnostic);
7708
7715
  }
7709
7716
  }
7710
7717
  return matching;
7711
7718
  };
7712
7719
  const fallbackDisplayStringLanguageId = 'typescript'; // TODO remove this
7713
- const getHoverPositionXy = (editor, rowIndex, wordStart, documentationHeight) => {
7714
- const x$1 = x(editor, rowIndex, wordStart);
7715
- const y$1 = editor.height - y(editor, rowIndex) + editor.y + 40;
7716
- return {
7717
- x: x$1,
7718
- y: y$1
7719
- };
7720
- };
7720
+ const hoverWidth = 600;
7721
7721
  const getEditorHoverInfo = async (editorUid, position) => {
7722
7722
  number(editorUid);
7723
7723
  const instance = get$8(editorUid);
@@ -7728,34 +7728,41 @@ const getEditorHoverInfo = async (editorUid, position) => {
7728
7728
  const {
7729
7729
  columnIndex,
7730
7730
  rowIndex
7731
- } = getHoverPosition(position, selections);
7731
+ } = position || {
7732
+ columnIndex: selections[1],
7733
+ rowIndex: selections[0]
7734
+ };
7732
7735
  const offset = offsetAt(editor, rowIndex, columnIndex);
7733
- const hover = await getHover(editor, offset);
7734
- if (!hover) {
7736
+ const diagnostics = editor.diagnostics || [];
7737
+ const matchingDiagnostics = getMatchingDiagnostics(diagnostics, rowIndex, columnIndex);
7738
+ let hover;
7739
+ try {
7740
+ hover = await getHover(editor, offset);
7741
+ } catch {}
7742
+ if (!hover && matchingDiagnostics.length === 0) {
7735
7743
  return undefined;
7736
7744
  }
7737
7745
  const {
7738
- displayString,
7739
- displayStringLanguageId,
7740
- documentation
7741
- } = hover;
7746
+ displayString = '',
7747
+ displayStringLanguageId = '',
7748
+ documentation = ''
7749
+ } = hover || {};
7742
7750
  const tokenizerPath = '';
7743
- const lineInfos = await tokenizeCodeBlock(displayString, displayStringLanguageId || fallbackDisplayStringLanguageId, tokenizerPath);
7751
+ const lineInfos = displayString ? await tokenizeCodeBlock(displayString, displayStringLanguageId || fallbackDisplayStringLanguageId, tokenizerPath) : [];
7744
7752
  const wordPart = getWordBefore(editor, rowIndex, columnIndex);
7745
7753
  const wordStart = columnIndex - wordPart.length;
7746
- await measureTextBlockHeight();
7747
- const {
7748
- x,
7749
- y
7750
- } = getHoverPositionXy(editor, rowIndex, wordStart);
7751
- const diagnostics = editor.diagnostics || [];
7752
- const matchingDiagnostics = getMatchingDiagnostics(diagnostics, rowIndex);
7754
+ const documentationHeight = await measureTextBlockHeight();
7755
+ const height = Math.min((matchingDiagnostics.length > 0 ? 30 : 0) + (lineInfos.length > 0 ? lineInfos.length * editor.rowHeight + 12 : 0) + (documentation ? documentationHeight + 11 : 0) || 20, editor.height);
7756
+ const x$1 = Math.max(editor.x, Math.min(x(editor, rowIndex, wordStart), editor.x + editor.width - hoverWidth));
7757
+ const rowBottom = y(editor, rowIndex);
7758
+ const y$1 = rowBottom + height <= editor.y + editor.height ? rowBottom : Math.max(editor.y, rowBottom - editor.rowHeight - height);
7753
7759
  return {
7754
7760
  documentation,
7761
+ height,
7755
7762
  lineInfos,
7756
7763
  matchingDiagnostics,
7757
- x,
7758
- y
7764
+ x: x$1,
7765
+ y: y$1
7759
7766
  };
7760
7767
  };
7761
7768
 
@@ -7766,6 +7773,7 @@ const loadHoverContent = async (state, position) => {
7766
7773
  }
7767
7774
  const {
7768
7775
  documentation,
7776
+ height,
7769
7777
  lineInfos,
7770
7778
  matchingDiagnostics,
7771
7779
  x,
@@ -7775,6 +7783,7 @@ const loadHoverContent = async (state, position) => {
7775
7783
  ...state,
7776
7784
  diagnostics: matchingDiagnostics,
7777
7785
  documentation,
7786
+ height,
7778
7787
  lineInfos,
7779
7788
  width: 600,
7780
7789
  x,
@@ -7782,7 +7791,61 @@ const loadHoverContent = async (state, position) => {
7782
7791
  };
7783
7792
  };
7784
7793
 
7794
+ const updateWidget = (editor, widgetId, newState) => {
7795
+ // TODO avoid closure
7796
+ const isWidget = widget => {
7797
+ return widget.id === widgetId;
7798
+ };
7799
+ const childIndex = editor.widgets.findIndex(isWidget);
7800
+ if (childIndex === -1) {
7801
+ return editor;
7802
+ }
7803
+ // TODO scroll up/down if necessary
7804
+ const childWidget = editor.widgets[childIndex];
7805
+ const newWidget = {
7806
+ ...childWidget,
7807
+ newState,
7808
+ oldState: childWidget.newState
7809
+ };
7810
+ const newWidgets = [...editor.widgets.slice(0, childIndex), newWidget, ...editor.widgets.slice(childIndex + 1)];
7811
+ return {
7812
+ ...editor,
7813
+ widgets: newWidgets
7814
+ };
7815
+ };
7816
+
7817
+ const getHoverWidgetIndex = widgets => {
7818
+ return widgets.findIndex(widget => widget.id === Hover);
7819
+ };
7820
+ const updateHover = async (editor, widgetIndex, position) => {
7821
+ const widgetRevision = next(editor.uid);
7822
+ const widget = editor.widgets[widgetIndex];
7823
+ const newState = await loadHoverContent(widget.newState, position);
7824
+ if (get$2(editor.uid) !== widgetRevision) {
7825
+ return editor;
7826
+ }
7827
+ if (!newState) {
7828
+ return {
7829
+ ...editor,
7830
+ additionalFocus: Empty,
7831
+ focused: true,
7832
+ widgetRevision,
7833
+ widgets: removeEditorWidget(editor.widgets, Hover)
7834
+ };
7835
+ }
7836
+ return {
7837
+ ...updateWidget(editor, Hover, newState),
7838
+ widgetRevision
7839
+ };
7840
+ };
7785
7841
  const showHover$1 = async (editor, position) => {
7842
+ const {
7843
+ widgets = []
7844
+ } = editor;
7845
+ const widgetIndex = getHoverWidgetIndex(widgets);
7846
+ if (widgetIndex !== -1) {
7847
+ return updateHover(editor, widgetIndex, position);
7848
+ }
7786
7849
  const newStateGenerator = async state => {
7787
7850
  return loadHoverContent(state, position);
7788
7851
  };
@@ -7829,7 +7892,7 @@ const onHoverIdle = async token => {
7829
7892
  // Hover providers are optional and should not surface errors from an idle mouse event.
7830
7893
  }
7831
7894
  };
7832
- const hoverDelay = 300;
7895
+ const hoverDelay = 200;
7833
7896
  const handleMouseMove = async (editor, x, y, altKey) => {
7834
7897
  if (altKey) {
7835
7898
  return handleMouseMoveWithAltKey(editor, x, y);
@@ -8866,29 +8929,6 @@ const getWidgetInvoke = widgetId => {
8866
8929
  const SearchValue = 'search-value';
8867
8930
  const Close = 'Close';
8868
8931
 
8869
- const updateWidget = (editor, widgetId, newState) => {
8870
- // TODO avoid closure
8871
- const isWidget = widget => {
8872
- return widget.id === widgetId;
8873
- };
8874
- const childIndex = editor.widgets.findIndex(isWidget);
8875
- if (childIndex === -1) {
8876
- return editor;
8877
- }
8878
- // TODO scroll up/down if necessary
8879
- const childWidget = editor.widgets[childIndex];
8880
- const newWidget = {
8881
- ...childWidget,
8882
- newState,
8883
- oldState: childWidget.newState
8884
- };
8885
- const newWidgets = [...editor.widgets.slice(0, childIndex), newWidget, ...editor.widgets.slice(childIndex + 1)];
8886
- return {
8887
- ...editor,
8888
- widgets: newWidgets
8889
- };
8890
- };
8891
-
8892
8932
  const getEditorByWidgetUid = (widgetUid, widgetId) => {
8893
8933
  for (const key of getKeys$2()) {
8894
8934
  const editor = get$8(Number(key)).newState;
@@ -10944,6 +10984,7 @@ const loadContent$1 = async (editorUid, state, position) => {
10944
10984
  }
10945
10985
  const {
10946
10986
  documentation,
10987
+ height,
10947
10988
  lineInfos,
10948
10989
  matchingDiagnostics,
10949
10990
  x,
@@ -10953,6 +10994,7 @@ const loadContent$1 = async (editorUid, state, position) => {
10953
10994
  ...state,
10954
10995
  diagnostics: matchingDiagnostics,
10955
10996
  documentation,
10997
+ height,
10956
10998
  lineInfos,
10957
10999
  x,
10958
11000
  y
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "19.29.9",
3
+ "version": "19.29.11",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"