Refactor code completion, container layouts, and webkit settings
- Renamed alt_provider.py file under words completer - Improve word completion matching logic with character validation - Change container orientations (header→vertical, left/right→horizontal) - Add separators to all container edges - Refactor webkit UI loading into separate load_url/load_context_base_path methods - Add comprehensive webkit browser-like settings
This commit is contained in:
68
plugins/code/completers/words_completer/default_provider.py
Normal file
68
plugins/code/completers/words_completer/default_provider.py
Normal file
@@ -0,0 +1,68 @@
|
||||
# Python imports
|
||||
import re
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
gi.require_version('GtkSource', '4')
|
||||
|
||||
from gi.repository import GObject
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import GtkSource
|
||||
|
||||
# Application imports
|
||||
from .provider_response_cache import ProviderResponseCache
|
||||
|
||||
|
||||
|
||||
class Provider(GtkSource.CompletionWords):
|
||||
"""
|
||||
This is a Words Completion Provider.
|
||||
# NOTE: used information from here --> https://warroom.rsmus.com/do-that-auto-complete/
|
||||
"""
|
||||
__gtype_name__ = 'WordsCompletionProvider'
|
||||
|
||||
def __init__(self):
|
||||
super(Provider, self).__init__()
|
||||
|
||||
self.response_cache: ProviderResponseCache = ProviderResponseCache()
|
||||
|
||||
|
||||
def do_get_name(self):
|
||||
return 'Words Completion'
|
||||
|
||||
def do_match(self, context):
|
||||
# Note: If provider is in interactive activation then need to check
|
||||
# view focus as otherwise non focus views start trying to grab it.
|
||||
completion = context.get_property("completion")
|
||||
if not completion.get_view().has_focus(): return
|
||||
|
||||
word = self.response_cache.get_word(context)
|
||||
if not word or len(word) < 2: return False
|
||||
|
||||
iter = self.response_cache.get_iter_correctly(context)
|
||||
iter.backward_char()
|
||||
ch = iter.get_char()
|
||||
# NOTE: Look to re-add or apply supprting logic to use spaces
|
||||
# As is it slows down the editor in certain contexts...
|
||||
# if not (ch in ('_', '.', ' ') or ch.isalnum()):
|
||||
if not (ch in ('_', '.') or ch.isalnum()):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def do_get_priority(self):
|
||||
return 0
|
||||
|
||||
def do_activate_proposal(self, proposal, iter_):
|
||||
buffer = iter_.get_buffer()
|
||||
# Note: Flag mostly intended for SourceViewsMultiInsertState
|
||||
# to insure marker processes inserted text correctly.
|
||||
buffer.is_processing_completion = True
|
||||
return False
|
||||
|
||||
def do_get_activation(self):
|
||||
""" The context for when a provider will show results """
|
||||
# return GtkSource.CompletionActivation.NONE
|
||||
# return GtkSource.CompletionActivation.USER_REQUESTED
|
||||
return GtkSource.CompletionActivation.INTERACTIVE
|
||||
Reference in New Issue
Block a user