def common_do_populate(obj, filter_func, all_func,
                       context: GtkSource.CompletionContext):
    _, textiter = context.get_iter()
    buffer: Gtk.TextBuffer = textiter.get_buffer()

    prev_textiter = textiter.copy()
    prev_textiter.backward_char()
    previous_char = prev_textiter.get_char()

    if textiter.ends_word() or previous_char == '_':
        start_word = textiter.copy()
        backward_until_special_char(start_word)
        word = buffer.get_text(start_word, textiter, False)
        context.add_proposals(obj, filter_func(word), True)
    context.add_proposals(obj, all_func(), True)
Beispiel #2
0
 def do_match(self, context: GtkSource.CompletionContext):
     if context.get_activation(
     ) == GtkSource.CompletionActivation.USER_REQUESTED:
         return True
     iterator: Gtk.TextIter = get_context_iter(context).copy()
     if not iterator.backward_char():
         return False
     char = iterator.get_char()
     return char in SymbolsSet.SYMBOL_CHARS or char == "%"
 def do_get_start_iter(
     self, context: GtkSource.CompletionContext,
     proposal: GtkSource.CompletionProposal
 ) -> Tuple[bool, Optional[Gtk.TextIter]]:
     correctly_set, textiter = context.get_iter()
     assert correctly_set
     copy = textiter.copy()
     backward_until_special_char(copy)
     return True, copy
def common_do_match(filter_func, all_func,
                    context: GtkSource.CompletionContext) -> bool:
    _, textiter = context.get_iter()
    buffer: Gtk.TextBuffer = textiter.get_buffer()

    prev_textiter = textiter.copy()
    prev_textiter.backward_char()
    previous_char = prev_textiter.get_char()

    if textiter.ends_word() or previous_char == '_':
        start_word = textiter.copy()
        backward_until_special_char(start_word)
        word = buffer.get_text(start_word, textiter, False)
        return (len(word) > 2 or
                (len(word) > 0 and word[0] == '$') or context.get_activation()
                == GtkSource.CompletionActivation.USER_REQUESTED) and len(
                    filter_func(word)) > 0
    return not textiter.inside_word() and context.get_activation(
    ) == GtkSource.CompletionActivation.USER_REQUESTED
Beispiel #5
0
def get_context_iter(context: GtkSource.CompletionContext) -> Gtk.TextIter:
    end_iter = context.get_iter()
    if not isinstance(end_iter, Gtk.TextIter):
        end_iter = end_iter[1]
    return end_iter
Beispiel #6
0
 def do_populate(self, context: GtkSource.CompletionContext):
     end_iter = get_context_iter(context)
     self.symbols_set.extract(end_iter)
     proposals = list(self.get_proposals(end_iter))
     if len(proposals) > 0:
         context.add_proposals(self, proposals, True)