X Tutup
Skip to content

Commit b6230d9

Browse files
paste events work in stdin and save dialogs
1 parent ec023e0 commit b6230d9

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

bpython/curtsiesfrontend/interaction.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ def process_event(self, e):
5252
if isinstance(e, events.RefreshRequestEvent):
5353
self.waiting_for_refresh = False
5454
self.request_greenlet.switch()
55+
elif isinstance(e, events.PasteEvent):
56+
for ee in e.events:
57+
self.add_normal_character(ee if len(ee) == 1 else ee[-1]) #strip control seq
5558
elif e in rl_char_sequences:
5659
self.cursor_offset_in_line, self._current_line = rl_char_sequences[e](self.cursor_offset_in_line, self._current_line)
5760
elif e == "":
@@ -72,10 +75,13 @@ def process_event(self, e):
7275
self.request_greenlet.switch(False)
7376
self.escape()
7477
else: # add normal character
75-
self._current_line = (self._current_line[:self.cursor_offset_in_line] +
76-
e +
77-
self._current_line[self.cursor_offset_in_line:])
78-
self.cursor_offset_in_line += 1
78+
self.add_normal_character(e)
79+
80+
def add_normal_character(self, e):
81+
self._current_line = (self._current_line[:self.cursor_offset_in_line] +
82+
e +
83+
self._current_line[self.cursor_offset_in_line:])
84+
self.cursor_offset_in_line += 1
7985

8086
def escape(self):
8187
"""unfocus from statusbar, clear prompt state, wait for notify call"""

bpython/curtsiesfrontend/repl.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ def __init__(self, coderunner, repl):
5555

5656
def process_event(self, e):
5757
assert self.has_focus
58-
if e in rl_char_sequences:
58+
if isinstance(e, events.PasteEvent):
59+
for ee in e.events:
60+
self.add_normal_character(ee if len(ee) == 1 else ee[-1]) #strip control seq
61+
elif e in rl_char_sequences:
5962
self.cursor_offset_in_line, self.current_line = rl_char_sequences[e](self.cursor_offset_in_line, self.current_line)
6063
elif isinstance(e, events.SigIntEvent):
6164
self.coderunner.sigint_happened = True
@@ -64,12 +67,7 @@ def process_event(self, e):
6467
self.cursor_offset_in_line = 0
6568
self.repl.run_code_and_maybe_finish()
6669
else: # add normal character
67-
logging.debug('adding normal char %r to current line', e)
68-
c = e if py3 else e.encode('utf8')
69-
self.current_line = (self.current_line[:self.cursor_offset_in_line] +
70-
c +
71-
self.current_line[self.cursor_offset_in_line:])
72-
self.cursor_offset_in_line += 1
70+
self.add_normal_character(e)
7371

7472
if self.current_line.endswith(("\n", "\r")):
7573
line = self.current_line
@@ -82,6 +80,14 @@ def process_event(self, e):
8280
else:
8381
self.repl.send_to_stdin(self.current_line)
8482

83+
def add_normal_character(self, e):
84+
logging.debug('adding normal char %r to current line', e)
85+
c = e if py3 else e.encode('utf8')
86+
self.current_line = (self.current_line[:self.cursor_offset_in_line] +
87+
c +
88+
self.current_line[self.cursor_offset_in_line:])
89+
self.cursor_offset_in_line += 1
90+
8591
def readline(self):
8692
self.has_focus = True
8793
self.repl.send_to_stdin(self.current_line)

0 commit comments

Comments
 (0)
X Tutup