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
parent
402cf718c4
commit
318ed6b105
|
@ -269,6 +269,8 @@ void do_cut_till_eof(void)
|
||||||
/* Copy text from the cutbuffer into the current filestruct. */
|
/* Copy text from the cutbuffer into the current filestruct. */
|
||||||
void do_uncut_text(void)
|
void do_uncut_text(void)
|
||||||
{
|
{
|
||||||
|
int was_lineno = openfile->current->lineno;
|
||||||
|
|
||||||
assert(openfile->current != NULL && openfile->current->data != NULL);
|
assert(openfile->current != NULL && openfile->current->data != NULL);
|
||||||
|
|
||||||
/* If the cutbuffer is empty, get out. */
|
/* If the cutbuffer is empty, get out. */
|
||||||
|
@ -287,6 +289,9 @@ void do_uncut_text(void)
|
||||||
update_undo(PASTE);
|
update_undo(PASTE);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (openfile->current->lineno - was_lineno < editwinrows)
|
||||||
|
focusing = FALSE;
|
||||||
|
|
||||||
/* Set the current place we want to where the text from the
|
/* Set the current place we want to where the text from the
|
||||||
* cutbuffer ends. */
|
* cutbuffer ends. */
|
||||||
openfile->placewewant = xplustabs();
|
openfile->placewewant = xplustabs();
|
||||||
|
|
|
@ -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)",
|
"Read %lu lines (Warning: No write permission)",
|
||||||
(unsigned long)num_lines), (unsigned long)num_lines);
|
(unsigned long)num_lines), (unsigned long)num_lines);
|
||||||
|
|
||||||
|
if (num_lines < editwinrows)
|
||||||
|
focusing = FALSE;
|
||||||
|
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
if (ISSET(MAKE_IT_UNIX))
|
if (ISSET(MAKE_IT_UNIX))
|
||||||
openfile->fmt = NIX_FILE;
|
openfile->fmt = NIX_FILE;
|
||||||
|
|
|
@ -37,7 +37,7 @@ bool meta_key;
|
||||||
/* Whether the current keystroke is a Meta key. */
|
/* Whether the current keystroke is a Meta key. */
|
||||||
bool func_key;
|
bool func_key;
|
||||||
/* Whether the current keystroke is an extended keypad value. */
|
/* 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. */
|
/* Whether an update of the edit window should center the cursor. */
|
||||||
|
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
|
|
|
@ -44,6 +44,7 @@ void do_last_line(void)
|
||||||
openfile->current_y = editwinrows - 1;
|
openfile->current_y = editwinrows - 1;
|
||||||
|
|
||||||
refresh_needed = TRUE;
|
refresh_needed = TRUE;
|
||||||
|
focusing = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Move up one page. */
|
/* Move up one page. */
|
||||||
|
@ -253,8 +254,10 @@ void do_prev_word(bool allow_punct, bool allow_update)
|
||||||
openfile->current_x);
|
openfile->current_x);
|
||||||
|
|
||||||
/* If allow_update is TRUE, update the screen. */
|
/* If allow_update is TRUE, update the screen. */
|
||||||
if (allow_update)
|
if (allow_update) {
|
||||||
|
focusing = FALSE;
|
||||||
edit_redraw(current_save);
|
edit_redraw(current_save);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Move to the previous word in the file, treating punctuation as part of a
|
/* Move to the previous word in the file, treating punctuation as part of a
|
||||||
|
@ -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 is TRUE, update the screen. */
|
||||||
if (allow_update)
|
if (allow_update) {
|
||||||
|
focusing = FALSE;
|
||||||
edit_redraw(current_save);
|
edit_redraw(current_save);
|
||||||
|
}
|
||||||
|
|
||||||
/* Return whether we started on a word. */
|
/* Return whether we started on a word. */
|
||||||
return started_on_word;
|
return started_on_word;
|
||||||
|
|
|
@ -2652,7 +2652,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
currmenu = MMAIN;
|
currmenu = MMAIN;
|
||||||
focusing = FALSE;
|
focusing = TRUE;
|
||||||
|
|
||||||
/* If constant cursor position display is on, and there are no
|
/* If constant cursor position display is on, and there are no
|
||||||
* keys waiting in the input buffer, display the current cursor
|
* keys waiting in the input buffer, display the current cursor
|
||||||
|
|
|
@ -105,7 +105,6 @@ void not_found_msg(const char *str)
|
||||||
void search_replace_abort(void)
|
void search_replace_abort(void)
|
||||||
{
|
{
|
||||||
display_main_list();
|
display_main_list();
|
||||||
focusing = FALSE;
|
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
if (openfile->mark_set)
|
if (openfile->mark_set)
|
||||||
edit_refresh();
|
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,
|
* do_search() or do_replace() and be called again. In that case,
|
||||||
* we should put the same search string back up. */
|
* we should put the same search string back up. */
|
||||||
|
|
||||||
focusing = TRUE;
|
|
||||||
|
|
||||||
if (last_search[0] != '\0') {
|
if (last_search[0] != '\0') {
|
||||||
char *disp = display_string(last_search, 0, COLS / 3, FALSE);
|
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. */
|
/* Search for the last string without prompting. */
|
||||||
void do_research(void)
|
void do_research(void)
|
||||||
{
|
{
|
||||||
focusing = TRUE;
|
|
||||||
|
|
||||||
#ifndef DISABLE_HISTORIES
|
#ifndef DISABLE_HISTORIES
|
||||||
/* If nothing was searched for yet during this run of nano, but
|
/* If nothing was searched for yet during this run of nano, but
|
||||||
* there is a search history, take the most recent item. */
|
* 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
|
/* If count is zero, we've found a matching bracket. Update
|
||||||
* the screen and get out. */
|
* the screen and get out. */
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
|
focusing = FALSE;
|
||||||
edit_redraw(current_save);
|
edit_redraw(current_save);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -616,7 +616,6 @@ void do_undo(void)
|
||||||
openfile->placewewant = xplustabs();
|
openfile->placewewant = xplustabs();
|
||||||
openfile->totsize = u->wassize;
|
openfile->totsize = u->wassize;
|
||||||
set_modified();
|
set_modified();
|
||||||
focusing = TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Redo the last thing(s) we undid. */
|
/* Redo the last thing(s) we undid. */
|
||||||
|
@ -751,7 +750,6 @@ void do_redo(void)
|
||||||
openfile->placewewant = xplustabs();
|
openfile->placewewant = xplustabs();
|
||||||
openfile->totsize = u->newsize;
|
openfile->totsize = u->newsize;
|
||||||
set_modified();
|
set_modified();
|
||||||
focusing = TRUE;
|
|
||||||
}
|
}
|
||||||
#endif /* !NANO_TINY */
|
#endif /* !NANO_TINY */
|
||||||
|
|
||||||
|
@ -2394,8 +2392,6 @@ bool do_int_spell_fix(const char *word)
|
||||||
save_search = last_search;
|
save_search = last_search;
|
||||||
last_search = mallocstrcpy(NULL, word);
|
last_search = mallocstrcpy(NULL, word);
|
||||||
|
|
||||||
focusing = TRUE;
|
|
||||||
|
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
if (old_mark_set) {
|
if (old_mark_set) {
|
||||||
/* Trim the filestruct so that it contains only the marked text. */
|
/* Trim the filestruct so that it contains only the marked text. */
|
||||||
|
|
Loading…
Reference in New Issue