generated from itdominator/Python-With-Gtk-Template
text insertion fixes
This commit is contained in:
parent
84b24d6767
commit
8eb8c4d543
|
@ -13,7 +13,9 @@ class CompletionItem(Gtk.Label):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(CompletionItem, self).__init__()
|
super(CompletionItem, self).__init__()
|
||||||
|
|
||||||
|
self.newText: str = ""
|
||||||
self.insertText: str = ""
|
self.insertText: str = ""
|
||||||
|
self.textEdit: [] = []
|
||||||
self.additionalTextEdits: [] = []
|
self.additionalTextEdits: [] = []
|
||||||
|
|
||||||
self._setup_styling()
|
self._setup_styling()
|
||||||
|
@ -34,8 +36,13 @@ class CompletionItem(Gtk.Label):
|
||||||
keys = item.keys()
|
keys = item.keys()
|
||||||
self.set_label(item["label"])
|
self.set_label(item["label"])
|
||||||
|
|
||||||
|
|
||||||
if "insertText" in keys:
|
if "insertText" in keys:
|
||||||
self.insertText = item["insertText"]
|
self.insertText = item["insertText"]
|
||||||
|
|
||||||
|
if "textEdit" in keys:
|
||||||
|
self.textEdit = item["textEdit"]
|
||||||
|
self.newText = item["textEdit"]["newText"]
|
||||||
|
|
||||||
if "additionalTextEdits" in keys:
|
if "additionalTextEdits" in keys:
|
||||||
self.additionalTextEdits = item["additionalTextEdits"]
|
self.additionalTextEdits = item["additionalTextEdits"]
|
|
@ -53,6 +53,7 @@ class CompletionView(Gtk.ScrolledWindow):
|
||||||
self.button_box.set_selection_mode( Gtk.SelectionMode.BROWSE )
|
self.button_box.set_selection_mode( Gtk.SelectionMode.BROWSE )
|
||||||
|
|
||||||
self.button_box.connect("key-release-event", self._key_release_event)
|
self.button_box.connect("key-release-event", self._key_release_event)
|
||||||
|
self.button_box.connect("button-release-event", self._button_release_event)
|
||||||
|
|
||||||
viewport.add(self.button_box)
|
viewport.add(self.button_box)
|
||||||
self.add(viewport)
|
self.add(viewport)
|
||||||
|
@ -70,6 +71,10 @@ class CompletionView(Gtk.ScrolledWindow):
|
||||||
self.activate_completion()
|
self.activate_completion()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def _button_release_event(self, widget, eve):
|
||||||
|
if eve.button == 1: # lclick
|
||||||
|
self.activate_completion()
|
||||||
|
return True
|
||||||
|
|
||||||
def clear_items(self):
|
def clear_items(self):
|
||||||
for child in self.button_box.get_children():
|
for child in self.button_box.get_children():
|
||||||
|
@ -128,6 +133,30 @@ class CompletionView(Gtk.ScrolledWindow):
|
||||||
siter = buffer.get_iter_at_mark( buffer.get_insert() )
|
siter = buffer.get_iter_at_mark( buffer.get_insert() )
|
||||||
pre_char = self.get_pre_char(siter)
|
pre_char = self.get_pre_char(siter)
|
||||||
|
|
||||||
|
if completion_item.textEdit:
|
||||||
|
sline = completion_item.textEdit["range"]["start"]["line"]
|
||||||
|
schar = completion_item.textEdit["range"]["start"]["character"]
|
||||||
|
eline = completion_item.textEdit["range"]["end"]["line"]
|
||||||
|
echar = completion_item.textEdit["range"]["end"]["character"]
|
||||||
|
siter = buffer.get_iter_at_line_offset( sline, schar )
|
||||||
|
eiter = buffer.get_iter_at_line_offset( eline, echar )
|
||||||
|
|
||||||
|
buffer.delete(siter, eiter)
|
||||||
|
buffer.insert(siter, completion_item.newText, -1)
|
||||||
|
|
||||||
|
source_view.remove(self)
|
||||||
|
GLib.idle_add( source_view.grab_focus )
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
if pre_char == '.':
|
||||||
|
buffer.insert(siter, completion_item.insertText, -1)
|
||||||
|
|
||||||
|
source_view.remove(self)
|
||||||
|
GLib.idle_add( source_view.grab_focus )
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
if siter.inside_word() or siter.ends_word() or pre_char == '_':
|
if siter.inside_word() or siter.ends_word() or pre_char == '_':
|
||||||
eiter = siter.copy()
|
eiter = siter.copy()
|
||||||
siter.backward_visible_word_start()
|
siter.backward_visible_word_start()
|
||||||
|
@ -139,7 +168,6 @@ class CompletionView(Gtk.ScrolledWindow):
|
||||||
buffer.delete(siter, eiter)
|
buffer.delete(siter, eiter)
|
||||||
|
|
||||||
buffer.insert(siter, completion_item.insertText, -1)
|
buffer.insert(siter, completion_item.insertText, -1)
|
||||||
|
|
||||||
for edit in completion_item.additionalTextEdits:
|
for edit in completion_item.additionalTextEdits:
|
||||||
print()
|
print()
|
||||||
print()
|
print()
|
||||||
|
|
Loading…
Reference in New Issue