@veltra/sheet 4.1.1 → 4.1.2

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.
@@ -1,11 +1,12 @@
1
1
  import _sfc_main$1 from "./formula-suggest-list.js";
2
2
  import { applySuggest, filterFormulaSuggestions, getSuggestContext, moveSuggestIndex } from "./use-formula-suggest.js";
3
3
  import _sfc_main$2 from "./popups/functions-popup.js";
4
- import { insertRefText, isRefSelectContext } from "./use-formula-ref-select.js";
4
+ import { REF_HIGHLIGHT_COLORS, insertRefText, isRefSelectContext, replaceRefText } from "./use-formula-ref-select.js";
5
5
  import { formatAddress, formatRange, parseRange } from "infinitable/sheet";
6
6
  import { computed, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, nextTick, normalizeClass, onBeforeUnmount, onMounted, openBlock, ref, shallowRef, unref, useTemplateRef, vModelText, watch, withCtx, withDirectives, withModifiers } from "vue";
7
7
  import { UDropdown, message } from "@veltra/desktop";
8
8
  import { bem } from "@veltra/utils";
9
+ import { scanFormulaReferences } from "infinitable";
9
10
  //#region src/components/sheet/formula-bar.vue
10
11
  const _hoisted_1 = ["disabled"];
11
12
  const _hoisted_2 = ["disabled", "readonly"];
@@ -15,7 +16,8 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
15
16
  props: {
16
17
  sheet: {},
17
18
  context: {},
18
- setSelectionAnchor: { type: Function }
19
+ setSelectionAnchor: { type: Function },
20
+ setRefHighlights: { type: Function }
19
21
  },
