Refactor and add the TypeAt command#24
Open
GustavoMF31 wants to merge 4 commits intoedwinb:masterfrom
Open
Conversation
The previous behavior was to just save the cursor position. That worked fine in most cases, but caused the window to scroll back up when it was scrolled more than the height of the text. Info about winsaveview is available on ':help winsaveview()'. The undo history is kept by temporarily turning on the 'hidden' option. That prevents the code buffer from being abandoned when the buffer switch is made.
Having these as part of the responsibilities of each command led to them being duplicated in most commands. This does mean that commands that previously didn't need to write the file now will.
Turns out the :e command also moves the cursor and repositions the window. To prevent this, the window view is saved before the :e and restored afterwards.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The refactors were:
s:IdrisCommand(removes a lot of code duplication)IWrite(this guarantees that the window always returns to it's previous position. The reload command used to save just the cursor position, not the whole window view, and that caused annoyances)A change made that isn't really a refactor is that now undo still works after issuing a command that updates the
idris-responsebuffer. Previously, the process of writing to it made the buffer with the current file be temporarily abandoned, causing the undo history to be lost. The fix is implemented by temporarily overwriting thehiddenoption, making it become a hidden buffer, rather than abandoned. There might be a more straightforward way of implementing this though, suggestions are welcomed.The implementation of TypeAt is rather simple. I'm not sure about which key would be the best for it though. My initial idea was
<LocalLeader>ta,TypeAt's initials, but that would make Vim wait for a second keypress before issuing a regular<LocalLeader>t, which is rather inconvenient. I settled on<LocalLeader>yfor lack of anything better.I'm sorry if I ended up coupling too many unrelated changes into this pull request, i'm kind of still learning how to help with open source. If any changes are necessary just let me know and I'll do my best.