Exemplo n.º 1
2
/* If scroll_only is FALSE, move up one line.  If scroll_only is TRUE,
 * scroll up one line without scrolling the cursor. */
void do_up(bool scroll_only)
{
    size_t was_column = xplustabs();

    /* If we're at the top of the file, or if scroll_only is TRUE and
     * the top of the file is onscreen, get out. */
    if (openfile->current == openfile->fileage ||
		(scroll_only && openfile->edittop == openfile->fileage))
	return;

    assert(ISSET(SOFTWRAP) || openfile->current_y == openfile->current->lineno - openfile->edittop->lineno);

    /* Move the current line of the edit window up. */
    openfile->current = openfile->current->prev;
    openfile->current_x = actual_x(openfile->current->data,
					openfile->placewewant);

    /* When the cursor was on the first line of the edit window (or when just
     * scrolling without moving the cursor), scroll the edit window up -- one
     * line if we're in smooth scrolling mode, and half a page otherwise. */
    if (openfile->current->next == openfile->edittop || scroll_only)
	edit_scroll(UPWARD, (ISSET(SMOOTH_SCROLL) || scroll_only) ?
				1 : editwinrows / 2 + 1);

    /* If the lines weren't already redrawn, see if they need to be. */
    if (openfile->current_y > 0) {
	/* Redraw the prior line if it was horizontally scrolled. */
	if (need_horizontal_scroll(was_column, 0))
	    update_line(openfile->current->next, 0);
	/* Redraw the current line if it needs to be horizontally scrolled. */
	if (need_horizontal_scroll(0, xplustabs()))
	    update_line(openfile->current, openfile->current_x);
    }
}
Exemplo n.º 2
1
/* Move down one page. */
void do_page_down(void)
{
    int i;

    /* If there's less than a page of text left on the screen, put the
     * cursor at the beginning of the last line of the file, and then
     * update the edit window. */
    if (openfile->current->lineno + editwinrows - 2 >=
	openfile->filebot->lineno) {
	do_last_line();
	return;
    }

    /* If we're not in smooth scrolling mode, put the cursor at the
     * beginning of the top line of the edit window, as Pico does. */
#ifndef NANO_TINY
    if (!ISSET(SMOOTH_SCROLL)) {
#endif
	openfile->current = openfile->edittop;
	openfile->placewewant = 0;
#ifndef NANO_TINY
    }
#endif

    for (i = editwinrows - 2; i > 0 && openfile->current !=
	openfile->filebot; i--)
	openfile->current = openfile->current->next;

    openfile->current_x = actual_x(openfile->current->data,
	openfile->placewewant);

    /* Scroll the edit window down a page. */
    edit_scroll(DOWN_DIR, editwinrows - 2);
}
Exemplo n.º 3
1
Arquivo: move.c Projeto: rofl0r/nano
/* If scroll_only is FALSE, move down one line.  If scroll_only is TRUE,
 * scroll down one line without scrolling the cursor. */
void do_down(
#ifndef NANO_TINY
	bool scroll_only
#else
	void
#endif
	)
{
    bool onlastline = FALSE;

    /* If we're at the bottom of the file, get out. */
    if (openfile->current == openfile->filebot)
	return;


    assert(ISSET(SOFTWRAP) || openfile->current_y == openfile->current->lineno - openfile->edittop->lineno);

    /* Move the current line of the edit window down. */
    openfile->current = openfile->current->next;
    openfile->current_x = actual_x(openfile->current->data,
	openfile->placewewant);

    if (ISSET(SOFTWRAP)) {
	if (openfile->current->lineno - openfile->edittop->lineno >= maxrows)
	    onlastline = TRUE;
    }

    /* If scroll_only is FALSE and if we're on the first line of the
     * edit window, scroll the edit window down one line if we're in
     * smooth scrolling mode, or down half a page if we're not.  If
     * scroll_only is TRUE, scroll the edit window down one line
     * unconditionally. */
    if (onlastline || openfile->current_y == editwinrows - 1
#ifndef NANO_TINY
	|| scroll_only
#endif
	) {
	edit_scroll(DOWN_DIR,
#ifndef NANO_TINY
		(ISSET(SMOOTH_SCROLL) || scroll_only) ? 1 :
#endif
		editwinrows / 2 + 1);

	edit_refresh_needed = TRUE;
    }
    /* If we're above the last line of the edit window, update the line
     * we were on before and the line we're on now.  The former needs to
     * be redrawn if we're not on the first page, and the latter needs
     * to be drawn unconditionally. */
    if (ISSET(SOFTWRAP) || openfile->current_y < editwinrows - 1) {
	if (need_vertical_update(0))
	    update_line(openfile->current->prev, 0);
	update_line(openfile->current, openfile->current_x);
    }
}
Exemplo n.º 4
1
Arquivo: move.c Projeto: rofl0r/nano
/* If scroll_only is FALSE, move up one line.  If scroll_only is TRUE,
 * scroll up one line without scrolling the cursor. */
