Ejemplo n.º 1
0
    def _(event):
        """
        Scroll page up. (Prefer the cursor at the bottom of the page, after scrolling.)
        """
        w = find_window_for_buffer_name(event.cli.layout,
                                        event.cli.current_buffer_name)
        b = event.cli.current_buffer

        if w and w.render_info:
            # Scroll down one page.
            w.vertical_scroll = max(
                0, w.vertical_scroll - w.render_info.rendered_height)

            # Put cursor at the bottom of the visible region.
            try:
                new_document_line = w.render_info.screen_line_to_input_line[
                    w.vertical_scroll + w.render_info.rendered_height - 1]
            except KeyError:
                new_document_line = 0

            b.cursor_position = min(
                b.cursor_position,
                b.document.translate_row_col_to_index(new_document_line, 0))
            b.cursor_position += b.document.get_start_of_line_position(
                after_whitespace=True)
Ejemplo n.º 2
0
    def _(event):
        """
        Center Window vertically around cursor.
        """
        w = find_window_for_buffer_name(event.cli, event.cli.current_buffer_name)
        b = event.cli.current_buffer
        info = w.render_info

        if w and info:
            # Calculate the offset that we need in order to position the row
            # containing the cursor in the center.
            scroll_height = info.window_height // 2

            y = max(0, b.document.cursor_position_row - 1)
            height = 0
            while y > 0:
                line_height = info.get_height_for_line(y)

                if height + line_height < scroll_height:
                    height += line_height
                    y -= 1
                else:
                    break

            w.vertical_scroll = y
Ejemplo n.º 3
0
def scroll_one_line_up(event):
    """
    scroll_offset -= 1
    """
    w = find_window_for_buffer_name(event.cli, event.cli.current_buffer_name)
    b = event.cli.current_buffer

    if w:
        # When the cursor is at the bottom, move to the previous line. (Otherwise, only scroll.)
        if w.render_info:
            info = w.render_info

            if w.vertical_scroll > 0:
                first_line_height = info.get_height_for_line(info.first_visible_line())

                cursor_up = info.cursor_position.y - (info.window_height - 1 - first_line_height -
                                                      info.configured_scroll_offsets.bottom)

                # Move cursor up, as many steps as the height of the first line.
                # TODO: not entirely correct yet, in case of line wrapping and many long lines.
                for _ in range(max(0, cursor_up)):
                    b.cursor_position += b.document.get_cursor_up_position()

                # Scroll window
                w.vertical_scroll -= 1
Ejemplo n.º 4
0
def scroll_one_line_up(event):
    """
    scroll_offset -= 1
    """
    w = find_window_for_buffer_name(event.cli, event.cli.current_buffer_name)
    b = event.cli.current_buffer

    if w:
        # When the cursor is at the bottom, move to the previous line. (Otherwise, only scroll.)
        if w.render_info:
            info = w.render_info

            if w.vertical_scroll > 0:
                first_line_height = info.get_height_for_line(info.first_visible_line())

                cursor_up = info.cursor_position.y - (info.window_height - 1 - first_line_height -
                                                      info.configured_scroll_offsets.bottom)

                # Move cursor up, as many steps as the height of the first line.
                # TODO: not entirely correct yet, in case of line wrapping and many long lines.
                for _ in range(max(0, cursor_up)):
                    b.cursor_position += b.document.get_cursor_up_position()

                # Scroll window
                w.vertical_scroll -= 1
Ejemplo n.º 5
0
 def _(event):
     """
     Scrolls the window to makes the current line the first line in the visible region.
     """
     w = find_window_for_buffer_name(event.cli, event.cli.current_buffer_name)
     b = event.cli.current_buffer
     w.vertical_scroll = b.document.cursor_position_row
Ejemplo n.º 6
0
    def _(event):
        """
        Scrolls the window to makes the current line the last line in the visible region.
        """
        w = find_window_for_buffer_name(event.cli, event.cli.current_buffer_name)

        # We can safely set the scroll offset to zero; the Window will meke
        # sure that it scrolls at least enough to make the cursor visible
        # again.
        w.vertical_scroll = 0
Ejemplo n.º 7
0
    def _(event):
        """
        Scroll window up.
        """
        w = find_window_for_buffer_name(event.cli.layout, event.cli.current_buffer_name)
        b = event.cli.current_buffer

        if w and w.render_info:
            new_document_line = max(0, b.document.cursor_position_row -
                                    int(w.render_info.rendered_height / 2))
            b.cursor_position = b.document.translate_row_col_to_index(new_document_line, 0)
            w.vertical_scroll = w.render_info.input_line_to_screen_line(new_document_line)
Ejemplo n.º 8
0
    def _(event):
        """
        scroll_offset += 1
        """
        w = find_window_for_buffer_name(event.cli.layout, event.cli.current_buffer_name)
        b = event.cli.current_buffer

        if w:
            # When the cursor is at the bottom, move to the previous line. (Otherwise, only scroll.)
            if w.render_info and w.render_info.first_visible_line == b.document.cursor_position_row:
                b.cursor_position += b.document.get_cursor_down_position()

            w.vertical_scroll += 1
Ejemplo n.º 9
0
    def _(event):
        """
        scroll_offset -= 1
        """
        w = find_window_for_buffer_name(event.cli.layout, event.cli.current_buffer_name)
        b = event.cli.current_buffer

        if w:
            # When the cursor is at the top, move to the next line. (Otherwise, only scroll.)
            if w.render_info and w.render_info.last_visible_line == b.document.cursor_position_row:
                b.cursor_position += b.document.get_cursor_up_position()

            # Scroll window
            w.vertical_scroll -= 1
Ejemplo n.º 10
0
    def _(event):
        """
        Center Window vertically around cursor.
        """
        w = find_window_for_buffer_name(event.cli.layout, event.cli.current_buffer_name)
        b = event.cli.current_buffer

        if w and w.render_info:
            # Calculate the offset that we need in order to position the row
            # containing the cursor in the center.
            cursor_position_row = b.document.cursor_position_row

            render_row = w.render_info.input_line_to_screen_line.get(cursor_position_row)
            if render_row is not None:
                w.vertical_scroll = max(0, int(render_row - w.render_info.window_height / 2))
Ejemplo n.º 11
0
    def _(event):
        """
        scroll_offset += 1
        """
        w = find_window_for_buffer_name(event.cli.layout, event.cli.current_buffer_name)
        b = event.cli.current_buffer

        if w:
            # When the cursor is at the top, move to the next line. (Otherwise, only scroll.)
            if w.render_info:
                info = w.render_info
                if info.cursor_position.y <= info.configured_scroll_offset:
                    b.cursor_position += b.document.get_cursor_down_position()

            w.vertical_scroll += 1
Ejemplo n.º 12
0
    def _(event):
        """
        Scrolls the window to makes the current line the first line in the visible region.
        """
        w = find_window_for_buffer_name(event.cli.layout, event.cli.current_buffer_name)
        b = event.cli.current_buffer

        if w and w.render_info:
            # Calculate the offset that we need in order to position the row
            # containing the cursor in the center.
            cursor_position_row = b.document.cursor_position_row

            render_row = w.render_info.input_line_to_screen_line.get(cursor_position_row)
            if render_row is not None:
                w.vertical_scroll = max(0, render_row)
Ejemplo n.º 13
0
    def _(event):
        """
        Scrolls the window to makes the current line the last line in the visible region.
        """
        w = find_window_for_buffer_name(event.cli.layout, event.cli.current_buffer_name)
        b = event.cli.current_buffer

        if w and w.render_info:
            # Calculate the offset that we need in order to position the row
            # containing the cursor in the center.
            cursor_position_row = b.document.cursor_position_row

            render_row = w.render_info.input_line_to_screen_line(cursor_position_row)
            if render_row is not None:
                w.vertical_scroll = max(0, (render_row - w.render_info.rendered_height))
Ejemplo n.º 14
0
    def _(event):
        """
        Center Window vertically around cursor.
        """
        w = find_window_for_buffer_name(event.cli.layout, event.cli.current_buffer_name)
        b = event.cli.current_buffer

        if w and w.render_info:
            # Calculate the offset that we need in order to position the row
            # containing the cursor in the center.
            cursor_position_row = b.document.cursor_position_row

            render_row = w.render_info.input_line_to_screen_line(cursor_position_row)
            if render_row is not None:
                w.vertical_scroll = max(0, int(render_row - w.render_info.rendered_height / 2))