20
22
  setup(__props, { expose: __expose }) {
21
23
  /**
@@ -60,28 +62,102 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
60
62
  function isRefSelecting() {
61
63
  return editing.value && !mirroring.value && isRefSelectContext(fxDraft.value, fxCursor.value);
62
64
  }
63
- /** 网格 pointerdown(capture)→ 挂起即将到来的 blur 提交 */
65
+ /** 上次引用插入的文本区间(fxDraft 内 [start, end)):插入引用后光标离开触发位、
66
+ * isRefSelectContext 判定失效,拾取会话延续依赖它维持 blur 抑制与替换/扩展语义 */
67
+ let lastRefInsert = null;
68
+ function clearRefInsert() {
69
+ lastRefInsert = null;
70
+ }
71
+ /** 引用拾取延续中(上次插入的引用可被后续点选替换/扩展,点击画布不退出编辑) */
72
+ function hasRefInsert() {
73
+ return lastRefInsert !== null;
74
+ }
75
+ /** 网格 pointerdown(capture)→ 挂起即将到来的 blur 提交;拾取会话延续中
76
+ * (上次插入的引用未被打断)同样挂起——任意点击都消费为引用替换/扩展 */
64
77
  function beginBlurSuppress() {
65
- if (!isRefSelecting()) return;
78
+ if (!isRefSelecting() && !lastRefInsert) return;
66
79
  suppressBlurCommit = true;
67
80
  }
68
- /** 选区拦截回调:插入 A1 / A1:B2 到光标处(仅引用选择模式;弹框打开但非引用上下文时不插入) */
81
+ /** 选区拦截回调:插入 A1 / A1:B2 到光标处(仅引用选择模式;弹框打开但非引用上下文时不插入)。
82
+ * 拾取会话延续(lastRefInsert 存在):替换上次插入的引用——shift 扩展回交(Excel 锚点
83
+ * 恒定连续扩展)与普通点选(Point mode 换目标)同走此路径,编辑不中断 */
69
84
  function handleRefSelect(range) {
70
- if (!isRefSelecting()) return;
85
+ if (!isRefSelecting() && !lastRefInsert) return;
86
+ if (editAddr && range.start.row === range.end.row && range.start.col === range.end.col && range.start.row === editAddr.row && range.start.col === editAddr.col) return;
71
87
  const rangeText = formatRange(range);
72
- const selEnd = fxRef.value?.selectionEnd ?? fxCursor.value;
73
- const result = insertRefText(fxDraft.value, fxCursor.value, rangeText, selEnd);
74
- fxDraft.value = result.text;
75
- fxCursor.value = result.cursor;
88
+ if (lastRefInsert) {
89
+ const { start } = lastRefInsert;
90
+ const result = replaceRefText(fxDraft.value, start, lastRefInsert.end, rangeText);
91
+ fxDraft.value = result.text;
92
+ fxCursor.value = result.cursor;
93
+ lastRefInsert = {
94
+ start,
95
+ end: result.cursor
96
+ };
97
+ } else {
98
+ const selEnd = fxRef.value?.selectionEnd ?? fxCursor.value;
99
+ const result = insertRefText(fxDraft.value, fxCursor.value, rangeText, selEnd);
100
+ fxDraft.value = result.text;
101
+ fxCursor.value = result.cursor;
102
+ lastRefInsert = {
103
+ start: result.cursor - rangeText.length,
104
+ end: result.cursor
105
+ };
106
+ }
76
107
  closeSuggest();
77
108
  nextTick(() => {
78
109
  const input = fxRef.value;
79
110
  if (!input) return;
80
111
  input.focus();
81
- input.setSelectionRange(result.cursor, result.cursor);
112
+ input.setSelectionRange(fxCursor.value, fxCursor.value);
82
113
  autosizeFx();
83
114
  });
84
115
  }
116
+ /** 公式文本扫描 → 画布染色框:编辑中且 `=` 开头时逐引用上框(颜色按出现顺序循环),
117
+ * 手输/点选/扩展一视同仁(对齐 Excel:编辑公式即染色全部引用);其余状态清除 */
118
+ function syncRefHighlights() {
119
+ if (!editing.value || mirroring.value || !fxDraft.value.startsWith("=")) {
120
+ props.setRefHighlights?.([]);
121
+ return;
122
+ }
123
+ props.setRefHighlights?.(scanFormulaReferences(fxDraft.value).map(refToHighlight));
124
+ }
125
+ /** 扫描结果 → 染色框条目(RangeRef 展开为区域,单格引用同形) */
126
+ function refToHighlight(scanned, index) {
127
+ const color = REF_HIGHLIGHT_COLORS[index % REF_HIGHLIGHT_COLORS.length];
128
+ const ref = scanned.ref;
129
+ if (scanned.isRange) return {
130
+ range: {
131
+ start: {
132
+ row: ref.startRow,
133
+ col: ref.startCol
134
+ },
135
+ end: {
136
+ row: ref.endRow,
137
+ col: ref.endCol
138
+ }
139
+ },
140
+ color
141
+ };
142
+ return {
143
+ range: {
144
+ start: {
145
+ row: ref.row,
146
+ col: ref.col
147
+ },
148
+ end: {
149
+ row: ref.row,
150
+ col: ref.col
151
+ }
152
+ },
153
+ color
154
+ };
155
+ }
156
+ watch([
157
+ fxDraft,
158
+ editing,
159
+ mirroring
160
+ ], syncRefHighlights);
85
161
  function nameText(state) {
86
162
  const range = state.ranges[0];
87
163
  if (range) {
@@ -164,6 +240,7 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
164
240
  refreshSuggest();
165
241
  }
166
242
  function handleFxInput() {
243
+ clearRefInsert();
167
244
  syncFxCursor();
168
245
  autosizeFx();
169
246
  }
@@ -193,6 +270,7 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
193
270
  const result = applySuggest(fxDraft.value, ctx.start, ctx.end, pick.name);
194
271
  fxDraft.value = result.text;
195
272
  fxCursor.value = result.cursor;
273
+ clearRefInsert();
196
274
  closeSuggest();
197
275
  nextTick(() => {
198
276
  const el = fxRef.value;
@@ -293,6 +371,7 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
293
371
  editAddr = null;
294
372
  suppressBlurCommit = false;
295
373
  props.setSelectionAnchor?.(null);
374
+ clearRefInsert();
296
375
  closeSuggest();
297
376
  if (addr) {
298
377
  props.context.setCellValue(addr, fxDraft.value);
@@ -307,6 +386,7 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
307
386
  editAddr = null;
308
387
  suppressBlurCommit = false;
309
388
  props.setSelectionAnchor?.(null);
389
+ clearRefInsert();
310
390
  closeSuggest();
311
391
  refreshFx();
312
392
  }
@@ -337,6 +417,7 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
337
417
  mirroring.value = true;
338
418
  mirrorAddr = addr;
339
419
  fxDraft.value = cellText(addr);
420
+ clearRefInsert();
340
421
  closeSuggest();
341
422
  }
342
423
  function exitMirror(addr) {
@@ -398,6 +479,7 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
398
479
  fxDraft.value = text;
399
480
  fxCursor.value = cursor;
400
481
  suppressBlurCommit = false;
482
+ clearRefInsert();
401
483
  props.setSelectionAnchor?.(addr);
402
484
  closeSuggest();
403
485
  nextTick(() => {
@@ -414,6 +496,7 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
414
496
  mirrorGridEdit,
415
497
  exitMirror,
416
498
  isRefSelecting,
499
+ hasRefInsert,
417
500
  isFunctionPopupOpen: () => functionsOpen.value,
418
501
  beginBlurSuppress,
419
502
  handleRefSelect,
@@ -431,6 +514,7 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
431
514
  mirroring.value = false;
432
515
  mirrorAddr = null;
433
516
  suppressBlurCommit = false;
517
+ clearRefInsert();
434
518
  functionsOpen.value = false;
435
519
  closeSuggest();
436
520
  bindSheet(sheet);
@@ -202,7 +202,7 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
202
202
  }
203
203
  const gridRef = useTemplateRef("gridRef");
204
204
  const formulaBarRef = useTemplateRef("formulaBarRef");
205
- const { rebuildGrid, activateGrid, pruneCache, getGrid, setSelectionAnchor } = useSheetGrid({
205
+ const { rebuildGrid, activateGrid, pruneCache, getGrid, setSelectionAnchor, setRefHighlights } = useSheetGrid({
206
206
  props,
207
207
  gridRef,
208
208
  getActiveSheet: () => activeSheet.value,
@@ -301,11 +301,13 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
301
301
  ref: formulaBarRef,
302
302
  sheet: unref(activeSheet),
303
303
  context: unref(context),
304
- "set-selection-anchor": unref(setSelectionAnchor)
304
+ "set-selection-anchor": unref(setSelectionAnchor),
305
+ "set-ref-highlights": unref(setRefHighlights)
305
306
  }, null, 8, [
306
307
  "sheet",
307
308
  "context",
308
- "set-selection-anchor"
309
+ "set-selection-anchor",
310
+ "set-ref-highlights"
309
311
  ])) : createCommentVNode("v-if", true),
310
312
  createElementVNode("div", {
311
313
  ref_key: "gridRef",
@@ -13,6 +13,12 @@ const REF_TRIGGER_CHARS = /* @__PURE__ */ new Set([
13
13
  "<",
14
14
  ">"
15
15
  ]);
16
+ /** 引用拾取染色框循环色板(对齐 Excel 蓝/绿/红循环惯例),按引用在公式中的出现顺序取色 */
17
+ const REF_HIGHLIGHT_COLORS = [
18
+ "#2563eb",
19
+ "#16a34a",
20
+ "#dc2626"
21
+ ];
16
22
  /**
17
23
  * 判定是否处于「可插入引用」位置(无状态:每次按文本 + 光标重算)。
18
24
  * `-` 的一元/二元歧义基础版不区分(`A1-` 后框选 → `A1-B2`,合法且误判无害)。
@@ -26,12 +32,14 @@ function isRefSelectContext(text, cursor) {
26
32
  }
27
33
  /** 在光标处插入引用文本(替换空选区;有选区时覆盖选区) */
28
34
  function insertRefText(text, cursor, rangeText, selectionEnd = cursor) {
29
- const start = Math.min(cursor, selectionEnd);
30
- const end = Math.max(cursor, selectionEnd);
35
+ return replaceRefText(text, Math.min(cursor, selectionEnd), Math.max(cursor, selectionEnd), rangeText);
36
+ }
37
+ /** 替换 [start, end) 区间为引用文本(shift+点选扩展:扩展上次插入的引用) */
38
+ function replaceRefText(text, start, end, rangeText) {
31
39
  return {
32
40
  text: text.slice(0, start) + rangeText + text.slice(end),
33
41
  cursor: start + rangeText.length
34
42
  };
35
43
  }
36
44
  //#endregion
37
- export { insertRefText, isRefSelectContext };
45
+ export { REF_HIGHLIGHT_COLORS, insertRefText, isRefSelectContext, replaceRefText };
@@ -124,7 +124,7 @@ function useSheetGrid(options) {
124
124
  onEditStart: (addr) => formulaBarRef.value?.mirrorGridEdit(addr),
125
125
  onEditEnd: (addr) => formulaBarRef.value?.exitMirror(addr),
126
126
  onColResizeEnd: options.onColResizeEnd,
127
- interceptSelection: () => (formulaBarRef.value?.isRefSelecting() ?? false) || (formulaBarRef.value?.isFunctionPopupOpen() ?? false) || (options.isFunctionPopupOpen?.() ?? false),
127
+ interceptSelection: () => (formulaBarRef.value?.isRefSelecting() ?? false) || (formulaBarRef.value?.hasRefInsert() ?? false) || (formulaBarRef.value?.isFunctionPopupOpen() ?? false) || (options.isFunctionPopupOpen?.() ?? false),
128
128
  onSelectionIntercept: (range) => formulaBarRef.value?.handleRefSelect(range)
129
129
  });
130
130
  let dirty = false;
@@ -212,7 +212,10 @@ function useSheetGrid(options) {
212
212
  function activateGrid() {
213
213
  const sheet = getActiveSheet();
214
214
  if (!gridRef.value) return;
215
- if (active && active.sheet !== sheet) active.grid.setSelectionAnchor(null);
215
+ if (active && active.sheet !== sheet) {
216
+ active.grid.setSelectionAnchor(null);
217
+ active.grid.setHighlightRanges([]);
218
+ }
216
219
  const cached = cache.get(sheet);
217
220
  if (cached && !cached.dirty) {
218
221
  cached.lastUsed = ++seq;
@@ -284,12 +287,17 @@ function useSheetGrid(options) {
284
287
  function setSelectionAnchor(addr) {
285
288
  active?.grid.setSelectionAnchor(addr);
286
289
  }
290
+ /** 公式引用染色框同步(公式栏 → 活动实例透传;空数组清除;无活动实例时静默) */
291
+ function setRefHighlights(items) {
292
+ active?.grid.setHighlightRanges(items);
293
+ }
287
294
  return {
288
295
  rebuildGrid,
289
296
  activateGrid,
290
297
  pruneCache,
291
298
  getGrid: () => active?.grid,
292
- setSelectionAnchor
299
+ setSelectionAnchor,
300
+ setRefHighlights
293
301
  };
294
302
  }
295
303
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veltra/sheet",
3
- "version": "4.1.1",
3
+ "version": "4.1.2",
4
4
  "homepage": "https://github.com/cabinet-fe/ultra-ui#readme",
5
5
  "bugs": {
6
6
  "url": "https://github.com/cabinet-fe/ultra-ui/issues"
@@ -33,9 +33,6 @@
33
33
  "import": "./dist/*"
34
34
  }
35
35
  },
36
- "dependencies": {
37
- "infinitable": "^0.1.8"
38
- },
39
36
  "peerDependencies": {
40
37
  "@cat-kit/core": ">=1.2.1",
41
38
  "@cat-kit/fe": ">=1.2.1",
@@ -43,6 +40,7 @@
43
40
  "@veltra/icons": "^1.5.0",
44
41
  "@veltra/styles": "^1.7.14",
45
42
  "@veltra/utils": "^1.7.14",
43
+ "infinitable": "^0.2.2",
46
44
  "vue": ">=3.5.43"
47
45
  }
48
46
  }
@@ -631,6 +631,78 @@ describe('USheet 公式栏:函数补全与引用选择', () => {
631
631
  expect(fxInput(el).value).toBe('=A1+B1')
632
632
  })
633
633
 
634
+ it('shift 扩展:替换上次插入的引用(extend 回交),连续扩展锚点不重置', async () => {
635
+ const sheet = new Workbook().activeSheet
636
+ const { el, exposed } = mountFormulaBar(sheet)
637
+ await nextTick()
638
+ sheet.selectCell({ row: 2, col: 0 })
639
+ await nextTick()
640
+
641
+ setFxText(el, '=SUM(')
642
+ await nextTick()
643
+ exposed.value!.handleRefSelect(parseRange('A1'))
644
+ await nextTick()
645
+ expect(fxInput(el).value).toBe('=SUM(A1')
646
+ // 插入后光标离开触发位(上下文断裂),拾取延续仍成立
647
+ expect(exposed.value!.hasRefInsert()).toBe(true)
648
+
649
+ // shift+点选扩展(引擎 extend 回交):A1 被替换为 A1:C3 而非追加
650
+ exposed.value!.handleRefSelect(parseRange('A1:C3'))
651
+ await nextTick()
652
+ expect(fxInput(el).value).toBe('=SUM(A1:C3')
653
+ expect(fxInput(el).selectionStart).toBe('=SUM(A1:C3'.length)
654
+
655
+ // 连续扩展:引擎锚点恒为首次拾取锚点,A1:C3 整体替换为 A1:D5
656
+ exposed.value!.handleRefSelect(parseRange('A1:D5'))
657
+ await nextTick()
658
+ expect(fxInput(el).value).toBe('=SUM(A1:D5')
659
+ })
660
+
661
+ it('shift 扩展无上次插入(无 extend 上下文)时按普通插入处理', async () => {
662
+ const sheet = new Workbook().activeSheet
663
+ const { el, exposed } = mountFormulaBar(sheet)
664
+ await nextTick()
665
+ sheet.selectCell({ row: 2, col: 0 })
666
+ await nextTick()
667
+
668
+ setFxText(el, '=SUM(')
669
+ await nextTick()
670
+ exposed.value!.handleRefSelect(parseRange('B2'))
671
+ await nextTick()
672
+ expect(fxInput(el).value).toBe('=SUM(B2')
673
+ })
674
+
675
+ it('用户手动输入 / 提交后引用拾取延续终止:extend 不再替换', async () => {
676
+ const sheet = new Workbook().activeSheet
677
+ const { el, exposed } = mountFormulaBar(sheet)
678
+ await nextTick()
679
+ sheet.selectCell({ row: 2, col: 0 })
680
+ await nextTick()
681
+
682
+ setFxText(el, '=SUM(')
683
+ await nextTick()
684
+ exposed.value!.handleRefSelect(parseRange('A1'))
685
+ await nextTick()
686
+ expect(exposed.value!.hasRefInsert()).toBe(true)
687
+
688
+ // 用户输入逗号(input 事件):延续状态清除,回到光标上下文判定
689
+ const input = fxInput(el)
690
+ input.value = '=SUM(A1,'
691
+ input.setSelectionRange(9, 9)
692
+ input.dispatchEvent(new Event('input', { bubbles: true }))
693
+ await nextTick()
694
+ expect(exposed.value!.hasRefInsert()).toBe(false)
695
+ exposed.value!.handleRefSelect(parseRange('B2'))
696
+ await nextTick()
697
+ // 光标在逗号后处于引用上下文 → 普通插入 B2,而非替换 A1
698
+ expect(fxInput(el).value).toBe('=SUM(A1,B2')
699
+
700
+ // Enter 提交:会话结束,延续状态随编辑态一并清除
701
+ input.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }))
702
+ await nextTick()
703
+ expect(exposed.value!.hasRefInsert()).toBe(false)
704
+ })
705
+
634
706
  it('多行文本:默认保持单行高度,鼠标进入展开,移出后收起', async () => {
635
707
  const workbook = new Workbook()
636
708
  const sheet = workbook.activeSheet
@@ -661,6 +733,137 @@ describe('USheet 公式栏:函数补全与引用选择', () => {
661
733
  })
662
734
  })
663
735
 
736
+ describe('USheet 公式栏:Point mode 拾取会话(Excel 语义)', () => {
737
+ it('拾取会话中普通点选画布:替换上次引用、编辑不中断、blur 不提交;Enter 提交替换后公式', async () => {
738
+ const workbook = new Workbook()
739
+ const sheet = workbook.activeSheet
740
+ const exposed: { value: SheetExposed | undefined } = { value: undefined }
741
+ const { el } = mount(() => ({ workbook, rows: 20, cols: 8 }), exposed)
742
+ await nextTick()
743
+ sheet.selectCell({ row: 2, col: 0 })
744
+ await nextTick()
745
+
746
+ const input = setFxText(el, '=SUM(')
747
+ await nextTick()
748
+
749
+ // 首拾取 A4(引擎选区事件管线:pointerdown 起手 → pointerup 收敛回交)
750
+ const gridEl = gridEventTarget(el)
751
+ const pick = (x: number, y: number) => {
752
+ gridEl.dispatchEvent(
753
+ new PointerEvent('pointerdown', { clientX: x, clientY: y, bubbles: true })
754
+ )
755
+ gridEl.dispatchEvent(new PointerEvent('pointerup', { clientX: x, clientY: y, bubbles: true }))
756
+ }
757
+ pick(51, 117)
758
+ await nextTick()
759
+ expect(input.value).toBe('=SUM(A4')
760
+
761
+ // 普通点选 C3(画布几何:行号列 46、列头 28、列宽 80、行高 28)→ 替换 A4 而非追加
762
+ pick(211, 89)
763
+ await nextTick()
764
+ expect(input.value).toBe('=SUM(C3')
765
+
766
+ // 编辑未中断:模型未写入(真实 blur 已在第二次 pointerdown 时被挂起并消费)
767
+ expect(sheet.getCellData({ row: 2, col: 0 })).toBeUndefined()
768
+ expect(input.value).toBe('=SUM(C3')
769
+
770
+ // Enter 提交替换后的公式
771
+ input.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }))
772
+ await nextTick()
773
+ expect(sheet.getCellData({ row: 2, col: 0 })).toMatchObject({ f: 'SUM(C3' })
774
+ })
775
+
776
+ it('拾取会话中点选被编辑格自身:忽略不替换(防循环引用),会话延续', async () => {
777
+ const sheet = new Workbook().activeSheet
778
+ const { el, exposed } = mountFormulaBar(sheet)
779
+ await nextTick()
780
+ sheet.selectCell({ row: 2, col: 0 })
781
+ await nextTick()
782
+
783
+ setFxText(el, '=SUM(')
784
+ await nextTick()
785
+ exposed.value!.handleRefSelect(parseRange('A1'))
786
+ await nextTick()
787
+ expect(fxInput(el).value).toBe('=SUM(A1')
788
+
789
+ // 被编辑格 = A3:拾取视作无操作
790
+ exposed.value!.handleRefSelect(parseRange('A3'))
791
+ await nextTick()
792
+ expect(fxInput(el).value).toBe('=SUM(A1')
793
+ expect(exposed.value!.hasRefInsert()).toBe(true)
794
+ })
795
+ })
796
+
797
+ describe('USheet 公式栏:引用染色框(画布视觉反馈)', () => {
798
+ function mountFormulaBarWithHighlights(
799
+ sheet: Workbook['activeSheet'],
800
+ onHighlights: (items: { range: ReturnType<typeof parseRange>; color: string }[]) => void
801
+ ) {
802
+ const el = document.createElement('div')
803
+ document.body.appendChild(el)
804
+ containers.push(el)
805
+ const exposed: { value: InstanceType<typeof UFormulaBar> | undefined } = { value: undefined }
806
+ const app = createApp({
807
+ render: () =>
808
+ h(UFormulaBar, {
809
+ sheet,
810
+ context: createSheetContext(sheet),
811
+ setRefHighlights: onHighlights,
812
+ ref: (value: unknown) => {
813
+ exposed.value = value as InstanceType<typeof UFormulaBar> | undefined
814
+ }
815
+ })
816
+ })
817
+ app.mount(el)
818
+ apps.push(app)
819
+ return { el, exposed }
820
+ }
821
+
822
+ it('公式编辑中按文本扫描逐引用上框(出现顺序循环取色);手输/拾取替换/会话结束同步', async () => {
823
+ const sheet = new Workbook().activeSheet
824
+ const highlights: { range: ReturnType<typeof parseRange>; color: string }[][] = []
825
+ const { el, exposed } = mountFormulaBarWithHighlights(sheet, (items) => highlights.push(items))
826
+ await nextTick()
827
+ sheet.selectCell({ row: 5, col: 5 })
828
+ await nextTick()
829
+
830
+ // 手输多引用:蓝 / 绿按出现顺序(B2:C4 → (1,1)-(3,2))
831
+ setFxText(el, '=SUM(A1,B2:C4)')
832
+ await nextTick()
833
+ expect(highlights.at(-1)).toEqual([
834
+ { range: { start: { row: 0, col: 0 }, end: { row: 0, col: 0 } }, color: '#2563eb' },
835
+ { range: { start: { row: 1, col: 1 }, end: { row: 3, col: 2 } }, color: '#16a34a' }
836
+ ])
837
+
838
+ // 非公式文本:清除
839
+ setFxText(el, 'plain')
840
+ await nextTick()
841
+ expect(highlights.at(-1)).toEqual([])
842
+
843
+ // 拾取会话:插入 B2:C4 → 染色;普通点选 D1 替换 → 染色跟随(仍单引用、蓝色)
844
+ setFxText(el, '=SUM(')
845
+ await nextTick()
846
+ expect(highlights.at(-1)).toEqual([])
847
+ exposed.value!.handleRefSelect(parseRange('B2:C4'))
848
+ await nextTick()
849
+ expect(highlights.at(-1)).toEqual([
850
+ { range: { start: { row: 1, col: 1 }, end: { row: 3, col: 2 } }, color: '#2563eb' }
851
+ ])
852
+ exposed.value!.handleRefSelect(parseRange('D1'))
853
+ await nextTick()
854
+ expect(fxInput(el).value).toBe('=SUM(D1')
855
+ expect(highlights.at(-1)).toEqual([
856
+ { range: { start: { row: 0, col: 3 }, end: { row: 0, col: 3 } }, color: '#2563eb' }
857
+ ])
858
+
859
+ // 提交(编辑态结束):清除
860
+ expect(highlights.at(-1)).toHaveLength(1)
861
+ fxInput(el).dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }))
862
+ await nextTick()
863
+ expect(highlights.at(-1)).toEqual([])
864
+ })
865
+ })
866
+
664
867
  // ─── 目标格选区高亮保持(弹框打开与参数点选期间)──────────────
665
868
 
666
869
  type GridTable = ReturnType<SheetGrid['getTable']>
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, it } from 'vite-plus/test'
2
2
 
3
- import { insertRefText, isRefSelectContext } from '../use-formula-ref-select'
3
+ import { insertRefText, isRefSelectContext, replaceRefText } from '../use-formula-ref-select'
4
4
 
5
5
  describe('isRefSelectContext', () => {
6
6
  it('运算符 / ( / , / = 之后可插入引用', () => {
@@ -33,3 +33,14 @@ describe('insertRefText', () => {
33
33
  expect(insertRefText('=SUM(XX)', 5, 'A1', 7)).toEqual({ text: '=SUM(A1)', cursor: 7 })
34
34
  })
35
35
  })
36
+
37
+ describe('replaceRefText', () => {
38
+ it('替换区间为引用文本,光标落替换文本后(shift 扩展语义)', () => {
39
+ expect(replaceRefText('=SUM(A1', 5, 7, 'A1:C3')).toEqual({ text: '=SUM(A1:C3', cursor: 10 })
40
+ expect(replaceRefText('=SUM(A1:C3', 5, 10, 'A1:D5')).toEqual({ text: '=SUM(A1:D5', cursor: 10 })
41
+ })
42
+
43
+ it('区间收缩为空等价插入', () => {
44
+ expect(replaceRefText('=SUM(', 5, 5, 'B2')).toEqual({ text: '=SUM(B2', cursor: 7 })
45
+ })
46
+ })
@@ -96,6 +96,7 @@
96
96
  <script lang="ts" setup>
97
97
  import { message, UDropdown } from '@veltra/desktop'
98
98
  import { bem } from '@veltra/utils'
99
+ import { scanFormulaReferences, type ScannedReference } from 'infinitable'
99
100
  import {
100
101
  formatAddress,
101
102
  formatRange,
@@ -119,7 +120,12 @@ import {
119
120
  import type { SheetContext } from '../../tools/context'
120
121
  import UFormulaSuggestList from './formula-suggest-list.vue'
121
122
  import USheetFunctionsPopup from './popups/functions-popup.vue'
122
- import { insertRefText, isRefSelectContext } from './use-formula-ref-select'
123
+ import {
124
+ REF_HIGHLIGHT_COLORS,
125
+ insertRefText,
126
+ isRefSelectContext,
127
+ replaceRefText
128
+ } from './use-formula-ref-select'
123
129
  import {
124
130
  applySuggest,
125
131
  filterFormulaSuggestions,
@@ -145,6 +151,8 @@ const props = defineProps<{
145
151
  context: SheetContext
146
152
  /** fx 编辑会话置/清引擎选区锚点(use-sheet-grid 经活动实例透传;缺省静默) */
147
153
  setSelectionAnchor?: (addr: CellAddress | null) => void
154
+ /** 公式引用染色框同步(use-sheet-grid 经活动实例透传;空数组清除;缺省静默) */
155
+ setRefHighlights?: (items: { range: CellRange; color: string }[]) => void
148
156
  }>()
149
157
 
150
158
  const cls = bem('sheet')
@@ -182,31 +190,106 @@ function isRefSelecting(): boolean {
182
190
  return editing.value && !mirroring.value && isRefSelectContext(fxDraft.value, fxCursor.value)
183
191
  }
184
192
 
185
- /** 网格 pointerdown(capture)→ 挂起即将到来的 blur 提交 */
193
+ /** 上次引用插入的文本区间(fxDraft 内 [start, end)):插入引用后光标离开触发位、
194
+ * isRefSelectContext 判定失效,拾取会话延续依赖它维持 blur 抑制与替换/扩展语义 */
195
+ let lastRefInsert: { start: number; end: number } | null = null
196
+
197
+ function clearRefInsert(): void {
198
+ lastRefInsert = null
199
+ }
200
+
201
+ /** 引用拾取延续中(上次插入的引用可被后续点选替换/扩展,点击画布不退出编辑) */
202
+ function hasRefInsert(): boolean {
203
+ return lastRefInsert !== null
204
+ }
205
+
206
+ /** 网格 pointerdown(capture)→ 挂起即将到来的 blur 提交;拾取会话延续中
207
+ * (上次插入的引用未被打断)同样挂起——任意点击都消费为引用替换/扩展 */
186
208
  function beginBlurSuppress(): void {
187
- if (!isRefSelecting()) return
209
+ if (!isRefSelecting() && !lastRefInsert) return
188
210
  suppressBlurCommit = true
189
211
  }
190
212
 
191
- /** 选区拦截回调:插入 A1 / A1:B2 到光标处(仅引用选择模式;弹框打开但非引用上下文时不插入) */
213
+ /** 选区拦截回调:插入 A1 / A1:B2 到光标处(仅引用选择模式;弹框打开但非引用上下文时不插入)。
214
+ * 拾取会话延续(lastRefInsert 存在):替换上次插入的引用——shift 扩展回交(Excel 锚点
215
+ * 恒定连续扩展)与普通点选(Point mode 换目标)同走此路径,编辑不中断 */
192
216
  function handleRefSelect(range: CellRange): void {
193
- if (!isRefSelecting()) return
217
+ // 延续拾取放行:插入后光标离开触发位、isRefSelectContext 失效,延续回交
218
+ // 靠 lastRefInsert 而非光标上下文成立
219
+ if (!isRefSelecting() && !lastRefInsert) return
220
+ // 被编辑格自身不可拾取为引用(Excel 语义:避免循环引用;点中目标格视作无操作)
221
+ if (
222
+ editAddr &&
223
+ range.start.row === range.end.row &&
224
+ range.start.col === range.end.col &&
225
+ range.start.row === editAddr.row &&
226
+ range.start.col === editAddr.col
227
+ ) {
228
+ return
229
+ }
194
230
  const rangeText = formatRange(range)
195
- const el = fxRef.value
196
- const selEnd = el?.selectionEnd ?? fxCursor.value
197
- const result = insertRefText(fxDraft.value, fxCursor.value, rangeText, selEnd)
198
- fxDraft.value = result.text
199
- fxCursor.value = result.cursor
231
+ if (lastRefInsert) {
232
+ const { start } = lastRefInsert
233
+ const result = replaceRefText(fxDraft.value, start, lastRefInsert.end, rangeText)
234
+ fxDraft.value = result.text
235
+ fxCursor.value = result.cursor
236
+ lastRefInsert = { start, end: result.cursor }
237
+ } else {
238
+ const el = fxRef.value
239
+ const selEnd = el?.selectionEnd ?? fxCursor.value
240
+ const result = insertRefText(fxDraft.value, fxCursor.value, rangeText, selEnd)
241
+ fxDraft.value = result.text
242
+ fxCursor.value = result.cursor
243
+ lastRefInsert = { start: result.cursor - rangeText.length, end: result.cursor }
244
+ }
200
245
  closeSuggest()
201
246
  void nextTick(() => {
202
247
  const input = fxRef.value
203
248
  if (!input) return
204
249
  input.focus()
205
- input.setSelectionRange(result.cursor, result.cursor)
250
+ input.setSelectionRange(fxCursor.value, fxCursor.value)
206
251
  autosizeFx()
207
252
  })
208
253
  }
209
254
 
255
+ // ─── 引用染色框(画布视觉反馈) ────────────────────────────
256
+
257
+ /** 公式文本扫描 → 画布染色框:编辑中且 `=` 开头时逐引用上框(颜色按出现顺序循环),
258
+ * 手输/点选/扩展一视同仁(对齐 Excel:编辑公式即染色全部引用);其余状态清除 */
259
+ function syncRefHighlights(): void {
260
+ if (!editing.value || mirroring.value || !fxDraft.value.startsWith('=')) {
261
+ props.setRefHighlights?.([])
262
+ return
263
+ }
264
+ props.setRefHighlights?.(scanFormulaReferences(fxDraft.value).map(refToHighlight))
265
+ }
266
+
267
+ /** 扫描结果 → 染色框条目(RangeRef 展开为区域,单格引用同形) */
268
+ function refToHighlight(
269
+ scanned: ScannedReference,
270
+ index: number
271
+ ): { range: CellRange; color: string } {
272
+ const color = REF_HIGHLIGHT_COLORS[index % REF_HIGHLIGHT_COLORS.length]!
273
+ const ref = scanned.ref
274
+ if (scanned.isRange) {
275
+ return {
276
+ range: {
277
+ start: { row: ref.startRow, col: ref.startCol },
278
+ end: { row: ref.endRow, col: ref.endCol }
279
+ },
280
+ color
281
+ }
282
+ }
283
+ return {
284
+ range: { start: { row: ref.row, col: ref.col }, end: { row: ref.row, col: ref.col } },
285
+ color
286
+ }
287
+ }
288
+
289
+ // 草稿/编辑态/镜像态任一变化即重扫(拾取回交改稿、手输、会话结束都经这三者;
290
+ // 提交同文提交时 fxDraft 不变但 editing 翻转,watch 仍触发完成清除)
291
+ watch([fxDraft, editing, mirroring], syncRefHighlights)
292
+
210
293
  // ─── 显示文本 ──────────────────────────────────────────────
211
294
 
212
295
  function nameText(state: SelectionState): string {
@@ -316,6 +399,8 @@ function syncFxCursor(): void {
316
399
  }
317
400
 
318
401
  function handleFxInput(): void {
402
+ // 用户手动编辑使上次插入区间失效(shift 扩展只对未经编辑的插入文本有效)
403
+ clearRefInsert()
319
404
  syncFxCursor()
320
405
  autosizeFx()
321
406
  }
@@ -350,6 +435,7 @@ function confirmSuggest(item?: FormulaSuggestItem): void {
350
435
  const result = applySuggest(fxDraft.value, ctx.start, ctx.end, pick.name)
351
436
  fxDraft.value = result.text
352
437
  fxCursor.value = result.cursor
438
+ clearRefInsert()
353
439
  closeSuggest()
354
440
  void nextTick(() => {
355
441
  const el = fxRef.value
@@ -466,8 +552,9 @@ function commitEdit(): void {
466
552
  editing.value = false
467
553
  editAddr = null
468
554
  suppressBlurCommit = false
469
- // 会话结束清锚点(Enter / ✓ / 失焦同路径)
555
+ // 会话结束清锚点(Enter / ✓ / 失焦同路径)与引用插入延续状态
470
556
  props.setSelectionAnchor?.(null)
557
+ clearRefInsert()
471
558
  closeSuggest()
472
559
  if (addr) {
473
560
  props.context.setCellValue(addr, fxDraft.value)
@@ -485,8 +572,9 @@ function cancelEdit(): void {
485
572
  editing.value = false
486
573
  editAddr = null
487
574
  suppressBlurCommit = false
488
- // 会话结束清锚点(Esc / ✗)
575
+ // 会话结束清锚点(Esc / ✗)与引用插入延续状态
489
576
  props.setSelectionAnchor?.(null)
577
+ clearRefInsert()
490
578
  closeSuggest()
491
579
  refreshFx()
492
580
  }
@@ -524,6 +612,7 @@ function mirrorGridEdit(addr: CellAddress): void {
524
612
  mirroring.value = true
525
613
  mirrorAddr = addr
526
614
  fxDraft.value = cellText(addr)
615
+ clearRefInsert()
527
616
  closeSuggest()
528
617
  }
529
618
 
@@ -601,7 +690,8 @@ function insertFunction(name: string): void {
601
690
  fxDraft.value = text
602
691
  fxCursor.value = cursor
603
692
  suppressBlurCommit = false
604
- // 插入函数即进入引用拾取会话:目标格置选区锚点
693
+ // 插入函数即进入引用拾取会话:目标格置选区锚点,新会话清引用插入延续状态
694
+ clearRefInsert()
605
695
  props.setSelectionAnchor?.(addr)
606
696
  closeSuggest()
607
697
  void nextTick(() => {
@@ -621,6 +711,7 @@ defineExpose({
621
711
  mirrorGridEdit,
622
712
  exitMirror,
623
713
  isRefSelecting,
714
+ hasRefInsert,
624
715
  isFunctionPopupOpen: () => functionsOpen.value,
625
716
  beginBlurSuppress,
626
717
  handleRefSelect,
@@ -647,6 +738,7 @@ watch(
647
738
  mirroring.value = false
648
739
  mirrorAddr = null
649
740
  suppressBlurCommit = false
741
+ clearRefInsert()
650
742
  functionsOpen.value = false
651
743
  closeSuggest()
652
744
  bindSheet(sheet)
@@ -57,6 +57,7 @@
57
57
  :sheet="activeSheet"
58
58
  :context="context"
59
59
  :set-selection-anchor="setSelectionAnchor"
60
+ :set-ref-highlights="setRefHighlights"
60
61
  />
61
62
 
62
63
  <div ref="gridRef" :class="cls.e('grid')">
@@ -348,32 +349,33 @@ function handleImageLinkClick(event: ImageLinkClickEvent): void {
348
349
  const gridRef = useTemplateRef<HTMLElement>('gridRef')
349
350
  const formulaBarRef = useTemplateRef<InstanceType<typeof UFormulaBar>>('formulaBarRef')
350
351
 
351
- const { rebuildGrid, activateGrid, pruneCache, getGrid, setSelectionAnchor } = useSheetGrid({
352
- props,
353
- gridRef,
354
- getActiveSheet: () => activeSheet.value,
355
- context,
356
- formulaBarRef,
357
- // 工具栏「函数」弹框打开期间与 fx 入口一致:画布点击不清除目标格高亮
358
- isFunctionPopupOpen: () => popupTool.value?.popup === 'functions',
359
- onColResizeEnd: (event) => emit('col-resize-end', event),
360
- // 引擎链接 / 浮动图事件透传(openCellLinkOnClick=false:链接格直开、图片链接确认后开);
361
- // hover/leave 同时喂给 tooltip 状态机(与组件 emit 同源)
362
- onCellLinkHover: (event) => {
363
- emit('cell-link-hover', event)
364
- showCellLinkTooltip(event)
365
- },
366
- onCellLinkLeave: (event) => {
367
- emit('cell-link-leave', event)
368
- hideCellLinkTooltip(event)
369
- },
370
- onCellLinkClick: (event) => handleCellLinkClick(event),
371
- onImageLinkClick: (event) => handleImageLinkClick(event),
372
- onFloatContextMenu: (event) => emit('float-context-menu', event),
373
- // body 菜单超链接项 → 拉起配置弹窗;右键「预览」→ 打开 lightbox
374
- openHyperlinkPopup,
375
- openImagePreview
376
- })
352
+ const { rebuildGrid, activateGrid, pruneCache, getGrid, setSelectionAnchor, setRefHighlights } =
353
+ useSheetGrid({
354
+ props,
355
+ gridRef,
356
+ getActiveSheet: () => activeSheet.value,
357
+ context,
358
+ formulaBarRef,
359
+ // 工具栏「函数」弹框打开期间与 fx 入口一致:画布点击不清除目标格高亮
360
+ isFunctionPopupOpen: () => popupTool.value?.popup === 'functions',
361
+ onColResizeEnd: (event) => emit('col-resize-end', event),
362
+ // 引擎链接 / 浮动图事件透传(openCellLinkOnClick=false:链接格直开、图片链接确认后开);
363
+ // hover/leave 同时喂给 tooltip 状态机(与组件 emit 同源)
364
+ onCellLinkHover: (event) => {
365
+ emit('cell-link-hover', event)
366
+ showCellLinkTooltip(event)
367
+ },
368
+ onCellLinkLeave: (event) => {
369
+ emit('cell-link-leave', event)
370
+ hideCellLinkTooltip(event)
371
+ },
372
+ onCellLinkClick: (event) => handleCellLinkClick(event),
373
+ onImageLinkClick: (event) => handleImageLinkClick(event),
374
+ onFloatContextMenu: (event) => emit('float-context-menu', event),
375
+ // body 菜单超链接项 → 拉起配置弹窗;右键「预览」→ 打开 lightbox
376
+ openHyperlinkPopup,
377
+ openImagePreview
378
+ })
377
379
 
378
380
  const exposed: _SheetExposed = {
379
381
  workbook,
@@ -1,6 +1,9 @@
1
1
  /** 引用选择上下文:光标前一个非空字符属于此集合时可插入单元格引用 */
2
2
  const REF_TRIGGER_CHARS = new Set(['=', '(', ',', '+', '-', '*', '/', '^', '&', '<', '>'])
3
3
 
4
+ /** 引用拾取染色框循环色板(对齐 Excel 蓝/绿/红循环惯例),按引用在公式中的出现顺序取色 */
5
+ export const REF_HIGHLIGHT_COLORS = ['#2563eb', '#16a34a', '#dc2626'] as const
6
+
4
7
  /**
5
8
  * 判定是否处于「可插入引用」位置(无状态:每次按文本 + 光标重算)。
6
9
  * `-` 的一元/二元歧义基础版不区分(`A1-` 后框选 → `A1-B2`,合法且误判无害)。
@@ -29,6 +32,16 @@ export function insertRefText(
29
32
  ): InsertRefResult {
30
33
  const start = Math.min(cursor, selectionEnd)
31
34
  const end = Math.max(cursor, selectionEnd)
35
+ return replaceRefText(text, start, end, rangeText)
36
+ }
37
+
38
+ /** 替换 [start, end) 区间为引用文本(shift+点选扩展:扩展上次插入的引用) */
39
+ export function replaceRefText(
40
+ text: string,
41
+ start: number,
42
+ end: number,
43
+ rangeText: string
44
+ ): InsertRefResult {
32
45
  const next = text.slice(0, start) + rangeText + text.slice(end)
33
46
  return { text: next, cursor: start + rangeText.length }
34
47
  }
@@ -10,6 +10,7 @@ import type {
10
10
  import type { CellAddress, CellRange } from 'infinitable/sheet'
11
11
  import type { Sheet } from 'infinitable/sheet'
12
12
  import { SheetGrid, type SheetGridContextMenuInfo } from 'infinitable/sheet'
13
+ import type { SheetGridHighlight } from 'infinitable/sheet'
13
14
  import { onBeforeUnmount, onMounted, watch } from 'vue'
14
15
 
15
16
  import type { SheetContext } from '../../tools/context'
@@ -33,11 +34,13 @@ export interface FormulaBarMirror {
33
34
  exitMirror: (addr: CellAddress) => void
34
35
  /** fx 编辑中且处于可插入引用位置 */
35
36
  isRefSelecting: () => boolean
37
+ /** 引用拾取延续中(上次插入的引用可被点选替换/扩展) */
38
+ hasRefInsert: () => boolean
36
39
  /** 函数弹框打开中(fx 入口)——画布点击不清除目标格高亮 */
37
40
  isFunctionPopupOpen: () => boolean
38
- /** 网格 pointerdown → 挂起 blur 提交 */
41
+ /** 网格 pointerdown → 挂起 blur 提交(引用选择或拾取会话延续中) */
39
42
  beginBlurSuppress: () => void
40
- /** 画布选区 → 插入引用文本 */
43
+ /** 画布选区 → 插入/替换引用文本(拾取会话延续中替换上次插入的引用) */
41
44
  handleRefSelect: (range: CellRange) => void
42
45
  }
43
46
 
@@ -198,10 +201,13 @@ export function useSheetGrid(options: UseSheetGridOptions) {
198
201
  onEditStart: (addr) => formulaBarRef.value?.mirrorGridEdit(addr),
199
202
  onEditEnd: (addr) => formulaBarRef.value?.exitMirror(addr),
200
203
  onColResizeEnd: options.onColResizeEnd,
201
- // 引用选择:不回写模型选区,序列化为 A1 / A1:B2 交给公式栏;
202
- // 函数弹框打开期间(fx / 工具栏两入口)同样拦截,画布点击不离开目标格
204
+ // 引用选择:不回写模型选区,序列化为 A1 / A1:B2 交给公式栏;函数弹框打开期间
205
+ // (fx / 工具栏两入口)同样拦截,画布点击不离开目标格;拾取会话延续中(上次插入
206
+ // 的引用未被打断)任何点击都拦截——Excel Point mode:普通点选替换上次引用、
207
+ // shift 点选以上次锚点扩展,编辑不中断
203
208
  interceptSelection: () =>
204
209
  (formulaBarRef.value?.isRefSelecting() ?? false) ||
210
+ (formulaBarRef.value?.hasRefInsert() ?? false) ||
205
211
  (formulaBarRef.value?.isFunctionPopupOpen() ?? false) ||
206
212
  (options.isFunctionPopupOpen?.() ?? false),
207
213
  onSelectionIntercept: (range) => formulaBarRef.value?.handleRefSelect(range)
@@ -305,10 +311,11 @@ export function useSheetGrid(options: UseSheetGridOptions) {
305
311
  const sheet = getActiveSheet()
306
312
  const host = gridRef.value
307
313
  if (!host) return
308
- // 换实例前清旧实例的选区锚点:fx 编辑会话随切 sheet 结束(公式栏同步复位
309
- // 编辑态),缓存实例复用时不得残留上次会话的高亮
314
+ // 换实例前清旧实例的编辑会话视图态(选区锚点 + 引用染色框):fx 编辑会话随切
315
+ // sheet 结束(公式栏同步复位编辑态),缓存实例复用时不得残留上次会话的高亮
310
316
  if (active && active.sheet !== sheet) {
311
317
  active.grid.setSelectionAnchor(null)
318
+ active.grid.setHighlightRanges([])
312
319
  }
313
320
  const cached = cache.get(sheet)
314
321
  if (cached && !cached.dirty) {
@@ -405,5 +412,17 @@ export function useSheetGrid(options: UseSheetGridOptions) {
405
412
  active?.grid.setSelectionAnchor(addr)
406
413
  }
407
414
 
408
- return { rebuildGrid, activateGrid, pruneCache, getGrid: () => active?.grid, setSelectionAnchor }
415
+ /** 公式引用染色框同步(公式栏 → 活动实例透传;空数组清除;无活动实例时静默) */
416
+ function setRefHighlights(items: readonly SheetGridHighlight[]): void {
417
+ active?.grid.setHighlightRanges(items)
418
+ }
419
+
420
+ return {
421
+ rebuildGrid,
422
+ activateGrid,
423
+ pruneCache,
424
+ getGrid: () => active?.grid,
425
+ setSelectionAnchor,
426
+ setRefHighlights
427
+ }
409
428
  }