-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathhist.py
50 lines (36 loc) · 1.33 KB
/
hist.py
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
import sublime
import sublime_plugin
class History:
hist = []
index = None
def insert(self, user_input):
if not self.hist or (user_input != self.last() and user_input != "last_regex"):
self.hist.append(user_input)
self.index = None
def roll(self, backwards=False):
if self.index is None:
self.index = -1 if backwards else 0
else:
self.index += -1 if backwards else 1
if self.index == len(self.hist) or self.index < -len(self.hist):
self.index = -1 if backwards else 0
def last(self):
return self.hist[-1] if self.hist else None
def get(self, index=None):
if not index:
index = self.index
return self.hist[index] if self.hist else None
def reset_index(self):
self.index = None
if 'history' not in globals():
history = History()
class AlignTabHistory(sublime_plugin.TextCommand):
def run(self, edit, backwards=False):
history.roll(backwards)
self.view.erase(edit, sublime.Region(0, self.view.size()))
self.view.insert(edit, 0, history.get())
class AlignTabHistoryListener(sublime_plugin.EventListener):
# restore History index
def on_deactivated(self, view):
if view.settings().get("AlignTabInputPanel"):
history.reset_index()