Skip to content

Commit b23fdc6

Browse files
fixed selection issue and highlight fixes
1 parent cd454e0 commit b23fdc6

File tree

5 files changed

+39
-27
lines changed

5 files changed

+39
-27
lines changed

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
884884
const maxColumnWidth = Math.max(maxColumnWidthIn, minColumnWidth);
885885
const maxColumnAutoWidth = Math.max(maxColumnAutoWidthIn ?? maxColumnWidth, minColumnWidth);
886886

887-
const freezeLeftColumns = typeof freezeColumns === "number" ? freezeColumns: freezeColumns[0];
887+
const freezeLeftColumns = typeof freezeColumns === "number" ? freezeColumns : freezeColumns[0];
888888
const freezeRightColumns = typeof freezeColumns === "number" ? 0 : freezeColumns[1];
889889

890890
const docStyle = React.useMemo(() => {
@@ -1555,7 +1555,8 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
15551555
}
15561556

15571557
// scrollBounds is already scaled
1558-
let sLeft = frozenLeftWidth * scale + scrollBounds.left + rowMarkerOffset * rowMarkerWidth * scale;
1558+
let sLeft =
1559+
frozenLeftWidth * scale + scrollBounds.left + rowMarkerOffset * rowMarkerWidth * scale;
15591560
let sRight = scrollBounds.right - frozenRightWidth * scale;
15601561
let sTop = scrollBounds.top + totalHeaderHeight * scale;
15611562
let sBottom = scrollBounds.bottom - trailingRowHeight * scale;

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

+11-5
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
}
@@ -810,24 +810,30 @@ export function computeBounds(
810810

811811
const freezeLeftColumns = typeof freezeColumns === "number" ? freezeColumns : freezeColumns[0];
812812
const freezeRightColumns = typeof freezeColumns === "number" ? 0 : freezeColumns[1];
813+
const column = mappedColumns[col];
813814

814815
if (col >= mappedColumns.length || row >= rows || row < -2 || col < 0) {
815816
return result;
816817
}
817818

818819
const headerHeight = totalHeaderHeight - groupHeaderHeight;
819820

820-
if (col >= freezeLeftColumns) {
821+
if (col >= freezeLeftColumns && col < mappedColumns.length - freezeRightColumns) {
821822
const dir = cellXOffset > col ? -1 : 1;
822-
const [freezeLeftWidth, freezeRightWidth] = getStickyWidth(mappedColumns);
823+
const [freezeLeftWidth] = getStickyWidth(mappedColumns);
823824
result.x += freezeLeftWidth + translateX;
824825
for (let i = cellXOffset; i !== col; i += dir) {
825826
result.x += mappedColumns[dir === 1 ? i : i - 1].width * dir;
826827
}
827-
} else {
828+
} else if (column.stickyPosition === "left") {
828829
for (let i = 0; i < col; i++) {
829830
result.x += mappedColumns[i].width;
830831
}
832+
} else if (column.stickyPosition === "right") {
833+
result.x = width;
834+
for (let i = col; i < mappedColumns.length; i++) {
835+
result.x -= mappedColumns[i].width;
836+
}
831837
}
832838
result.width = mappedColumns[col].width + 1;
833839

@@ -863,7 +869,7 @@ export function computeBounds(
863869
end++;
864870
}
865871
if (!sticky) {
866-
const [freezeLeftWidth, freezeRightWidth] = getStickyWidth(mappedColumns);
872+
const [freezeLeftWidth] = getStickyWidth(mappedColumns);
867873
const clip = result.x - freezeLeftWidth;
868874
if (clip < 0) {
869875
result.x -= clip;

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

+18-17
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.rings.ts

+7-2
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

-1
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

0 commit comments

Comments
 (0)