Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix(web): sync excel source-locate scrollbar and fix highlight contrast (#20960)

chanx6679a3964b2f
diff --git a/web/src/components/document-preview/hooks.test.ts b/web/src/components/document-preview/hooks.test.ts
index a1c029d052..b791288e2f 100644
--- a/web/src/components/document-preview/hooks.test.ts
+++ b/web/src/components/document-preview/hooks.test.ts
@@ -49,6 +49,8 @@ function mockPreviewer(sheetCount = 2) {
data: datas[0],
reload: jest.fn(),
table: { render: jest.fn() },
+ verticalScrollbar: { move: jest.fn() },
+ horizontalScrollbar: { move: jest.fn() },
},
bottombar: {
items,
@@ -59,25 +61,11 @@ function mockPreviewer(sheetCount = 2) {
}
describe('applyExcelSourceLocate', () => {
- beforeEach(() => {
- jest.spyOn(window, 'getComputedStyle').mockReturnValue({
- getPropertyValue: (name: string) => {
- if (name === '--background-highlight') {
- return 'rgba(76, 164, 231, 0.1)';
- }
- if (name === '--text-title') {
- return 'rgba(22, 22, 24, 1)';
- }
- return '';
- },
- } as CSSStyleDeclaration);
- });
-
afterEach(() => {
jest.restoreAllMocks();
});
- it('selects the 1-based sheet and paints the cell range with theme tokens', () => {
+ it('selects the 1-based sheet, paints the range, and scrolls via the scrollbar', () => {
const previewer = mockPreviewer();
applyExcelSourceLocate(previewer as never, [2, 3, 4, 1, 2]);
@@ -85,8 +73,15 @@ describe('applyExcelSourceLocate', () => {
previewer.xs.bottombar.items[1],
);
expect(previewer.xs.datas[1].addStyle).toHaveBeenCalledWith({
- bgcolor: 'rgba(76, 164, 231, 0.1)',
- color: 'rgba(22, 22, 24, 1)',
+ bgcolor: '#ffe58f',
+ color: '#1a1a1a',
+ });
+ expect(previewer.xs.sheet.horizontalScrollbar.move).toHaveBeenCalledWith({
+ left: 0,
+ });
+ // r1 = 2 rows above at 20px each -> y = 40, and scrolly() needs y - 1.
+ expect(previewer.xs.sheet.verticalScrollbar.move).toHaveBeenCalledWith({
+ top: 39,
});
expect(previewer.xs.datas[1].rows.setCell).toHaveBeenCalledTimes(4);
expect(previewer.xs.datas[1].rows.setCell).toHaveBeenCalledWith(
@@ -111,22 +106,23 @@ describe('applyExcelSourceLocate', () => {
it('falls back to resetData when clickSwap2 is missing', () => {
const previewer = mockPreviewer();
- delete previewer.xs.bottombar.clickSwap2;
+ (previewer.xs.bottombar as { clickSwap2?: unknown }).clickSwap2 = undefined;
applyExcelSourceLocate(previewer as never, [1, 2, 2, 1, 1]);
expect(previewer.xs.sheet.resetData).toHaveBeenCalledWith(
previewer.xs.datas[0],
);
});
- it('uses hex fallbacks when theme tokens are empty', () => {
- jest.spyOn(window, 'getComputedStyle').mockReturnValue({
- getPropertyValue: () => ' ',
- } as CSSStyleDeclaration);
+ it('sets data.scroll directly when the scrollbar API is unavailable', () => {
const previewer = mockPreviewer();
- applyExcelSourceLocate(previewer as never, [1, 2, 2, 1, 1]);
- expect(previewer.xs.datas[0].addStyle).toHaveBeenCalledWith({
- bgcolor: '#ffe58f',
- color: '#1a1a1a',
- });
+ const sheet = previewer.xs.sheet as Record<string, unknown>;
+ sheet.verticalScrollbar = undefined;
+ sheet.horizontalScrollbar = undefined;
+ applyExcelSourceLocate(previewer as never, [1, 3, 3, 1, 1]);
+
+ // r1 = 2 rows above, each 20px high
+ expect(previewer.xs.datas[0].scroll).toEqual({ x: 0, y: 40 });
+ expect(previewer.xs.reRender).toHaveBeenCalled();
+ expect(previewer.xs.sheet.table.render).toHaveBeenCalled();
});
});
diff --git a/web/src/components/document-preview/hooks.ts b/web/src/components/document-preview/hooks.ts
index a0cb3717f9..3b82b0b51c 100644
--- a/web/src/components/document-preview/hooks.ts
+++ b/web/src/components/document-preview/hooks.ts
@@ -235,6 +235,10 @@ type XsData = {
scroll?: { x: number; y: number };
};
+type XsScrollbar = {
+ move: (offset: { top?: number; left?: number }) => unknown;
+};
+
type XsInstance = {
datas: XsData[];
reRender?: () => void;
@@ -243,6 +247,8 @@ type XsInstance = {
data?: XsData & { row?: { height?: number } };
reload?: () => void;
table?: { render?: () => void };
+ verticalScrollbar?: XsScrollbar;
+ horizontalScrollbar?: XsScrollbar;
};
bottombar?: {
items: HTMLElement[];
@@ -284,12 +290,14 @@ export function applyExcelSourceLocate(
c2 = Math.min(c2, lastCol);
}
- const theme = getComputedStyle(document.documentElement);
+ // The spreadsheet canvas is always rendered on a light sheet background
+ // regardless of app theme, so the locate highlight must use fixed light
+ // colors rather than theme tokens (which resolve to near-white text in dark
+ // mode and become invisible). Matches the yellow used by the PDF highlighter.
if (r2 >= r1 && c2 >= c1) {
const styleIdx = data.addStyle({
- bgcolor:
- theme.getPropertyValue('--background-highlight').trim() || '#ffe58f',
- color: theme.getPropertyValue('--text-title').trim() || '#1a1a1a',
+ bgcolor: '#ffe58f',
+ color: '#1a1a1a',
});
for (let r = r1; r <= r2; r++) {
for (let c = c1; c <= c2; c++) {
@@ -314,6 +322,19 @@ export function applyExcelSourceLocate(
for (let r = 0; r < r1; r++) {
y += data.rows.getHeight?.(r) ?? rowHeight;
}
+
+ // Drive the scroll through the library scrollbar: setting data.scroll and
+ // re-rendering directly moves the canvas but leaves the scrollbar thumb at
+ // the top, so the user has to scroll down before they can scroll back up.
+ // move() sets the native scroll element, whose scroll event updates
+ // data.scroll and re-renders the table, keeping both in sync.
+ const vScrollbar = xs.sheet.verticalScrollbar;
+ if (vScrollbar?.move) {
+ xs.sheet.horizontalScrollbar?.move?.({ left: 0 });
+ vScrollbar.move({ top: y > 0 ? y - 1 : 0 });
+ return;
+ }
+
data.scroll = { ...(data.scroll || { x: 0, y: 0 }), x: 0, y };
if (xs.sheet.data && xs.sheet.data !== data) {
xs.sheet.data.scroll = {