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

chore: use InsertLeave instead of TextChangedI #88

Merged
merged 2 commits into from
Jan 4, 2024
Merged

Conversation

argshook
Copy link
Contributor

@argshook argshook commented Jan 4, 2024

hey there!

thank you for this superb plugin, it's extremely useful!

i had a small issue with undoing changes done in insert mode and took
few minutes to fix it.

Not sure if it's the best way to fix it, and i haven't thoroughly tested
all features (there're a lot!).

gp.nvim has autosave feature which is triggered by few events, one of which is TextChangedI.

when typing text in insert mode, any change done there saves the file. This grows the :undolist too much, because any change in insert mode is saved and treated as a separate change.

Normally to undo the last change, you would press u once in normal mode. But with autosave triggered by TextChangedI, you have to press u multiple times, for each change.

using InsertLeave instead of TextChangedI avoids such problem.

For comparison, consider scenario:

  1. open neovim
  2. run :GpChatNew
  3. go to insert mode and type 123
  4. leave insert mode
  5. run :undolist

on my setup it shows:

number changes  when               saved
     4       4  2 seconds ago

doing the equivalent when InsertLeave is used instead of TextChangedI:

number changes  when               saved
     1       1  2 seconds ago        1

this is much better, because now you can undo the last change with single u press!

argshook and others added 2 commits January 4, 2024 16:44
`gp.nvim` has autosave feature which is triggered by few events, one of
which is `TextChangedI`.

when typing text in insert mode, any change done there saves the file.
This grows the `:undolist` too much, because any change in insert mode
is saved and treated as a separate change.

Normally to undo the last change, you would press `u` once in normal mode.
But with autosave triggered by `TextChangedI`, you have to press `u` multiple times, for each change.

using `InsertLeave` instead of `TextChangedI` avoids such problem.

For comparison, consider scenario:

1. open neovim
2. run `:GpChatNew`
3. go to insert mode and type `123`
4. leave insert mode
5. run `:undolist`

on my setup it shows:

```
number changes  when               saved
     4       4  2 seconds ago
```

doing the equivalent when `InsertLeave` is used instead of `TextChangedI`:

```
number changes  when               saved
     1       1  2 seconds ago        1
```

this is much better, because now you can undo the last change with single `u` press!
@Robitx
Copy link
Owner

Robitx commented Jan 4, 2024

@argshook hey, thanks for the PR! InsertLeave in the first instance is a nice improvement, the second use of TextChangedI actually has a purpose (so that ChatPicker can dynamically grep and update listing of old chats).

@Robitx Robitx merged commit 555c487 into Robitx:main Jan 4, 2024
1 check passed
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.

2 participants