summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorlouiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 <louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13>2011-01-06 19:57:31 +0000
committerlouiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 <louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13>2011-01-06 19:57:31 +0000
commitc2344d0d339bd3538be1210b841e0340ca3b44a2 (patch)
tree816056235b0dc5f72573adb4b72e23d098c5197f /src
parent850bde1655f9dac06b0345f34443db5931d5bdf8 (diff)
downloadpoezio-c2344d0d339bd3538be1210b841e0340ca3b44a2.tar.gz
poezio-c2344d0d339bd3538be1210b841e0340ca3b44a2.tar.bz2
poezio-c2344d0d339bd3538be1210b841e0340ca3b44a2.tar.xz
poezio-c2344d0d339bd3538be1210b841e0340ca3b44a2.zip
Fix input history, and avoid consecutive duplicates. fixed #1851
Diffstat (limited to 'src')
-rw-r--r--src/windows.py29
1 files changed, 12 insertions, 17 deletions
diff --git a/src/windows.py b/src/windows.py
index d85548a5..dc4092f2 100644
--- a/src/windows.py
+++ b/src/windows.py
@@ -1014,7 +1014,7 @@ class MessageInput(Input):
def __init__(self):
Input.__init__(self)
self.last_completion = None
- self.histo_pos = 0
+ self.histo_pos = -1
self.key_func["KEY_UP"] = self.key_up
self.key_func["M-A"] = self.key_up
self.key_func["KEY_DOWN"] = self.key_down
@@ -1027,10 +1027,9 @@ class MessageInput(Input):
if not len(MessageInput.history):
return
self.reset_completion()
- self._win.erase()
- if self.histo_pos >= 0:
- self.histo_pos -= 1
- self.text = MessageInput.history[self.histo_pos+1]
+ if self.histo_pos < len(MessageInput.history) - 1:
+ self.histo_pos += 1
+ self.text = MessageInput.history[self.histo_pos]
self.key_end()
def key_down(self):
@@ -1040,22 +1039,18 @@ class MessageInput(Input):
if not len(MessageInput.history):
return
self.reset_completion()
- if self.histo_pos < len(MessageInput.history)-1:
- self.histo_pos += 1
- self.text = self.history[self.histo_pos]
- self.key_end()
- else:
- self.histo_pos = len(MessageInput.history)-1
- self.text = ''
- self.pos = 0
- self.line_pos = 0
- self.rewrite_text()
+ if self.histo_pos > 0:
+ self.histo_pos -= 1
+ self.text = MessageInput.history[self.histo_pos]
+ self.key_end()
def key_enter(self):
txt = self.get_text()
if len(txt) != 0:
- self.history.append(txt)
- self.histo_pos = len(self.history)-1
+ if not MessageInput.history or MessageInput.history[0] != txt:
+ # add the message to history, but avoid duplicates
+ MessageInput.history.insert(0, txt)
+ self.histo_pos = -1
self.clear_text()
return txt