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

Better view patching that preserves cursor position #17

Open
mitranim opened this issue Mar 4, 2020 · 0 comments
Open

Better view patching that preserves cursor position #17

mitranim opened this issue Mar 4, 2020 · 0 comments

Comments

@mitranim
Copy link
Contributor

mitranim commented Mar 4, 2020

Currently the plugin calls view.replace on the entire buffer contents and then restores the scroll position. This preserves the scroll position, but not the cursor position.

There's a different method we can borrow from DisposaBoy/GoSublime: diff the two buffers, and call view.replace only on the changed regions on the view. This tends to preserve both the scroll and the cursor position. I've tested this in mitranim/sublime-rust-fmt and mitranim/sublime-gofmt (my simplified alternative to this plugin), and it seems to work well. Performance seems fine; I tested this on a 5k LoC file and couldn't feel the difference.

Both of my plugins provide this as an option. If this method causes issues for some users, they can opt out. Anyway if you like the idea, I can make a PR.

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

No branches or pull requests

1 participant