diff --git a/frontends/src/primitivus/primitivus b/frontends/src/primitivus/primitivus index ab89da58..28afb4a9 100755 --- a/frontends/src/primitivus/primitivus +++ b/frontends/src/primitivus/primitivus @@ -301,6 +301,7 @@ class PrimitivusApp(QuickApp, InputHistory): # we already manage exit with a_key['APP_QUIT'], so we don't want C-c signal.signal(signal.SIGINT, signal.SIG_IGN) + self._bracketed_paste = False @property def visible_widgets(self): @@ -377,6 +378,33 @@ class PrimitivusApp(QuickApp, InputHistory): 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. + if input_[0] == 'begin paste' and not self._bracketed_paste: + log.info(u"Bracketed paste mode detected") + self._bracketed_paste = True + + if self._bracketed_paste: + # after this block, extra will contain non pasted keys + # and input_ will contain pasted keys + try: + begin_idx = input_.index('begin paste') + except ValueError: + # this is not a paste, maybe we have something buffering + # or bracketed mode is set in conf but not enabled in term + extra = input_ + input_ = [] + else: + try: + end_idx = input_.index('end paste') + except ValueError: + log.warning(u"missing end paste sequence, discarding paste") + extra = input_[:begin_idx] + del input_[begin_idx:] + else: + extra = input_[:begin_idx] + input_[end_idx+1:] + input_ = input_[begin_idx+1:end_idx] + else: + extra = None + log.debug(u"Paste detected (len {})".format(len(input_))) try: edit_bar = self.editBar @@ -389,7 +417,9 @@ class PrimitivusApp(QuickApp, InputHistory): 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) + if not extra: return + input_ = extra for i in input_: if isinstance(i,tuple):