feat(editor): add configurable line-end multi-cursors
This commit is contained in:
19 files changed
+174
-4
No files matched your search
@@ -110,6 +110,7 @@ import { clampEditorFontSize, createEditorWheelZoomGestureGuard, createEditorZoo
|
||||
import { buildSqlShortcutExecutionSql, enabledSqlShortcutActions, resolveSqlShortcutForDatabase, uniqueSqlShortcutBindings } from "@/lib/sql/sqlShortcutActions";
|
||||
import { resolveSqlShortcutTableToken } from "@/lib/sql/sqlShortcutTableTarget";
|
||||
import { normalizeShortcutSettings, shortcutToCodeMirrorKey } from "@/lib/editor/shortcutRegistry";
|
||||
import { matchesShortcut } from "@/lib/editor/keyboardShortcuts";
|
||||
import { trimmedSelectionLayer } from "@/lib/editor/codemirrorTrimmedSelectionLayer";
|
||||
import { editorClipboardLineEndingsExtension } from "@/lib/editor/editorClipboardLineEndings";
|
||||
import { applyVimConfig, isVimMappingCommand, loadVimConfig } from "@/lib/editor/vimConfig";
|
||||
@@ -129,6 +130,7 @@ import { computePasteCaretResyncTarget } from "@/lib/editor/queryEditorPasteCare
|
||||
|
||||
import { extendQueryEditorSelection, runQueryEditorAltExtendSelection } from "@/lib/editor/queryEditorExtendSelection";
|
||||
import { addNextQueryEditorSelectionOccurrence, selectAllQueryEditorSelectionOccurrences } from "@/lib/editor/queryEditorOccurrenceSelection";
|
||||
import { selectLineEnds } from "@/lib/editor/selectLineEnds";
|
||||
import { createQueryEditorStringMouseSelection } from "@/lib/editor/queryEditorStringMouseSelection";
|
||||
import { createQueryEditorCompletionShortcutBindings } from "@/lib/editor/queryEditorCompletionShortcut";
|
||||
import { createQueryEditorSelectionCaseShortcutBindings } from "@/lib/editor/queryEditorSelectionCaseShortcut";
|
||||
@@ -1394,6 +1396,7 @@ function runKeymapExtension(codeMirrorKeymap: (typeof import("@codemirror/view")
|
||||
...binding(shortcuts.extendSelection, extendQueryEditorSelectionForView),
|
||||
...binding(shortcuts.addNextSelectionOccurrence, addNextQueryEditorSelectionOccurrence),
|
||||
...binding(shortcuts.selectAllSelectionOccurrences, selectAllQueryEditorSelectionOccurrences),
|
||||
...binding(shortcuts.selectLineEnds, selectLineEnds),
|
||||
...createQueryEditorSelectionCaseShortcutBindings(shortcuts.uppercaseSelection, () => convertSelectedSqlCase("upper")),
|
||||
...createQueryEditorSelectionCaseShortcutBindings(shortcuts.lowercaseSelection, () => convertSelectedSqlCase("lower")),
|
||||
...createQueryEditorSelectionCaseShortcutBindings(shortcuts.toggleCaseSelection, () => convertSelectedSqlCase("toggle")),
|
||||
@@ -2077,6 +2080,10 @@ const codeMirrorLifecycle = useQueryEditorCodeMirror({
|
||||
EditorView.domEventHandlers({
|
||||
keydown(event, currentView) {
|
||||
const shortcuts = normalizeShortcutSettings(settingsStore.editorSettings.shortcuts);
|
||||
if (matchesShortcut(event, shortcuts.selectLineEnds)) {
|
||||
event.preventDefault();
|
||||
return selectLineEnds(currentView);
|
||||
}
|
||||
return runQueryEditorAltExtendSelection(event, shortcuts.extendSelection, currentView, extendQueryEditorSelectionForView);
|
||||
},
|
||||
}),
|
||||
|
||||
@@ -4,7 +4,7 @@ import { computed, nextTick, onActivated, onBeforeUnmount, onDeactivated, onMoun
|
||||
import { Compartment, StateEffect, StateField } from "@codemirror/state";
|
||||
import { ensureSyntaxTree } from "@codemirror/language";
|
||||
import { setDiagnostics } from "@codemirror/lint";
|
||||
import { Decoration, EditorView } from "@codemirror/view";
|
||||
import { Decoration, EditorView, keymap as codeMirrorKeymap } from "@codemirror/view";
|
||||
import { Archive, ArrowLeftRight, CheckCircle2, ChevronDown, ChevronLeft, ChevronRight, Clipboard, Columns3, Download, ExternalLink, FileClock, FileInput, FileText, Loader2, Maximize2, Minimize2, Network, Plus, RefreshCw, ReplaceAll, Save, Search, Send, Server, Trash2, X } from "@lucide/vue";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
@@ -57,6 +57,9 @@ import { editorFontTheme, loadEditorTheme } from "@/lib/editor/editorThemes";
|
||||
import { clampEditorFontSize, createEditorWheelZoomGestureGuard, createEditorZoomCommitScheduler, fontSizeFromWheelDelta } from "@/lib/editor/editorZoom";
|
||||
import { replaceFallbackKey } from "@/lib/editor/queryEditorSearchKeymap";
|
||||
import { isTauriRuntime } from "@/lib/backend/tauriRuntime";
|
||||
import { matchesShortcut } from "@/lib/editor/keyboardShortcuts";
|
||||
import { selectLineEndsDefaultShortcut, shortcutToCodeMirrorKey } from "@/lib/editor/shortcutRegistry";
|
||||
import { selectLineEnds } from "@/lib/editor/selectLineEnds";
|
||||
import { useSettingsStore } from "@/stores/settingsStore";
|
||||
import { useTheme } from "@/composables/useTheme";
|
||||
import { executeWithProductionContextGuard } from "@/lib/database/productionExecutionGuard";
|
||||
@@ -249,6 +252,8 @@ const configEditorFontTheme = new Compartment();
|
||||
const configEditorWordWrap = new Compartment();
|
||||
const configEditorLanguage = new Compartment();
|
||||
const configValidationHighlight = new Compartment();
|
||||
const configEditorShortcut = new Compartment();
|
||||
const selectLineEndsShortcut = () => settingsStore.editorSettings?.shortcuts?.selectLineEnds ?? selectLineEndsDefaultShortcut();
|
||||
const setConfigValidationHighlight = StateEffect.define<NacosConfigDiagnostic[]>();
|
||||
const configListRequestGuard = createNacosLatestRequestGuard();
|
||||
const configDetailRequestGuard = createNacosLatestRequestGuard();
|
||||
@@ -593,6 +598,10 @@ function configValidationHighlightExtension() {
|
||||
return field;
|
||||
}
|
||||
|
||||
watch(selectLineEndsShortcut, (shortcut) => {
|
||||
configEditorView.value?.dispatch({ effects: configEditorShortcut.reconfigure(codeMirrorKeymap.of([{ key: shortcutToCodeMirrorKey(shortcut), preventDefault: true, run: selectLineEnds }])) });
|
||||
});
|
||||
|
||||
async function mountConfigEditor() {
|
||||
await nextTick();
|
||||
if (!configEditorHost.value || configEditorView.value || !selectedConfig.value) return;
|
||||
@@ -627,9 +636,15 @@ async function mountConfigEditor() {
|
||||
basicSetup,
|
||||
EditorState.allowMultipleSelections.of(true),
|
||||
trimmedSelectionLayer(),
|
||||
configEditorShortcut.of(keymap.of([{ key: shortcutToCodeMirrorKey(selectLineEndsShortcut()), preventDefault: true, run: selectLineEnds }])),
|
||||
Prec.highest(keymap.of([{ key: "Mod-f", run: () => configSearchPanelRef.value?.openSearch() ?? false, preventDefault: true }, { key: replaceFallbackKey(), run: () => configSearchPanelRef.value?.openReplace() ?? false, preventDefault: true }, indentWithTab])),
|
||||
keymap.of([...defaultKeymap, ...historyKeymap]),
|
||||
EditorView.domEventHandlers({
|
||||
keydown(event, eventView) {
|
||||
if (!matchesShortcut(event, selectLineEndsShortcut())) return false;
|
||||
event.preventDefault();
|
||||
return selectLineEnds(eventView);
|
||||
},
|
||||
wheel(event, eventView) {
|
||||
if (!configEditorWheelZoomGestureGuard.accepts(event)) return false;
|
||||
event.preventDefault();
|
||||
|
||||
@@ -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 { computed, nextTick, onUnmounted, ref, shallowRef, watch } from "vue";
|
||||
@@ -6,6 +8,9 @@ import { useI18n } from "vue-i18n";
|
||||
import { Clipboard, ExternalLink, Loader2, Maximize2, Minimize2, RefreshCw } from "@lucide/vue";
|
||||
import { useToast } from "@/composables/useToast";
|
||||
import { useTheme } from "@/composables/useTheme";
|
||||
import { matchesShortcut } from "@/lib/editor/keyboardShortcuts";
|
||||
import { selectLineEndsDefaultShortcut, shortcutToCodeMirrorKey } from "@/lib/editor/shortcutRegistry";
|
||||
import { selectLineEnds } from "@/lib/editor/selectLineEnds";
|
||||
import { useSettingsStore } from "@/stores/settingsStore";
|
||||
import { loadEditorTheme, editorFontTheme } from "@/lib/editor/editorThemes";
|
||||
import { editorClipboardLineEndingsExtension } from "@/lib/editor/editorClipboardLineEndings";
|
||||
@@ -21,7 +26,7 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { HelpTooltip } from "@/components/ui/tooltip";
|
||||
import EditorSearchPanel from "@/components/editor/EditorSearchPanel.vue";
|
||||
import type { EditorView } from "@codemirror/view";
|
||||
import { EditorView } from "@codemirror/view";
|
||||
import type { DatabaseType, ObjectSourceKind } from "@/types/database";
|
||||
|
||||
const props = withDefaults(
|
||||
@@ -61,6 +66,8 @@ const ddlError = ref("");
|
||||
const ddlEditorContainer = ref<HTMLDivElement>();
|
||||
const ddlSearchPanelRef = ref<InstanceType<typeof EditorSearchPanel>>();
|
||||
const ddlEditorView = shallowRef<EditorView | null>(null);
|
||||
const ddlEditorShortcut = new Compartment();
|
||||
const selectLineEndsShortcut = () => settingsStore.editorSettings?.shortcuts?.selectLineEnds ?? selectLineEndsDefaultShortcut();
|
||||
let ddlEditorResizeObserver: ResizeObserver | null = null;
|
||||
|
||||
// Keep the dialog movable for the duration of one open cycle. This mirrors the
|
||||
@@ -367,6 +374,10 @@ function onDdlDialogCloseAutoFocus(event: Event) {
|
||||
* - Prec.highest overrides Cmd+F to open EditorSearchPanel.
|
||||
* - Editor theme/font are loaded from user settings for consistent appearance.
|
||||
*/
|
||||
watch(selectLineEndsShortcut, (shortcut) => {
|
||||
ddlEditorView.value?.dispatch({ effects: ddlEditorShortcut.reconfigure(codeMirrorKeymap.of([{ key: shortcutToCodeMirrorKey(shortcut), preventDefault: true, run: selectLineEnds }])) });
|
||||
});
|
||||
|
||||
async function initDdlEditor(content: string) {
|
||||
if (!ddlEditorContainer.value) return;
|
||||
destroyDdlEditor();
|
||||
@@ -399,6 +410,14 @@ async function initDdlEditor(content: string) {
|
||||
fontExt,
|
||||
// Intercept Cmd+F at highest precedence so EditorSearchPanel opens
|
||||
// instead of the default search panel (which is hidden above).
|
||||
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 }])),
|
||||
// Remove CodeMirror's default 1px dotted focus outline,
|
||||
// which is visible below the content when the DDL is short.
|
||||
|
||||
@@ -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" },
|
||||
|
||||
Reference in new issue
Block a user