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":
self.keyboard_move_lines_down()
if keyname == "z":
self.keyboard_undo()
if keyname == "y":
self.keyboard_redo()
return True
if is_alt:
@ -87,10 +92,6 @@ class KeyInputController:
return True
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":
self.keyboard_insert_mark()
if keyname == "s":

View File

@ -43,25 +43,40 @@ class SourceViewControllerMixin(KeyInputController, SourceViewEvents):
event_system.emit("textDocument/definition", (self.get_filetype(), uri, line, offset,))
def duplicate_line(self, buffer = None):
buffer = self.get_buffer() if not buffer else buffer
itr = buffer.get_iter_at_mark( buffer.get_insert() )
start_itr = itr.copy()
end_itr = itr.copy()
start_line = itr.get_line() + 1
start_char = itr.get_line_offset()
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() )
start_itr = itr.copy()
end_itr = itr.copy()
start_line = itr.get_line() + 1
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.forward_line()
end_itr.forward_line()
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()
buffer.insert(end_itr, f"{line_str}\n", -1)
new_itr = buffer.get_iter_at_line_offset(start_line, start_char)
buffer.place_cursor(new_itr)
if not had_selection:
new_itr = buffer.get_iter_at_line_offset(start_line, start_char)
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):
self.cancel_timer()