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

Jumping back and forth to the latest history entry, erases all histories entries on the next new history entry addition #2962

Closed
evandrocoan opened this issue Sep 1, 2019 · 3 comments

Comments

@evandrocoan
Copy link

evandrocoan commented Sep 1, 2019

Description

This happens because when you go back on the history, the self.current_item is decremented twice as showed next:

    def jump_back(self, active_view):
        """
        Return the view and selection list to jump back to
        Jump back in history. If the current_item is -1, it also pushes the
        active view sel() into the history.
        """
        if self.current_item == 0:
            ...
            self.current_item = -1

        ...
        self.current_item -= 1

Then, once we go back on history and jump forth with jump_forward command, the self.current_item will be -1, instead of 0.

This will cause the line del self.history_list[self.current_item + 1:] to become

del self.history_list[-1 + 1:]

# which is equivalent to the following, and deletes the whole list
del self.history_list[:]

This simple patch can fix this whole history deletion bug while keeping the plugin correctly trimming old branches of history:

 history_list.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/history_list.py b/history_list.py
index 0dc2318..188c4a8 100644
--- a/history_list.py
+++ b/history_list.py
@@ -120,7 +120,8 @@ class JumpHistory():
         for i in range(-1, self.current_item):
             view, key = self.history_list[i]
             view.erase_regions(key)
-        del self.history_list[self.current_item + 1:]
+        if self.current_item < -1:
+            del self.history_list[self.current_item + 1:]
         # set current_item to the imaginary back (current caret position not yet pushed)
         self.current_item = 0

Note: self.current_item is either 0 or negative, but never positive because the history list is built backwards, i.e., from the front its to back.

Environment

  • Operating system and version:
    • Windows 10 build 15063 x64
    • Resolution 1920x1080
    • dpi_scale 1.0
    • Sublime Text:
    • Build 3207
    • 64 bit

Related threads

  1. jump_backandjump_forward` does not record most actions jump_back and jump_forward does not record most actions #2959
  2. jump_prev jumps too far jump_prev jumps too far #1424
  3. Jump to the last caret/cursor, on the current file Jump to the last caret/cursor, on the current file #1374
  4. Jump forward doesn't work on Linux Jump forward doesn't work on Linux #861
@FichteFoll
Copy link
Collaborator

Shouldn't that be if self.current_item > -1:?

@evandrocoan
Copy link
Author

Shouldn't that be if self.current_item > -1:?

As the note I added at the bottom, the possible values of self.current_item are from 0 up to -sys.maxsize, not +sys.maxsize:

Note: self.current_item is either 0 or negative, but never positive because the history list is built backwards, i.e., from the front its to back.

Also there is this note on the history_list.py explaining this:

        # current_item point to newest item of the queue, which is at the back of the
        # list. To make appending easier current_item is a negative index
        # current_item would be -1 to point to the newest item and -len to point to oldest
        self.current_item = 0
        self.key_counter = 0

@wbond
Copy link
Member

wbond commented Aug 14, 2020

This was significantly rewritten in build 4059, and does not appear to suffer from this bug any longer

@wbond wbond added the R: fixed label Aug 14, 2020
@wbond wbond added this to the Build 4059 milestone Aug 14, 2020
@wbond wbond closed this as completed Aug 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants