Added deep indent on : or { ending lines plus regular indent for multi insert

This commit is contained in:
itdominator 2023-10-28 20:18:50 -05:00
parent 35bc3faa70
commit d90ed2fdc8
6 changed files with 70 additions and 13 deletions

View File

@ -6,6 +6,7 @@ gi.require_version('Gtk', '3.0')
from gi.repository import Gtk from gi.repository import Gtk
# Application imports # Application imports
from ..widgets.separator_widget import Separator
from ..widgets.miniview_widget import MiniViewWidget from ..widgets.miniview_widget import MiniViewWidget
from ..widgets.base.notebook.editor_notebook import EditorNotebook from ..widgets.base.notebook.editor_notebook import EditorNotebook
@ -38,7 +39,6 @@ class EditorsPaned(Gtk.Paned):
class EditorsContainer(Gtk.Box): class EditorsContainer(Gtk.Box):
def __init__(self): def __init__(self):
super(EditorsContainer, self).__init__() super(EditorsContainer, self).__init__()
@ -61,5 +61,7 @@ class EditorsContainer(Gtk.Box):
... ...
def _load_widgets(self): def _load_widgets(self):
self.add(Separator("separator_left"))
self.add(EditorsPaned()) self.add(EditorsPaned())
self.add(Separator("separator_right"))
self.add(MiniViewWidget()) self.add(MiniViewWidget())

View File

@ -59,6 +59,7 @@ class EditorControllerMixin:
if action == "set_buffer_style": if action == "set_buffer_style":
self.set_buffer_style(source_view, query) self.set_buffer_style(source_view, query)
if action == "save_file": if action == "save_file":
source_view.save_file() return source_view.save_file()
if action == "save_file_as": if action == "save_file_as":
source_view.save_file_as() return source_view.save_file_as()

View File

@ -214,4 +214,4 @@ class EditorNotebook(EditorEventsMixin, EditorControllerMixin, Gtk.Notebook):
self.action_controller("save_file") self.action_controller("save_file")
def _keyboard_save_file_as(self): def _keyboard_save_file_as(self):
self.action_controller("save_file_as") self.action_controller("save_file_as")

View File

@ -92,6 +92,49 @@ class MarkEventsMixin:
buffer.backspace(iter, interactive = True, default_editable = True) buffer.backspace(iter, interactive = True, default_editable = True)
self.end_user_action(buffer) self.end_user_action(buffer)
def _new_line_on_multi_line_markers(self, buffer):
self.insert_indent_handler(buffer)
for mark in self._multi_insert_marks:
iter = buffer.get_iter_at_mark(mark)
self.insert_indent_handler(buffer, iter)
self.end_user_action(buffer)
def insert_indent_handler(self, buffer, iter = None):
if not iter:
iter = buffer.get_iter_at_mark( buffer.get_insert() )
iter_copy = iter.copy()
iter_moved = iter_copy.backward_char()
if iter_moved:
_char = iter_copy.get_char()
self._base_indent(buffer, iter, iter_copy)
if _char in ["{", ":"]:
self._indent_deeper(buffer, iter)
return True
def _base_indent(self, buffer, iter, iter_copy):
line_num = iter_copy.get_line()
iter_copy = buffer.get_iter_at_line(line_num)
spaces = ""
_char = iter_copy.get_char()
while _char == " ":
spaces += " "
iter_copy.forward_char()
_char = iter_copy.get_char()
buffer.insert(iter, f"\n{spaces}")
def _indent_deeper(self, buffer, iter):
buffer.insert(iter, " ")
def begin_user_action(self, buffer): def begin_user_action(self, buffer):
if len(self._multi_insert_marks) > 0: if len(self._multi_insert_marks) > 0:
@ -101,4 +144,4 @@ class MarkEventsMixin:
def end_user_action(self, buffer): def end_user_action(self, buffer):
if len(self._multi_insert_marks) > 0: if len(self._multi_insert_marks) > 0:
buffer.end_user_action() buffer.end_user_action()
self.freeze_multi_line_insert = False self.freeze_multi_line_insert = False

View File

@ -160,9 +160,6 @@ class SourceView(SourceViewEventsMixin, GtkSource.View):
is_alt = True if modifiers & Gdk.ModifierType.MOD1_MASK else False is_alt = True if modifiers & Gdk.ModifierType.MOD1_MASK else False
if is_control: if is_control:
if keyname in [ "slash", "Up", "Down", "z" ]:
return True
if is_shift: if is_shift:
if keyname in [ "z", "Up", "Down", "Left", "Right" ]: if keyname in [ "z", "Up", "Down", "Left", "Right" ]:
# NOTE: For now do like so for completion sake above. # NOTE: For now do like so for completion sake above.
@ -171,17 +168,31 @@ class SourceView(SourceViewEventsMixin, GtkSource.View):
return True return True
if keyname in [ "slash", "Up", "Down", "z" ]:
return True
if is_alt: if is_alt:
if keyname in [ "Up", "Down", "Left", "Right" ]: if keyname in [ "Up", "Down", "Left", "Right" ]:
return True return True
if keyname == "BackSpace":
if len(self._multi_insert_marks) > 0: if len(self._multi_insert_marks) > 0:
if keyname == "BackSpace":
self.begin_user_action(buffer) self.begin_user_action(buffer)
with buffer.freeze_notify(): with buffer.freeze_notify():
GLib.idle_add(self._delete_on_multi_line_markers, *(buffer,)) GLib.idle_add(self._delete_on_multi_line_markers, *(buffer,))
return True if keyname in {"Return", "Enter"}:
self.begin_user_action(buffer)
with buffer.freeze_notify():
GLib.idle_add(self._new_line_on_multi_line_markers, *(buffer,))
else:
...
return True
if keyname in {"Return", "Enter"}:
return self.insert_indent_handler(buffer)
# NOTE: if a plugin recieves the call and handles, it will be the final decider for propigation # NOTE: if a plugin recieves the call and handles, it will be the final decider for propigation
return event_system.emit_and_await("autopairs", (keyname, is_control, is_alt, is_shift)) return event_system.emit_and_await("autopairs", (keyname, is_control, is_alt, is_shift))
@ -274,4 +285,4 @@ class SourceView(SourceViewEventsMixin, GtkSource.View):
except Exception as e: except Exception as e:
gfile = Gio.File.new_for_path(uri) gfile = Gio.File.new_for_path(uri)
event_system.emit('create_view', (gfile,)) event_system.emit('create_view', (gfile,))

View File

@ -114,4 +114,4 @@ class SourceViewEventsMixin(MarkEventsMixin, FileEventsMixin):
if not gfile: return if not gfile: return
event_system.emit("set_bottom_labels", (gfile, None, self._current_filetype, None)) event_system.emit("set_bottom_labels", (gfile, None, self._current_filetype, None))
self.update_cursor_position() self.update_cursor_position()