Send a real \t when pasting a text containing tabs.

This commit is contained in:
Florent Le Coz 2012-10-09 06:00:43 +00:00
parent c9a244ceb0
commit b50acaae0b
2 changed files with 16 additions and 13 deletions

View file

@ -354,10 +354,6 @@ class Core(object):
"""
main loop waiting for the user to press a key
"""
def sanitize_input(key):
if key == '^I':
return ' '
return key
def replace_line_breaks(key):
if key == '^J':
return '\n'
@ -383,9 +379,16 @@ class Core(object):
if len(char) == 1:
current.append(char)
else:
res.append(current)
# special case for the ^I key, its considered as \t
# only when pasting some text, otherwise thats the ^I
# (or M-i) key, which stands for completion by default.
if char == '^I' and len(char_list) != 1:
current.append('\t')
continue
if current:
res.append(current)
current = []
res.append([char])
current = []
if current:
res.append(current)
return res
@ -393,8 +396,6 @@ class Core(object):
if self.paused: continue
big_char_list = [common.replace_key_with_bound(key)\
for key in self.read_keyboard()]
log.debug(big_char_list)
log.debug(separate_chars_from_bindings(big_char_list))
# whether to refresh after ALL keys have been handled
for char_list in separate_chars_from_bindings(big_char_list):
if self.paused:
@ -421,10 +422,7 @@ class Core(object):
else:
res = self.do_command(replace_line_breaks(char), False)
else:
self.do_command(''.join(map(
lambda x: sanitize_input(x),
char_list)
), True)
self.do_command(''.join(char_list), True)
self.doupdate()
def save_config(self):

View file

@ -1380,7 +1380,12 @@ class MessageInput(Input):
Refresh the line onscreen, from the pos and pos_line, with colors
"""
with g_lock:
text = self.text.replace('\n', '|')
# Replace \t with ' ' just to make the input easily editable.
# That's not perfect, because we cannot differenciate a tab and
# a space. But at least it makes it possible to paste text
# containing a tab by sending a real tab, not just four spaces
# while still being able to edit the input in that case.
text = self.text.replace('\n', '|').replace('\t', ' ')
self._win.erase()
if self.color:
self._win.attron(to_curses_attr(self.color))