Пример #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 = find_wrapping(view,
                                      term=pattern,
                                      start=view.word(s.end()).end(),
                                      end=view.size(),
                                      flags=0,
                                      times=1)
            else:
                match = find_wrapping(view,
                                      term=pattern,
                                      start=view.word(s.end()).end(),
                                      end=view.size(),
                                      flags=0,
                                      times=1)

            if match:
                if mode == _MODE_INTERNAL_NORMAL:
                    return sublime.Region(s.a, match.begin())
                elif state.mode == MODE_VISUAL:
                    return sublime.Region(s.a, match.begin())
                elif state.mode == MODE_NORMAL:
                    return sublime.Region(match.begin(), match.begin())
            return s
Пример #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 = find_wrapping(view,
                                      term=pattern,
                                      start=view.word(s.end()).end(),
                                      end=view.size(),
                                      flags=0,
                                      times=1)
            else:
                match = find_wrapping(view,
                                      term=pattern,
                                      start=view.word(s.end()).end(),
                                      end=view.size(),
                                      flags=0,
                                      times=1)

            if match:
                if mode == _MODE_INTERNAL_NORMAL:
                    return sublime.Region(s.a, match.begin())
                elif state.mode == MODE_VISUAL:
                    return sublime.Region(s.a, match.begin())
                elif state.mode == MODE_NORMAL:
                    return sublime.Region(match.begin(), match.begin())
            return s
Пример #3
0
    def run(self, edit, search_string, mode=None, count=1, extend=False):
        def f(view, s):
            if mode == MODE_VISUAL:
                return sublime.Region(s.a, match.a + 1)

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

            elif mode == MODE_NORMAL:
                return sublime.Region(match.a, match.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

        # We want to start searching right after the current selection.
        current_sel = self.view.sel()[0]
        start = current_sel.b if not current_sel.empty() else current_sel.b + 1
        wrapped_end = self.view.size()

        # TODO: What should we do here? Case-sensitive or case-insensitive search? Configurable?
        # Search wrapping around the end of the buffer.
        match = find_wrapping(self.view, search_string, start, wrapped_end, flags=0, times=count)
        if not match:
            return

        regions_transformer(self.view, f)
        self.hilite(search_string)
Пример #4
0
    def run(self, edit, search_string, mode=None, count=1, extend=False):
        def f(view, s):
            if mode == MODE_VISUAL:
                return sublime.Region(s.a, match.a + 1)

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

            elif mode == MODE_NORMAL:
                return sublime.Region(match.a, match.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

        # We want to start searching right after the current selection.
        current_sel = self.view.sel()[0]
        start = current_sel.b if not current_sel.empty() else current_sel.b + 1
        wrapped_end = self.view.size()

        # TODO: What should we do here? Case-sensitive or case-insensitive search? Configurable?
        # Search wrapping around the end of the buffer.
        match = find_wrapping(self.view,
                              search_string,
                              start,
                              wrapped_end,
                              flags=0,
                              times=count)
        if not match:
            return

        regions_transformer(self.view, f)
        self.hilite(search_string)
Пример #5
0
    def testCanWrapAroundBuffer(self):
        self.write('''xxx
aaa aaa xxx aaa
''')
        self.clear_sel()
        self.add_sel(a=15, b=15)

        # 15 is after the second xxx
        match = find_wrapping(self.view, 'xxx', 15, self.view.size())
        self.assertEqual(match, self.R(0, 3))
Пример #6
0
    def testCanFindNextOccurrence(self):
        self.write('''xxx
aaa aaa xxx aaa
''')
        self.clear_sel()
        self.add_sel(a=4, b=4)

        # 4 is the beginning of the second line
        match = find_wrapping(self.view, 'xxx', 4, self.view.size())
        self.assertEqual(match, self.R(12, 15))
Пример #7
0
    def testFailsIfSearchStringNotPresent(self):
        self.write('''xxx
aaa aaa xxx aaa
''')
        self.clear_sel()
        self.add_sel(a=15, b=15)

        # 15 is after the second xxx
        match = find_wrapping(self.view, 'yyy', 15, self.view.size())
        self.assertEqual(match, None)
Пример #8
0
    def on_change(self, s):
        self.view.erase_regions("vi_inc_search")
        state = VintageState(self.view)
        next_hit = find_wrapping(
            self.view, term=s, start=self.view.sel()[0].b + 1, end=self.view.size(), flags=0, times=state.count
        )
        if next_hit:
            if state.mode == MODE_VISUAL:
                next_hit = sublime.Region(self.view.sel()[0].a, next_hit.a + 1)

            self.view.add_regions("vi_inc_search", [next_hit], "comment", "")
            if not self.view.visible_region().contains(next_hit.b):
                self.view.show(next_hit.b)
Пример #9
0
    def on_change(self, s):
        self.view.erase_regions('vi_inc_search')
        state = VintageState(self.view)
        next_hit = find_wrapping(self.view,
                                 term=s,
                                 start=self.view.sel()[0].b + 1,
                                 end=self.view.size(),
                                 flags=0,
                                 times=state.count)
        if next_hit:
            if state.mode == MODE_VISUAL:
                next_hit = sublime.Region(self.view.sel()[0].a, next_hit.a + 1)

            self.view.add_regions('vi_inc_search', [next_hit], 'comment', '')
            if not self.view.visible_region().contains(next_hit.b):
                self.view.show(next_hit.b)