Fixed ctrl w

This commit is contained in:
Henrique 2019-11-25 18:55:12 -05:00
parent 046779615f
commit 8449db103e

View File

@ -222,13 +222,19 @@ class CommandEdit(urwid.WidgetWrap):
pos = len(self.cbuf.text) pos = len(self.cbuf.text)
self.cbuf.cursor = pos self.cbuf.cursor = pos
elif key == "ctrl w": elif key == "ctrl w":
txt = self.cbuf.text.strip() prev_cursor = self.cbuf.cursor
if(txt != ''): pos = self.cbuf.text.rfind(' ', 0, self.cbuf.cursor - 1)
chunks = txt.split(' ')[0:-1] if pos == -1:
if len(chunks) == 0: new_text = self.cbuf.text[self.cbuf.cursor:]
self.cbuf.set_text(' '.join(chunks)) cursor_pos = 0
else: else:
self.cbuf.set_text(' '.join(chunks) + ' ') txt_after = self.cbuf.text[self.cbuf.cursor:]
txt_before = self.cbuf.text[0:pos]
new_text = f"{txt_before} {txt_after}"
cursor_pos = prev_cursor - (prev_cursor - pos) + 1
self.cbuf.set_text(new_text)
self.cbuf.cursor = cursor_pos
elif key == "backspace": elif key == "backspace":
self.cbuf.backspace() self.cbuf.backspace()
elif key == "left" or key == "ctrl b": elif key == "left" or key == "ctrl b":