fix(grid): keep select all inside cell details
This commit is contained in:
1 parent
ead9a05c3c
commit
7c0fd73f7d
3 files changed
+38
No files matched your search
@@ -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 EditorSearchPanel from "@/components/editor/EditorSearchPanel.vue";
|
||||||
import type { EditorTheme } from "@/stores/settingsStore";
|
import type { EditorTheme } from "@/stores/settingsStore";
|
||||||
import type { AppThemeAppearance, AppThemePalette } from "@/lib/app/appTheme";
|
import type { AppThemeAppearance, AppThemePalette } from "@/lib/app/appTheme";
|
||||||
|
import { selectAllCellDetailText } from "@/lib/dataGrid/cellDetailSelection";
|
||||||
|
|
||||||
export interface UseCellDetailEditorOptions {
|
export interface UseCellDetailEditorOptions {
|
||||||
onChange?: (value: string) => void;
|
onChange?: (value: string) => void;
|
||||||
@@ -198,6 +199,10 @@ export function useCellDetailEditor(options: UseCellDetailEditorOptions): UseCel
|
|||||||
themeComp.of(theme),
|
themeComp.of(theme),
|
||||||
fontThemeComp.of(fontTheme),
|
fontThemeComp.of(fontTheme),
|
||||||
keymap.of([
|
keymap.of([
|
||||||
|
{
|
||||||
|
key: "Mod-a",
|
||||||
|
run: selectAllCellDetailText,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
key: "Escape",
|
key: "Escape",
|
||||||
run: () => {
|
run: () => {
|
||||||
@@ -227,6 +232,9 @@ export function useCellDetailEditor(options: UseCellDetailEditorOptions): UseCel
|
|||||||
}),
|
}),
|
||||||
EditorState.readOnly.of(!!options.readOnly),
|
EditorState.readOnly.of(!!options.readOnly),
|
||||||
EditorView.editable.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;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user