From 9f2c80db24d96b46283387c49030edbf744f7828 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Fri, 7 Apr 2017 11:21:26 +0200 Subject: [PATCH] moving: when determining where we are on the screen, use placewewant To make dynamic Home and End work properly when double-width characters straddle a chunk boundary, use the spot where the cursor is really shown instead of the "actual x" position of the current character, because the latter might be on the preceding row. This fixes https://savannah.gnu.org/bugs/?50737. --- src/move.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/move.c b/src/move.c index 9cd882e8..30a2da6c 100644 --- a/src/move.c +++ b/src/move.c @@ -350,7 +350,7 @@ void do_next_word_void(void) void do_home(bool be_clever) { filestruct *was_current = openfile->current; - size_t was_column = xplustabs(); + size_t was_column = openfile->placewewant; bool moved_off_chunk = TRUE; #ifndef NANO_TINY bool moved = FALSE; @@ -380,17 +380,19 @@ void do_home(bool be_clever) if (!moved && ISSET(SOFTWRAP)) { /* If already at the left edge of the screen, move fully home. * Otherwise, move to the left edge. */ - if (openfile->current_x == leftedge_x && be_clever) + if (was_column % editwincols == 0 && be_clever) openfile->current_x = 0; else { openfile->current_x = leftedge_x; + openfile->placewewant = (was_column / editwincols) * editwincols; moved_off_chunk = FALSE; } } else if (!moved) #endif openfile->current_x = 0; - openfile->placewewant = xplustabs(); + if (moved_off_chunk) + openfile->placewewant = 0; /* If we changed chunk, we might be offscreen. Otherwise, * update current if the mark is on or we changed "page". */ @@ -413,7 +415,7 @@ void do_home_void(void) void do_end(bool be_clever) { filestruct *was_current = openfile->current; - size_t was_column = xplustabs(); + size_t was_column = openfile->placewewant; size_t line_len = strlen(openfile->current->data); bool moved_off_chunk = TRUE;