A very useful feature I'm missing. You do something, then scroll somewhere to check something else and want to return to your original location, but can't find it easily. Currently it is solvable by setting a marker beforehand, but it's less convenient than automatic tracking and requires more actions and things to remember (don't forget to set the marker, don't forget to remove the marker) and doesn't allow you to move farther back than to the latest position.
This might solve much of your use-case, if you scroll away and don't move the cursor you can scroll back to the current line with `ctrl+shift+L`.
Otherwise you are saying you want to have a history of *some* cursor positions (since presumably you don't want every arrow key movement while you were editing, that would be useless). So you need to come up with a definition of when a cursor move is savable in history in a form that can be programmed easily and reliably.
This might solve much of your use-case, if you scroll away and don't move the cursor you can scroll back to the current line with `ctrl+shift+L`.
Or just move the cursor slightly with an arrow key, no need to remember a new keybinding :]
I usually scroll by keyboard, Page Up/Down, Ctrl+Home/End, and may even edit something, so the cursor is definitely not there anymore. For the case where it's just mouse scroll, I usually use @b4n's method. Although thanks for the suggestion.
Another hack I sometimes resort to is Undo, Redo, which brings me to the latest edit place. But I feel unsafe each time because of risk of not to redo something important. And again, I can't travel farther back than the latest edit. And the edit isn't always what I need, I may want to look at what I have been looking recently.
As for how it is best to implement the feature, I'm not sure, but some other editors done it somehow. I believe it is something like a timer that is reset on each cursor move which saves the position on timeout.
Or it may be implemented without a timer: simply save each caret movement, but if the latest element in the caret history stack was added, say, less than a second ago, overwrite it (except for some cases, listed below). You don't need to keep the time for each position in the stack, the latest addition time variable is enough. In fact it shouldn't be real time, but monotonic time.
Perhaps there should be some additional checks, for example make sure to save (not to reset or overwrite): - when the previous caret movement was caused by an edit and this one is caused by user movement, so an edit is never missing in history. - before any special/external caret movement: before going to marker, before code navigation, before Ctrl+Home/End. Is there an easy way to hook somewhere in the API in a general way?
Actually, I see that there is already Code Navigation History, it should save the location before code navigation, maybe it can be merged with the new system, or even the new system can be built atop of it.
Actually, I see that there is already Code Navigation History, it should save the location before code navigation, maybe it can be merged with the new system, or even the new system can be built atop of it.
Quite frankly I don't think two systems will interact well, navigation history saves positions of symbol navigation actions, ie things it can clearly identify with a navigation action, and AFAICT it does store the location before the navigation action.
If somebody examined what other editors do and implemented it and provided a pull request then it can be trialled and issues like interactions between the systems evaluated.
IME QtCreator does this flawlessly, if someone wanted to extract their algorithm.
I'd suggest only saving the caret position when the its line changes. Also, I'd feel very comfortable if history navigation was bound to the (now common) buttons 4 and 5 of the mouse, like in any current internet browser.
github-comments@lists.geany.org