1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-11 18:24:43 +02:00

Desktop: Fixes #10768: Make :w trigger sync in the beta editor's Vim mode (#10778)

This commit is contained in:
Henry Heino 2024-07-26 04:38:07 -07:00 committed by GitHub
parent 77b74daa0e
commit 3fbb3b6b82
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 3 deletions

View File

@ -160,7 +160,7 @@ export default function useKeymap(CodeMirror: any) {
keymapService.on(EventName.KeymapChange, registerKeymap);
setupEmacs();
setupVim(CodeMirror);
setupVim(CodeMirror, null);
// eslint-disable-next-line @seiyab/react-hooks/exhaustive-deps -- Old code before rule was applied
}, []);
}

View File

@ -12,6 +12,7 @@ import setupVim from '@joplin/editor/CodeMirror/utils/setupVim';
import { dirname } from 'path';
import useKeymap from './utils/useKeymap';
import useEditorSearch from '../utils/useEditorSearchExtension';
import CommandService from '@joplin/lib/services/CommandService';
interface Props extends EditorProps {
style: React.CSSProperties;
@ -145,7 +146,11 @@ const Editor = (props: Props, ref: ForwardedRef<CodeMirrorControl>) => {
return;
}
setupVim(editor);
setupVim(editor, {
sync: () => {
void CommandService.instance().execute('synchronize');
},
});
}, [editor]);
useKeymap(editor);

View File

@ -1,12 +1,22 @@
import CodeMirrorControl from '../CodeMirrorControl';
const setupVim = (CodeMirror: CodeMirrorControl) => {
interface AppCommands {
sync(): void;
}
const setupVim = (CodeMirror: CodeMirrorControl, commands: AppCommands|null) => {
CodeMirror.Vim.defineAction('swapLineDown', CodeMirror.commands.swapLineDown);
CodeMirror.Vim.mapCommand('<A-j>', 'action', 'swapLineDown', {}, { context: 'normal', isEdit: true });
CodeMirror.Vim.defineAction('swapLineUp', CodeMirror.commands.swapLineUp);
CodeMirror.Vim.mapCommand('<A-k>', 'action', 'swapLineUp', {}, { context: 'normal', isEdit: true });
CodeMirror.Vim.defineAction('insertListElement', CodeMirror.commands.vimInsertListElement);
CodeMirror.Vim.mapCommand('o', 'action', 'insertListElement', { after: true }, { context: 'normal', isEdit: true, interlaceInsertRepeat: true });
if (commands) {
CodeMirror.Vim.defineEx('write', 'w', () => {
commands.sync();
});
}
};
export default setupVim;