about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/core/actions.py57
1 files changed, 41 insertions, 16 deletions
diff --git a/ranger/core/actions.py b/ranger/core/actions.py
index 5a1ea258..b5a763f8 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -1244,31 +1244,56 @@ class Actions(  # pylint: disable=too-many-instance-attributes,too-many-public-m
             self.signal_emit('tab.layoutchange')
         return None
 
-    def tab_shift(self, offset):
+    def tab_shift(self, offset=0, pos=None):
         """Shift the tab left/right
 
-        Shift the current tab to the left or right
+        Shift the current tab to the left or right by either:
+        offset - changes the tab number by offset
+        pos - shifts the tab to the specified tab number
         """
-        assert isinstance(offset, int)
-        tablist = self.get_tab_list()
+
         oldtab_index = self.current_tab
-        old_index = tablist.index(oldtab_index)
-        new_index = (old_index + offset)
-        if new_index < 0:
-            return None
-        if new_index > (len(tablist)-1):
-            return None
-        newtab_index = tablist[new_index]
+        if pos is None:
+            assert isinstance(offset, int)
+            # enumerated index (1 to 9)
+            newtab_index = oldtab_index + offset
+            if newtab_index < 1:
+                newtab_index = 1
+            if newtab_index > 9:
+                newtab_index = 9
+        else:
+            assert isinstance(pos, int)
+            if pos < 1 or pos > 9:
+                return None
+            newtab_index = pos
+        # shift tabs without enumerating, preserve tab numbers when can
         if newtab_index != oldtab_index:
+            # the other tabs shift in the opposite direction
+            if (newtab_index - oldtab_index) > 0:
+                direction = -1
+            else:
+                direction = 1
+
+            def tabshiftreorder(source_index):
+                # shift the tabs to make source_index empty
+                if source_index in self.tabs:
+                    target_index = source_index + direction
+                    # make the target_index empty recursively
+                    tabshiftreorder(target_index)
+                    # shift the source to target
+                    source_tab = self.tabs[source_index]
+                    self.tabs[target_index] = source_tab
+                    del self.tabs[source_index]
+
+            # first remove the current tab from the dict
             oldtab = self.tabs[oldtab_index]
-            newtab = self.tabs[newtab_index]
-            self.tabs[oldtab_index] = newtab
+            del self.tabs[oldtab_index]
+            # make newtab_index empty by shifting
+            tabshiftreorder(newtab_index)
             self.tabs[newtab_index] = oldtab
             self.current_tab = newtab_index
             self.thistab = oldtab
-            self.change_mode('normal')
-            self.signal_emit('tab.change', old=oldtab, new=newtab)
-            self.signal_emit('tab.change', old=newtab, new=oldtab)
+            self.ui.titlebar.request_redraw()
             self.signal_emit('tab.layoutchange')
         return None
 
he previous revision' href='/akkartik/mu/blame/html/071rewrite_stash.cc.html?h=hlt&id=859f35fbe2f6a78157b875e12eb7dc8cd95c1152'>^
3e1349d2 ^
a654e4ec ^
f344b250 ^
a654e4ec ^

32b8fac2 ^

a654e4ec ^
c842d90b ^
3e1349d2 ^
c842d90b ^
f344b250 ^
c842d90b ^




a654e4ec ^



3e1349d2 ^
a654e4ec ^
3e1349d2 ^
a654e4ec ^

32b8fac2 ^



3e1349d2 ^
32b8fac2 ^
f344b250 ^
32b8fac2 ^


a654e4ec ^
c842d90b ^
3e1349d2 ^
f344b250 ^
c842d90b ^
3e1349d2 ^
c842d90b ^









c02478c4 ^
a654e4ec ^

c02478c4 ^
a654e4ec ^
ced133e4 ^
a654e4ec ^

ced133e4 ^
a654e4ec ^

ced133e4 ^
a654e4ec ^
d059fe74 ^
a654e4ec ^
ced133e4 ^
a654e4ec ^
d059fe74 ^
f344b250 ^
a654e4ec ^
32b8fac2 ^
ced133e4 ^
c842d90b ^


d059fe74 ^
f344b250 ^
c842d90b ^

ced133e4 ^








f344b250 ^
cfa5a9f8 ^
ced133e4 ^



a654e4ec ^







c842d90b ^

ced133e4 ^
c842d90b ^
f344b250 ^
c842d90b ^



















2f02189d ^
44c1aeef ^

a654e4ec ^
44c1aeef ^
a654e4ec ^

2f02189d ^
32b8fac2 ^
44c1aeef ^
32b8fac2 ^

ced133e4 ^

3e1349d2 ^
ced133e4 ^
f344b250 ^
ced133e4 ^


f344b250 ^
ced133e4 ^

a654e4ec ^


a654e4ec ^

3e1349d2 ^
f344b250 ^

a654e4ec ^
3e1349d2 ^
a654e4ec ^




a654e4ec ^



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