diff --git a/src/cut.c b/src/cut.c index 109d37e3cbb1a327798bf46c858c04d78f679c6d..91fddcdf72f9791e1b81d3f2dfcc1a9d68d9d61d 100644 --- a/src/cut.c +++ b/src/cut.c @@ -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(); diff --git a/src/files.c b/src/files.c index 99d532c71a2e80d89b95f5049e1e40ca95dcca88..4cc8239efb3825b7792e72f52fbcf1034af6d4e0 100644 --- a/src/files.c +++ b/src/files.c @@ -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; diff --git a/src/global.c b/src/global.c index c284c443a176462d98a76b442e1fa5d0ab90ab7e..3421eca87684b1730736b399494f23efd8a13161 100644 --- a/src/global.c +++ b/src/global.c @@ -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 diff --git a/src/move.c b/src/move.c index e2f9823ac399519b3ce5b647ee1af98650b6aacc..8dfc47664c0a23889bd6aa2cf31d6d9a1e6f8ab9 100644 --- a/src/move.c +++ b/src/move.c @@ -44,6 +44,7 @@ void do_last_line(void) openfile->current_y = editwinrows - 1; refresh_needed = TRUE; + focusing = FALSE; } /* Move up one page. */ @@ -253,8 +254,10 @@ 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 @@ -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; diff --git a/src/nano.c b/src/nano.c index 4492061a15627b869bdbae916115c04c42fc5f3c..152f809ebe80c57f30f6810d28a9da7df14d0ce5 100644 --- a/src/nano.c +++ b/src/nano.c @@ -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 diff --git a/src/search.c b/src/search.c index 6f4f3e0359ecff3407aba6be0d41bc581cb5b810..54c1185925c4f659a2ff1103eeebfaabcefb2bb7 100644 --- a/src/search.c +++ b/src/search.c @@ -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; } diff --git a/src/text.c b/src/text.c index e50b6675f50658d47c2903518a84cae87d98439d..571e04b6a778f151ffdd660d22acc294dd489b71 100644 --- a/src/text.c +++ b/src/text.c @@ -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. */