mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
ui: support ctrl+enter
This commit is contained in:
1 parent
e67c1c333a
commit
16fcd80a00
4 files changed
+54
-38
No files matched your search
@@ -1,4 +1,6 @@
|
||||
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
|
||||
import loadFormatter from 'vj/components/wastyle/index';
|
||||
import Notification from 'vj/components/notification';
|
||||
|
||||
monaco.languages.typescript.javascriptDefaults.setDiagnosticsOptions({
|
||||
noSemanticValidation: false,
|
||||
@@ -105,3 +107,50 @@ monaco.languages.yaml.yamlDefaults.setDiagnosticsOptions({
|
||||
});
|
||||
|
||||
export default monaco;
|
||||
|
||||
/** @param {import('monaco-editor').editor.IStandaloneCodeEditor} editor */
|
||||
export function registerAction(editor, model, element) {
|
||||
editor.addAction({
|
||||
id: 'theme-dark',
|
||||
label: 'Use dark theme',
|
||||
run: () => monaco.editor.setTheme('vs-dark'),
|
||||
});
|
||||
editor.addAction({
|
||||
id: 'theme-light',
|
||||
label: 'Use light theme',
|
||||
run: () => monaco.editor.setTheme('vs-light'),
|
||||
});
|
||||
if (element) {
|
||||
editor.addAction({
|
||||
id: 'submit-form',
|
||||
label: 'Use light',
|
||||
keybindings: [
|
||||
monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter,
|
||||
monaco.KeyMod.WinCtrl | monaco.KeyCode.Enter,
|
||||
],
|
||||
run: () => $(element).closest('form').submit(),
|
||||
});
|
||||
}
|
||||
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyMod.Shift | monaco.KeyCode.KEY_P, () => {
|
||||
editor.getAction('editor.action.quickCommand').run();
|
||||
});
|
||||
loadFormatter().then(([loaded, format]) => {
|
||||
if (!loaded) return;
|
||||
editor.addAction({
|
||||
id: 'hydro.format',
|
||||
label: 'Format Code',
|
||||
contextMenuOrder: 0,
|
||||
contextMenuGroupId: 'operation',
|
||||
keybindings: [monaco.KeyMod.Alt | monaco.KeyMod.Shift | monaco.KeyCode.KEY_F],
|
||||
run: () => {
|
||||
if (!['cpp', 'c'].includes(model._languageIdentifier.language)) return;
|
||||
const [success, result] = format(editor.getValue(), `${UserContext.astyleOptions.trim()} mode=c`);
|
||||
if (success) editor.setValue(result);
|
||||
else Notification.warn(result);
|
||||
},
|
||||
});
|
||||
editor.addCommand(monaco.KeyMod.Alt | monaco.KeyMod.Shift | monaco.KeyCode.KEY_F, () => {
|
||||
editor.getAction('hydro.format').run();
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user