mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-11 18:24:43 +02:00
This commit is contained in:
parent
77b74daa0e
commit
3fbb3b6b82
@ -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
|
||||
}, []);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user