-
Notifications
You must be signed in to change notification settings - Fork 30
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
Extension state get's resetted on reconfigure #130
Comments
It should not be very hard to add methods to save and restore the vim state, Do you have an example of another plugin that properly handles the state, or maybe you can point me to the documentation that describes how this should work with facets. |
I'm far from an expert but from my understanding the correct way should be to create a StateField (this should be an Extension that you just return in an array with your extension) https://codemirror.net/docs/ref/#state.StateField To recover that state you should use the facet method on the Editor state https://codemirror.net/docs/ref/#state.EditorState.facet I totally understand that this would be a huge refactor. There some way I can export the current vim extension state and than reapply it? |
@nightwing do you have any update on this? The pr to add the vim extension to the svelte REPL is ready but we are waiting to merge it because this behavior it's quite inconvenient. But if there's no way to get and restore the state and you have no man power to update the extension we will merge anyway. |
Unfortunately there is no method to set inputState correctly to vim. I think i will be able to implement it and use it from a facet by the end of next week, but most likely some followup work will be needed as well, to get tabs to work the way they do in vim (e.g. some commands are meant to jump between tabs, etc.). So i think it would be better to merge your pr, and add state handling in a followup. |
Thanks for the heads up...we will probably merge it now and than update as soon as you publish the new version. Just to better understand, you are doing the rework of the entire state using facets or just the ability to get and set the state? |
There is no way to use facets in vim code itself, as it is meant to be interoperable with old codemirror and ace. But i think it should be possible to add a way to update the internal state when facet is reconfigured. One problem though is that i would either have to copy cm.state.vim object with every change, or make it partially compatible with codemirror's immutable api, so that it would work with your usecase but won't work for restoring vim to an earlier state. |
We want to use this extension to provide the svelte repl with Vim keybinginds. However we are running into an issue because we need to store the state of the editor on a per document basis (you can swap between tabs and each tab has it's own state and most importantly history). To reset the history we need store the codemirror state of every tab, and upon swapping tab restore the old codemirror state.
By doing so however every extension get's resetted so we need to also add an effect to reconfigure the set of extensions. Doing this reset the internal state of this extension (so for example if you are in insert mode it get's resetted to normal mode) and that's kinda of annoying. Part of the reason this happens is because this extension store all the information in a custom class (also called Codemirror) which is not a facet so when you save the state from Codemirror it doesn't gets serialized. I realize this is a massive overhaul of the current implementation so i totally understand if you decide to not address this.
However in case you are not planning to implement this would you consider instruct me on how could i store the vim state and re-apply this state after the reconfiguration? I'm especially concerned about the mode but all the other state would be cool to.
The text was updated successfully, but these errors were encountered: