Mercurial > libervia-backend
changeset 1947:be4b143cf123
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
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 22 Apr 2016 22:30:13 +0200 |
parents | 827bb478d8af |
children | 373550000092 |
files | frontends/src/primitivus/primitivus |
diffstat | 1 files changed, 20 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/frontends/src/primitivus/primitivus Thu Apr 21 20:20:40 2016 +0200 +++ b/frontends/src/primitivus/primitivus Fri Apr 22 22:30:13 2016 +0200 @@ -25,6 +25,7 @@ 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 @@ 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 @@ 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_: