scrolling: center the cursor when inserted stuff does not fit on screen

Since nano-2.4.1, reading in or pasting a large piece of text would put
the cursor on the bottom line, leaving only one line of the non-read or
non-pasted text visible.  This is different from the centering behavior
of Pico, and somewhat disorienting, as you can't see "where you are" any
more in relation to the file as it was.

So now center the cursor whenever the read or pasted text is larger than
the screen, but don't center it when the text fits entirely on the screen.
(The latter avoids the effect of the screen jumping unnecessarily when
inserting just a few lines while the cursor is near the bottom.)

To achieve this behavior: default to focusing, and temporarily set it to
FALSE when the focusing effect is unwanted.

This fixes https://savannah.gnu.org/bugs/?47841.
master
Benno Schulenberg 2016-04-12 10:24:57 +02:00
parent 402cf718c4
commit 318ed6b105
7 changed files with 18 additions and 13 deletions

View File

@ -269,6 +269,8 @@ void do_cut_till_eof(void)
/* Copy text from the cutbuffer into the current filestruct. */
void do_uncut_text(void)
{
int was_lineno = openfile->current->lineno;
assert(openfile->current != NULL && openfile->current->data != NULL);
/* If the cutbuffer is empty, get out. */
@ -287,6 +289,9 @@ void do_uncut_text(void)
update_undo(PASTE);
#endif
if (openfile->current->lineno - was_lineno < editwinrows)
focusing = FALSE;
/* Set the current place we want to where the text from the
* cutbuffer ends. */
openfile->placewewant = xplustabs();

View File

@ -954,6 +954,9 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable, bool checkw
"Read %lu lines (Warning: No write permission)",
(unsigned long)num_lines), (unsigned long)num_lines);
if (num_lines < editwinrows)
focusing = FALSE;
#ifndef NANO_TINY
if (ISSET(MAKE_IT_UNIX))
openfile->fmt = NIX_FILE;

View File

@ -37,7 +37,7 @@ bool meta_key;
/* Whether the current keystroke is a Meta key. */
bool func_key;
/* Whether the current keystroke is an extended keypad value. */
bool focusing = FALSE;
bool focusing = TRUE;
/* Whether an update of the edit window should center the cursor. */
#ifndef NANO_TINY

View File

@ -44,6 +44,7 @@ void do_last_line(void)
openfile->current_y = editwinrows - 1;
refresh_needed = TRUE;
focusing = FALSE;
}
/* Move up one page. */
@ -253,9 +254,11 @@ void do_prev_word(bool allow_punct, bool allow_update)
openfile->current_x);
/* If allow_update is TRUE, update the screen. */
if (allow_update)
if (allow_update) {
focusing = FALSE;
edit_redraw(current_save);
}
}
/* Move to the previous word in the file, treating punctuation as part of a
* word if the WORD_BOUNDS flag is set, and update the screen afterwards. */
@ -303,8 +306,10 @@ bool do_next_word(bool allow_punct, bool allow_update)
}
/* If allow_update is TRUE, update the screen. */
if (allow_update)
if (allow_update) {
focusing = FALSE;
edit_redraw(current_save);
}
/* Return whether we started on a word. */
return started_on_word;

View File

@ -2652,7 +2652,7 @@ int main(int argc, char **argv)
while (TRUE) {
currmenu = MMAIN;
focusing = FALSE;
focusing = TRUE;
/* If constant cursor position display is on, and there are no
* keys waiting in the input buffer, display the current cursor

View File

@ -105,7 +105,6 @@ void not_found_msg(const char *str)
void search_replace_abort(void)
{
display_main_list();
focusing = FALSE;
#ifndef NANO_TINY
if (openfile->mark_set)
edit_refresh();
@ -143,8 +142,6 @@ int search_init(bool replacing, bool use_answer)
* do_search() or do_replace() and be called again. In that case,
* we should put the same search string back up. */
focusing = TRUE;
if (last_search[0] != '\0') {
char *disp = display_string(last_search, 0, COLS / 3, FALSE);
@ -453,8 +450,6 @@ void do_findnext(void)
/* Search for the last string without prompting. */
void do_research(void)
{
focusing = TRUE;
#ifndef DISABLE_HISTORIES
/* If nothing was searched for yet during this run of nano, but
* there is a search history, take the most recent item. */
@ -1120,6 +1115,7 @@ void do_find_bracket(void)
/* If count is zero, we've found a matching bracket. Update
* the screen and get out. */
if (count == 0) {
focusing = FALSE;
edit_redraw(current_save);
break;
}

View File

@ -616,7 +616,6 @@ void do_undo(void)
openfile->placewewant = xplustabs();
openfile->totsize = u->wassize;
set_modified();
focusing = TRUE;
}
/* Redo the last thing(s) we undid. */
@ -751,7 +750,6 @@ void do_redo(void)
openfile->placewewant = xplustabs();
openfile->totsize = u->newsize;
set_modified();
focusing = TRUE;
}
#endif /* !NANO_TINY */
@ -2394,8 +2392,6 @@ bool do_int_spell_fix(const char *word)
save_search = last_search;
last_search = mallocstrcpy(NULL, word);
focusing = TRUE;
#ifndef NANO_TINY
if (old_mark_set) {
/* Trim the filestruct so that it contains only the marked text. */