From c2344d0d339bd3538be1210b841e0340ca3b44a2 Mon Sep 17 00:00:00 2001 From: "louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13" Date: Thu, 6 Jan 2011 19:57:31 +0000 Subject: [PATCH] Fix input history, and avoid consecutive duplicates. fixed #1851 --- src/windows.py | 29 ++++++++++++----------------- 1 file 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