feat(editor): add naming style conversion for selections

This commit is contained in:
yanguibao1997 authored and GitHub committed 2026-09-04 16:52:47 +08:00
1 parent a2e4d15bbc
commit 5e03c20821
24 files changed
+858 -1

No files matched your search

@@ -8,6 +8,7 @@ import { ChevronUp, ChevronDown, ChevronRight, TextSelect, X } from "@lucide/vue
import { collectEditorSearchMatches, countEditorSearchMatches, createEditorSearchQuery, replaceEditorSearchMatches, type EditorSearchMatch } from "@/lib/editor/editorSearchQuery";
import { appendSearchMatchSelection, findSearchMatch, isSearchAddSelectionModifier, selectionRangesForSearchMatches, type EditorSearchSelectionDirection } from "@/lib/editor/editorSearchSelection";
import { useSettingsStore } from "@/stores/settingsStore";
import { vNamingStyleSupport } from "@/directives/vNamingStyleSupport";
const props = defineProps<{
view: EditorView | null;
@@ -501,6 +502,7 @@ defineExpose({
<input
ref="searchInputRef"
v-model="searchText"
v-naming-style-support
autocapitalize="off"
autocorrect="off"
spellcheck="false"
@@ -556,6 +558,7 @@ defineExpose({
<input
ref="replaceInputRef"
v-model="replaceText"
v-naming-style-support
autocapitalize="off"
autocorrect="off"
spellcheck="false"
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { ref, onMounted, onBeforeUnmount, onActivated, onDeactivated, watch, shallowRef, computed, nextTick } from "vue";
import { AlignLeft, Camera, CaseLower, CaseUpper, ClipboardPaste, Code2, Download, Eye, FileCode, MessageSquareText, Minimize2, Pencil, PencilRuler, Play, Copy, List, Scissors, Search, Sparkles, Table2, TextSelect, Trash2 } from "@lucide/vue";
import { AlignLeft, Camera, CaseLower, CaseSensitive, CaseUpper, ClipboardPaste, Code2, Download, Eye, FileCode, MessageSquareText, Minimize2, Pencil, PencilRuler, Play, Copy, List, Scissors, Search, Sparkles, Table2, TextSelect, Trash2 } from "@lucide/vue";
import { useI18n } from "vue-i18n";
import type { Completion, CompletionContext } from "@codemirror/autocomplete";
import { Transaction, StateEffect } from "@codemirror/state";
@@ -32,6 +32,7 @@ import { createSqlSignatureTooltipDom } from "@/lib/editor/sqlSignatureTooltip";
import { buildSqlInConditionFromPasteSource, insertTextForSqlInCondition } from "@/lib/sql/sqlInListPaste";
import { resolveSqlSingleQuoteKeyAction } from "@/lib/sql/sqlQuoteCaret";
import { convertSqlSelectionCase, type SqlSelectionCaseMode } from "@/lib/sql/sqlSelectionCase";
import { convertToNextNamingStyle } from "@/lib/naming/namingStyleConverter";
import { formatMongoShellText } from "@/lib/mongo/mongoFormatter";
import { detectAndFormatElasticsearchRequests } from "@/lib/elasticsearch/elasticsearchFormatter";
import { useConnectionStore, COMPLETION_METADATA_CONCURRENCY } from "@/stores/connectionStore";
@@ -1598,6 +1599,35 @@ function convertSelectedSqlCase(mode: SqlSelectionCaseMode): boolean {
return false;
}
function convertSelectedNamingStyle(): boolean {
const currentView = view.value;
const EditorSelection = codeMirrorEditorSelection;
if (!currentView || !EditorSelection) return false;
const state = currentView.state;
const transaction = state.changeByRange((range) => {
if (range.empty) return { range };
const selectedText = state.doc.sliceString(range.from, range.to);
const result = convertToNextNamingStyle(selectedText);
return {
changes: { from: range.from, to: range.to, insert: result.text },
range: EditorSelection.range(range.from, range.from + result.text.length),
};
});
if (!transaction.changes.empty) {
currentView.dispatch({
...transaction,
scrollIntoView: true,
userEvent: "input",
});
focusEditor();
return true;
}
return false;
}
async function pasteClipboardAsSqlInCondition(): Promise<boolean> {
if (!supportsSqlInListPaste(props.databaseType)) return false;
if (props.readOnly) return false;
@@ -1950,6 +1980,13 @@ const contextMenuItems = computed<ContextMenuItem[]>(() => {
icon: CaseLower,
shortcut: shortcuts.lowercaseSelection,
},
{
label: t("editor.contextMenu.convertNamingStyle"),
action: convertSelectedNamingStyle,
disabled: !canCopySelectedSql.value,
icon: CaseSensitive,
shortcut: shortcuts.convertNamingStyle,
},
{
label: t("editor.contextMenu.delimitedList"),
action: openDelimitedListDialog,
@@ -2136,6 +2173,7 @@ function runKeymapExtension(codeMirrorKeymap: (typeof import("@codemirror/view")
...binding(shortcuts.selectAllSelectionOccurrences, selectAllQueryEditorSelectionOccurrences),
...createQueryEditorSelectionCaseShortcutBindings(shortcuts.uppercaseSelection, () => convertSelectedSqlCase("upper")),
...createQueryEditorSelectionCaseShortcutBindings(shortcuts.lowercaseSelection, () => convertSelectedSqlCase("lower")),
...createQueryEditorSelectionCaseShortcutBindings(shortcuts.convertNamingStyle, () => convertSelectedNamingStyle()),
...binding(shortcuts.toggleLineComment, (view) => codeMirrorToggleLineComment?.(view) ?? false),
...binding(shortcuts.toggleBlockComment, (view) => {
if (!supportsQueryEditorBlockComments(props.databaseType)) return false;
@@ -2,6 +2,7 @@
import { ref } from "vue";
import { ChevronDown, ChevronUp, Search, X } from "@lucide/vue";
import { useI18n } from "vue-i18n";
import { vNamingStyleSupport } from "@/directives/vNamingStyleSupport";
const { t } = useI18n();
@@ -52,6 +53,7 @@ defineExpose({
<input
ref="searchInput"
v-model="searchText"
v-naming-style-support
type="search"
autocapitalize="off"
autocomplete="off"