sminez / ad

an adaptable text editor
https://crates.io/crates/ad-editor
MIT License
264 stars 10 forks source link

Set editor mode on tui init to NORMAL #37

Closed izuzak closed 1 month ago

izuzak commented 1 month ago

When you start ad, the initial mode is NORMAL, but the cursor looks as if it is in INSERT mode.

Here's a gif where I start ad, observe that the editor is in NORMAL mode but the cursor is a bar, then enter INSERT mode and observe the cursor is still a bar, and then switch back to NORMAL mode and observe the cursor finally being a block:

Screenshot 2024-10-14 at 00 03 29

This PR is my attempt to fix this by calling set_mode within tui_init. This helps because set_mode is where the cursor's shape is actually changed. So, I guess that by default the editor's mode is NORMAL (perhaps due to normal mode being the first mode listed in the list of modes), but the default cursor shape is a bar (where is this defined?). So, we need to call set_mode to set the cursor shape to what it should be, even though the mode is already NORMAL.

There's quite possibly a better way to do this, so please feel free to edit this PR, or close it and open a new one with a better fix. πŸ˜„ I just wanted to use this as an opportunity to dig into the code a little bit and offer a potential fix.

sminez commented 1 month ago

Thanks for this @izuzak, I think I've overlooked this as I have a block cursor by default in my terminal setup. I think it'd be better to set the cursor based on the current mode as part of init_tui rather than hard coding it as setting the mode to NORMAL so as you've mentioned I'll close this and make that change instead :slightly_smiling_face:

izuzak commented 1 month ago

Many thanks again for the quick feedback and for fixing this! πŸ™‡ πŸŽ‰

sminez commented 1 month ago

No worries! I'm hacking on this pretty much daily at the moment so you can expect to see a fair amount of change over the next few weeks. There are a couple of outstanding features and bugs I'd like to work on and ideally get the generated documentation in :help improved to the point that things are more discoverable for users. If you find any other weird quirks or bugs please do raise them like you have been doing so far! Its much appreciated :slightly_smiling_face: