From: David Lawrence Ramsey Date: Thu, 16 Aug 2007 02:34:23 +0000 (+0000) Subject: in do_insertfile(), make sure the mark is always properly positioned X-Git-Tag: v2.1.0~76 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=908b127b448ac867a7436e8ccb1b9982b7cf2de2;p=nano.git in do_insertfile(), make sure the mark is always properly positioned after inserting a one-line file with the mark on git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4152 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index cfd063f2..2fb39cde 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,8 @@ * Makefile.am: Remove erroneous backslash after ChangeLog.pre-2.1 in EXTRA_DIST, so that "make dist" works again. + * files.c (do_insertfile): Make sure the mark is always properly + positioned after inserting a one-line file with the mark on. 2007-08-11 David Lawrence Ramsey diff --git a/src/files.c b/src/files.c index e3421137..c30982c0 100644 --- a/src/files.c +++ b/src/files.c @@ -697,6 +697,9 @@ void do_insertfile( ssize_t current_y_save = openfile->current_y; bool at_edittop = FALSE; /* Whether we're at the top of the edit window. */ +#ifndef NANO_TINY + bool do_mark_shift = FALSE; +#endif while (TRUE) { #ifndef NANO_TINY @@ -800,14 +803,20 @@ void do_insertfile( #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 keep track of whether - * the top of the partition is the top of the edit - * window. */ + * looks like a new buffer, keep track of whether the + * top of the partition is the top of the edit + * window, and keep track of whether the mark begins + * inside the partition and will need adjustment. */ filepart = partition_filestruct(openfile->current, openfile->current_x, openfile->current, openfile->current_x); at_edittop = (openfile->fileage == openfile->edittop); +#ifndef NANO_TINY + if (openfile->mark_set) + do_mark_shift = (openfile->current_x <= + openfile->mark_begin_x); +#endif #ifdef ENABLE_MULTIBUFFER } #endif @@ -870,8 +879,20 @@ void do_insertfile( /* Update the current x-coordinate to account for the * number of characters inserted on the current line. */ openfile->current_x = strlen(openfile->filebot->data); - if (openfile->fileage == openfile->filebot) - openfile->current_x += current_x_save; + if (openfile->fileage == openfile->filebot) { +#ifndef NANO_TINY + /* If the mark begins inside the partition, update + * the mark coordinates to account for the number of + * characters inserted on the current line. */ + if (openfile->mark_set) { + openfile->mark_begin = openfile->current; + if (do_mark_shift) + openfile->mark_begin_x += + openfile->current_x; + } +#endif + openfile->current_x += strlen(filepart->top_data); + } /* Update the current y-coordinate to account for the * number of lines inserted. */