Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: vim mode #280

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

WIP: vim mode #280

wants to merge 1 commit into from

Conversation

diegodorado
Copy link
Contributor

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 diegodorado marked this pull request as draft May 2, 2024 12:56
@diegodorado diegodorado changed the title add a keybinding for vim keymap WIP: vim mode May 2, 2024
@diegodorado
Copy link
Contributor Author

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)

@Bubobubobubobubo
Copy link
Contributor

Bubobubobubobubo commented May 3, 2024

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
Copy link
Contributor

Bubobubobubobubo commented May 3, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants