From a30fb3260a78f98764a1dce5ea46674931e0776a Mon Sep 17 00:00:00 2001 From: lan-yonghui Date: Wed, 24 Jun 2026 16:27:11 +0800 Subject: [PATCH] feat: add quick toggle comment functionality in the editor --- frontend/src/utils/file.ts | 2 +- frontend/src/utils/monaco.ts | 1 + .../src/views/host/file-management/code-editor/index.vue | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/frontend/src/utils/file.ts b/frontend/src/utils/file.ts index 1f2bdc3087d0..7d29c8ec4fe0 100644 --- a/frontend/src/utils/file.ts +++ b/frontend/src/utils/file.ts @@ -174,7 +174,7 @@ const isSpecialEditorFileName = (value: string) => { if (!normalized) { return false; } - return specialEditorFileNames.some((filename) => normalized === filename || normalized.startsWith(`${filename}.`)); + return specialEditorFileNames.some((filename) => normalized === filename); }; export const resolveEditorLanguage = (path: string, extension = '', name = '') => { diff --git a/frontend/src/utils/monaco.ts b/frontend/src/utils/monaco.ts index 8d3b22000c09..a5cb7a4c32b4 100644 --- a/frontend/src/utils/monaco.ts +++ b/frontend/src/utils/monaco.ts @@ -41,6 +41,7 @@ export async function loadMonacoLanguageSupport() { import('monaco-editor/esm/vs/editor/contrib/folding/browser/folding.js'), import('monaco-editor/esm/vs/editor/contrib/contextmenu/browser/contextmenu.js'), import('monaco-editor/esm/vs/editor/contrib/clipboard/browser/clipboard.js'), + import('monaco-editor/esm/vs/editor/contrib/comment/browser/comment.js'), import('monaco-editor/esm/vs/editor/contrib/dropOrPasteInto/browser/copyPasteContribution.js'), import('monaco-editor/esm/vs/editor/contrib/find/browser/findController.js'), import('monaco-editor/esm/vs/editor/contrib/multicursor/browser/multicursor.js'), diff --git a/frontend/src/views/host/file-management/code-editor/index.vue b/frontend/src/views/host/file-management/code-editor/index.vue index 3b53896b1f27..e2997c03c716 100644 --- a/frontend/src/views/host/file-management/code-editor/index.vue +++ b/frontend/src/views/host/file-management/code-editor/index.vue @@ -965,6 +965,8 @@ const initEditor = async () => { editor.getModel()?.pushEOL(config.eol); editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, quickSave); + editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.Slash, quickToggleComment); + editor.focus(); editor.onDidChangeModelContent(() => { if (editor) { @@ -980,6 +982,10 @@ const quickSave = () => { saveContent(); }; +const quickToggleComment = () => { + void editor?.getAction('editor.action.commentLine')?.run(); +}; + const openHistoryDrawer = () => { if (!form.value.path) { MsgWarning(i18n.global.t('file.historyNeedFile'));