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
VIM - Strange behavior in VIM mode with Controlled Usage #37
Comments
Interesting, thanks for opening this up, I'll give this a look later today. There is a bit of logic going on for controlled mode to retain/set the cursor in certain cases. I hope VIM isn't going to be a one-off to work around this. I'll keep you posted! |
@edmondxiexie Sorry for the delayed response. Okay yep I can definitely reproduce this. Can you use the uncontrolled variant for now? I'm unsure how much work this could entail. I haven't used this mode before nor am I that much of a VIM power user, so when looking for somewhere to get started I came across this on this note over on codemirror
This has me a little hesitant to dive in as it could lead to an unraveling of who knows what. Either way, I'll start to look and keep you posted. |
@edmondxiexie okay so I dug into this a bit and think I may know whats going on here. Basically, for the controlled component there is also a dummy DOMless codemirror instance that mirrors and tracks changes, to which is later applied to the main instance upon state management (new props). However, when using VIM mode (and likely others), there is a notion of a key map that alters the behavior of the editor e.g. for insert => press "i" The issue is, I don't believe I can emulate this key event to the mirror (dummy), so when I go ahead and extract the mirrored value, it's now incorrect because the keymap altered what would have been applied to the main instance, and is something different entirely. So what I've been digging for is a way to trigger a keystroke change programatically to the dummy, but I have been having trouble to find such a way. There is a I might need help with this one, but I'll keep at it when I have time. |
same issue on both Controlled and UnControlled |
@xralphack odd, this shouldn't be an issue for uncontrolled |
@scniro you are right, just ignore my comment |
@xralphack Cool - no worries. Yea I haven't been able to make a lot of forward progress on this one. It's pretty gnarly on the inside of whats going on as you can see in my investigation above, so hopefully the uncontrolled component is a decent workaround for you, for now. |
@scniro I figured out the problem I want to wrap the codemirror2 component // wrapper component
// codemirror2 component
use uncontrolled version not work, I think this is due to the parent component rerender
anyway, thanks for your effort. |
@xralphack |
@scniro I think using freeze makes sense, but I am not sure using boolean prop is ok for all conditions |
@xralphack why would it not be okay? |
maybe someone want to toggle this boolean on specific condition ( I'm not sure) |
@xralphack gotcha. So I'm thinking then of a |
@xralphack okay there is now a |
I was able to successfully dispatch the key maps to the mirror like so:
(note: I had to use the spread operator to get all three event arguments and avoid a typescript error. I'm not sure what that is all about). This seems to correctly dispatch to the mirror, because I can listen for However... the behavior is still exactly the same as described in the original bug. So no luck yet. See below the results of logging the |
Have there been any updates on this? Vim mode is unusable in this component... |
@edmondxiexie @taniarascia @joeldouglass @xralphack I am a lot shorter on time these days as when I started this project. Codemirror & React APIs are moving to quickly for me to keep atop of for the day-to-day. I am looking for a co-maintainer of this project. Please contact me directly if you are interested. Thank you for understanding. |
The VIM mode has strange behavior when working with states. For example, when I press either 'o' or 'i' to enter insert mode, then press Backspace. It doesn't seem to allow me to delete previous characters before the insert position, which seems weird. And also, the cursor in insert mode will change from the line shape to the block shape after one insertion operation. Is it related to the rerendering when state changing? Because it does not happen in UnControlled Usage.
I use the OnClick function to change the state and use states for changing the value in the editor.
Preview:
I enter the edit mode and move cursor to the end of the line.

Then I press Backspace and the cursor change its shape and I cannot delete any more.

The text was updated successfully, but these errors were encountered: