@@ -542,7 +542,7 @@ import {useLanguageRegistry} from './composables/useLanguageRegistry'
542542import {useWorkspace } from ' ./composables/useWorkspace'
543543import {useTextCommands } from ' ./composables/useTextCommands'
544544import {useBookmarks } from ' ./composables/useBookmarks'
545- import {foldAll , unfoldAll } from ' @codemirror/language'
545+ import {foldAll , unfoldAll , matchBrackets } from ' @codemirror/language'
546546import {useGitPermalink } from ' ./composables/useGitPermalink'
547547import {useRevealInTree } from ' ./composables/useRevealInTree'
548548import {useWorkspaceRoots } from ' ./composables/useWorkspaceRoots'
@@ -1173,6 +1173,23 @@ const convertIndentation = (toTabs: boolean) => {
11731173 toast .success (t (' app.indentConverted' ))
11741174}
11751175
1176+ // 转到匹配括号:取光标前后的括号,跳到其配对处
1177+ const goToMatchingBracket = () => {
1178+ const view = editorView .value
1179+ if (! view ) {
1180+ return
1181+ }
1182+ const pos = view .state .selection .main .head
1183+ const m = matchBrackets (view .state , pos , - 1 ) || matchBrackets (view .state , pos , 1 )
1184+ if (m && m .matched && m .end ) {
1185+ view .dispatch ({selection: {anchor: m .end .from }, scrollIntoView: true })
1186+ view .focus ()
1187+ }
1188+ else {
1189+ toast .info (t (' app.noMatchingBracket' ))
1190+ }
1191+ }
1192+
11761193// AI 自然语言生成 / 选区改写
11771194const showGenerate = ref (false )
11781195const generateSelection = ref (' ' )
@@ -2235,6 +2252,7 @@ const paletteCommands = computed<PaletteCommand[]>(() => [
22352252 {id: ' indentToTabs' , label: t (' command.indentToTabs' ), group: t (' command.groupText' ), icon: Eraser , run : () => convertIndentation (true )},
22362253 {id: ' foldAll' , label: t (' command.foldAll' ), group: t (' command.groupCode' ), icon: FoldVertical , run : () => { if (editorView .value ) foldAll (editorView .value ) }},
22372254 {id: ' unfoldAll' , label: t (' command.unfoldAll' ), group: t (' command.groupCode' ), icon: UnfoldVertical , run : () => { if (editorView .value ) unfoldAll (editorView .value ) }},
2255+ {id: ' goToMatchingBracket' , label: t (' command.goToMatchingBracket' ), group: t (' command.groupCode' ), icon: Code2 , run : () => goToMatchingBracket ()},
22382256 {id: ' toggleBookmark' , label: t (' command.toggleBookmark' ), group: t (' command.groupBookmark' ), icon: Bookmark , hint: hintOf (' toggleBookmark' ), run : () => toggleBookmark ()},
22392257 {id: ' nextBookmark' , label: t (' command.nextBookmark' ), group: t (' command.groupBookmark' ), icon: Bookmark , run : () => nextBookmark ()},
22402258 {id: ' prevBookmark' , label: t (' command.prevBookmark' ), group: t (' command.groupBookmark' ), icon: Bookmark , run : () => prevBookmark ()},
0 commit comments