primitivus: fixed paste detection/handling:

- mouse and window events are discarded
    - input_ is used to get text
    - cursor position is used to paste buffer in the good place, and updated once finished
This commit is contained in:
Goffi 2016-04-22 22:30:13 +02:00
commit 6c30009ef8

View file

@ -25,6 +25,7 @@ log_config.satConfigure(C.LOG_BACKEND_STANDARD, C)
from sat.core import log as logging
log = logging.getLogger(__name__)
import urwid
from urwid.util import is_wide_char
from urwid_satext import sat_widgets
from urwid_satext.files_management import FileDialog
from sat_frontends.bridge.DBus import DBusBridgeFrontend
@ -358,15 +359,25 @@ class PrimitivusApp(QuickApp, InputHistory):
self.showPopUp(popup)
super(PrimitivusApp, self).postInit(self.main_widget)
def keysToText(self, keys):
"""Generator return normal text from urwid keys"""
for k in keys:
if k == 'tab':
yield u'\t'
elif k == 'enter':
yield u'\n'
elif is_wide_char(k,0) or (len(k)==1 and ord(k) >= 32):
yield k
def inputFilter(self, input_, raw):
if self.__saved_overlay and input_ != a_key['OVERLAY_HIDE']:
return
if len(input_) > 1: # XXX: it may be needed to increase this value if buffer
# or other things result in several chars at once
# (e.g. using Primitivus through ssh). Need some testing
# and experience to adjust value.
log.debug(u"Paste detected")
if (len(input_) > 1 and # XXX: it may be needed to increase this value if buffer
not isinstance(input_[0], tuple) and # or other things result in several chars at once
not 'window' in input_[0]): # (e.g. using Primitivus through ssh). Need some testing
# and experience to adjust value.
log.debug(u"Paste detected (len {})".format(len(input_)))
try:
edit_bar = self.editBar
except AttributeError:
@ -374,8 +385,10 @@ class PrimitivusApp(QuickApp, InputHistory):
else:
# XXX: if a paste is detected, we append it directly to the edit bar text
# so the use can check it and press [enter] if it's OK
buf_paste = u''.join((unichr(k) for k in raw))
edit_bar.set_edit_text(u'{}{}'.format(edit_bar.edit_text, buf_paste))
buf_paste = u''.join(self.keysToText(input_))
pos = edit_bar.edit_pos
edit_bar.set_edit_text(u'{}{}{}'.format(edit_bar.edit_text[:pos], buf_paste, edit_bar.edit_text[pos:]))
edit_bar.edit_pos+=len(buf_paste)
return
for i in input_: