Pasting text is now handled has one single big key.

This avoids looping over each char we are pasting, making it
a lot faster (actually, should be instant).
This commit is contained in:
Florent Le Coz 2011-11-18 19:14:07 +01:00
parent 18dbc880e1
commit 7dd8691f8c
3 changed files with 25 additions and 22 deletions

View file

@ -787,7 +787,10 @@ class Core(object):
""" """
main loop waiting for the user to press a key main loop waiting for the user to press a key
""" """
# curses.ungetch(0) # FIXME def replace_line_breaks(key):
if key == '^J':
return '\n'
return key
while self.running: while self.running:
char_list = [common.replace_key_with_bound(key)\ char_list = [common.replace_key_with_bound(key)\
for key in self.read_keyboard()] for key in self.read_keyboard()]
@ -812,8 +815,7 @@ class Core(object):
if res: if res:
self.refresh_window() self.refresh_window()
else: else:
for char in char_list: self.do_command(''.join(list(map(replace_line_breaks, char_list))), True)
self.do_command(char, True)
self.refresh_window() self.refresh_window()
self.doupdate() self.doupdate()

View file

@ -941,7 +941,7 @@ class MucTab(ChatTab):
if not raw and key in self.key_func: if not raw and key in self.key_func:
self.key_func[key]() self.key_func[key]()
return False return False
self.input.do_command(key) self.input.do_command(key, raw=raw)
empty_after = self.input.get_text() == '' or (self.input.get_text().startswith('/') and not self.input.get_text().startswith('//')) 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) self.send_composing_chat_state(empty_after)
return False return False
@ -1432,7 +1432,7 @@ class PrivateTab(ChatTab):
if not raw and key in self.key_func: if not raw and key in self.key_func:
self.key_func[key]() self.key_func[key]()
return False return False
self.input.do_command(key) self.input.do_command(key, raw=raw)
if not self.on: if not self.on:
return False return False
empty_after = self.input.get_text() == '' or (self.input.get_text().startswith('/') and not self.input.get_text().startswith('//')) empty_after = self.input.get_text() == '' or (self.input.get_text().startswith('/') and not self.input.get_text().startswith('//'))
@ -1901,12 +1901,12 @@ class RosterInfoTab(Tab):
return self.name return self.name
def on_input(self, key, raw): def on_input(self, key, raw):
if key == '^M': if raw and key == '^M':
selected_row = self.roster_win.get_selected_row() selected_row = self.roster_win.get_selected_row()
res = self.input.do_command(key) res = self.input.do_command(key, raw=raw)
if res: if res:
return True return True
if key == '^M': if raw and key == '^M':
self.core.on_roster_enter_key(selected_row) self.core.on_roster_enter_key(selected_row)
return selected_row return selected_row
elif not raw and key in self.key_func: elif not raw and key in self.key_func:
@ -2173,7 +2173,7 @@ class ConversationTab(ChatTab):
if not raw and key in self.key_func: if not raw and key in self.key_func:
self.key_func[key]() self.key_func[key]()
return False return False
self.input.do_command(key) self.input.do_command(key, raw=raw)
empty_after = self.input.get_text() == '' or (self.input.get_text().startswith('/') and not self.input.get_text().startswith('//')) 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) self.send_composing_chat_state(empty_after)
return False return False
@ -2355,7 +2355,7 @@ class MucListTab(Tab):
self.complete_commands(self.input) self.complete_commands(self.input)
def on_input(self, key, raw): def on_input(self, key, raw):
res = self.input.do_command(key) res = self.input.do_command(key, raw=raw)
if res: if res:
return True return True
if not raw and key in self.key_func: if not raw and key in self.key_func:
@ -2400,7 +2400,7 @@ class SimpleTextTab(Tab):
self.input.do_command("/") # we add the slash self.input.do_command("/") # we add the slash
def on_input(self, key, raw): def on_input(self, key, raw):
res = self.input.do_command(key) res = self.input.do_command(key, raw=raw)
if res: if res:
return True return True
if not raw and key in self.key_func: if not raw and key in self.key_func:

View file

@ -756,7 +756,7 @@ class HelpText(Win):
self.finish_line(get_theme().COLOR_INFORMATION_BAR) self.finish_line(get_theme().COLOR_INFORMATION_BAR)
self._refresh() self._refresh()
def do_command(self, key): def do_command(self, key, raw=False):
return False return False
class Input(Win): class Input(Win):
@ -796,7 +796,7 @@ class Input(Win):
"KEY_BACKSPACE": self.key_backspace, "KEY_BACKSPACE": self.key_backspace,
"M-KEY_BACKSPACE": self.delete_word, "M-KEY_BACKSPACE": self.delete_word,
'^?': self.key_backspace, '^?': self.key_backspace,
'^J': self.add_line_break, # '^J': self.add_line_break,
} }
Win.__init__(self) Win.__init__(self)
self.text = '' self.text = ''
@ -1088,22 +1088,23 @@ class Input(Win):
self.text += nick self.text += nick
self.key_end(False) self.key_end(False)
def do_command(self, key, reset=True): def do_command(self, key, reset=True, raw=False):
if key in self.key_func: if key in self.key_func:
res = self.key_func[key]() res = self.key_func[key]()
if self.on_input: if not raw and self.on_input:
self.on_input(self.get_text()) self.on_input(self.get_text())
return res return res
if not key or len(key) > 1: if not raw and (not key or len(key) > 1):
return False # ignore non-handled keyboard shortcuts return False # ignore non-handled keyboard shortcuts
if reset: if reset:
self.reset_completion() self.reset_completion()
self.text = self.text[:self.pos+self.line_pos]+key+self.text[self.pos+self.line_pos:] self.text = self.text[:self.pos+self.line_pos]+key+self.text[self.pos+self.line_pos:]
(y, x) = self._win.getyx() (y, x) = self._win.getyx()
if x == self.width-1: for i in range(len(key)):
self.line_pos += 1 # wcwidth.wcswidth(key) if x == self.width-1:
else: self.line_pos += 1 # wcwidth.wcswidth(key)
self.pos += 1 # wcwidth.wcswidth(key) else:
self.pos += 1 # wcwidth.wcswidth(key)
if reset: if reset:
self.rewrite_text() self.rewrite_text()
if self.on_input: if self.on_input:
@ -1269,8 +1270,8 @@ class CommandInput(Input):
self.key_func["M-B"] = self.key_down self.key_func["M-B"] = self.key_down
self.histo_pos = -1 self.histo_pos = -1
def do_command(self, key): def do_command(self, key, refresh=True, raw=False):
res = Input.do_command(self, key) res = Input.do_command(self, key, refresh, raw)
if self.on_input: if self.on_input:
self.on_input(self.get_text()) self.on_input(self.get_text())
return res return res