summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2011-09-30 17:20:36 +0200
committerFlorent Le Coz <louiz@louiz.org>2011-09-30 17:20:36 +0200
commitfdf6a00bbc5b8fe6ee2882e7dfbcb061771ed9e3 (patch)
tree5031564e5ad229853fd047a63fbd2f5cc9589207 /src
parentc89d9a3aa4cefa881a6347878ec5c940160a1c33 (diff)
downloadpoezio-fdf6a00bbc5b8fe6ee2882e7dfbcb061771ed9e3.tar.gz
poezio-fdf6a00bbc5b8fe6ee2882e7dfbcb061771ed9e3.tar.bz2
poezio-fdf6a00bbc5b8fe6ee2882e7dfbcb061771ed9e3.tar.xz
poezio-fdf6a00bbc5b8fe6ee2882e7dfbcb061771ed9e3.zip
fixes #2185 completion can be done with the cursor ANYWHERE!
Diffstat (limited to 'src')
-rw-r--r--src/tabs.py8
-rw-r--r--src/windows.py51
2 files changed, 34 insertions, 25 deletions
diff --git a/src/tabs.py b/src/tabs.py
index bc656cdd..0fde715c 100644
--- a/src/tabs.py
+++ b/src/tabs.py
@@ -125,7 +125,7 @@ class Tab(object):
# complete the command's name
words = ['/%s'% (name) for name in self.core.commands] +\
['/%s' % (name) for name in self.commands]
- the_input.auto_completion(words, '')
+ the_input.auto_completion(words, ' ')
return True
return False
@@ -725,12 +725,12 @@ class MucTab(ChatTab):
word_list = [user.nick for user in sorted(self._room.users, key=compare_users, reverse=True)\
if user.nick != self._room.own_nick]
after = config.get('after_completion', ',')+" "
- if ' ' not in self.input.get_text() or (self.input.last_completion and\
- self.input.get_text()[:-len(after)] == self.input.last_completion):
+ input_pos = self.input.pos + self.input.line_pos
+ if ' ' not in self.input.get_text()[:input_pos] or (self.input.last_completion and\
+ self.input.get_text()[:input_pos] == self.input.last_completion + after):
add_after = after
else:
add_after = ' '
-
self.input.auto_completion(word_list, add_after)
empty_after = self.input.get_text() == '' or (self.input.get_text().startswith('/') and not self.input.get_text().startswith('//'))
self.send_composing_chat_state(empty_after)
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):
"""