Improved ctrl+d functionality; improved undo/redo

This commit is contained in:
itdominator 2024-09-22 21:10:50 -05:00
parent 30634d9af7
commit dc387d1d4c
2 changed files with 30 additions and 14 deletions

View File

@ -36,6 +36,11 @@ class KeyInputController:
if keyname == "Down": if keyname == "Down":
self.keyboard_move_lines_down() self.keyboard_move_lines_down()
if keyname == "z":
self.keyboard_undo()
if keyname == "y":
self.keyboard_redo()
return True return True
if is_alt: if is_alt:
@ -87,10 +92,6 @@ class KeyInputController:
return True return True
if keyname in ["z", "y", "m", "s", "h", "g", "d", "k", "u", "space", "equal", "minus"]: if keyname in ["z", "y", "m", "s", "h", "g", "d", "k", "u", "space", "equal", "minus"]:
if keyname == "z":
self.keyboard_undo()
if keyname == "y":
self.keyboard_redo()
if keyname == "m": if keyname == "m":
self.keyboard_insert_mark() self.keyboard_insert_mark()
if keyname == "s": if keyname == "s":

View File

@ -44,11 +44,22 @@ class SourceViewControllerMixin(KeyInputController, SourceViewEvents):
def duplicate_line(self, buffer = None): def duplicate_line(self, buffer = None):
buffer = self.get_buffer() if not buffer else buffer buffer = self.get_buffer() if not buffer else buffer
if not buffer.get_has_selection():
had_selection = False
itr = buffer.get_iter_at_mark( buffer.get_insert() ) itr = buffer.get_iter_at_mark( buffer.get_insert() )
start_itr = itr.copy() start_itr = itr.copy()
end_itr = itr.copy() end_itr = itr.copy()
start_line = itr.get_line() + 1 start_line = itr.get_line() + 1
start_char = itr.get_line_offset() start_char = itr.get_line_offset()
else:
had_selection = True
start_itr, end_itr = buffer.get_selection_bounds()
sline = start_itr.get_line()
eline = end_itr.get_line()
start_line = eline + 1
start_char = start_itr.get_line_offset()
end_char = end_itr.get_line_offset()
range_line_size = eline - sline
start_itr.backward_visible_line() start_itr.backward_visible_line()
start_itr.forward_line() start_itr.forward_line()
@ -56,12 +67,16 @@ class SourceViewControllerMixin(KeyInputController, SourceViewEvents):
end_itr.backward_char() end_itr.backward_char()
line_str = buffer.get_slice(start_itr, end_itr, True) line_str = buffer.get_slice(start_itr, end_itr, True)
end_itr.forward_char() end_itr.forward_char()
buffer.insert(end_itr, f"{line_str}\n", -1) buffer.insert(end_itr, f"{line_str}\n", -1)
if not had_selection:
new_itr = buffer.get_iter_at_line_offset(start_line, start_char) new_itr = buffer.get_iter_at_line_offset(start_line, start_char)
buffer.place_cursor(new_itr) buffer.place_cursor(new_itr)
else:
new_itr = buffer.get_iter_at_line_offset(start_line, start_char)
new_end_itr = buffer.get_iter_at_line_offset((start_line + range_line_size), end_char)
buffer.select_range(new_itr, new_end_itr)
def cut_to_buffer(self, buffer = None): def cut_to_buffer(self, buffer = None):
self.cancel_timer() self.cancel_timer()