feat(grid): support word wrap in cell detail and value editors

This commit is contained in:
lxk955 authored and GitHub committed 2026-10-01 23:49:29 +08:00
1 parent 51f9dfc854
commit 3d6a5088f4
8 files changed
+272 -6

No files matched your search

@@ -14,13 +14,15 @@ const mocks = vi.hoisted(() => ({
onChange: undefined as undefined | ((value: string) => void),
onSaveShortcut: undefined as undefined | ((event: KeyboardEvent) => boolean),
fontFamily: undefined as undefined | (() => string),
lineWrapping: undefined as undefined | (() => boolean),
}));
vi.mock("@/composables/useCellDetailEditor", () => ({
useCellDetailEditor: (options: { onChange?: (value: string) => void; onSaveShortcut?: (event: KeyboardEvent) => boolean; fontFamily: () => string }) => {
useCellDetailEditor: (options: { onChange?: (value: string) => void; onSaveShortcut?: (event: KeyboardEvent) => boolean; fontFamily: () => string; lineWrapping?: () => boolean }) => {
mocks.onChange = options.onChange;
mocks.onSaveShortcut = options.onSaveShortcut;
mocks.fontFamily = options.fontFamily;
mocks.lineWrapping = options.lineWrapping;
return {
create: mocks.create,
destroy: mocks.destroy,
@@ -33,7 +35,7 @@ vi.mock("@/composables/useCellDetailEditor", () => ({
}));
vi.mock("@/composables/useTheme", () => ({ useTheme: () => ({ isDark: ref(false), themePalette: ref({}) }) }));
vi.mock("@/stores/settingsStore", () => ({
useSettingsStore: () => ({ editorSettings: { theme: "default", fontSize: 13, fontFamily: "monospace", tableFontFamily: "'Grid Font', sans-serif" } }),
useSettingsStore: () => ({ editorSettings: { theme: "default", fontSize: 13, fontFamily: "monospace", tableFontFamily: "'Grid Font', sans-serif", wordWrap: true } }),
}));
vi.mock("@/lib/dataGrid/geometryPreview", () => ({ renderWktOnCanvas: vi.fn() }));
@@ -65,6 +67,7 @@ beforeEach(() => {
mocks.onChange = undefined;
mocks.onSaveShortcut = undefined;
mocks.fontFamily = undefined;
mocks.lineWrapping = undefined;
mocks.getValue.mockReturnValue("");
});
@@ -79,6 +82,7 @@ describe("useDataGridCellDetail", () => {
expect(mocks.focus).toHaveBeenCalledOnce();
expect(mocks.fontFamily?.()).toBe("'Grid Font', sans-serif");
expect(mocks.lineWrapping?.()).toBe(true);
composable.detailsEditorContainer.value = undefined;
await nextTick();
@@ -107,6 +107,10 @@ export function useCellDetailEditor(options: UseCellDetailEditorOptions): UseCel
return typeof options.readOnly === "function" ? options.readOnly() : Boolean(options.readOnly);
}
function isLineWrapping(): boolean {
return typeof options.lineWrapping === "function" ? options.lineWrapping() : settingsStore.editorSettings.wordWrap;
}
function readOnlyExtensions(readOnly: boolean) {
return [EditorState.readOnly.of(readOnly), EditorView.editable.of(!readOnly), EditorView.contentAttributes.of(readOnly ? { tabindex: "0" } : {})];
}
@@ -173,7 +177,7 @@ export function useCellDetailEditor(options: UseCellDetailEditorOptions): UseCel
});
watch(
() => options.lineWrapping?.() ?? false,
() => isLineWrapping(),
(lineWrapping) => {
const editor = view.value;
if (!editor || destroyed) return;
@@ -250,7 +254,7 @@ export function useCellDetailEditor(options: UseCellDetailEditorOptions): UseCel
]),
]),
languageComp.of(currentIsJson ? json() : []),
lineWrappingComp.of(options.lineWrapping?.() ? EditorView.lineWrapping : []),
lineWrappingComp.of(isLineWrapping() ? EditorView.lineWrapping : []),
readOnlyComp.of(readOnlyExtensions(isReadOnly())),
themeComp.of(theme),
fontThemeComp.of(fontTheme),
@@ -22,6 +22,7 @@ export function useDataGridCellDetail(options: { detail: Ref<DataGridCellDetail>
appPalette: () => themePalette.value,
fontSize: () => settingsStore.editorSettings.fontSize,
fontFamily: () => settingsStore.editorSettings.tableFontFamily,
lineWrapping: () => settingsStore.editorSettings.wordWrap,
});
watch(geometryPreviewOpen, async (open) => {