feat(editor): add configurable line-end multi-cursors

This commit is contained in:
二丫讲梵 authored and GitHub committed 2026-10-04 16:41:40 +08:00
1 parent 500c0ae692
commit 8ca612d1f7
19 files changed
+174 -4

No files matched your search

@@ -1,4 +1,6 @@
<script setup lang="ts">
import { Compartment } from "@codemirror/state";
import { keymap as codeMirrorKeymap } from "@codemirror/view";
import { applyDdlStoragePreference } from "@/lib/sql/ddlStorage";
import DdlStorageToggle from "@/components/objects/DdlStorageToggle.vue";
import StructureIndexColumnPicker from "./StructureIndexColumnPicker.vue";
@@ -26,6 +28,9 @@ import { useProductionSafetyStore } from "@/stores/productionSafetyStore";
import { productionContextForDatabase } from "@/lib/database/productionSafety";
import { useQueryStore } from "@/stores/queryStore";
import { useHistoryStore } from "@/stores/historyStore";
import { matchesShortcut } from "@/lib/editor/keyboardShortcuts";
import { selectLineEndsDefaultShortcut, shortcutToCodeMirrorKey } from "@/lib/editor/shortcutRegistry";
import { selectLineEnds } from "@/lib/editor/selectLineEnds";
import { useSettingsStore, type StructureEditorDensity } from "@/stores/settingsStore";
import { useTheme } from "@/composables/useTheme";
import { editorFontTheme, loadEditorTheme } from "@/lib/editor/editorThemes";
@@ -139,7 +144,7 @@ import {
import { CREATE_DATABASE_CHARSET_OPTIONS, createDatabaseCollationOptionsForCharset, fallbackCreateDatabaseCharsetMetadata, normalizeCreateDatabaseCharsetKey, parseCreateDatabaseCharsetMetadata } from "@/lib/database/createDatabaseCharsetOptions";
import type { CreateDatabaseCharsetMetadata } from "@/lib/database/createDatabaseCharsetOptions";
import * as api from "@/lib/backend/api";
import type { EditorView } from "@codemirror/view";
import { EditorView } from "@codemirror/view";
const { t } = useI18n();
const { isDark, themePalette } = useTheme();
@@ -248,6 +253,8 @@ const ddlEditorContainer = ref<HTMLDivElement>();
const ddlSearchPanelRef = ref<InstanceType<typeof EditorSearchPanel>>();
const ddlSearchOpen = ref(false);
const ddlEditorView = shallowRef<EditorView | null>(null);
const ddlEditorShortcut = new Compartment();
const selectLineEndsShortcut = () => settingsStore.editorSettings?.shortcuts?.selectLineEnds ?? selectLineEndsDefaultShortcut();
let ddlEditorInitRequestId = 0;
let ddlEditorScrollCleanup: (() => void) | null = null;
const loadedMetadataFacets = new Set<ObjectMetadataFacet>();
@@ -344,6 +351,10 @@ function observeDdlEditorScroll(view: EditorView) {
ddlEditorScrollCleanup = () => scrollDOM.removeEventListener("scroll", onScroll);
}
watch(selectLineEndsShortcut, (shortcut) => {
ddlEditorView.value?.dispatch({ effects: ddlEditorShortcut.reconfigure(codeMirrorKeymap.of([{ key: shortcutToCodeMirrorKey(shortcut), preventDefault: true, run: selectLineEnds }])) });
});
async function initDdlEditor(content: string) {
const container = ddlEditorContainer.value;
if (!container) return;
@@ -387,6 +398,14 @@ async function initDdlEditor(content: string) {
langSql.sql({ dialect }),
themeExt,
fontExt,
ddlEditorShortcut.of(keymap.of([{ key: shortcutToCodeMirrorKey(selectLineEndsShortcut()), preventDefault: true, run: selectLineEnds }])),
EditorView.domEventHandlers({
keydown(event, eventView) {
if (!matchesShortcut(event, selectLineEndsShortcut())) return false;
event.preventDefault();
return selectLineEnds(eventView);
},
}),
Prec.highest(keymap.of([{ key: "Mod-f", run: () => ddlSearchPanelRef.value?.openSearch() ?? false, preventDefault: true }])),
EditorView.theme({
"&.cm-focused": { outline: "none" },