Send a real \t when pasting a text containing tabs.
This commit is contained in:
parent
c9a244ceb0
commit
b50acaae0b
2 changed files with 16 additions and 13 deletions
22
src/core.py
22
src/core.py
|
@ -354,10 +354,6 @@ class Core(object):
|
||||||
"""
|
"""
|
||||||
main loop waiting for the user to press a key
|
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):
|
def replace_line_breaks(key):
|
||||||
if key == '^J':
|
if key == '^J':
|
||||||
return '\n'
|
return '\n'
|
||||||
|
@ -383,9 +379,16 @@ class Core(object):
|
||||||
if len(char) == 1:
|
if len(char) == 1:
|
||||||
current.append(char)
|
current.append(char)
|
||||||
else:
|
else:
|
||||||
res.append(current)
|
# special case for the ^I key, it’s considered as \t
|
||||||
|
# only when pasting some text, otherwise that’s 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])
|
res.append([char])
|
||||||
current = []
|
|
||||||
if current:
|
if current:
|
||||||
res.append(current)
|
res.append(current)
|
||||||
return res
|
return res
|
||||||
|
@ -393,8 +396,6 @@ class Core(object):
|
||||||
if self.paused: continue
|
if self.paused: continue
|
||||||
big_char_list = [common.replace_key_with_bound(key)\
|
big_char_list = [common.replace_key_with_bound(key)\
|
||||||
for key in self.read_keyboard()]
|
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
|
# whether to refresh after ALL keys have been handled
|
||||||
for char_list in separate_chars_from_bindings(big_char_list):
|
for char_list in separate_chars_from_bindings(big_char_list):
|
||||||
if self.paused:
|
if self.paused:
|
||||||
|
@ -421,10 +422,7 @@ class Core(object):
|
||||||
else:
|
else:
|
||||||
res = self.do_command(replace_line_breaks(char), False)
|
res = self.do_command(replace_line_breaks(char), False)
|
||||||
else:
|
else:
|
||||||
self.do_command(''.join(map(
|
self.do_command(''.join(char_list), True)
|
||||||
lambda x: sanitize_input(x),
|
|
||||||
char_list)
|
|
||||||
), True)
|
|
||||||
self.doupdate()
|
self.doupdate()
|
||||||
|
|
||||||
def save_config(self):
|
def save_config(self):
|
||||||
|
|
|
@ -1380,7 +1380,12 @@ class MessageInput(Input):
|
||||||
Refresh the line onscreen, from the pos and pos_line, with colors
|
Refresh the line onscreen, from the pos and pos_line, with colors
|
||||||
"""
|
"""
|
||||||
with g_lock:
|
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()
|
self._win.erase()
|
||||||
if self.color:
|
if self.color:
|
||||||
self._win.attron(to_curses_attr(self.color))
|
self._win.attron(to_curses_attr(self.color))
|
||||||
|
|
Loading…
Reference in a new issue