inkdropapp / inkdrop-vim

Provides Vim modal control for Inkdrop, blending the best of Vim and Inkdrop
https://www.inkdrop.app/
MIT License
101 stars 9 forks source link

Increment list number at line break #40

Open seachicken opened 2 years ago

seachicken commented 2 years ago

The list number is automatically incremented when the enter key is used to create a new line but is not incremented when the o key is used to create a new line. I often use ESC + o key to create a new line in vim, so it would be easier to type if the number is incremented. ordered_list

craftzdog commented 2 years ago

I don't know whether it should be a default behavior or not because people may want to just insert a new line without inserting a list bullet/number.

But you can replicate the enter key behavior by making a custom command like so:

inkdrop.onEditorLoad(() => {
  const editor = inkdrop.getActiveEditor();
  const inputField = editor.cm.getInputField();

  const { commands } = inkdrop;
  commands.add(inputField, {
    "custom:insert-below-with-newline": () => {
      commands.dispatch(inputField, "vim:activate-insert-mode");
      commands.dispatch(inputField, "editor:go-line-end");
      commands.dispatch(inputField, "editor:new-line");
    },
  });
});

And bind it in keymap.cson:

'.CodeMirror.vim-mode.normal-mode:not(.key-buffering):not(.visual-mode) textarea':
  'o': 'custom:insert-below-with-newline'