fix(grid): keep select all inside cell details
This commit is contained in:
parent
ead9a05c3c
commit
7c0fd73f7d
|
|
@ -0,0 +1,21 @@
|
|||
import { describe, expect, it, vi } from "vitest";
|
||||
import { EditorState } from "@codemirror/state";
|
||||
import { selectAllCellDetailText } from "@/lib/dataGrid/cellDetailSelection";
|
||||
|
||||
describe("selectAllCellDetailText", () => {
|
||||
it("selects the entire cell detail document", () => {
|
||||
const state = EditorState.create({ doc: '{"name":"收入合同"}' });
|
||||
const dispatch = vi.fn();
|
||||
|
||||
expect(selectAllCellDetailText({ state, dispatch } as any)).toBe(true);
|
||||
expect(dispatch).toHaveBeenCalledWith({ selection: { anchor: 0, head: state.doc.length } });
|
||||
});
|
||||
|
||||
it("handles empty cell values", () => {
|
||||
const state = EditorState.create({ doc: "" });
|
||||
const dispatch = vi.fn();
|
||||
|
||||
selectAllCellDetailText({ state, dispatch } as any);
|
||||
expect(dispatch).toHaveBeenCalledWith({ selection: { anchor: 0, head: 0 } });
|
||||
});
|
||||
});
|
||||
|
|
@ -15,6 +15,7 @@ import i18n from "@/i18n";
|
|||
import EditorSearchPanel from "@/components/editor/EditorSearchPanel.vue";
|
||||
import type { EditorTheme } from "@/stores/settingsStore";
|
||||
import type { AppThemeAppearance, AppThemePalette } from "@/lib/app/appTheme";
|
||||
import { selectAllCellDetailText } from "@/lib/dataGrid/cellDetailSelection";
|
||||
|
||||
export interface UseCellDetailEditorOptions {
|
||||
onChange?: (value: string) => void;
|
||||
|
|
@ -198,6 +199,10 @@ export function useCellDetailEditor(options: UseCellDetailEditorOptions): UseCel
|
|||
themeComp.of(theme),
|
||||
fontThemeComp.of(fontTheme),
|
||||
keymap.of([
|
||||
{
|
||||
key: "Mod-a",
|
||||
run: selectAllCellDetailText,
|
||||
},
|
||||
{
|
||||
key: "Escape",
|
||||
run: () => {
|
||||
|
|
@ -227,6 +232,9 @@ export function useCellDetailEditor(options: UseCellDetailEditorOptions): UseCel
|
|||
}),
|
||||
EditorState.readOnly.of(!!options.readOnly),
|
||||
EditorView.editable.of(!options.readOnly),
|
||||
// Read-only CodeMirror content is not editable or focusable by default.
|
||||
// Keep it keyboard-focusable so selection shortcuts stay inside the detail value.
|
||||
EditorView.contentAttributes.of(options.readOnly ? { tabindex: "0" } : {}),
|
||||
],
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
interface CellDetailSelectionEditor {
|
||||
state: { doc: { length: number } };
|
||||
dispatch(spec: { selection: { anchor: number; head: number } }): void;
|
||||
}
|
||||
|
||||
export function selectAllCellDetailText(editor: CellDetailSelectionEditor): boolean {
|
||||
editor.dispatch({ selection: { anchor: 0, head: editor.state.doc.length } });
|
||||
return true;
|
||||
}
|
||||
Loading…
Reference in New Issue