Esempio n. 1
0
    def find_spell_word(self, original_words, lang, from_cursor=True, center_on_cursor=True):
        c = self.textCursor()
        c.setPosition(c.position())
        if not from_cursor:
            c.movePosition(c.Start)
        c.movePosition(c.End, c.KeepAnchor)

        def find_first_word(haystack):
            match_pos, match_word = -1, None
            for w in original_words:
                idx = index_of(w, haystack, lang=lang)
                if idx > -1 and (match_pos == -1 or match_pos > idx):
                    match_pos, match_word = idx, w
            return match_pos, match_word

        while True:
            text = unicode(c.selectedText()).rstrip("\0")
            idx, word = find_first_word(text)
            if idx == -1:
                return False
            c.setPosition(c.anchor() + idx)
            c.setPosition(c.position() + string_length(word), c.KeepAnchor)
            if self.smarts.verify_for_spellcheck(c, self.highlighter):
                self.setTextCursor(c)
                if center_on_cursor:
                    self.centerCursor()
                return True
            c.setPosition(c.position())
            c.movePosition(c.End, c.KeepAnchor)

        return False
Esempio n. 2
0
    def find_spell_word(self, original_words, lang, from_cursor=True, center_on_cursor=True):
        c = self.textCursor()
        c.setPosition(c.position())
        if not from_cursor:
            c.movePosition(QTextCursor.MoveOperation.Start)
        c.movePosition(QTextCursor.MoveOperation.End, QTextCursor.MoveMode.KeepAnchor)

        def find_first_word(haystack):
            match_pos, match_word = -1, None
            for w in original_words:
                idx = index_of(w, haystack, lang=lang)
                if idx > -1 and (match_pos == -1 or match_pos > idx):
                    match_pos, match_word = idx, w
            return match_pos, match_word

        while True:
            text = unicode_type(c.selectedText()).rstrip('\0')
            idx, word = find_first_word(text)
            if idx == -1:
                return False
            c.setPosition(c.anchor() + idx)
            c.setPosition(c.position() + string_length(word), QTextCursor.MoveMode.KeepAnchor)
            if self.smarts.verify_for_spellcheck(c, self.highlighter):
                self.highlighter.join()  # Ensure highlighting is finished
                locale = self.spellcheck_locale_for_cursor(c)
                if not lang or not locale or (locale and lang == locale.langcode):
                    self.setTextCursor(c)
                    if center_on_cursor:
                        self.centerCursor()
                    return True
            c.setPosition(c.position())
            c.movePosition(QTextCursor.MoveOperation.End, QTextCursor.MoveMode.KeepAnchor)

        return False
Esempio n. 3
0
    def find_spell_word(self, original_words, lang, from_cursor=True):
        c = self.textCursor()
        c.setPosition(c.position())
        if not from_cursor:
            c.movePosition(c.Start)
        c.movePosition(c.End, c.KeepAnchor)

        def find_first_word(haystack):
            match_pos, match_word = -1, None
            for w in original_words:
                idx = index_of(w, haystack, lang=lang)
                if idx > -1 and (match_pos == -1 or match_pos > idx):
                    match_pos, match_word = idx, w
            return match_pos, match_word

        while True:
            text = unicode(c.selectedText()).rstrip('\0')
            idx, word = find_first_word(text)
            if idx == -1:
                return False
            c.setPosition(c.anchor() + idx)
            c.setPosition(c.position() + string_length(word), c.KeepAnchor)
            if self.smarts.verify_for_spellcheck(c, self.highlighter):
                self.setTextCursor(c)
                self.centerCursor()
                return True
            c.setPosition(c.position())
            c.movePosition(c.End, c.KeepAnchor)

        return False
Esempio n. 4
0
 def activate_current_result(self):
     if self.current_completion is not None:
         c = self.current_completion
         text = self.current_query if self.current_index == -1 else self.current_results[self.current_index][0]
         c.insertText(text)
         chars = string_length(text)
         c.setPosition(c.position() - chars)
         c.setPosition(c.position() + chars, c.KeepAnchor)
Esempio n. 5
0
 def set_items(self, items, descriptions=None):
     self.current_results = items
     self.current_size_hint = None
     self.descriptions = descriptions or {}
     self.clear_caches()
     self.max_text_length = 0
     self.current_index = -1
     self.current_top_index = 0
     if self.current_results:
         self.max_text_length = max(string_length(text) for text, pos in self.current_results)
Esempio n. 6
0
 def set_query(self, query='', limit=100):
     self.current_size_hint = None
     self.current_query = query
     if self.matcher is None:
         self.current_results = ()
     else:
         if query:
             self.current_results = tuple(self.matcher(query, limit=limit).iteritems())
         else:
             self.current_results = tuple((text, ()) for text in self.matcher.items[:limit])
     self.max_text_length = 0
     self.current_index = -1
     self.current_top_index = 0
     if self.current_results:
         self.max_text_length = max(string_length(text) for text, pos in self.current_results)
Esempio n. 7
0
 def mark_completion(self, editor, query):
     self.current_completion = c = editor.textCursor()
     chars = string_length(query or '')
     c.setPosition(c.position() - chars), c.setPosition(
         c.position() + chars, c.KeepAnchor)
     self.hide()
Esempio n. 8
0
 def mark_completion(self, editor, query):
     self.current_completion = c = editor.textCursor()
     chars = string_length(query or '')
     c.setPosition(c.position() - chars), c.setPosition(c.position() + chars, c.KeepAnchor)
     self.hide()