if we're not inserting a file into a new buffer, partition the current

buffer so that it's effectively a new buffer just before inserting the
file, and only restore placewewant afterwards; this is the same behavior
we would get if we opened the file, added all of it to the cutbuffer,
uncut at the current cursor position, and closed the file


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2062 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
David Lawrence Ramsey
2004-11-05 15:25:53 +00:00
parent 1539837fe0
commit b73c0c0b09
6 changed files with 45 additions and 15 deletions

View File

@@ -490,6 +490,7 @@ void do_insertfile(
const char *msg;
char *ans = mallocstrcpy(NULL, "");
/* The last answer the user typed on the statusbar. */
filestruct *edittop_save = edittop;
#ifndef DISABLE_WRAPPING
wrap_reset();
@@ -535,7 +536,6 @@ void do_insertfile(
statusbar(_("Cancelled"));
break;
} else {
size_t old_current_x = current_x;
size_t old_pww = placewewant;
ans = mallocstrcpy(ans, answer);
@@ -575,7 +575,43 @@ void do_insertfile(
else {
#endif
answer = mallocstrassn(answer, real_dir_from_tilde(answer));
#ifdef ENABLE_MULTIBUFFER
if (!ISSET(MULTIBUFFER)) {
#endif
/* If we're not inserting into a new buffer,
* partition the filestruct so that it contains no
* text and hence looks like a new buffer, and set
* edittop to the top of the partition. */
filepart = partition_filestruct(current, current_x,
current, current_x);
edittop = fileage;
#ifdef ENABLE_MULTIBUFFER
}
#endif
load_buffer(answer);
#ifdef ENABLE_MULTIBUFFER
if (!ISSET(MULTIBUFFER))
#endif
{
filestruct *top_save = fileage;
/* If we're not inserting into a new buffer,
* unpartition the filestruct so that it contains
* all the text again. Note that we've replaced the
* non-text originally in the partition with the
* text in the inserted file. */
unpartition_filestruct(filepart);
/* Renumber starting with the beginning line of the
* old partition. */
renumber(top_save);
/* Set edittop back to what it was before. */
edittop = edittop_save;
}
#ifndef NANO_SMALL
}
#endif
@@ -592,8 +628,7 @@ void do_insertfile(
/* Mark the file as modified. */
set_modified();
/* Restore the old cursor position. */
current_x = old_current_x;
/* Restore the old place we want. */
placewewant = old_pww;
#ifdef ENABLE_MULTIBUFFER
}