flok icon indicating copy to clipboard operation
flok copied to clipboard

WIP: vim mode

Open diegodorado opened this issue 9 months ago • 3 comments

Maybe a naif implementation, and a bit shady... but works. Open to comments on what the preffered way of adding this feature should be

diegodorado avatar May 02 '24 02:05 diegodorado

converted to draft because it seems that the binding toggle resets itself when another exception happens? or maybe it is some sort of rerendering issue that turns it back to its default state (and curious if that isn't also the case for the other toggles)

diegodorado avatar May 02 '24 12:05 diegodorado

Interesting, I would like to help tackling this as well! Took my first deep dive in that section of the code and the handling of extensions using keybindings is a bit fragile.

I can confirm that other extension toggles also deactivate when an error occurs (e.g. line numbering). I'm not quite sure as of why, there is nothing that explicitly deactivate them but some refresh process might be wiping the state of extensions when this happens. The easy/safe solution would be to refactor this part to use booleans attached to session state.

EDIT: I have something working using the following technique:

session.tsx

const [lineNumbers, setLineNumbers] = useState<boolean>(false);
const [vimMode, setVimMode] = useState<boolean>(false);

Then:

  • mapping global keybindings in the same file to flip the boolean
  • passing lineNumbers, vimMode, etc as props

editor.tsx

    const extensions = [
      baseTheme,
      flokSetup(document, { readOnly }),
      languageExtension(),
      highlightExtension,
      readOnly ? EditorState.readOnly.of(true) : [],
      props.lineNumbers ? lineNumbers() : [],
      props.vimMode ? vim() : [],
      // toggleWith("shift-ctrl-w", EditorView.lineWrapping), // toggle linewrapping on/off
    ];

Bubobubobubobubo avatar May 03 '24 08:05 Bubobubobubobubo

I have also added a few options in the popup menu for various extensions. They persist for the duration of the session. I can't find keybindings good enough to work on my keyboard (AZERTY). This should probably be open to discussion. QWERTY based shortcuts means that many of them are not usable for everyone.

Capture d’écran 2024-05-03 à 15 53 16

PS: Everything is already on my personal branch. I'm not contributing directly because I try to add more features along with the Vim extension.

Bubobubobubobubo avatar May 03 '24 13:05 Bubobubobubobubo