Ejemplo n.º 15
0
    def _(event):
        """
        Scroll window up.
        """
        w = find_window_for_buffer_name(event.cli.layout,
                                        event.cli.current_buffer_name)
        b = event.cli.current_buffer

        if w and w.render_info:
            new_document_line = max(
                0, b.document.cursor_position_row -
                int(w.render_info.rendered_height / 2))
            b.cursor_position = b.document.translate_row_col_to_index(
                new_document_line, 0)
            w.vertical_scroll = w.render_info.input_line_to_screen_line(
                new_document_line)
Ejemplo n.º 16
0
    def _(event):
        " Scroll half page to the left. "
        w = find_window_for_buffer_name(event.cli,
                                        event.cli.current_buffer_name)
        b = event.cli.current_buffer

        if w and w.render_info:
            info = w.render_info
            amount = info.window_width // 2

            # Move cursor horizontally.
            value = b.cursor_position - min(
                amount, len(b.document.current_line_before_cursor))
            b.cursor_position = value

            # Scroll.
            w.horizontal_scroll = max(0, w.horizontal_scroll - amount)
Ejemplo n.º 17
0
def scroll_one_line_down(event):
    """
    scroll_offset += 1
    """
    w = find_window_for_buffer_name(event.cli, event.cli.current_buffer_name)
    b = event.cli.current_buffer

    if w:
        # When the cursor is at the top, move to the next line. (Otherwise, only scroll.)
        if w.render_info:
            info = w.render_info

            if w.vertical_scroll < info.content_height - info.window_height:
                if info.cursor_position.y <= info.configured_scroll_offsets.top:
                    b.cursor_position += b.document.get_cursor_down_position()

                w.vertical_scroll += 1
Ejemplo n.º 18
0
    def _(event):
        """
        scroll_offset -= 1
        """
        w = find_window_for_buffer_name(event.cli.layout, event.cli.current_buffer_name)
        b = event.cli.current_buffer

        if w:
            # When the cursor is at the bottom, move to the previous line. (Otherwise, only scroll.)
            if w.render_info:
                info = w.render_info

                if info.cursor_position.y >= info.rendered_height - 1 - info.configured_scroll_offset:
                    b.cursor_position += b.document.get_cursor_up_position()

            # Scroll window
            w.vertical_scroll -= 1
Ejemplo n.º 19
0
    def _(event):
        """
        Moves cursor to the vertical center of the visible region.
        Implements 'cM', 'dM', 'M'.
        """
        w = find_window_for_buffer_name(event.cli.layout, event.cli.current_buffer_name)
        b = event.current_buffer

        if w:
            # When we find a Window that has BufferControl showing this window,
            # move to the center of the visible area.
            pos = b.document.translate_row_col_to_index(w.render_info.center_visible_line(), 0) - b.cursor_position

        else:
            # Otherwise, move to the start of the input.
            pos = -len(b.document.text_before_cursor)
        return CursorRegion(pos)
Ejemplo n.º 20
0
    def _(event):
        """
        Moves to the end of the visible region.
        """
        w = find_window_for_buffer_name(event.cli.layout, event.cli.current_buffer_name)
        b = event.current_buffer

        if w:
            # When we find a Window that has BufferControl showing this window,
            # move to the end of the visible area.
            pos = (b.document.translate_row_col_to_index(w.render_info.last_visible_line, 0) -
                   b.cursor_position)

        else:
            # Otherwise, move to the end of the input.
            pos = len(b.document.text_after_cursor)
        return CursorRegion(pos)
Ejemplo n.º 21
0
    def _(event):
        """
        Moves to the end of the visible region.
        """
        w = find_window_for_buffer_name(event.cli.layout,
                                        event.cli.current_buffer_name)
        b = event.current_buffer

        if w:
            # When we find a Window that has BufferControl showing this window,
            # move to the end of the visible area.
            pos = (b.document.translate_row_col_to_index(
                w.render_info.last_visible_line, 0) - b.cursor_position)

        else:
            # Otherwise, move to the end of the input.
            pos = len(b.document.text_after_cursor)
        return CursorRegion(pos)
Ejemplo n.º 22
0
def scroll_one_line_up(event):
    """
    scroll_offset -= 1
    """
    w = find_window_for_buffer_name(event.cli, event.cli.current_buffer_name)
    b = event.cli.current_buffer

    if w:
        # When the cursor is at the bottom, move to the previous line. (Otherwise, only scroll.)
        if w.render_info:
            info = w.render_info

            if w.vertical_scroll > 0:
                if info.cursor_position.y >= info.window_height - 1 - info.configured_scroll_offsets.bottom:
                    b.cursor_position += b.document.get_cursor_up_position()

                # Scroll window
                w.vertical_scroll -= 1