void do_up(
#ifndef NANO_TINY
	bool scroll_only
#else
	void
#endif
	)
{
    /* If we're at the top of the file, or if scroll_only is TRUE and
     * the top of the file is onscreen, get out. */
    if (openfile->current == openfile->fileage
#ifndef NANO_TINY
	|| (scroll_only && openfile->edittop == openfile->fileage)
#endif
	)
	return;

    assert(ISSET(SOFTWRAP) || openfile->current_y == openfile->current->lineno - openfile->edittop->lineno);

    /* Move the current line of the edit window up. */
    openfile->current = openfile->current->prev;
    openfile->current_x = actual_x(openfile->current->data,
	openfile->placewewant);

    /* If scroll_only is FALSE and if we're on the first line of the
     * edit window, scroll the edit window up one line if we're in
     * smooth scrolling mode, or up half a page if we're not.  If
     * scroll_only is TRUE, scroll the edit window up one line
     * unconditionally. */
    if (openfile->current_y == 0 || (ISSET(SOFTWRAP) && openfile->edittop->lineno == openfile->current->next->lineno)
#ifndef NANO_TINY
	|| scroll_only
#endif
	)
	edit_scroll(UP_DIR,
#ifndef NANO_TINY
		(ISSET(SMOOTH_SCROLL) || scroll_only) ? 1 :
#endif
		editwinrows / 2 + 1);

    /* If we're below the first line of the edit window, update the
     * line we were on before and the line we're on now.  The former
     * needs to be redrawn if we're not on the first page, and the
     * latter needs to be drawn unconditionally. */
    if (openfile->current_y > 0) {
	if (need_vertical_update(0))
	    update_line(openfile->current->next, 0);
	update_line(openfile->current, openfile->current_x);
    }
}
Exemplo n.º 5
0
Arquivo: move.c Projeto: sria91/nano
/* If scroll_only is FALSE, move down one line.  If scroll_only is TRUE,
 * scroll down one line without scrolling the cursor. */
