generated from itdominator/Python-With-Gtk-Template
Improved ctrl+d functionality; improved undo/redo
This commit is contained in:
parent
30634d9af7
commit
dc387d1d4c
|
@ -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":
|
||||
|
|
|
@ -44,11 +44,22 @@ class SourceViewControllerMixin(KeyInputController, SourceViewEvents):
|
|||
|
||||
def duplicate_line(self, buffer = None):
|
||||
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()
|
||||
|
@ -56,12 +67,16 @@ class SourceViewControllerMixin(KeyInputController, SourceViewEvents):
|
|||
end_itr.backward_char()
|
||||
|
||||
line_str = buffer.get_slice(start_itr, end_itr, True)
|
||||
|
||||
end_itr.forward_char()
|
||||
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)
|
||||
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()
|
||||
|
|
Loading…
Reference in New Issue