fix(grid): support multiline bulk edit values
This commit is contained in:
1 parent
fa5e55a376
commit
90bdacfd12
5 files changed
+59
-6
No files matched your search
@@ -0,0 +1,10 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { firstLineCellDisplayValue } from "@/lib/dataGrid/cellValue";
|
||||
|
||||
describe("firstLineCellDisplayValue", () => {
|
||||
it("shows only the first line in fixed-height cells", () => {
|
||||
expect(firstLineCellDisplayValue("111\n222")).toBe("111");
|
||||
expect(firstLineCellDisplayValue("111\r\n222")).toBe("111");
|
||||
expect(firstLineCellDisplayValue("111\r222")).toBe("111");
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { CellValue } from "@/lib/dataGrid/cellValue";
|
||||
import { firstLineCellDisplayValue, type CellValue } from "@/lib/dataGrid/cellValue";
|
||||
import type { RowStatus } from "@/lib/dataGrid/gridRowStatus";
|
||||
import { DATA_GRID_DARK_SEARCH_COLORS, resolveDataGridPaintTheme, type DataGridPaintTheme } from "@/lib/dataGrid/dataGridPaintTheme";
|
||||
|
||||
@@ -374,7 +374,8 @@ export function drawCanvasDataGrid(options: DrawCanvasDataGridOptions) {
|
||||
const textLeft = alignCanvasPixel(x + 12, dpr);
|
||||
const paddedMaxWidth = Math.max(0, x + colWidth - textLeft - 12);
|
||||
const isEditingThisCell = editingCell?.rowId === item.id && editingCell.col === actualColIdx;
|
||||
const displayText = isEditingThisCell ? "" : item.isDraft && value === null ? (draftCellPlaceholder ?? "") : formatCell(value, actualColIdx);
|
||||
const rawDisplayText = item.isDraft && value === null ? (draftCellPlaceholder ?? "") : formatCell(value, actualColIdx);
|
||||
const displayText = isEditingThisCell ? "" : firstLineCellDisplayValue(rawDisplayText);
|
||||
const needsTruncation = ctx.measureText(displayText).width > paddedMaxWidth;
|
||||
const textMaxWidth = needsTruncation ? Math.max(0, x + colWidth - textLeft) : paddedMaxWidth;
|
||||
const text = isEditingThisCell ? displayText : fitCanvasText(ctx, displayText, textMaxWidth - 12);
|
||||
|
||||
@@ -6,3 +6,8 @@ export function displayCellValue(value: CellValue): string {
|
||||
if (typeof value === "object") return JSON.stringify(value);
|
||||
return String(value);
|
||||
}
|
||||
|
||||
export function firstLineCellDisplayValue(value: string): string {
|
||||
const lineBreakIndex = value.search(/\r\n|\r|\n/);
|
||||
return lineBreakIndex === -1 ? value : value.slice(0, lineBreakIndex);
|
||||
}
|
||||
Reference in new issue
Block a user