diff options
Diffstat (limited to 'src/move.c')
-rw-r--r-- | src/move.c | 77 |
1 files changed, 52 insertions, 25 deletions
@@ -1,9 +1,9 @@ -/* $Id: move.c 4486 2010-03-21 04:56:37Z astyanax $ */ +/* $Id: move.c 5013 2014-06-23 18:20:12Z bens $ */ /************************************************************************** * move.c * * * * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, * - * 2008, 2009 Free Software Foundation, Inc. * + * 2008, 2009, 2010, 2011, 2013, 2014 Free Software Foundation, Inc. * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 3, or (at your option) * @@ -33,7 +33,7 @@ void do_first_line(void) openfile->current_x = 0; openfile->placewewant = 0; - edit_refresh_needed = 1; + edit_refresh_needed = TRUE; } /* Move to the last line of the file. */ @@ -44,7 +44,7 @@ void do_last_line(void) openfile->placewewant = xplustabs(); openfile->current_y = editwinrows - 1; - edit_refresh_needed = 1; + edit_refresh_needed = TRUE; } /* Move up one page. */ @@ -55,7 +55,10 @@ void do_page_up(void) /* If there's less than a page of text left on the screen, put the * cursor at the beginning of the first line of the file, and then * update the edit window. */ - if (openfile->current->lineno == 1 || (!ISSET(SOFTWRAP) && + if (openfile->current->lineno == 1 || ( +#ifndef NANO_TINY + !ISSET(SOFTWRAP) && +#endif openfile->current->lineno <= editwinrows - 2)) { do_first_line(); return; @@ -63,7 +66,6 @@ void do_page_up(void) /* 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 @@ -76,20 +78,23 @@ void do_page_up(void) for (i = editwinrows - 2; i - skipped > 0 && openfile->current != openfile->fileage; i--) { openfile->current = openfile->current->prev; +#ifndef NANO_TINY if (ISSET(SOFTWRAP) && openfile->current) { skipped += strlenpt(openfile->current->data) / COLS; #ifdef DEBUG - fprintf(stderr, "do_page_up: i = %d, skipped = %d based on line %ld len %d\n", i, (unsigned long) skipped, -openfile->current->lineno, strlenpt(openfile->current->data)); + fprintf(stderr, "do_page_up: i = %d, skipped = %d based on line %ld len %lu\n", + i, skipped, (long)openfile->current->lineno, (unsigned long)strlenpt(openfile->current->data)); #endif } +#endif } openfile->current_x = actual_x(openfile->current->data, openfile->placewewant); #ifdef DEBUG - fprintf(stderr, "do_page_up: openfile->current->lineno = %lu, skipped = %d\n", (unsigned long) openfile->current->lineno, skipped); + fprintf(stderr, "do_page_up: openfile->current->lineno = %lu, skipped = %d\n", + (unsigned long)openfile->current->lineno, skipped); #endif /* Scroll the edit window up a page. */ @@ -125,7 +130,7 @@ void do_page_down(void) openfile->filebot; i--) { openfile->current = openfile->current->next; #ifdef DEBUG - fprintf(stderr, "do_page_down: moving to line %lu\n", (unsigned long) openfile->current->lineno); + fprintf(stderr, "do_page_down: moving to line %lu\n", (unsigned long)openfile->current->lineno); #endif } @@ -513,12 +518,12 @@ void do_up( * 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) + if (openfile->current_y == 0 #ifndef NANO_TINY - || scroll_only + || (ISSET(SOFTWRAP) && openfile->edittop->lineno == openfile->current->next->lineno) || scroll_only #endif ) - edit_scroll(UP_DIR, + edit_scroll(UPWARD, #ifndef NANO_TINY (ISSET(SMOOTH_SCROLL) || scroll_only) ? 1 : #endif @@ -563,13 +568,15 @@ void do_down( #endif ) { - bool onlastline = FALSE; +#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) + 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. */ @@ -577,34 +584,54 @@ void do_down( openfile->current_x = actual_x(openfile->current->data, openfile->placewewant); +#ifndef NANO_TINY if (ISSET(SOFTWRAP)) { - if (openfile->current->lineno - openfile->edittop->lineno >= maxrows) - onlastline = TRUE; + /* 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 first line of the + /* 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 (onlastline || openfile->current_y == editwinrows - 1 + if (openfile->current_y == editwinrows - 1 #ifndef NANO_TINY - || scroll_only + || amount > 0 || scroll_only #endif ) { - edit_scroll(DOWN_DIR, #ifndef NANO_TINY - (ISSET(SMOOTH_SCROLL) || scroll_only) ? 1 : + 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 (ISSET(SOFTWRAP) || openfile->current_y < editwinrows - 1) { + if (openfile->current_y < editwinrows - 1 +#ifndef NANO_TINY + || ISSET(SOFTWRAP) +#endif + ) { if (need_vertical_update(0)) update_line(openfile->current->prev, 0); update_line(openfile->current, openfile->current_x); |