Ejemplo n.º 23
0
    def _(event):
        """
        Moves to the start of the visible region. (Below the scroll offset.)
        Implements 'cH', 'dH', 'H'.
        """
        w = find_window_for_buffer_name(event.cli.layout, event.cli.current_buffer_name)
        b = event.current_buffer

        if w:
            # When we find a Window that has BufferControl showing this window,
            # move to the start of the visible area.
            pos = (b.document.translate_row_col_to_index(
                       w.render_info.first_visible_line(after_scroll_offset=True), 0) -
                   b.cursor_position)

        else:
            # Otherwise, move to the start of the input.
            pos = -len(b.document.text_before_cursor)
        return CursorRegion(pos)
Ejemplo n.º 24
0
    def _(event):
        """
        Moves to the start of the visible region. (Below the scroll offset.)
        Implements 'cH', 'dH', 'H'.
        """
        w = find_window_for_buffer_name(event.cli.layout, event.cli.current_buffer_name)
        b = event.current_buffer

        if w:
            # When we find a Window that has BufferControl showing this window,
            # move to the start of the visible area.
            pos = (b.document.translate_row_col_to_index(
                       w.render_info.first_visible_line(after_scroll_offset=True), 0) -
                   b.cursor_position)

        else:
            # Otherwise, move to the start of the input.
            pos = -len(b.document.text_before_cursor)
        return CursorRegion(pos)
Ejemplo n.º 25
0
    def _(event):
        """
        Scroll page down. (Prefer the cursor at the top of the page, after scrolling.)
        """
        w = find_window_for_buffer_name(event.cli.layout, event.cli.current_buffer_name)
        b = event.cli.current_buffer

        if w and w.render_info:
            # Scroll down one page.
            w.vertical_scroll += w.render_info.rendered_height

            # Put cursor at the top of the visible region.
            try:
                new_document_line = w.render_info.screen_line_to_input_line[w.vertical_scroll]
            except KeyError:
                new_document_line = b.document.line_count - 1

            b.cursor_position = b.document.translate_row_col_to_index(new_document_line, 0)
            b.cursor_position += b.document.get_start_of_line_position(after_whitespace=True)
Ejemplo n.º 26
0
    def _(event):
        """
        Moves cursor to the vertical center of the visible region.
        Implements 'cM', 'dM', 'M'.
        """
        w = find_window_for_buffer_name(event.cli.layout,
                                        event.cli.current_buffer_name)
        b = event.current_buffer

        if w:
            # When we find a Window that has BufferControl showing this window,
            # move to the center of the visible area.
            pos = (b.document.translate_row_col_to_index(
                w.render_info.center_visible_line(), 0) - b.cursor_position)

        else:
            # Otherwise, move to the start of the input.
            pos = -len(b.document.text_before_cursor)
        return CursorRegion(pos)
Ejemplo n.º 27
0
    def _(event):
        " Scroll half page to the right. "
        w = find_window_for_buffer_name(event.cli,
                                        event.cli.current_buffer_name)
        b = event.cli.current_buffer

        if w and w.render_info:
            info = w.render_info
            amount = info.window_width // 2

            # Move the cursor first to a visible line that is long enough to
            # have the cursor visible after scrolling. (Otherwise, the Window
            # will scroll back.)
            xpos = w.horizontal_scroll + amount

            for line in info.displayed_lines:
                if len(b.document.lines[line]) >= xpos:
                    b.cursor_position = b.document.translate_row_col_to_index(
                        line, xpos)
                    break

            # Scroll.
            w.horizontal_scroll = max(0, w.horizontal_scroll + amount)
Ejemplo n.º 28
0
def _current_window_for_event(event):
    """
    Return the `Window` for the currently focussed Buffer.
    """
    return find_window_for_buffer_name(event.cli.layout, event.cli.current_buffer_name)
Ejemplo n.º 29
0
def _current_window_for_event(event):
    """
    Return the `Window` for the currently focussed Buffer.
    """
    return find_window_for_buffer_name(event.cli,
                                       event.cli.current_buffer_name)