X Tutup
Skip to content

Commit b7d7420

Browse files
committed
urwid: implement C-w (clear word).
1 parent 82389e2 commit b7d7420

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

bpython/urwid.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,23 @@ def keypress(self, size, key):
404404
self.edit_pos = 0
405405
elif urwid.command_map[key] == 'cursor max right':
406406
self.edit_pos = len(self.get_edit_text())
407+
elif urwid.command_map[key] == 'clear word':
408+
# ^w
409+
if self.edit_pos == 0:
410+
return
411+
line = self.get_edit_text()
412+
# delete any space left of the cursor
413+
p = len(line[:self.edit_pos].strip())
414+
line = line[:p] + line[self.edit_pos:]
415+
# delete a full word
416+
np = line.rfind(' ', 0, p)
417+
if np == -1:
418+
line = line[p:]
419+
np = 0
420+
else:
421+
line = line[:np] + line[p:]
422+
self.set_edit_text(line)
423+
self.edit_pos = np
407424
elif key == 'backspace':
408425
line = self.get_edit_text()
409426
cpos = len(line) - self.edit_pos
@@ -1275,10 +1292,11 @@ def load_urwid_command_map(config):
12751292
urwid.command_map[key_dispatch['C-f']] = 'cursor right'
12761293
urwid.command_map[key_dispatch['C-b']] = 'cursor left'
12771294
urwid.command_map[key_dispatch['C-d']] = 'delete'
1295+
urwid.command_map[key_dispatch[config.clear_word_key]] = 'clear word'
1296+
12781297
"""
12791298
'clear_line': 'C-u',
12801299
'clear_screen': 'C-l',
1281-
'clear_word': 'C-w',
12821300
'cut_to_buffer': 'C-k',
12831301
'down_one_line': 'C-n',
12841302
'exit': '',

0 commit comments

Comments
 (0)
X Tutup