diff --git a/src/files.c b/src/files.c index c94404a9..82eb79ec 100644 --- a/src/files.c +++ b/src/files.c @@ -498,7 +498,7 @@ bool open_buffer(const char *filename, bool new_buffer) #ifdef ENABLE_SPELLER /* Open the specified file, and if that succeeds, blow away the text of * the current buffer and read the file contents into its place. */ -void replace_buffer(const char *filename) +void replace_buffer(const char *filename, undo_type action, bool marked) { FILE *f; int descriptor; @@ -516,21 +516,25 @@ void replace_buffer(const char *filename) openfile->undotop->strdata = mallocstrcpy(NULL, _("spelling correction")); #endif - /* Throw away the text of the file. */ + /* When nothing is marked, start at the top of the buffer. */ + if (!marked) { + openfile->current = openfile->filetop; + openfile->current_x = 0; + } + + /* Throw away the marked region or the whole buffer. */ cutbuffer = NULL; - openfile->current = openfile->filetop; - openfile->current_x = 0; #ifndef NANO_TINY - add_undo(CUT_TO_EOF); + add_undo(action); #endif - do_cut_text(FALSE, FALSE, TRUE, FALSE); + do_cut_text(FALSE, marked, !marked, FALSE); #ifndef NANO_TINY - update_undo(CUT_TO_EOF); + update_undo(action); #endif free_lines(cutbuffer); cutbuffer = was_cutbuffer; - /* Insert the processed file into its place. */ + /* Insert the spell-checked file into the cleared area. */ read_file(f, descriptor, filename, TRUE); #ifndef NANO_TINY diff --git a/src/proto.h b/src/proto.h index 22a761cd..e5f7742d 100644 --- a/src/proto.h +++ b/src/proto.h @@ -267,7 +267,7 @@ void make_new_buffer(void); void set_modified(void); bool open_buffer(const char *filename, bool new_buffer); #ifdef ENABLE_SPELLER -void replace_buffer(const char *filename); +void replace_buffer(const char *filename, undo_type action, bool marked); #ifndef NANO_TINY void replace_marked_buffer(const char *filename); #endif diff --git a/src/text.c b/src/text.c index 299c5562..1b1e2204 100644 --- a/src/text.c +++ b/src/text.c @@ -2596,7 +2596,7 @@ const char *do_alt_speller(char *tempfile_name) openfile->mark_x < openfile->current_x)); ssize_t was_mark_lineno = openfile->mark->lineno; - replace_marked_buffer(tempfile_name); + replace_buffer(tempfile_name, CUT, TRUE); /* Adjust the end point of the marked region for any change in * length of the region's last line. */ @@ -2609,7 +2609,7 @@ const char *do_alt_speller(char *tempfile_name) openfile->mark = fsfromline(was_mark_lineno); } else #endif - replace_buffer(tempfile_name); + replace_buffer(tempfile_name, CUT_TO_EOF, FALSE); /* Go back to the old position. */ goto_line_posx(lineno_save, current_x_save);