]> git.wh0rd.org Git - nano.git/commitdiff
in do_insertfile(), make sure the mark is always properly positioned
authorDavid Lawrence Ramsey <pooka109@gmail.com>
Thu, 16 Aug 2007 02:34:23 +0000 (02:34 +0000)
committerDavid Lawrence Ramsey <pooka109@gmail.com>
Thu, 16 Aug 2007 02:34:23 +0000 (02:34 +0000)
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

ChangeLog
src/files.c

index cfd063f24cd11ce72b2d9e9152ae66c2c09027d6..2fb39cde57e7f70395d8f30d80702b561b8fd6f9 100644 (file)
--- 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  <pooka109@gmail.com>
 
index e342113753df87c980e407a1af2326c632adbaaa..c30982c0ad23c746dc608bb37fb4c1e4727b471f 100644 (file)
@@ -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. */