diff --git a/apps/sheets/src/renderer/App.tsx b/apps/sheets/src/renderer/App.tsx index 9a60e54..eb36974 100644 --- a/apps/sheets/src/renderer/App.tsx +++ b/apps/sheets/src/renderer/App.tsx @@ -146,6 +146,12 @@ import { import { InMemoryWorkbookAdapter } from '../domain/in-memory-workbook' import { cfRuleUnsaveableReason, iconSetSaveable } from '../gateway/xlsx-cf' import { installLazyFindBridge } from './lazy-find' +import { + installCrossHighlight, + loadCrossHighlightPreference, + storeCrossHighlightPreference, + type CrossHighlightHandle, +} from './cross-highlight' import type { ApplyOutcome, ChangePlan } from '../domain/workbook.types' import { createElectronTransport } from './ai/transport' import { MAX_READ_RANGE_CELLS, type ActiveSheetInfo, type SheetsSkillDeps } from './ai/tools' @@ -401,6 +407,10 @@ export function App(): React.JSX.Element { /// App-level setting, Excel-style: not stored in the file, kept across /// workbook switches. const [formulaBarVisible, setFormulaBarVisible] = useState(true) + /// Cross-highlight ("reading mode") of the active row/column, persisted in + /// localStorage like the auto-save flag; off until the user opts in. + const [crossHighlightVisible, setCrossHighlightVisible] = useState(loadCrossHighlightPreference) + const crossHighlightRef = useRef(null) const visualInstallTimerRef = useRef | null>(null) const sparklineDisposablesRef = useRef<{ dispose(): void }[]>([]) const sparklineTimerRef = useRef | null>(null) @@ -1479,6 +1489,32 @@ export function App(): React.JSX.Element { // Ctrl+F covers every row of a streamed workbook, not just the loaded // window: the bridge pages the underlying file for out-of-window hits. const lazyFindDisposable = installLazyFindBridge({ runtime, lazyWorkbookRef, setMessage }) + // Cross-highlight bands track the active cell while the View toggle is on. + crossHighlightRef.current = installCrossHighlight(runtime, { + extents: () => { + // Mirror page-break preview: bands must reach past the data extent, + // so take the max of the file-backed numbers (shifted through the + // journal's structural ops) and whatever has already streamed in — + // clicking a legitimate grid cell beyond the last data row keeps its + // row/column highlighted. + const state = lazyWorkbookRef.current + const worksheet = univerRef.current?.univerAPI.getActiveWorkbook()?.getActiveSheet() + if (!worksheet) return null + const sheetId = worksheet.getSheetId() + const loadedRows = worksheet.getLastRow() + 1 + const loadedColumns = worksheet.getLastColumn() + 1 + const fileSheet = state?.file.sheets.find((sheet) => sheet.id === sheetId) + if (!state || !fileSheet) { + return { rows: loadedRows, columns: loadedColumns } + } + const ops = state.editJournal.structuralOps.get(sheetId) ?? [] + return { + rows: Math.max(fileSheet.rowCount + netAxisDelta(ops, 'row'), loadedRows), + columns: Math.max(fileSheet.columnCount + netAxisDelta(ops, 'column'), loadedColumns), + } + }, + }) + crossHighlightRef.current.setVisible(crossHighlightVisible) const scrollDisposable = runtime.univerAPI.addEvent( runtime.univerAPI.Event.Scroll, (params) => { @@ -2333,6 +2369,8 @@ export function App(): React.JSX.Element { dataValidationArrowDisposable.dispose() ruleDetailDisposable() lazyFindDisposable.dispose() + crossHighlightRef.current?.dispose() + crossHighlightRef.current = null scrollDisposable.dispose() zoomDisposable.dispose() editStartDisposable.dispose() @@ -2360,6 +2398,11 @@ export function App(): React.JSX.Element { } }, []) + // The bands live outside React; mirror the toggle into the installer. + useEffect(() => { + crossHighlightRef.current?.setVisible(crossHighlightVisible) + }, [crossHighlightVisible]) + function handleSend( overrideInstruction?: string, overrideAttachments?: readonly AttachmentMeta[], @@ -3627,6 +3670,13 @@ export function App(): React.JSX.Element { togglePageBreakPreview() return } + if (command === 'toggle-cross-highlight') { + const next = !crossHighlightVisible + setCrossHighlightVisible(next) + storeCrossHighlightPreference(next) + setMessage(t(next ? 'appCrossHighlightOn' : 'appCrossHighlightOff')) + return + } if (command === 'toggle-formula-bar') { const next = !formulaBarVisible document.getElementById('univer-container')?.classList.toggle('formula-bar-hidden', !next) @@ -4261,6 +4311,7 @@ export function App(): React.JSX.Element { onGetSheetProtection={sheetProtectionEcho} onGetWorkbookProtection={workbookProtectionEcho} formulaBarVisible={formulaBarVisible} + crossHighlightVisible={crossHighlightVisible} onGetProtectedRanges={protectedRangesSnapshot} onApplyProtectedRanges={applyProtectedRanges} onGetDefinedNames={definedNameRows} diff --git a/apps/sheets/src/renderer/ExcelShell.tsx b/apps/sheets/src/renderer/ExcelShell.tsx index f47e572..01b7180 100644 --- a/apps/sheets/src/renderer/ExcelShell.tsx +++ b/apps/sheets/src/renderer/ExcelShell.tsx @@ -201,6 +201,8 @@ interface ExcelShellProps { /// Effective workbook structure lock (null = no file open). readonly onGetWorkbookProtection: () => boolean | null readonly formulaBarVisible: boolean + /// Cross-highlight ("reading mode") of the active row/column, echoed by the View checkbox. + readonly crossHighlightVisible: boolean /// Allow-edit ranges of the active sheet, read when the dialog opens. readonly onGetProtectedRanges: () => { ranges: readonly { name: string; sqref: string; hasPassword: boolean }[] @@ -288,6 +290,7 @@ export function ExcelShell({ onGetSheetProtection, onGetWorkbookProtection, formulaBarVisible, + crossHighlightVisible, onGetProtectedRanges, onApplyProtectedRanges, onGetDefinedNames, @@ -510,6 +513,7 @@ export function ExcelShell({ sheetProtected={onGetSheetProtection()} workbookProtected={onGetWorkbookProtection()} formulaBarVisible={formulaBarVisible} + crossHighlightVisible={crossHighlightVisible} pageLayout={pageLayout} selectedChart={selectedChart} onListNames={() => { @@ -1145,6 +1149,7 @@ function Ribbon({ sheetProtected, workbookProtected, formulaBarVisible, + crossHighlightVisible, pageLayout, selectedChart, onCommand, @@ -1163,6 +1168,7 @@ function Ribbon({ readonly workbookProtected: boolean | null /// View > Show echo for the formula bar toggle (app-level, not per sheet). readonly formulaBarVisible: boolean + readonly crossHighlightVisible: boolean readonly pageLayout: PageLayoutEcho readonly selectedChart: SelectedChartRibbon | null readonly onCommand: (command: string) => void @@ -2246,6 +2252,14 @@ function Ribbon({ {pageLayout.showHeadings ? '✓' : ''} {t('appHeadings')} + diff --git a/apps/sheets/src/renderer/cross-highlight.tsx b/apps/sheets/src/renderer/cross-highlight.tsx new file mode 100644 index 0000000..9bd5876 --- /dev/null +++ b/apps/sheets/src/renderer/cross-highlight.tsx @@ -0,0 +1,236 @@ +/** + * Cross-highlight ("reading mode"): while navigating, the active cell's whole + * row and column carry a translucent band so wide sheets stay readable + * (issue #112). The bands are float-DOM layers anchored to ranges — the same + * mechanism the page-break preview and formula-audit traces use — so they + * scroll and zoom with the grid. Off by default; the View tab toggles it and + * the choice persists in localStorage. + */ +import type { UniverRuntime } from './univer-state' + +interface Disposable { + dispose(): void +} + +/// Float-DOM layers are not free: cap the walked extent so a million-row +/// sheet cannot freeze the grid (the page-break preview draws the line at +/// the same numbers). Beyond the cap the bands simply stop short. +export const CROSS_HIGHLIGHT_MAX_ROWS = 20_000 +export const CROSS_HIGHLIGHT_MAX_COLUMNS = 2_000 + +/** One translucent band anchored over the grid. */ +export interface CrossHighlightLayer { + readonly key: 'row' | 'column' + readonly startRow: number + readonly startColumn: number + readonly rowCount: number + readonly columnCount: number +} + +/// The row and column bands covering an active cell, clamped to the walked +/// extent. Empty when the cell sits outside the extent (freshly inserted +/// rows before metadata catches up, for example). +export function crossHighlightLayers( + activeRow: number, + activeColumn: number, + extentRows: number, + extentColumns: number, +): CrossHighlightLayer[] { + // Zero/negative extents mean the sheet metadata is not ready yet. + if (!(extentRows > 0) || !(extentColumns > 0)) return [] + const rows = Math.min(Math.max(Math.floor(extentRows), 1), CROSS_HIGHLIGHT_MAX_ROWS) + const columns = Math.min(Math.max(Math.floor(extentColumns), 1), CROSS_HIGHLIGHT_MAX_COLUMNS) + if (!Number.isFinite(activeRow) || !Number.isFinite(activeColumn)) return [] + if (activeRow < 0 || activeColumn < 0 || activeRow >= rows || activeColumn >= columns) return [] + return [ + { key: 'row', startRow: activeRow, startColumn: 0, rowCount: 1, columnCount: columns }, + { key: 'column', startRow: 0, startColumn: activeColumn, rowCount: rows, columnCount: 1 }, + ] +} + +const STORAGE_KEY = 'ai-sheets-cross-highlight' + +/** + * Per-axis maximum of two extent sources (either may be missing): the + * file-backed sheet extent and the grid's loaded extent. Null only when + * neither source knows anything. + */ +export function mergeExtents( + primary: { rows: number; columns: number } | null | undefined, + secondary: { rows: number; columns: number } | null | undefined, +): { rows: number; columns: number } | null { + if (!primary && !secondary) return null + return { + rows: Math.max(primary?.rows ?? 0, secondary?.rows ?? 0), + columns: Math.max(primary?.columns ?? 0, secondary?.columns ?? 0), + } +} + +/** The persisted View-tab toggle; defaults to off (also headless-safe). */ +export function loadCrossHighlightPreference(): boolean { + try { + return window.localStorage.getItem(STORAGE_KEY) === '1' + } catch { + // No localStorage (tests, blocked storage): the safe default is off. + return false + } +} + +export function storeCrossHighlightPreference(enabled: boolean): void { + try { + window.localStorage.setItem(STORAGE_KEY, enabled ? '1' : '0') + } catch { + // Preference stays session-only when storage is unavailable. + } +} + +export interface CrossHighlightOptions { + /// Sheet data extent in screen coordinates; under lazy streaming + /// getLastRow/getLastColumn only see what already streamed in, so the app + /// supplies the file-backed numbers (null falls back to the loaded ones). + extents: () => { rows: number; columns: number } | null +} + +export interface CrossHighlightHandle { + setVisible(visible: boolean): void + dispose(): void +} + +/** Milliseconds of selection settle time before reinstalling the bands. */ +const SETTLE_MS = 60 + +/** + * Subscribes to selection/sheet changes once and keeps two float-DOM bands + * tracking the active cell whenever the feature is enabled. Reinstalling a + * band means disposing and re-adding it (float anchors are static), which + * is why moves are debounced and skipped when the cell did not change. + */ +export function installCrossHighlight( + runtime: UniverRuntime, + options: CrossHighlightOptions, +): CrossHighlightHandle { + let visible = false + let layers: Disposable[] = [] + let installedKey = '' + let prefix = 0 + let settleTimer: ReturnType | null = null + + const clearLayers = (): void => { + for (const layer of layers) { + try { + layer.dispose() + } catch { + // The float layer already died with a closed workbook or sheet. + } + } + layers = [] + installedKey = '' + } + + const apply = (): void => { + settleTimer = null + if (!visible) return + let position: { sheetId: string; row: number; column: number } | null = null + try { + const workbook = runtime.univerAPI.getActiveWorkbook() + const worksheet = workbook?.getActiveSheet() + const range = workbook?.getActiveRange() + if (workbook && worksheet && range) { + position = { + sheetId: worksheet.getSheetId(), + row: range.getRow(), + column: range.getColumn(), + } + } + } catch { + position = null + } + if (!position) { + clearLayers() + return + } + const key = `${position.sheetId}:${position.row}:${position.column}` + if (key === installedKey) return + clearLayers() + const loaded = (() => { + try { + const worksheet = runtime.univerAPI.getActiveWorkbook()?.getActiveSheet() + if (!worksheet) return null + return { rows: worksheet.getLastRow() + 1, columns: worksheet.getLastColumn() + 1 } + } catch { + return null + } + })() + // Mirror page-break preview: the bands must reach past the data extent, + // so take the max of what the app reports (file-backed, journal-shifted) + // and whatever has already streamed into the grid. + const extent = mergeExtents(options.extents(), loaded) + const bands = crossHighlightLayers( + position.row, + position.column, + extent?.rows ?? 1, + extent?.columns ?? 1, + ) + if (bands.length === 0) return + prefix += 1 + const worksheet = (() => { + try { + return runtime.univerAPI.getActiveWorkbook()?.getSheetBySheetId(position!.sheetId) ?? null + } catch { + return null + } + })() + if (!worksheet) return + for (const band of bands) { + const componentKey = `sheets-crosshair-${prefix}-${band.key}` + try { + layers.push( + runtime.univerAPI.registerComponent(componentKey, () => ( +
+ )), + ) + const floating = worksheet.addFloatDomToRange( + worksheet.getRange(band.startRow, band.startColumn, band.rowCount, band.columnCount), + { componentKey, allowTransform: false, eventPassThrough: true }, + {}, + componentKey, + ) + if (floating) layers.push(floating) + } catch { + // Closed workbook mid-install; drop whatever landed. + clearLayers() + return + } + } + installedKey = key + } + + const schedule = (): void => { + if (!visible) return + if (settleTimer !== null) clearTimeout(settleTimer) + settleTimer = setTimeout(apply, SETTLE_MS) + } + + const disposables: Disposable[] = [] + disposables.push(runtime.univerAPI.addEvent(runtime.univerAPI.Event.SelectionChanged, schedule)) + disposables.push(runtime.univerAPI.addEvent(runtime.univerAPI.Event.ActiveSheetChanged, schedule)) + + return { + setVisible(next: boolean): void { + visible = next + if (!next) { + if (settleTimer !== null) clearTimeout(settleTimer) + settleTimer = null + clearLayers() + return + } + apply() + }, + dispose(): void { + if (settleTimer !== null) clearTimeout(settleTimer) + settleTimer = null + clearLayers() + for (const disposable of disposables) disposable.dispose() + }, + } +} diff --git a/apps/sheets/src/renderer/i18n/strings-app.ts b/apps/sheets/src/renderer/i18n/strings-app.ts index 0003086..1e3a2f7 100644 --- a/apps/sheets/src/renderer/i18n/strings-app.ts +++ b/apps/sheets/src/renderer/i18n/strings-app.ts @@ -20,6 +20,9 @@ export const appStrings = defineStrings({ appBreakInserted: '已在所选位置插入分页符', appBreakRemoved: '已删除分页符', appBreakNoneHere: '所选位置没有手动分页符。', + appCrossHighlight: '突出显示活动行和列', + appCrossHighlightOn: '已开启行列高亮。', + appCrossHighlightOff: '已关闭行列高亮。', appPageBreakPreviewTitle: '在网格上显示分页边界', appPageBreakPreviewOn: '已开启分页预览。', appPageBreakPreviewOff: '已关闭分页预览。', @@ -1267,6 +1270,9 @@ export const appStrings = defineStrings({ appBreakInserted: 'page break inserted at the selection', appBreakRemoved: 'page break removed', appBreakNoneHere: 'No manual page break at the selection.', + appCrossHighlight: 'Highlight active row & column', + appCrossHighlightOn: 'Reading highlight on.', + appCrossHighlightOff: 'Reading highlight off.', appPageBreakPreviewTitle: 'Show page boundaries on the grid', appPageBreakPreviewOn: 'Page Break Preview on.', appPageBreakPreviewOff: 'Page Break Preview off.', @@ -2550,6 +2556,9 @@ export const appStrings = defineStrings({ appBreakInserted: '選択位置に改ページを挿入しました', appBreakRemoved: '改ページを解除しました', appBreakNoneHere: '選択位置に手動改ページはありません。', + appCrossHighlight: 'アクティブな行と列を強調表示', + appCrossHighlightOn: '行列ハイライトをオンにしました。', + appCrossHighlightOff: '行列ハイライトをオフにしました。', appPageBreakPreviewTitle: 'グリッドにページの境界を表示', appPageBreakPreviewOn: '改ページプレビューをオンにしました。', appPageBreakPreviewOff: '改ページプレビューをオフにしました。', @@ -3902,6 +3911,9 @@ export const appStrings = defineStrings({ appBreakInserted: '선택한 위치에 페이지 나누기가 삽입됨', appBreakRemoved: '페이지 나누기가 제거됨', appBreakNoneHere: '선택한 위치에 수동 페이지 나누기가 없습니다.', + appCrossHighlight: '활성 행 및 열 강조 표시', + appCrossHighlightOn: '행·열 강조를 켰습니다.', + appCrossHighlightOff: '행·열 강조를 껐습니다.', appPageBreakPreviewTitle: '그리드에 페이지 경계 표시', appPageBreakPreviewOn: '페이지 나누기 미리 보기를 켰습니다.', appPageBreakPreviewOff: '페이지 나누기 미리 보기를 껐습니다.', @@ -5224,6 +5236,9 @@ export const appStrings = defineStrings({ appBreakInserted: 'saut de page inséré à la sélection', appBreakRemoved: 'saut de page supprimé', appBreakNoneHere: 'Aucun saut de page manuel à la sélection.', + appCrossHighlight: 'Surligner la ligne et la colonne actives', + appCrossHighlightOn: 'Surlignage ligne-colonne activé.', + appCrossHighlightOff: 'Surlignage ligne-colonne désactivé.', appPageBreakPreviewTitle: 'Afficher les limites de page sur la grille', appPageBreakPreviewOn: 'Aperçu des sauts de page activé.', appPageBreakPreviewOff: 'Aperçu des sauts de page désactivé.', @@ -6585,6 +6600,9 @@ export const appStrings = defineStrings({ appBreakInserted: 'Seitenumbruch an der Auswahl eingefügt', appBreakRemoved: 'Seitenumbruch entfernt', appBreakNoneHere: 'Kein manueller Seitenumbruch an der Auswahl.', + appCrossHighlight: 'Aktive Zeile und Spalte hervorheben', + appCrossHighlightOn: 'Zeilen-/Spaltenhervorhebung aktiviert.', + appCrossHighlightOff: 'Zeilen-/Spaltenhervorhebung deaktiviert.', appPageBreakPreviewTitle: 'Seitengrenzen im Raster anzeigen', appPageBreakPreviewOn: 'Umbruchvorschau aktiviert.', appPageBreakPreviewOff: 'Umbruchvorschau deaktiviert.', @@ -7932,6 +7950,9 @@ export const appStrings = defineStrings({ appBreakInserted: 'salto de página insertado en la selección', appBreakRemoved: 'salto de página quitado', appBreakNoneHere: 'No hay ningún salto de página manual en la selección.', + appCrossHighlight: 'Resaltar fila y columna activas', + appCrossHighlightOn: 'Resaltado de fila y columna activado.', + appCrossHighlightOff: 'Resaltado de fila y columna desactivado.', appPageBreakPreviewTitle: 'Mostrar los límites de página en la cuadrícula', appPageBreakPreviewOn: 'Vista previa de salto de página activada.', appPageBreakPreviewOff: 'Vista previa de salto de página desactivada.', @@ -9265,6 +9286,9 @@ export const appStrings = defineStrings({ appBreakInserted: 'แทรกตัวแบ่งหน้าที่ตำแหน่งที่เลือกแล้ว', appBreakRemoved: 'เอาตัวแบ่งหน้าออกแล้ว', appBreakNoneHere: 'ไม่มีตัวแบ่งหน้าด้วยตนเองที่ตำแหน่งที่เลือก', + appCrossHighlight: 'ไฮไลต์แถวและคอลัมน์ที่ใช้งาน', + appCrossHighlightOn: 'เปิดการไฮไลต์แถวและคอลัมน์แล้ว', + appCrossHighlightOff: 'ปิดการไฮไลต์แถวและคอลัมน์แล้ว', appPageBreakPreviewTitle: 'แสดงขอบเขตหน้าบนตาราง', appPageBreakPreviewOn: 'เปิดตัวอย่างตัวแบ่งหน้าแล้ว', appPageBreakPreviewOff: 'ปิดตัวอย่างตัวแบ่งหน้าแล้ว', @@ -10534,6 +10558,9 @@ export const appStrings = defineStrings({ appBreakInserted: 'pemisah halaman disisipkan di posisi pilihan', appBreakRemoved: 'pemisah halaman dihapus', appBreakNoneHere: 'Tidak ada pemisah halaman manual di posisi pilihan.', + appCrossHighlight: 'Sorot baris & kolom aktif', + appCrossHighlightOn: 'Sorotan baris-kolom diaktifkan.', + appCrossHighlightOff: 'Sorotan baris-kolom dimatikan.', appPageBreakPreviewTitle: 'Tampilkan batas halaman pada kisi', appPageBreakPreviewOn: 'Pratinjau pemisah halaman diaktifkan.', appPageBreakPreviewOff: 'Pratinjau pemisah halaman dinonaktifkan.', @@ -11831,6 +11858,9 @@ export const appStrings = defineStrings({ appBreakInserted: 'разрыв страницы вставлен в выделенном месте', appBreakRemoved: 'разрыв страницы удалён', appBreakNoneHere: 'В выделенном месте нет ручного разрыва страницы.', + appCrossHighlight: 'Подсвечивать активную строку и столбец', + appCrossHighlightOn: 'Подсветка строки и столбца включена.', + appCrossHighlightOff: 'Подсветка строки и столбца выключена.', appPageBreakPreviewTitle: 'Показывать границы страниц на сетке', appPageBreakPreviewOn: 'Страничный режим включён.', appPageBreakPreviewOff: 'Страничный режим выключен.', @@ -13150,6 +13180,9 @@ export const appStrings = defineStrings({ appBreakInserted: 'تم إدراج فاصل صفحات عند التحديد', appBreakRemoved: 'تمت إزالة فاصل الصفحات', appBreakNoneHere: 'لا يوجد فاصل صفحات يدوي عند التحديد.', + appCrossHighlight: 'تمييز الصف والعمود النشطين', + appCrossHighlightOn: 'تم تشغيل تمييز الصف والعمود.', + appCrossHighlightOff: 'تم إيقاف تمييز الصف والعمود.', appPageBreakPreviewTitle: 'إظهار حدود الصفحات على الشبكة', appPageBreakPreviewOn: 'تم تشغيل معاينة فواصل الصفحات.', appPageBreakPreviewOff: 'تم إيقاف معاينة فواصل الصفحات.', @@ -14420,6 +14453,9 @@ export const appStrings = defineStrings({ appBreakInserted: 'quebra de página inserida na seleção', appBreakRemoved: 'quebra de página removida', appBreakNoneHere: 'Não há quebra de página manual na seleção.', + appCrossHighlight: 'Realçar linha e coluna ativas', + appCrossHighlightOn: 'Realce de linha e coluna ativado.', + appCrossHighlightOff: 'Realce de linha e coluna desativado.', appPageBreakPreviewTitle: 'Mostrar os limites de página na grade', appPageBreakPreviewOn: 'Visualização de quebra de página ativada.', appPageBreakPreviewOff: 'Visualização de quebra de página desativada.', @@ -15752,6 +15788,9 @@ export const appStrings = defineStrings({ appBreakInserted: 'interruzione di pagina inserita nella selezione', appBreakRemoved: 'interruzione di pagina rimossa', appBreakNoneHere: 'Nessuna interruzione di pagina manuale nella selezione.', + appCrossHighlight: 'Evidenzia riga e colonna attive', + appCrossHighlightOn: 'Evidenziazione riga e colonna attivata.', + appCrossHighlightOff: 'Evidenziazione riga e colonna disattivata.', appPageBreakPreviewTitle: 'Mostra i limiti di pagina sulla griglia', appPageBreakPreviewOn: 'Anteprima interruzioni di pagina attivata.', appPageBreakPreviewOff: 'Anteprima interruzioni di pagina disattivata.', @@ -17083,6 +17122,9 @@ export const appStrings = defineStrings({ appBreakInserted: 'wstawiono podział strony w miejscu zaznaczenia', appBreakRemoved: 'usunięto podział strony', appBreakNoneHere: 'Brak ręcznego podziału strony w miejscu zaznaczenia.', + appCrossHighlight: 'Wyróżnij aktywny wiersz i kolumnę', + appCrossHighlightOn: 'Wyróżnianie wiersza i kolumny włączone.', + appCrossHighlightOff: 'Wyróżnianie wiersza i kolumny wyłączone.', appPageBreakPreviewTitle: 'Pokaż granice stron na siatce', appPageBreakPreviewOn: 'Podgląd podziału stron włączony.', appPageBreakPreviewOff: 'Podgląd podziału stron wyłączony.', @@ -18412,6 +18454,9 @@ export const appStrings = defineStrings({ appBreakInserted: 'pagina-einde ingevoegd bij de selectie', appBreakRemoved: 'pagina-einde verwijderd', appBreakNoneHere: 'Geen handmatig pagina-einde bij de selectie.', + appCrossHighlight: 'Actieve rij en kolom markeren', + appCrossHighlightOn: 'Rij-/kolommarkering ingeschakeld.', + appCrossHighlightOff: 'Rij-/kolommarkering uitgeschakeld.', appPageBreakPreviewTitle: 'Paginagrenzen op het raster weergeven', appPageBreakPreviewOn: 'Pagina-eindevoorbeeld ingeschakeld.', appPageBreakPreviewOff: 'Pagina-eindevoorbeeld uitgeschakeld.', @@ -19747,6 +19792,9 @@ export const appStrings = defineStrings({ appBreakInserted: 'pemisah halaman disisipkan pada pemilihan', appBreakRemoved: 'pemisah halaman dialih keluar', appBreakNoneHere: 'Tiada pemisah halaman manual pada pemilihan.', + appCrossHighlight: 'Serlahkan baris & lajur aktif', + appCrossHighlightOn: 'Sorotan baris-lajur dihidupkan.', + appCrossHighlightOff: 'Sorotan baris-lajur dimatikan.', appPageBreakPreviewTitle: 'Tunjukkan sempadan halaman pada grid', appPageBreakPreviewOn: 'Pratonton pemisah halaman dihidupkan.', appPageBreakPreviewOff: 'Pratonton pemisah halaman dimatikan.', @@ -21046,6 +21094,9 @@ export const appStrings = defineStrings({ appBreakInserted: 'מעבר עמוד נוסף במיקום הבחירה', appBreakRemoved: 'מעבר העמוד הוסר', appBreakNoneHere: 'אין מעבר עמוד ידני במיקום הבחירה.', + appCrossHighlight: 'הדגשת השורה והעמודה הפעילות', + appCrossHighlightOn: 'הדגשת שורה ועמודה הופעלה.', + appCrossHighlightOff: 'הדגשת שורה ועמודה כובתה.', appPageBreakPreviewTitle: 'הצג גבולות עמודים על הרשת', appPageBreakPreviewOn: 'תצוגה מקדימה של מעברי עמוד הופעלה.', appPageBreakPreviewOff: 'תצוגה מקדימה של מעברי עמוד כובתה.', @@ -22295,6 +22346,9 @@ export const appStrings = defineStrings({ appBreakInserted: 'चयन के स्थान पर पेज ब्रेक सम्मिलित किया गया', appBreakRemoved: 'पेज ब्रेक हटाया गया', appBreakNoneHere: 'चयन के स्थान पर कोई मैनुअल पेज ब्रेक नहीं है।', + appCrossHighlight: 'सक्रिय पंक्ति और कॉलम हाइलाइट करें', + appCrossHighlightOn: 'पंक्ति-कॉलम हाइलाइट चालू।', + appCrossHighlightOff: 'पंक्ति-कॉलम हाइलाइट बंद।', appPageBreakPreviewTitle: 'ग्रिड पर पेज की सीमाएँ दिखाएँ', appPageBreakPreviewOn: 'पेज ब्रेक पूर्वावलोकन चालू।', appPageBreakPreviewOff: 'पेज ब्रेक पूर्वावलोकन बंद।', @@ -23592,6 +23646,9 @@ export const appStrings = defineStrings({ appBreakInserted: '已在所選位置插入分頁符', appBreakRemoved: '已移除分頁符', appBreakNoneHere: '所選位置沒有手動分頁符。', + appCrossHighlight: '突出顯示作用中列與欄', + appCrossHighlightOn: '已開啟列欄醒目提示。', + appCrossHighlightOff: '已關閉列欄醒目提示。', appPageBreakPreviewTitle: '在格線上顯示分頁邊界', appPageBreakPreviewOn: '已開啟分頁預覽。', appPageBreakPreviewOff: '已關閉分頁預覽。', diff --git a/apps/sheets/src/renderer/styles.css b/apps/sheets/src/renderer/styles.css index 649b829..21d6e07 100644 --- a/apps/sheets/src/renderer/styles.css +++ b/apps/sheets/src/renderer/styles.css @@ -57,6 +57,9 @@ * #1f5aa8 arrows in trace-arrows.tsx) and page-break preview lines */ --sheets-excel-blue: #1f5aa8; --sheets-excel-blue-bg: rgb(31 90 168 / 6%); + /* Cross-highlight ("reading mode") bands over the active row/column */ + --sheets-crosshair-bg: rgb(31 90 168 / 7%); + --sheets-crosshair-line: rgb(31 90 168 / 30%); --sheets-el-selected: #107c41; --sheets-float-btn-bg: rgb(255 255 255 / 92%); --sheets-shape-border: #aeb4b8; @@ -124,6 +127,8 @@ --sheets-chip-bg: #24312a; --sheets-member-bg: #2f2f2f; --sheets-member-ink: #a9b2ac; + --sheets-crosshair-bg: rgb(96 165 250 / 12%); + --sheets-crosshair-line: rgb(96 165 250 / 35%); } @media (prefers-color-scheme: dark) { @@ -152,6 +157,8 @@ --sheets-chip-bg: #24312a; --sheets-member-bg: #2f2f2f; --sheets-member-ink: #a9b2ac; + --sheets-crosshair-bg: rgb(96 165 250 / 12%); + --sheets-crosshair-line: rgb(96 165 250 / 35%); } } @@ -2321,6 +2328,24 @@ textarea:focus { pointer-events: none; } +/* Cross-highlight bands over the active row and column (View tab toggle); + * pass-through float DOM so cell clicks and edits land on the grid */ +.sheets-crosshair-band { + width: 100%; + height: 100%; + box-sizing: border-box; + background: var(--sheets-crosshair-bg); + pointer-events: none; +} + +.sheets-crosshair-band.crosshair-row { + border-bottom: 1px solid var(--sheets-crosshair-line); +} + +.sheets-crosshair-band.crosshair-column { + border-right: 1px solid var(--sheets-crosshair-line); +} + .trace-arrow-layer { width: 100%; height: 100%; diff --git a/apps/sheets/tests/cross-highlight.test.ts b/apps/sheets/tests/cross-highlight.test.ts new file mode 100644 index 0000000..023cd35 --- /dev/null +++ b/apps/sheets/tests/cross-highlight.test.ts @@ -0,0 +1,63 @@ +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([['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) + }) +})