void do_down(
#ifndef NANO_TINY
    bool scroll_only
#else
    void
#endif
)
{
#ifndef NANO_TINY
    int amount = 0, enough;
    filestruct *topline;
#endif

    /* If we're at the bottom of the file, get out. */
    if (openfile->current == openfile->filebot || !openfile->current->next)
        return;

    assert(ISSET(SOFTWRAP) || openfile->current_y == openfile->current->lineno - openfile->edittop->lineno);

    /* Move the current line of the edit window down. */
    openfile->current = openfile->current->next;
    openfile->current_x = actual_x(openfile->current->data,
                                   openfile->placewewant);

#ifndef NANO_TINY
    if (ISSET(SOFTWRAP)) {
        /* Compute the amount to scroll. */
        amount = (strlenpt(openfile->current->data) / COLS + openfile->current_y + 2
                  + strlenpt(openfile->current->prev->data) / COLS - editwinrows);
        topline = openfile->edittop;
        /* Reduce the amount when there are overlong lines at the top. */
        for (enough = 1; enough < amount; enough++) {
            if (amount <= strlenpt(topline->data) / COLS) {
                amount = enough;
                break;
            }
            amount -= strlenpt(topline->data) / COLS;
            topline = topline->next;
        }
    }
#endif

    /* If scroll_only is FALSE and if we're on the last line of the
     * edit window, scroll the edit window down one line if we're in
     * smooth scrolling mode, or down half a page if we're not.  If
     * scroll_only is TRUE, scroll the edit window down one line
     * unconditionally. */
    if (openfile->current_y == editwinrows - 1
#ifndef NANO_TINY
            || amount > 0 || scroll_only
#endif
       ) {
#ifndef NANO_TINY
        if (amount < 1 || scroll_only)
            amount = 1;
#endif
        edit_scroll(DOWNWARD,
#ifndef NANO_TINY
                    (ISSET(SMOOTH_SCROLL) || scroll_only) ? amount :
#endif
                    editwinrows / 2 + 1);
        edit_refresh_needed = TRUE;
    }
    /* If we're above the last line of the edit window, update the line
     * we were on before and the line we're on now.  The former needs to
     * be redrawn if we're not on the first page, and the latter needs
     * to be drawn unconditionally. */
    if (openfile->current_y < editwinrows - 1
#ifndef NANO_TINY
            || ISSET(SOFTWRAP)
#endif
       ) {
        if (need_screen_update(0))
            update_line(openfile->current->prev, 0);
        update_line(openfile->current, openfile->current_x);
    }
}
Exemplo n.º 6
0
/* If scroll_only is FALSE, move down one line.  If scroll_only is TRUE,
 * scroll down one line without scrolling the cursor. */
void do_down(bool scroll_only)
{
#ifndef NANO_TINY
    int amount = 0, enough;
    filestruct *topline;
#endif
    size_t was_column = xplustabs();

    /* If we're at the bottom of the file, get out. */
    if (openfile->current == openfile->filebot)
	return;

    assert(ISSET(SOFTWRAP) || openfile->current_y ==
		openfile->current->lineno - openfile->edittop->lineno);
    assert(openfile->current->next != NULL);

#ifndef NANO_TINY
    if (ISSET(SOFTWRAP)) {
	/* Compute the number of lines to scroll. */
	amount = strlenpt(openfile->current->data) / editwincols -
			xplustabs() / editwincols +
			strlenpt(openfile->current->next->data) / editwincols +
			openfile->current_y - editwinrows + 2;
	topline = openfile->edittop;
	/* Reduce the amount when there are overlong lines at the top. */
	for (enough = 1; enough < amount; enough++) {
	    amount -= strlenpt(topline->data) / editwincols;
	    if (amount > 0)
		topline = topline->next;
	    if (amount < enough) {
		amount = enough;
		break;
	    }
	}
    }
#endif

    /* Move to the next line in the file. */
    openfile->current = openfile->current->next;
    openfile->current_x = actual_x(openfile->current->data,
					openfile->placewewant);

    /* If scroll_only is FALSE and if we're on the last line of the
     * edit window, scroll the edit window down one line if we're in
     * smooth scrolling mode, or down half a page if we're not.  If
     * scroll_only is TRUE, scroll the edit window down one line
     * unconditionally. */
#ifndef NANO_TINY
    if (openfile->current_y == editwinrows - 1 || amount > 0 || scroll_only) {
	if (amount < 1 || scroll_only)
	    amount = 1;

	edit_scroll(DOWNWARD, (ISSET(SMOOTH_SCROLL) || scroll_only) ?
				amount : editwinrows / 2 + 1);

	if (ISSET(SOFTWRAP)) {
	    refresh_needed = TRUE;
	    return;
	}
    }
#else
    if (openfile->current_y == editwinrows - 1)
	edit_scroll(DOWNWARD, editwinrows / 2 + 1);
#endif

    /* If the lines weren't already redrawn, see if they need to be. */
    if (openfile->current_y < editwinrows - 1) {
	/* Redraw the prior line if it was horizontally scrolled. */
	if (need_horizontal_scroll(was_column, 0))
	    update_line(openfile->current->prev, 0);
	/* Redraw the current line if it needs to be horizontally scrolled. */
	if (need_horizontal_scroll(0, xplustabs()))
	    update_line(openfile->current, openfile->current_x);
    }
}