Skip to content

Commit 3ee044f

Browse files
rahulyadav5524Mihran Margaryan
authored andcommitted
fixed selection issue and highlight fixes
1 parent 1492ea6 commit 3ee044f

File tree

10 files changed

+77
-39
lines changed

10 files changed

+77
-39
lines changed

packages/core/src/data-editor/data-editor.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
894894
const maxColumnWidth = Math.max(maxColumnWidthIn, minColumnWidth);
895895
const maxColumnAutoWidth = Math.max(maxColumnAutoWidthIn ?? maxColumnWidth, minColumnWidth);
896896

897-
const freezeLeftColumns = typeof freezeColumns === "number" ? freezeColumns: freezeColumns[0];
897+
const freezeLeftColumns = typeof freezeColumns === "number" ? freezeColumns : freezeColumns[0];
898898
const freezeRightColumns = typeof freezeColumns === "number" ? 0 : freezeColumns[1];
899899

900900
const docStyle = React.useMemo(() => {
@@ -1564,7 +1564,8 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
15641564
}
15651565

15661566
// scrollBounds is already scaled
1567-
let sLeft = frozenLeftWidth * scale + scrollBounds.left + rowMarkerOffset * rowMarkerWidth * scale;
1567+
let sLeft =
1568+
frozenLeftWidth * scale + scrollBounds.left + rowMarkerOffset * rowMarkerWidth * scale;
15681569
let sRight = scrollBounds.right - frozenRightWidth * scale;
15691570
let sTop = scrollBounds.top + totalHeaderHeight * scale;
15701571
let sBottom = scrollBounds.bottom - trailingRowHeight * scale;

packages/core/src/internal/data-grid/data-grid.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,11 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
612612
let isEdge = bounds !== undefined && bounds.x + bounds.width - posX <= edgeDetectionBuffer;
613613

614614
const previousCol = col - 1;
615-
if (posX - bounds.x <= edgeDetectionBuffer && previousCol >= 0) {
615+
if (
616+
posX - bounds.x <= edgeDetectionBuffer &&
617+
previousCol >= 0 &&
618+
col < mappedColumns.length - freezeRightColumns
619+
) {
616620
isEdge = true;
617621
bounds = getBoundsForItem(canvas, previousCol, row);
618622
assert(bounds !== undefined);
@@ -709,6 +713,7 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
709713
selection,
710714
totalHeaderHeight,
711715
freezeColumns,
716+
freezeRightColumns,
712717
]
713718
);
714719

packages/core/src/internal/data-grid/render/data-grid-lib.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ export function getColumnIndexForX(
279279
const colIdx = effectiveColumns.length - 1 - fc;
280280
const col = effectiveColumns[colIdx];
281281
y -= col.width;
282-
if (targetX <= y) {
282+
if (targetX >= y) {
283283
return col.sourceIndex;
284284
}
285285
}
@@ -818,24 +818,30 @@ export function computeBounds(
818818

819819
const freezeLeftColumns = typeof freezeColumns === "number" ? freezeColumns : freezeColumns[0];
820820
const freezeRightColumns = typeof freezeColumns === "number" ? 0 : freezeColumns[1];
821+
const column = mappedColumns[col];
821822

822823
if (col >= mappedColumns.length || row >= rows || row < -2 || col < 0) {
823824
return result;
824825
}
825826

826827
const headerHeight = totalHeaderHeight - groupHeaderHeight;
827828

828-
if (col >= freezeLeftColumns) {
829+
if (col >= freezeLeftColumns && col < mappedColumns.length - freezeRightColumns) {
829830
const dir = cellXOffset > col ? -1 : 1;
830-
const [freezeLeftWidth, freezeRightWidth] = getStickyWidth(mappedColumns);
831+
const [freezeLeftWidth] = getStickyWidth(mappedColumns);
831832
result.x += freezeLeftWidth + translateX;
832833
for (let i = cellXOffset; i !== col; i += dir) {
833834
result.x += mappedColumns[dir === 1 ? i : i - 1].width * dir;
834835
}
835-
} else {
836+
} else if (column.stickyPosition === "left") {
836837
for (let i = 0; i < col; i++) {
837838
result.x += mappedColumns[i].width;
838839
}
840+
} else if (column.stickyPosition === "right") {
841+
result.x = width;
842+
for (let i = col; i < mappedColumns.length; i++) {
843+
result.x -= mappedColumns[i].width;
844+
}
839845
}
840846
result.width = mappedColumns[col].width + 1;
841847

@@ -871,7 +877,7 @@ export function computeBounds(
871877
end++;
872878
}
873879
if (!sticky) {
874-
const [freezeLeftWidth, freezeRightWidth] = getStickyWidth(mappedColumns);
880+
const [freezeLeftWidth] = getStickyWidth(mappedColumns);
875881
const clip = result.x - freezeLeftWidth;
876882
if (clip < 0) {
877883
result.x -= clip;

packages/core/src/internal/data-grid/render/data-grid-render.blit.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ export function blitLastFrame(
147147
args.dw = blitWidth * dpr;
148148

149149
drawRegions.push({
150-
x: width + deltaX,
150+
x: width + deltaX - stickyRightWidth,
151151
y: 0,
152-
width: -deltaX,
152+
width: -deltaX + stickyRightWidth,
153153
height: height,
154154
});
155155
}
@@ -168,6 +168,17 @@ export function blitLastFrame(
168168
const h = height * dpr;
169169
ctx.drawImage(blitSource, 0, 0, w, h, 0, 0, w, h);
170170
}
171+
if (
172+
stickyRightWidth > 0 &&
173+
deltaX !== 0 &&
174+
deltaY === 0 &&
175+
(targetScroll === undefined || blitSourceScroll?.[1] !== false)
176+
) {
177+
const x = (width - stickyRightWidth) * dpr;
178+
const w = stickyRightWidth * dpr;
179+
const h = height * dpr;
180+
ctx.drawImage(blitSource, x, 0, w, h, x, 0, w, h);
181+
}
171182
if (
172183
freezeTrailingRowsHeight > 0 &&
173184
deltaX === 0 &&

packages/core/src/internal/data-grid/render/data-grid-render.cells.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ export function drawCells(
299299

300300
const bgCell = cell.kind === GridCellKind.Protected ? theme.bgCellMedium : theme.bgCell;
301301
let fill: string | undefined;
302-
if (isSticky || bgCell !== outerTheme.bgCell) {
302+
if (isSticky || bgCell !== outerTheme.bgCell || c.sticky) {
303303
fill = blend(bgCell, fill);
304304
}
305305

packages/core/src/internal/data-grid/render/data-grid-render.header.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ export function drawGridHeaders(
6969
? outerTheme
7070
: mergeAndRealizeTheme(outerTheme, groupTheme, c.themeOverride);
7171

72+
if (c.sticky) {
73+
ctx.fillStyle = theme.bgHeader;
74+
ctx.fill();
75+
}
76+
7277
if (theme.bgHeader !== outerTheme.bgHeader) {
7378
ctx.fillStyle = theme.bgHeader;
7479
ctx.fill();

packages/core/src/internal/data-grid/render/data-grid-render.lines.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ export function drawGridLines(
331331
for (let index = 0; index < effectiveCols.length; index++) {
332332
const c = effectiveCols[index];
333333
if (c.width === 0) continue;
334+
if (c.sticky && c.stickyPosition !== "left") break;
334335
x += c.width;
335336
const tx = c.sticky ? x : x + translateX;
336337
if (tx >= minX && tx <= maxX && verticalBorder(index + 1)) {
@@ -344,23 +345,23 @@ export function drawGridLines(
344345
}
345346
}
346347

347-
// let rightX = 0.5;
348-
// for (let index = effectiveCols.length - 1; index >= 0; index--) {
349-
// const c = effectiveCols[index];
350-
// if (c.width === 0) continue;
351-
// if (!c.sticky) break;
352-
// rightX += c.width;
353-
// const tx = c.sticky ? rightX : rightX + translateX;
354-
// if (tx >= minX && tx <= maxX && verticalBorder(index + 1)) {
355-
// toDraw.push({
356-
// x1: tx,
357-
// y1: Math.max(groupHeaderHeight, minY),
358-
// x2: tx,
359-
// y2: Math.min(height, maxY),
360-
// color: vColor,
361-
// });
362-
// }
363-
// }
348+
let rightX = width + 0.5;
349+
for (let index = effectiveCols.length - 1; index >= 0; index--) {
350+
const c = effectiveCols[index];
351+
if (c.width === 0) continue;
352+
if (!c.sticky) break;
353+
rightX -= c.width;
354+
const tx = rightX;
355+
if (tx >= minX && tx <= maxX && verticalBorder(index + 1)) {
356+
toDraw.push({
357+
x1: tx,
358+
y1: Math.max(groupHeaderHeight, minY),
359+
x2: tx,
360+
y2: Math.min(height, maxY),
361+
color: vColor,
362+
});
363+
}
364+
}
364365

365366
let freezeY = height + 0.5;
366367
for (let i = rows - freezeTrailingRows; i < rows; i++) {

packages/core/src/internal/data-grid/render/data-grid-render.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,18 @@ export function drawGrid(arg: DrawGridArg, lastArg: DrawGridArg | undefined) {
418418
height: freezeTrailingRows,
419419
when: freezeTrailingRows > 0,
420420
},
421+
{
422+
x: viewRegionWidth - freezeRightColumns,
423+
y: cellYOffset,
424+
width: freezeRightColumns,
425+
height: 300,
426+
},
427+
{
428+
x: viewRegionWidth - freezeRightColumns,
429+
y: -2,
430+
width: freezeRightColumns,
431+
height: 2,
432+
},
421433
]);
422434

423435
const doDamage = (ctx: CanvasRenderingContext2D) => {

packages/core/src/internal/data-grid/render/data-grid.render.rings.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,13 @@ export function drawHighlightRings(
3434

3535
const [freezeLeft, freezeRight] = getStickyWidth(mappedColumns);
3636
const freezeBottom = getFreezeTrailingHeight(rows, freezeTrailingRows, rowHeight);
37-
const splitIndices = [freezeLeftColumns, 0, mappedColumns.length, rows - freezeTrailingRows] as const;
38-
const splitLocations = [freezeLeft, 0, width, height - freezeBottom] as const;
37+
const splitIndices = [
38+
freezeLeftColumns,
39+
0,
40+
mappedColumns.length - freezeRightColumns,
41+
rows - freezeTrailingRows,
42+
] as const;
43+
const splitLocations = [freezeLeft, 0, width - freezeRight, height - freezeBottom] as const;
3944

4045
const drawRects = highlightRegions.map(h => {
4146
const r = h.range;

packages/core/src/internal/scrolling-data-grid/scrolling-data-grid.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ const GridScroller: React.FunctionComponent<ScrollingDataGridProps> = p => {
103103
const lastSize = React.useRef<readonly [number, number] | undefined>();
104104

105105
const freezeLeftColumns = typeof freezeColumns === "number" ? freezeColumns : freezeColumns[0];
106-
const freezeRightColumns = typeof freezeColumns === "number"? 0 : freezeColumns[1];
107106

108107
const width = nonGrowWidth + Math.max(0, overscrollX ?? 0);
109108

@@ -222,14 +221,7 @@ const GridScroller: React.FunctionComponent<ScrollingDataGridProps> = p => {
222221
args.width !== lastSize.current?.[0] ||
223222
args.height !== lastSize.current?.[1]
224223
) {
225-
onVisibleRegionChanged?.(
226-
rect,
227-
args.width,
228-
args.height,
229-
args.paddingRight ?? 0,
230-
tx,
231-
ty
232-
);
224+
onVisibleRegionChanged?.(rect, args.width, args.height, args.paddingRight ?? 0, tx, ty);
233225
last.current = rect;
234226
lastX.current = tx;
235227
lastY.current = ty;

0 commit comments

Comments
 (0)