From fdf6a00bbc5b8fe6ee2882e7dfbcb061771ed9e3 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Fri, 30 Sep 2011 17:20:36 +0200 Subject: fixes #2185 completion can be done with the cursor ANYWHERE! --- src/windows.py | 51 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 21 deletions(-) (limited to 'src/windows.py') diff --git a/src/windows.py b/src/windows.py index 2352a82a..03066857 100644 --- a/src/windows.py +++ b/src/windows.py @@ -883,26 +883,28 @@ class Input(Win): self.rewrite_text() return True - def key_left(self, jump=True): + def key_left(self, jump=True, reset=True): """ Move the cursor one char to the left """ - self.reset_completion() + if reset: + self.reset_completion() if self.pos == self.width-1 and self.line_pos > 0: self.line_pos -= 1 elif self.pos >= 1: self.pos -= 1 if jump and self.pos+self.line_pos >= 1 and self.text[self.pos+self.line_pos-1] == '\x19': self.key_left() - else: + elif reset: self.rewrite_text() return True - def key_right(self, jump=True): + def key_right(self, jump=True, reset=True): """ Move the cursor one char to the right """ - self.reset_completion() + if reset: + self.reset_completion() if self.pos == self.width-1: if self.line_pos + self.width-1 < len(self.text): self.line_pos += 1 @@ -910,7 +912,7 @@ class Input(Win): self.pos += 1 if jump and self.pos+self.line_pos < len(self.text) and self.text[self.pos+self.line_pos-1] == '\x19': self.key_right() - else: + elif reset: self.rewrite_text() return True @@ -936,8 +938,6 @@ class Input(Win): plus a space, after the completion. If it's a string, we use it after the completion (with no additional space) """ - if self.pos+self.line_pos != len(self.text): # or len(self.text) == 0 - return # we don't complete if cursor is not at the end of line completion_type = config.get('completion', 'normal') if completion_type == 'shell' and self.text != '': self.shell_completion(word_list, add_after) @@ -957,12 +957,15 @@ class Input(Win): Normal completion """ (y, x) = self._win.getyx() + pos = self.pos + self.line_pos + if pos < len(self.text) and after.endswith(' ') and self.text[pos] == ' ': + after = after[:-1] # remove the last space if we are already on a space if not self.last_completion: - # begin is the begining of the word we want to complete - if self.text.strip() and not self.text.endswith(' '): - begin = self.text.split()[-1].lower() + space_before_cursor = self.text.rfind(' ', 0, pos-1) + if space_before_cursor != -1: + begin = self.text[space_before_cursor+1:pos] else: - begin = '' + begin = self.text[:pos] hit_list = [] # list of matching nicks for word in word_list: if word.lower().startswith(begin): @@ -972,18 +975,24 @@ class Input(Win): self.hit_list = hit_list end = len(begin) else: - if after: - begin = self.text[-len(after)-len(self.last_completion):-len(after)] - else: - begin = self.last_completion - self.hit_list.append(self.hit_list.pop(0)) # rotate list + begin = self.last_completion end = len(begin) + len(after) - if end: - self.text = self.text[:-end] + self.hit_list.append(self.hit_list.pop(0)) # rotate list + + self.text = self.text[:pos-end] + self.text[pos:] + pos -= end nick = self.hit_list[0] # take the first hit + self.text = self.text[:pos] + nick + after + self.text[pos:] + for i in range(end): + try: + self.key_left(reset=False) + except: + pass + for i in range(len(nick + after)): + self.key_right(reset=False) + + self.rewrite_text() self.last_completion = nick - self.text += nick +after - self.key_end(False) def shell_completion(self, word_list, after): """ -- cgit v1.2.3 From 347733804f8d61a01bc0a286f6f872f8dd14527d Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Sat, 1 Oct 2011 20:46:20 +0200 Subject: Do not try to cycle completion on commands if there was only one possibily. You can now see by the space appended at the end if it was the only one. It lets you complete arguments without having to add a stupid space after the command name --- src/windows.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/windows.py') diff --git a/src/windows.py b/src/windows.py index 03066857..fb99416c 100644 --- a/src/windows.py +++ b/src/windows.py @@ -122,7 +122,6 @@ class Win(object): self.move(y, x) next_attr_char = text.find('\x19') while next_attr_char != -1 and text: - log.debug('Addstr_Colored: [%s]' % text.replace('\x19', '\\x19')) if next_attr_char + 1 < len(text): attr_char = text[next_attr_char+1].lower() else: @@ -961,7 +960,7 @@ class Input(Win): if pos < len(self.text) and after.endswith(' ') and self.text[pos] == ' ': after = after[:-1] # remove the last space if we are already on a space if not self.last_completion: - space_before_cursor = self.text.rfind(' ', 0, pos-1) + space_before_cursor = self.text.rfind(' ', 0, pos) if space_before_cursor != -1: begin = self.text[space_before_cursor+1:pos] else: @@ -1043,7 +1042,8 @@ class Input(Win): return res if not key or len(key) > 1: return False # ignore non-handled keyboard shortcuts - self.reset_completion() + if reset: + self.reset_completion() self.text = self.text[:self.pos+self.line_pos]+key+self.text[self.pos+self.line_pos:] (y, x) = self._win.getyx() if x == self.width-1: -- cgit v1.2.3 From 5ae665b2535b2ff174bd9af357afc337748a57a3 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Sun, 2 Oct 2011 17:39:18 +0200 Subject: Fix completion case-sensitiveness --- src/windows.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/windows.py') diff --git a/src/windows.py b/src/windows.py index fb99416c..4f2c68c6 100644 --- a/src/windows.py +++ b/src/windows.py @@ -967,7 +967,7 @@ class Input(Win): begin = self.text[:pos] hit_list = [] # list of matching nicks for word in word_list: - if word.lower().startswith(begin): + if word.lower().startswith(begin.lower()): hit_list.append(word) if len(hit_list) == 0: return -- cgit v1.2.3