summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMichael Hoang <enzime@users.noreply.github.com>2016-08-21 13:00:30 +1000
committerMichael Hoang <enzime@users.noreply.github.com>2016-08-21 13:00:36 +1000
commit5dd709c9dcc6255bede0e419f226cf4bddecc2c9 (patch)
tree2b268b51e46a0883654fad9422bb464625415674
parentb093aa028839e26d19bf7ceefaf4666a036ec5da (diff)
downloadranger-5dd709c9dcc6255bede0e419f226cf4bddecc2c9.tar.gz
Fix cursor being lost when changing viewmodes
This results from finalize being called in order for the widgets.
Previously when ranger changed viewmodes, it would delete then readd the widget
object which meant that the finalize for the viewmode was called last instead
of before console, which meant the finalize of the viewmode was setting
and overriding the cursor position.
-rw-r--r--ranger/gui/displayable.py6
-rw-r--r--ranger/gui/ui.py14
2 files changed, 13 insertions, 7 deletions
diff --git a/ranger/gui/displayable.py b/ranger/gui/displayable.py
index 7b5aa954..62eb5300 100644
--- a/ranger/gui/displayable.py
+++ b/ranger/gui/displayable.py
@@ -211,6 +211,7 @@ class DisplayableContainer(Displayable):
     New methods:
 
     add_child(object) -- add the object to the container.
+    replace_child(old_obj, new_obj) -- replaces old object with new object.
     remove_child(object) -- remove the object from the container.
 
     New attributes:
@@ -290,6 +291,11 @@ class DisplayableContainer(Displayable):
         self.container.append(obj)
         obj.parent = self
 
+    def replace_child(self, old_obj, new_obj):
+        """Replace the old object with the new instance in the container."""
+        self.container[self.container.index(old_obj)] = new_obj
+        new_obj.parent = self
+
     def remove_child(self, obj):
         """Remove the object from the container."""
         try:
diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py
index 4c302e00..f10bc0f2 100644
--- a/ranger/gui/ui.py
+++ b/ranger/gui/ui.py
@@ -437,18 +437,18 @@ class UI(DisplayableContainer):
         if value in self.ALLOWED_VIEWMODES:
             if self._viewmode != value:
                 self._viewmode = value
-                resize = False
+                new_browser = self._viewmode_to_class(value)(self.win)
+
                 if hasattr(self, 'browser'):
                     old_size = self.browser.y, self.browser.x, self.browser.hei, self.browser.wid
-                    self.remove_child(self.browser)
+                    self.replace_child(self.browser, new_browser)
                     self.browser.destroy()
-                    resize = True
+                    new_browser.resize(*old_size)
+                else:
+                    self.add_child(new_browser)
 
-                self.browser = self._viewmode_to_class(value)(self.win)
+                self.browser = new_browser
                 self.redraw_window()
-                self.add_child(self.browser)
-                if resize:
-                    self.browser.resize(*old_size)
         else:
             raise ValueError("Attempting to set invalid viewmode `%s`, should "
                     "be one of `%s`." % (value, "`, `".join(self.ALLOWED_VIEWMODES)))