Adds an opt-in reading mode that keeps a translucent band over the active cell's whole row and column while navigating wide sheets. The bands are float-DOM layers anchored to ranges (the same mechanism as the page-break preview), so they follow scroll and zoom; moves are debounced and skipped when the cell did not change. Band extents take the max of the file-backed sheet extent and whatever has already streamed into the grid, so cells beyond the last data row keep their bands. Toggled from the View tab's Show group, persisted in localStorage like the auto-save flag, styled through new --sheets-crosshair-* tokens defined in all three theme blocks. Co-authored-by: Aniruddha Adak <aniruddhaadak80@users.noreply.github.com>
64 lines
2.3 KiB
TypeScript
64 lines
2.3 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest'
|
|
|
|
import {
|
|
CROSS_HIGHLIGHT_MAX_COLUMNS,
|
|
CROSS_HIGHLIGHT_MAX_ROWS,
|
|
crossHighlightLayers,
|
|
loadCrossHighlightPreference,
|
|
mergeExtents,
|
|
} from '../src/renderer/cross-highlight'
|
|
|
|
describe('crossHighlightLayers', () => {
|
|
it('returns one full row and one full column band', () => {
|
|
expect(crossHighlightLayers(4, 2, 100, 26)).toEqual([
|
|
{ key: 'row', startRow: 4, startColumn: 0, rowCount: 1, columnCount: 26 },
|
|
{ key: 'column', startRow: 0, startColumn: 2, rowCount: 100, columnCount: 1 },
|
|
])
|
|
})
|
|
|
|
it('clamps the walked extent to the float-DOM caps', () => {
|
|
const bands = crossHighlightLayers(5, 5, 10_000_000, 500_000)
|
|
expect(bands[0]?.columnCount).toBe(CROSS_HIGHLIGHT_MAX_COLUMNS)
|
|
expect(bands[1]?.rowCount).toBe(CROSS_HIGHLIGHT_MAX_ROWS)
|
|
})
|
|
|
|
it('stays empty outside the extent or on invalid input', () => {
|
|
expect(crossHighlightLayers(-1, 0, 10, 10)).toEqual([])
|
|
expect(crossHighlightLayers(0, -1, 10, 10)).toEqual([])
|
|
expect(crossHighlightLayers(10, 0, 10, 10)).toEqual([])
|
|
expect(crossHighlightLayers(Number.NaN, 0, 10, 10)).toEqual([])
|
|
expect(crossHighlightLayers(0, 0, 0, 0)).toEqual([])
|
|
})
|
|
})
|
|
|
|
describe('mergeExtents', () => {
|
|
it('takes the per-axis maximum so bands reach past the data extent', () => {
|
|
expect(mergeExtents({ rows: 100, columns: 26 }, { rows: 150, columns: 20 })).toEqual({
|
|
rows: 150,
|
|
columns: 26,
|
|
})
|
|
})
|
|
|
|
it('falls back to whichever source exists', () => {
|
|
expect(mergeExtents(null, { rows: 12, columns: 5 })).toEqual({ rows: 12, columns: 5 })
|
|
expect(mergeExtents({ rows: 40, columns: 9 }, null)).toEqual({ rows: 40, columns: 9 })
|
|
expect(mergeExtents(undefined, undefined)).toBeNull()
|
|
})
|
|
})
|
|
|
|
describe('loadCrossHighlightPreference', () => {
|
|
it('reads the stored flag', () => {
|
|
const store = new Map<string, string>([['ai-sheets-cross-highlight', '1']])
|
|
vi.stubGlobal('window', { localStorage: { getItem: (key: string) => store.get(key) ?? null } })
|
|
expect(loadCrossHighlightPreference()).toBe(true)
|
|
store.set('ai-sheets-cross-highlight', '0')
|
|
expect(loadCrossHighlightPreference()).toBe(false)
|
|
vi.unstubAllGlobals()
|
|
})
|
|
|
|
it('defaults to off without a localStorage', () => {
|
|
// No window at all (node test env): must not throw.
|
|
expect(loadCrossHighlightPreference()).toBe(false)
|
|
})
|
|
})
|