Index: src/move.c =================================================================== --- src/move.c (revision 4888) +++ src/move.c (working copy) @@ -26,6 +26,33 @@ #include #include +void update_page(void) +{ + size_t curr_col = xplustabs(); + size_t pg_start = get_page_start(curr_col); + if(pg_start != EDITWIN_CURR_PG_START){ + //if we made it in here then we moved to a line that ends before the current page starts + //back up the page_start so we are at the end of the line we moved to + size_t old_pg_start = EDITWIN_CURR_PG_START; + set_edit_pg_start(pg_start); + + size_t old_x = openfile->current_x; + openfile->current_x = actual_x(openfile->current->data, EDITWIN_CURR_PG_START); + + edit_refresh(); + set_edit_pg_start(old_pg_start); + openfile->current_x = old_x; + } + else if(curr_col != openfile->current_x){ + size_t old_x = openfile->current_x; + openfile->current_x = curr_col; + edit_refresh(); + openfile->current_x = old_x; + } + else + edit_refresh(); +} + /* Move to the first line of the file. */ void do_first_line(void) { @@ -85,17 +112,21 @@ } } - 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); #endif + if (SMOOTH_HORZ_SCROLL) + update_page(); + else{ + openfile->current_x = actual_x(openfile->current->data, + openfile->placewewant); + /* Scroll the edit window up a page. */ edit_update(NONE); } +} /* Move down one page. */ void do_page_down(void) @@ -131,12 +162,16 @@ } + if (SMOOTH_HORZ_SCROLL) + update_page(); + else{ openfile->current_x = actual_x(openfile->current->data, openfile->placewewant); /* Scroll the edit window down a page. */ edit_update(NONE); } +} #ifndef DISABLE_JUSTIFY /* Move up to the beginning of the last beginning-of-paragraph line @@ -223,7 +258,8 @@ filestruct *current_save = openfile->current; char *char_mb; int char_mb_len; - bool end_line = FALSE, started_on_word = FALSE; + bool started_on_word = FALSE; + bool end_line = (openfile->current_x >= strlen(openfile->current->data)); assert(openfile->current != NULL && openfile->current->data != NULL); @@ -278,6 +314,7 @@ if (!end_line) break; + set_edit_pg_start(0); if (openfile->current != openfile->filebot) { end_line = FALSE; openfile->current_x = 0; @@ -467,9 +504,13 @@ } #endif - if (need_horizontal_update(pww_save)) + if (need_horizontal_update(pww_save)){ + if(SMOOTH_HORZ_SCROLL) + edit_refresh(); + else update_line(openfile->current, openfile->current_x); } +} /* Move to the end of the current line. */ void do_end(void) @@ -479,9 +520,13 @@ openfile->current_x = strlen(openfile->current->data); openfile->placewewant = xplustabs(); - if (need_horizontal_update(pww_save)) + if (need_horizontal_update(pww_save)){ + if(SMOOTH_HORZ_SCROLL) + edit_refresh(); + else update_line(openfile->current, openfile->current_x); } +} /* If scroll_only is FALSE, move up one line. If scroll_only is TRUE, * scroll up one line without scrolling the cursor. */ @@ -506,6 +551,7 @@ /* Move the current line of the edit window up. */ openfile->current = openfile->current->prev; + if (!SMOOTH_HORZ_SCROLL) openfile->current_x = actual_x(openfile->current->data, openfile->placewewant); @@ -530,11 +576,15 @@ * 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(SMOOTH_HORZ_SCROLL) + update_page(); + else{ if (need_vertical_update(0)) update_line(openfile->current->next, 0); update_line(openfile->current, openfile->current_x); } } +} /* Move up one line. */ void do_up_void(void) @@ -577,6 +627,7 @@ /* Move the current line of the edit window down. */ openfile->current = openfile->current->next; + if (!SMOOTH_HORZ_SCROLL) openfile->current_x = actual_x(openfile->current->data, openfile->placewewant); @@ -624,11 +675,15 @@ * 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(SMOOTH_HORZ_SCROLL) + update_page(); + else{ if (need_vertical_update(0)) update_line(openfile->current->prev, 0); update_line(openfile->current, openfile->current_x); } } +} /* Move down one line. */ void do_down_void(void) @@ -653,9 +708,12 @@ { size_t pww_save = openfile->placewewant; - if (openfile->current_x > 0) - openfile->current_x = move_mbleft(openfile->current->data, - openfile->current_x); + if (openfile->current_x > 0){ + size_t nLen = strlen(openfile->current->data); + if(openfile->current_x > nLen) + openfile->current_x = nLen; + openfile->current_x = move_mbleft(openfile->current->data, openfile->current_x); + } else if (openfile->current != openfile->fileage) { do_up_void(); openfile->current_x = strlen(openfile->current->data); @@ -663,14 +721,21 @@ openfile->placewewant = xplustabs(); - if (need_horizontal_update(pww_save)) + if (need_horizontal_update(pww_save)){ + if(SMOOTH_HORZ_SCROLL) + edit_refresh(); + else update_line(openfile->current, openfile->current_x); } +} /* Move right one character. */ void do_right(void) { size_t pww_save = openfile->placewewant; + size_t nLen = strlen(openfile->current->data); + if(openfile->current_x > nLen) + openfile->current_x = nLen; assert(openfile->current_x <= strlen(openfile->current->data)); @@ -684,6 +749,10 @@ openfile->placewewant = xplustabs(); - if (need_horizontal_update(pww_save)) + if (need_horizontal_update(pww_save)){ + if(SMOOTH_HORZ_SCROLL) + edit_refresh(); + else update_line(openfile->current, openfile->current_x); } +} Index: src/nano.c =================================================================== --- src/nano.c (revision 4888) +++ src/nano.c (working copy) @@ -2017,6 +2017,9 @@ openfile->current->data = charealloc(openfile->current->data, current_len + (char_buf_len * 2)); + if(openfile->current_x > current_len) + openfile->current_x = current_len; + assert(openfile->current_x <= current_len); charmove(openfile->current->data + openfile->current_x + Index: src/nano.h =================================================================== --- src/nano.h (revision 4888) +++ src/nano.h (working copy) @@ -542,6 +542,8 @@ NOREAD_MODE }; +#define SMOOTH_HORZ_SCROLL (ISSET(SMOOTH_SCROLL) && !ISSET(SOFTWRAP)) +#define EDITWIN_CURR_PG_START get_edit_pg_start() /* Flags for the menus in which a given function should be present. */ #define MMAIN (1<<0) #define MWHEREIS (1<<1) Index: src/proto.h =================================================================== --- src/proto.h (revision 4888) +++ src/proto.h (working copy) @@ -720,6 +720,8 @@ char *mallocstrcpy(char *dest, const char *src); char *mallocstrassn(char *dest, char *src); size_t get_page_start(size_t column); +size_t get_edit_pg_start(); +void set_edit_pg_start(size_t column); size_t xplustabs(void); size_t actual_x(const char *s, size_t column); size_t strnlenpt(const char *s, size_t maxlen); Index: src/utils.c =================================================================== --- src/utils.c (revision 4888) +++ src/utils.c (working copy) @@ -457,12 +457,28 @@ return src; } +static size_t edit_pg_start=0; + +inline size_t get_edit_pg_start(){return edit_pg_start;} +inline void set_edit_pg_start(size_t column){edit_pg_start = column;} + /* nano scrolls horizontally within a line in chunks. Return the column * number of the first character displayed in the edit window when the * cursor is at the given column. Note that (0 <= column - * get_page_start(column) < COLS). */ size_t get_page_start(size_t column) { + if (SMOOTH_HORZ_SCROLL){ + if(column < edit_pg_start) + return column; + else if( (column - edit_pg_start) > COLS-2 ) + return column - (COLS - 2); + else if ((column) == edit_pg_start && column>0) + return column-1; + else + return edit_pg_start; + } + else { if (column == 0 || column < COLS - 1) return 0; else if (COLS > 8) @@ -470,6 +486,7 @@ else return column - (COLS - 2); } +} /* Return the placewewant associated with current_x, i.e. the zero-based * column position of the cursor. The value will be no smaller than Index: src/winio.c =================================================================== --- src/winio.c (revision 4888) +++ src/winio.c (working copy) @@ -2874,7 +2874,7 @@ * positions in the expanded line. */ if (ISSET(SOFTWRAP)) index = 0; - else + else if (!SMOOTH_HORZ_SCROLL) index = strnlenpt(fileptr->data, index); page_start = get_page_start(index); @@ -2920,6 +2920,8 @@ extralinesused++; } } + + set_edit_pg_start(page_start); return extralinesused; } @@ -3079,10 +3081,10 @@ if ((i == nlines && direction == DOWN_DIR) || (i == 1 && direction == UP_DIR)) { if (do_redraw) - update_line(foo, (foo == openfile->current) ? + update_line(foo, (foo == openfile->current || SMOOTH_HORZ_SCROLL) ? openfile->current_x : 0); } else - update_line(foo, (foo == openfile->current) ? + update_line(foo, (foo == openfile->current || SMOOTH_HORZ_SCROLL) ? openfile->current_x : 0); foo = foo->next; } @@ -3093,6 +3095,9 @@ * updated. Use this if we've moved without changing any text. */ void edit_redraw(filestruct *old_current, size_t pww_save) { + if(SMOOTH_HORZ_SCROLL) + return edit_refresh(); + bool do_redraw = need_vertical_update(0) || need_vertical_update(pww_save); filestruct *foo = NULL; @@ -3217,7 +3222,7 @@ #endif for (nlines = 0; nlines < editwinrows && foo != NULL; nlines++) { - nlines += update_line(foo, (foo == openfile->current) ? + nlines += update_line(foo, (foo == openfile->current || SMOOTH_HORZ_SCROLL) ? openfile->current_x : 0); foo = foo->next; }