def reassign(self, view):
        v = view.settings()
        v.clear_on_change("checkbounce_spelling_monitor")
        on = v.get("enable_checkbounce_spelling")
        vid = view.id()

        if not vid in self.prev_syntax:
            self.prev_syntax[vid] = v.get("syntax")
        elif self.prev_syntax[vid] != v.get("syntax"):
            SpellChecker.remove(view.id())
            view.erase_status('checkbounce')
            SpellChecker.assign(view, self.finish)

        if on != self.on:
            self.on = on
            SpellChecker.remove(vid)
            sublime.set_timeout(lambda: view.erase_status('checkbounce'), 0)

            if on:
                SpellChecker.assign(view, self.finish)
                SpellChecker.reload()
            if not on:
                if vid in self.loaded:
                    self.loaded.remove(vid)
                if vid in self.checked:
                    self.checked.remove(vid)

            self.on_modified(view)

        v.add_on_change('checkbounce_spelling_monitor', lambda: self.reassign(view))
    def check(self, view_id):
        view = SpellChecker.get_view(view_id)

        if view is not None:
            text, start = SpellChecker.text(view)
            args = (view_id, text, start, self.finish)
            threading.Thread(target=SpellChecker.check_view, args=args).start()
    def on_new(self, view):
        vid = view.id()
        self.loaded.add(vid)
        v = view.settings()
        if not v.has("enable_checkbounce_spelling"):
            default = sublime.load_settings("CheckBounce.sublime-settings").get("check_spelling", True)
            v.set("enable_checkbounce_spelling", default)

        v.add_on_change('checkbounce_spelling_monitor', lambda: self.reassign(view))
        SpellChecker.assign(view, self.finish)
Exemplo n.º 4
0
    def run(self, edit):
        SpellChecker.reload()
        try:
            errs = const.spell_error_regions[self.view.id()]
        except KeyError:
            sublime.status_message("Document has not been checked.")
            return
        errs = sorted(errs, key=lambda e: e.a)
        try:
            self.checker = SpellChecker.get_checker(self.view.id())
        except KeyError:
            sublime.status_message("Document has not been checked.")
            return

        if self.checker.orthography.dominantLanguage() == "und":
            sublime.status_message("Language could not be determined.")
            return
        if not len(errs):
            sublime.status_message("No errors!")
            return

        self.offset = 0
        self.reset = 0
        self.i = 0
        self.forward = True
        self.ignored = []

        pos = self.view.sel()[0].a
        # self.view.sel().clear()
        start = 0
        for j in range(len(errs)):
            if errs[j].contains(pos):
                start = j
                break

            b = errs[j].b
            try:
                x = errs[j + 1].a
            except IndexError:
                break

            if b < pos < x:
                start = j + 1
                break
        self.start = start
        end_chunk = errs[start:]
        beginning_chunk = errs[:start]
        self.chunks = []
        if not beginning_chunk == end_chunk:
            self.chunks.extend(end_chunk)
            self.chunks.extend(beginning_chunk)
        else:
            self.chunks = errs

        self.get_next_error(0, next=False)
    def hit(self, view):
        if not ST3:
            self.check(view.id())

        self.checked.add(view.id())
        if view.size() == 0:
            c = SpellChecker.get_checker(view.id())
            if c:
                c.clear()
            SpellChecker.reload()
            sublime.set_timeout(lambda: view.erase_status('checkbounce'), 0)
            return

        const.spell_queue.hit(view)
Exemplo n.º 6
0
 def is_enabled(self):
     win = sublime.active_window()
     if not win: return False
     view = win.active_view()
     if not view:
         return False
     whitelisted, _ = SpellChecker.is_whitelisted(view)
     return whitelisted
Exemplo n.º 7
0
 def is_checked(self):
     win = sublime.active_window()
     if not win: return False
     view = win.active_view()
     if not view:
         return False
     v = view.settings()
     whitelisted, _ = SpellChecker.is_whitelisted(view)
     return v.get("enable_checkbounce_spelling", True) and whitelisted
    def on_query_completions(self, view, prefix, locations):
        if not sublime.load_settings("CheckBounce.sublime-settings").get("autocorrect", False):
            return []

        if not (SpellChecker.is_whitelisted(view) and view.settings().get("enable_checkbounce_spelling", True)):
            return []

        vid = view.id()
        if not const.spell_checkers.get(vid, None):
            return []

        pt = locations[0] - len(prefix)
        loc = sublime.Region(pt, locations[0])

        sugg = const.spell_checkers[vid].suggest(loc)
        if not sugg:
            return []

        completion_list = []
        for suggestion in sugg:
            completion_list += [("{0}\tSuggestion".format(suggestion), suggestion)]

        return (completion_list, sublime.INHIBIT_EXPLICIT_COMPLETIONS | sublime.INHIBIT_WORD_COMPLETIONS)
 def check_spelling(self, view, check=False):
     if check and SpellChecker.assign(view, self.finish) != None:
         self.hit(view)
 def on_close(self, view):
     vid = view.id()
     view.settings().clear_on_change("checkbounce_spelling_monitor")
     if vid in self.loaded:
         SpellChecker.remove(vid)
         self.loaded.remove(vid)
Exemplo n.º 11
0
 def is_enabled(self):
     whitelisted, _ = SpellChecker.is_whitelisted(self.view)
     return whitelisted