예제 #1
0
    def testCalculateRelativeRef(self):
        self.assertEquals(calculate_relative_ref(g_test_view, '.'), 1)
        self.assertEquals(calculate_relative_ref(g_test_view, '$'), 538)

        select_line(g_test_view, 100)
        self.assertEquals(calculate_relative_ref(g_test_view, '.'), 100)

        select_line(g_test_view, 200)
        self.assertEquals(calculate_relative_ref(g_test_view, '.'), 200)
예제 #2
0
    def testCalculateRelativeRef2(self):
        self.assertEquals(calculate_relative_ref(g_test_view, '.'), 1)
        self.assertEquals(calculate_relative_ref(g_test_view, '$'), 538)

        select_line(g_test_view, 100)
        self.assertEquals(calculate_relative_ref(g_test_view, '.'), 100)

        select_line(g_test_view, 200)
        self.assertEquals(calculate_relative_ref(g_test_view, '.'), 200)
예제 #3
0
    def testCalculateRelativeRef(self):
        values = (
            (calculate_relative_ref(g_test_view, '.'), 1),
            (calculate_relative_ref(g_test_view, '.', start_line=100), 101),
            (calculate_relative_ref(g_test_view, '$'), 538),
            (calculate_relative_ref(g_test_view, '$', start_line=100), 538),
        )

        for actual, expected in values:
            self.assertEquals(actual, expected)
예제 #4
0
    def testCalculateRelativeRef(self):
        values = (
            (calculate_relative_ref(g_test_view, '.'), 1),
            (calculate_relative_ref(g_test_view, '.', start_line=100), 101),
            (calculate_relative_ref(g_test_view, '$'), 538),
            (calculate_relative_ref(g_test_view, '$', start_line=100), 538),
        )

        for actual, expected in values:
            self.assertEquals(actual, expected)
예제 #5
0
def reverse_search(view, what, start=0, end=-1, flags=0):
    """Do binary search to find `what` walking backwards in the buffer.
    """
    if end == -1:
        end = view.size()
    end = find_eol(view, view.line(end).a)

    last_match = None

    lo, hi = start, end
    while True:
        middle = (lo + hi) / 2
        line = view.line(middle)
        middle, eol = find_bol(view, line.a), find_eol(view, line.a)

        if search_in_range(view, what, middle, hi, flags):
            lo = middle
        elif search_in_range(view, what, lo, middle - 1, flags):
            hi = middle - 1
        else:
            return calculate_relative_ref(view, '.')

        # Don't search forever the same line.
        if last_match and line.contains(last_match):
            match = find_last_match(view, what, lo, hi, flags=flags)
            return view.rowcol(match.begin())[0] + 1

        last_match = sublime.Region(line.begin(), line.end())
def reverse_search(view, what, start=0, end=-1, flags=0):
    """Do binary search to find `what` walking backwards in the buffer.
    """
    if end == -1:
        end = view.size()
    end = find_eol(view, view.line(end).a)
    
    last_match = None

    lo, hi = start, end
    while True:
        middle = (lo + hi) / 2    
        line = view.line(middle)
        middle, eol = find_bol(view, line.a), find_eol(view, line.a)

        if search_in_range(view, what, middle, hi, flags):
            lo = middle
        elif search_in_range(view, what, lo, middle - 1, flags):
            hi = middle -1
        else:
            return calculate_relative_ref(view, '.')

        # Don't search forever the same line.
        if last_match and line.contains(last_match):
            match = find_last_match(view, what, lo, hi, flags=flags)
            return view.rowcol(match.begin())[0] + 1
        
        last_match = sublime.Region(line.begin(), line.end())    
예제 #7
0
def search(view, what, start_line=None, flags=0):
    # TODO: don't make start_line default to the first sel's begin(). It's
    # confusing. ???
    if start_line:
        start = view.text_point(start_line, 0)
    else:
        start = view.sel()[0].begin()
    reg = view.find(what, start, flags)
    if not reg is None:
        row = (view.rowcol(reg.begin())[0] + 1)
    else:
        row = calculate_relative_ref(view, '.', start_line=start_line)
    return row
def search(view, what, start_line=None, flags=0):
    # TODO: don't make start_line default to the first sel's begin(). It's
    # confusing. ???
    if start_line:
        start = view.text_point(start_line, 0)
    else:
        start = view.sel()[0].begin()
    reg = view.find(what, start, flags)
    if not reg is None:
        row = (view.rowcol(reg.begin())[0] + 1)
    else:
        row = calculate_relative_ref(view, '.', start_line=start_line)
    return row