about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lepus.uberspace.de>2016-08-21 23:21:07 +0200
committerhut <hut@lepus.uberspace.de>2016-08-21 23:21:07 +0200
commit40d6cf586b0c634c542f9808247aa90817ca3786 (patch)
tree139b8ba6f73ce68ba0b3bdd397a3fddac3bd2c37
parent17e9b4299373ebef70f7ad4a739512ae9d44d975 (diff)
parent5dd709c9dcc6255bede0e419f226cf4bddecc2c9 (diff)
downloadranger-40d6cf586b0c634c542f9808247aa90817ca3786.tar.gz
Merge branch 'fix/cursor-on-viewmode-change' of https://github.com/Enzime/ranger
-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)))
d.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
type screen-position-state {
  nrows: int  # const
  ncols: int  # const
  toprow: int
  botrow: int
  leftcol: int
  rightcol: int
  row: int
  col: int
}

fn init-screen-position-state _self: (addr screen-position-state) {
  # hardcoded parameters:
  #   top-margin
  #   page-margin
  #   page-width
  #   page-height (temporary)
  var self/esi: (addr screen-position-state) <- copy _self
  var nrows/eax: int <- copy 0
  var ncols/ecx: int <- copy 0
  nrows, ncols <- screen-size
  var dest/edx: (addr int) <- copy 0
  # self->nrows = nrows
  dest <- get self, nrows
  copy-to *dest, nrows
  # self->ncols = ncols
  dest <- get self, ncols
  copy-to *dest, ncols
  # self->toprow = top-margin
  dest <- get self, toprow
  copy-to *dest, 2  # top-margin
  # self->botrow = nrows
  dest <- get self, botrow
  copy-to *dest, 0x22  # top-margin + page-height
  # self->leftcol = page-margin
  dest <- get self, leftcol
  copy-to *dest, 5  # left-margin
  # self->rightcol = self->leftcol + page-width
  dest <- get self, rightcol
  copy-to *dest, 0x45  # left-margin + page-width
  #
  start-drawing self
}

fn start-drawing _self: (addr screen-position-state) {
  var self/esi: (addr screen-position-state) <- copy _self
  var tmp/eax: (addr int) <- copy 0
  var tmp2/ecx: int <- copy 0
  # self->row = self->toprow
  tmp <- get self, toprow
  tmp2 <- copy *tmp
  tmp <- get self, row
  copy-to *tmp, tmp2
  # self->col = self->leftcol
  tmp <- get self, leftcol
  tmp2 <- copy *tmp
  tmp <- get self, col
  copy-to *tmp, tmp2
  #
  reposition-cursor self
}

fn add-char _self: (addr screen-position-state), c: byte {
$add-char:body: {
  var self/esi: (addr screen-position-state) <- copy _self
  {
    compare c, 0xa  # newline
    break-if-!=
    next-line self
    reposition-cursor self
    break $add-char:body
  }
  # print c
  print-byte c
  # self->col++
  var tmp/eax: (addr int) <- get self, col
  increment *tmp
  # if (self->col > self->rightcol) next-line(self)
  var tmp2/ecx: int <- copy *tmp
  tmp <- get self, rightcol
  compare tmp2, *tmp
  {
    break-if-<=
    next-line self
    reposition-cursor self
  }
}
}

fn next-line _self: (addr screen-position-state) {
  var self/esi: (addr screen-position-state) <- copy _self
  var tmp/eax: (addr int) <- copy 0
  var tmp2/ecx: int <- copy 0
  # self->col = self->leftcol
  tmp <- get self, leftcol
  tmp2 <- copy *tmp
  tmp <- get self, col
  copy-to *tmp, tmp2
  # self->row++
  tmp <- get self, row
  increment *tmp
  # if (self->row > self->botrow) next-page(self)
  tmp2 <- copy *tmp
  tmp <- get self, botrow
  compare tmp2, *tmp
  {
    break-if-<=
    next-page self
  }
}

fn next-page _self: (addr screen-position-state) {
  var self/esi: (addr screen-position-state) <- copy _self
  # TMP
  var tmp/eax: (addr int) <- get self, row
  increment *tmp
}

fn done-drawing? _self: (addr screen-position-state) -> result/eax: boolean {
  var self/esi: (addr screen-position-state) <- copy _self
  # TMP
  var r/eax: (addr int) <- get self, row
  var tmp/ecx: (addr int) <- get self, botrow
  var max/ecx: int <- copy *tmp
$done-drawing?:check: {
    compare *r, max
    {
      break-if->=
      result <- copy 0  # false
      break $done-drawing?:check
    }
    {
      break-if-<
      result <- copy 1  # true
    }
  }
}

fn reposition-cursor _self: (addr screen-position-state) {
  var self/esi: (addr screen-position-state) <- copy _self
  var r/eax: (addr int) <- get self, row
  var c/ecx: (addr int) <- get self, col
  move-cursor *r *c
}
#x27;ingredient'' href='/akkartik/mu/commit/sandbox/006-sandbox-copy.mu?h=main&id=4a48bedcd1d708a43d43dc6259a4e45c52ea3d00'>4a48bedc ^
2d91279b ^
dd660682 ^
3d8b137c ^
4fcf032b ^


2d91279b ^
4fcf032b ^
4a48bedc ^
3d8b137c ^

4fcf032b ^


3d8b137c ^
4fcf032b ^
4a48bedc ^
3d8b137c ^

4fcf032b ^



6f65d591 ^
4fcf032b ^

294b2ab3 ^



6d12a8c4 ^
294b2ab3 ^
4fcf032b ^


294b2ab3 ^
4fcf032b ^


ceeb92d4 ^
4fcf032b ^


ceeb92d4 ^
4fcf032b ^








55479bc2 ^
4fcf032b ^




ceeb92d4 ^
4fcf032b ^


ceeb92d4 ^
4fcf032b ^






294b2ab3 ^
4fcf032b ^



ceeb92d4 ^
4fcf032b ^


ceeb92d4 ^
4fcf032b ^


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286