Пример #1
0
    def testReverseSearchNonMatchesReturnCurrentLine(self):
        self.assertEquals(g_test_view.rowcol(g_test_view.sel()[0].a)[0], 0)
        values = ((reverse_search(g_test_view, 'FOOBAR'), 1), )

        select_line(g_test_view, 10)
        values += ((reverse_search(g_test_view, 'FOOBAR'), 10), )

        select_line(g_test_view, 100)
        values += ((reverse_search(g_test_view, 'FOOBAR'), 100), )

        for actual, expected in values:
            self.assertEquals(actual, expected)
    def testReverseSearch(self):
        values = (
            (reverse_search(g_test_view, 'THIRTY'), 30),
        )

        for actual, expected in values:
            self.assertEquals(actual, expected)
Пример #3
0
    def search(self):
        if not getattr(self, "cmd", None):
            return
        SearchImpl.last_term = self.cmd
        sel = self.view.sel()[0]

        next_match = None
        if self.reversed:
            current_line = self.view.line(self.view.sel()[0])
            left_side = sublime.Region(current_line.begin(), self.view.sel()[0].begin())
            if ex_location.search_in_range(self.view, self.cmd, left_side.begin(), left_side.end()):
                next_match = ex_location.find_last_match(self.view, self.cmd, left_side.begin(), left_side.end())
            else:
                line_nr = ex_location.reverse_search(self.view, self.cmd,
                                                end=current_line.begin() - 1)
                if line_nr:
                    pt = self.view.text_point(line_nr - 1, 0)
                    next_match = self.view.find(self.cmd, pt)
        else:
            next_match = self.view.find(self.cmd, sel.end())
        if next_match:
            self.view.sel().clear()
            self.view.sel().add(next_match)
            self.view.show(next_match)
        else:
            sublime.status_message("VintageEx: Could not find:" + self.cmd)
    def testReverseSearchNonMatchesReturnCurrentLine(self):
        self.assertEquals(g_test_view.rowcol(g_test_view.sel()[0].a)[0], 0)
        values = (
            (reverse_search(g_test_view, 'FOOBAR'), 1),
        )

        select_line(g_test_view, 10)
        values += (
            (reverse_search(g_test_view, 'FOOBAR'), 10),
        )
        
        select_line(g_test_view, 100)
        values += (
            (reverse_search(g_test_view, 'FOOBAR'), 100),
        )

        for actual, expected in values:
            self.assertEquals(actual, expected)
Пример #5
0
    def search(self):
        if not getattr(self, "cmd", None):
            return
        if self.remember:
            SearchImpl.last_term = self.cmd
        sel = self.start_sel[0]

        next_match = None
        if self.reversed:
            current_line = self.view.line(self.view.sel()[0])
            left_side = sublime.Region(current_line.begin(),
                                       self.view.sel()[0].begin())
            if ex_location.search_in_range(self.view, self.cmd,
                                           left_side.begin(),
                                           left_side.end(),
                                           self.flags):
                next_match = ex_location.find_last_match(self.view,
                                                         self.cmd,
                                                         left_side.begin(),
                                                         left_side.end(),
                                                         self.flags)
            else:
                line_nr = ex_location.reverse_search(self.view, self.cmd,
                                                end=current_line.begin() - 1,
                                                flags=self.flags)
                if line_nr:
                    pt = self.view.text_point(line_nr - 1, 0)
                    line = self.view.full_line(pt)
                    next_match = ex_location.find_last_match(self.view,
                                                             self.cmd,
                                                             line.begin(),
                                                             line.end(),
                                                             self.flags)
        else:
            next_match = self.view.find(self.cmd, sel.end(), self.flags)
        if next_match:
            self.view.sel().clear()
            if not self.remember:
                self.view.add_regions("vi_search", [next_match], "search.vi",
                                      sublime.DRAW_OUTLINED)
            else:
                self.view.sel().add(next_match)
            self.view.show(next_match)
        else:
            sublime.status_message("VintageEx: Pattern not found:" + self.cmd)
Пример #6
0
    def search(self):
        if not getattr(self, "cmd", None):
            return
        if self.remember:
            SearchImpl.last_term = self.cmd
        sel = self.start_sel[0]

        next_match = None
        if self.reversed:
            current_line = self.view.line(self.view.sel()[0])
            left_side = sublime.Region(current_line.begin(),
                                       self.view.sel()[0].begin())
            if ex_location.search_in_range(self.view, self.cmd,
                                           left_side.begin(), left_side.end(),
                                           self.flags):
                next_match = ex_location.find_last_match(
                    self.view, self.cmd, left_side.begin(), left_side.end(),
                    self.flags)
            else:
                line_nr = ex_location.reverse_search(self.view,
                                                     self.cmd,
                                                     end=current_line.begin() -
                                                     1,
                                                     flags=self.flags)
                if line_nr:
                    pt = self.view.text_point(line_nr - 1, 0)
                    line = self.view.full_line(pt)
                    next_match = ex_location.find_last_match(
                        self.view, self.cmd, line.begin(), line.end(),
                        self.flags)
        else:
            next_match = self.view.find(self.cmd, sel.end(), self.flags)
        if next_match:
            self.view.sel().clear()
            if not self.remember:
                self.view.add_regions("vi_search", [next_match], "search.vi",
                                      sublime.DRAW_OUTLINED)
            else:
                self.view.sel().add(next_match)
            self.view.show(next_match)
        else:
            sublime.status_message("VintageEx: Pattern not found:" + self.cmd)
Пример #7
0
def calculate_range_part(view, range_part, start_line=None):
    """takes the left or right part of a range and returns the actual buffer
    line they refer to.
        returns: a 1-based line number
    """
    if range_part.isdigit():
        return int(range_part)
    if range_part.startswith('/') or range_part.startswith('?'):
        # we need to strip the search marks. FIXME won't work in edge cases
        # like ?foo\/ (doublecheck with vim)
        if (not range_part.endswith(r'\/') or range_part.endswith(r'\?')
                and (range_part.endswith('?') or range_part.endswith('/'))):
                search_term = range_part[1:-1]
        else:
            search_term = range_part[1:]
        if range_part.startswith('?'):
            if start_line:
                end = view.line(view.text_point(start_line, 0)).end()
            else:
                end = view.sel()[0].begin()
            return ex_location.reverse_search(view, search_term, end=end)
        return ex_location.search(view, search_term)
    if range_part in ('$', '.'):
        return ex_location.calculate_relative_ref(view, range_part, start_line)
Пример #8
0
    def testReverseSearch(self):
        values = ((reverse_search(g_test_view, 'THIRTY'), 30), )

        for actual, expected in values:
            self.assertEquals(actual, expected)