Example #1
0
        def f(view, s):

            if exact_word:
                pattern = r'\b{0}\b'.format(query)
            else:
                pattern = query

            flags = sublime.IGNORECASE

            if mode == _MODE_INTERNAL_NORMAL:
                match = reverse_find_wrapping(view,
                                              term=pattern,
                                              start=0,
                                              end=current_sel.a,
                                              flags=0,
                                              times=1)
            else:
                match = reverse_find_wrapping(view,
                                              term=pattern,
                                              start=0,
                                              end=current_sel.a,
                                              flags=0,
                                              times=1)

            if match:
                if mode == _MODE_INTERNAL_NORMAL:
                    return sublime.Region(s.b, match.begin())
                elif state.mode == MODE_VISUAL:
                    return sublime.Region(s.b, match.begin())
                elif state.mode == MODE_NORMAL:
                    return sublime.Region(match.begin(), match.begin())
            return s
Example #2
0
        def f(view, s):

            if exact_word:
                pattern = r'\b{0}\b'.format(query)
            else:
                pattern = query

            flags = sublime.IGNORECASE

            if mode == _MODE_INTERNAL_NORMAL:
                match = reverse_find_wrapping(view,
                                         term=pattern,
                                         start=0,
                                         end=current_sel.a,
                                         flags=0,
                                         times=1)
            else:
                match = reverse_find_wrapping(view,
                                         term=pattern,
                                         start=0,
                                         end=current_sel.a,
                                         flags=0,
                                         times=1)

            if match:
                if mode == _MODE_INTERNAL_NORMAL:
                    return sublime.Region(s.b, match.begin())
                elif state.mode == MODE_VISUAL:
                    return sublime.Region(s.b, match.begin())
                elif state.mode == MODE_NORMAL:
                    return sublime.Region(match.begin(), match.begin())
            return s
Example #3
0
    def run(self, edit, search_string, mode=None, count=1, extend=False):
        def f(view, s):
            # FIXME: Readjust carets if we searched for '\n'.
            if mode == MODE_VISUAL:
                return sublime.Region(s.end(), found.a)

            elif mode == _MODE_INTERNAL_NORMAL:
                return sublime.Region(s.end(), found.a)

            elif mode == MODE_NORMAL:
                return sublime.Region(found.a, found.a)

            return s

        # This happens when we attempt to repeat the search and there's no search term stored yet.
        if search_string is None:
            return

        # FIXME: What should we do here? Case-sensitive or case-insensitive search? Configurable?
        found = reverse_find_wrapping(
            self.view, term=search_string, start=0, end=self.view.sel()[0].b, flags=0, times=count
        )

        if not found:
            print("Vintageous: Pattern not found.")
            return

        regions_transformer(self.view, f)
        self.hilite(search_string)
Example #4
0
    def run(self, edit, search_string, mode=None, count=1, extend=False):
        def f(view, s):
            # FIXME: Readjust carets if we searched for '\n'.
            if mode == MODE_VISUAL:
                return sublime.Region(s.end(), found.a)

            elif mode == _MODE_INTERNAL_NORMAL:
                return sublime.Region(s.end(), found.a)

            elif mode == MODE_NORMAL:
                return sublime.Region(found.a, found.a)

            return s

        # This happens when we attempt to repeat the search and there's no search term stored yet.
        if search_string is None:
            return

        # FIXME: What should we do here? Case-sensitive or case-insensitive search? Configurable?
        found = reverse_find_wrapping(self.view,
                                      term=search_string,
                                      start=0,
                                      end=self.view.sel()[0].b,
                                      flags=0,
                                      times=count)

        if not found:
            print("Vintageous: Pattern not found.")
            return

        regions_transformer(self.view, f)
        self.hilite(search_string)
Example #5
0
 def on_change(self, s):
     self.view.erase_regions("vi_inc_search")
     state = VintageState(self.view)
     occurrence = reverse_find_wrapping(
         self.view, term=s, start=0, end=self.view.sel()[0].b, flags=0, times=state.count
     )
     if occurrence:
         if state.mode == MODE_VISUAL:
             occurrence = sublime.Region(self.view.sel()[0].a, occurrence.a)
         self.view.add_regions("vi_inc_search", [occurrence], "comment", "")
         if not self.view.visible_region().contains(occurrence):
             self.view.show(occurrence)
Example #6
0
 def on_change(self, s):
     self.view.erase_regions('vi_inc_search')
     state = VintageState(self.view)
     occurrence = reverse_find_wrapping(self.view,
                                        term=s,
                                        start=0,
                                        end=self.view.sel()[0].b,
                                        flags=0,
                                        times=state.count)
     if occurrence:
         if state.mode == MODE_VISUAL:
             occurrence = sublime.Region(self.view.sel()[0].a, occurrence.a)
         self.view.add_regions('vi_inc_search', [occurrence], 'comment', '')
         if not self.view.visible_region().contains(occurrence):
             self.view.show(occurrence)