Skip to content

Commit 8ae4336

Browse files
committed
Indent sensibly after enter, maintain cursor position better.
That is: listbox mutation no longer affects the cursor position, only events handled by the edit widget do.
1 parent 2a15412 commit 8ae4336

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

bpython/urwid.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,16 @@ class BPythonEdit(urwid.Edit):
129129
130130
This is currently a one-way operation, but that is just because
131131
I only need and test the readwrite->readonly transition.
132+
133+
- move_cursor_to_coords is ignored
134+
(except for internal calls from keypress or mouse_event).
132135
"""
133136

134137
def __init__(self, *args, **kwargs):
135138
self._bpy_text = ''
136139
self._bpy_attr = []
137140
self._bpy_selectable = True
141+
self._bpy_may_move_cursor = False
138142
urwid.Edit.__init__(self, *args, **kwargs)
139143

140144
def make_readonly(self):
@@ -182,6 +186,25 @@ def get_pref_col(self, size):
182186
return 'left'
183187
return urwid.Edit.get_pref_col(self, size)
184188

189+
def move_cursor_to_coords(self, *args):
190+
if self._bpy_may_move_cursor:
191+
return urwid.Edit.move_cursor_to_coords(self, *args)
192+
return False
193+
194+
def keypress(self, *args):
195+
self._bpy_may_move_cursor = True
196+
try:
197+
return urwid.Edit.keypress(self, *args)
198+
finally:
199+
self._bpy_may_move_cursor = False
200+
201+
def mouse_event(self, *args):
202+
self._bpy_may_move_cursor = True
203+
try:
204+
return urwid.Edit.mouse_event(self, *args)
205+
finally:
206+
self._bpy_may_move_cursor = False
207+
185208

186209
class Tooltip(urwid.BoxWidget):
187210

@@ -460,6 +483,8 @@ def prompt(self, more):
460483
self.stdout_hist += '... '
461484

462485
urwid.connect_signal(self.edit, 'change', self.on_input_change)
486+
# Do this after connecting the change signal handler:
487+
self.edit.insert_text(4 * self.next_indentation() * ' ')
463488
self.edits.append(self.edit)
464489
self.listbox.body.append(self.edit)
465490
self.listbox.set_focus(len(self.listbox.body) - 1)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy