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":
|
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":
|
||||||
|
|
|
@ -43,25 +43,40 @@ class SourceViewControllerMixin(KeyInputController, SourceViewEvents):
|
||||||
event_system.emit("textDocument/definition", (self.get_filetype(), uri, line, offset,))
|
event_system.emit("textDocument/definition", (self.get_filetype(), uri, line, offset,))
|
||||||
|
|
||||||
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
|
||||||
itr = buffer.get_iter_at_mark( buffer.get_insert() )
|
if not buffer.get_has_selection():
|
||||||
start_itr = itr.copy()
|
had_selection = False
|
||||||
end_itr = itr.copy()
|
itr = buffer.get_iter_at_mark( buffer.get_insert() )
|
||||||
start_line = itr.get_line() + 1
|
start_itr = itr.copy()
|
||||||
start_char = itr.get_line_offset()
|
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.backward_visible_line()
|
||||||
start_itr.forward_line()
|
start_itr.forward_line()
|
||||||
end_itr.forward_line()
|
end_itr.forward_line()
|
||||||
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)
|
||||||
|
|
||||||
new_itr = buffer.get_iter_at_line_offset(start_line, start_char)
|
if not had_selection:
|
||||||
buffer.place_cursor(new_itr)
|
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):
|
def cut_to_buffer(self, buffer = None):
|
||||||
self.cancel_timer()
|
self.cancel_timer()
|
||||||
|
|
Loading…
Reference in New Issue