fix(grid): align canvas selection visuals

This commit is contained in:
t8y2 committed 2026-06-02 16:15:55 +08:00
1 parent 396d2ff281
commit 06a862c539
3 files changed
+56 -16

No files matched your search

+30 -14
View File
@@ -249,8 +249,6 @@ export function drawCanvasDataGrid(options: DrawCanvasDataGridOptions) {
ctx.beginPath();
ctx.moveTo(rowNumberWidth + 0.5, y);
ctx.lineTo(rowNumberWidth + 0.5, y + CANVAS_DATA_GRID_ROW_HEIGHT);
ctx.moveTo(0, y + CANVAS_DATA_GRID_ROW_HEIGHT - 0.5);
ctx.lineTo(width, y + CANVAS_DATA_GRID_ROW_HEIGHT - 0.5);
ctx.stroke();
const rowNumberText =
@@ -317,16 +315,12 @@ export function drawCanvasDataGrid(options: DrawCanvasDataGridOptions) {
ctx.fillRect(clippedX, y, cellPaintWidth, CANVAS_DATA_GRID_ROW_HEIGHT);
}
if (isSearchMatch) {
ctx.globalAlpha = 1;
ctx.fillStyle = searchFill;
ctx.fillRect(clippedX, y, cellPaintWidth, CANVAS_DATA_GRID_ROW_HEIGHT);
ctx.globalAlpha = item.isDeleted ? 0.7 : 1;
}
if (isCurrentSearchMatch) {
ctx.globalAlpha = 1;
ctx.fillStyle = currentSearchFill;
ctx.fillRect(clippedX, y, cellPaintWidth, CANVAS_DATA_GRID_ROW_HEIGHT);
ctx.globalAlpha = item.isDeleted ? 0.7 : 1;
}
ctx.save();
@@ -356,9 +350,30 @@ export function drawCanvasDataGrid(options: DrawCanvasDataGridOptions) {
setCanvasNumericVariant(ctx, "normal");
ctx.font = normalFont;
if (selectedBorderVisual) {
ctx.strokeStyle = theme.border;
ctx.beginPath();
ctx.moveTo(x + colWidth - 0.5, y);
ctx.lineTo(x + colWidth - 0.5, y + CANVAS_DATA_GRID_ROW_HEIGHT);
ctx.stroke();
if (selectedBorderVisual && cellPaintWidth >= 2) {
const selectedLeftX = clippedX + 0.5;
const selectedRightX = clippedX + cellPaintWidth - 1.5;
const selectedTopY = y + 0.5;
const selectedBottomY = y + CANVAS_DATA_GRID_ROW_HEIGHT - 1.5;
ctx.strokeStyle = theme.cellSelectedBorder;
ctx.strokeRect(clippedX + 0.5, y + 0.5, Math.max(0, cellPaintWidth - 1), CANVAS_DATA_GRID_ROW_HEIGHT - 1);
ctx.beginPath();
if (!rowSelectionVisual) {
ctx.moveTo(selectedLeftX, selectedTopY);
ctx.lineTo(selectedRightX, selectedTopY);
ctx.moveTo(selectedLeftX, selectedBottomY);
ctx.lineTo(selectedRightX, selectedBottomY);
}
ctx.moveTo(selectedLeftX, selectedTopY);
ctx.lineTo(selectedLeftX, selectedBottomY);
ctx.moveTo(selectedRightX, selectedTopY);
ctx.lineTo(selectedRightX, selectedBottomY);
ctx.stroke();
}
if (isCurrentSearchMatch) {
@@ -367,15 +382,16 @@ export function drawCanvasDataGrid(options: DrawCanvasDataGridOptions) {
ctx.strokeRect(clippedX + 1, y + 1, Math.max(0, cellPaintWidth - 2), CANVAS_DATA_GRID_ROW_HEIGHT - 2);
ctx.lineWidth = 1;
}
ctx.strokeStyle = theme.border;
ctx.beginPath();
ctx.moveTo(x + colWidth - 0.5, y);
ctx.lineTo(x + colWidth - 0.5, y + CANVAS_DATA_GRID_ROW_HEIGHT);
ctx.stroke();
}
x += colWidth;
}
if (!isRowSelected(item.id)) {
ctx.strokeStyle = theme.border;
ctx.beginPath();
ctx.moveTo(0, y + CANVAS_DATA_GRID_ROW_HEIGHT - 0.5);
ctx.lineTo(width, y + CANVAS_DATA_GRID_ROW_HEIGHT - 0.5);
ctx.stroke();
}
ctx.globalAlpha = 1;
}
}
+3 -2
View File
@@ -59,10 +59,11 @@ export function resolveDataGridPaintTheme(options: {
const destructive = cssVarColor(getVar, "--destructive", "oklch(0.6 0.22 25)");
const accent = cssVarColor(getVar, "--accent", isDark ? "oklch(0.269 0 0)" : "oklch(0.97 0 0)");
const yellow500 = "oklch(0.795 0.184 86.047)";
const activeSurface = isDark ? "rgb(64 64 64)" : `color-mix(in oklab, ${primary} 10%, ${background})`;
const rowMuted = `color-mix(in oklab, ${muted} 30%, transparent)`;
const rowNew = `color-mix(in oklab, ${primary} 5%, transparent)`;
const rowDeleted = `color-mix(in oklab, ${destructive} 5%, transparent)`;
const cellActive = `color-mix(in oklab, ${primary} 15%, transparent)`;
const cellActive = activeSurface;
const cellDirty = `color-mix(in oklab, ${yellow500} 10%, transparent)`;
const cellSelected = `color-mix(in oklab, ${primary} 25%, transparent)`;
const cellSelectedDirty = `color-mix(in oklab, oklch(0.8 0.15 85) 30%, color-mix(in oklab, ${primary} 18%, transparent))`;
@@ -75,7 +76,7 @@ export function resolveDataGridPaintTheme(options: {
const rowNumberNew = `color-mix(in oklab, rgb(16 185 129) 15%, ${background})`;
const rowNumberEdited = `color-mix(in oklab, rgb(245 158 11) 15%, ${background})`;
const rowNumberDeleted = `color-mix(in oklab, ${destructive} 15%, ${background})`;
const rowNumberActive = `color-mix(in oklab, ${primary} 15%, ${background})`;
const rowNumberActive = activeSurface;
const rowNumberSelected = `color-mix(in oklab, ${primary} 25%, ${background})`;
return {