]> git.wh0rd.org Git - nano.git/commitdiff
* nano.c (do_mouse): Fix mouse support not working with soft wrapping. Fixes
authorChris Allegretta <chrisa@asty.org>
Fri, 13 Nov 2009 20:38:32 +0000 (20:38 +0000)
committerChris Allegretta <chrisa@asty.org>
Fri, 13 Nov 2009 20:38:32 +0000 (20:38 +0000)
          Savannah bug 27549 reported by Hannes Schueller.

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4422 35c25a1d-7b9e-4130-9fde-d3aeb78583b8

ChangeLog
src/nano.c

index 125a9a621de3c44d5800dc28507298ca9e7f3c34..09cd2cf2a02de1f544129039a6c89a385364ba70 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,8 @@
 2009-11-13 Chris Allegretta <chrisa@asty.org>
        * winio.c: Add new static maxsize to be able to easier calculation with
          softwrap.
+       * nano.c (do_mouse): Fix mouse support not working with soft wrapping.  Fixes
+         Savannah bug 27549 reported by Hannes Schueller.
 
 2009-11-11 Chris Allegretta <chrisa@asty.org>
        * winio.c: Large tweaking of cursor and text display based on COLS not COLS - 1, 
index 880c73603f90f88778e4ce982eb4bbd959fc6e29..416d9e32a13d3d0045a1ae9d62aa6d29131ab8a5 100644 (file)
@@ -1667,17 +1667,53 @@ int do_mouse(void)
 
        sameline = (mouse_y == openfile->current_y);
 
-       /* Move to where the click occurred. */
-       for (; openfile->current_y < mouse_y && openfile->current !=
-               openfile->filebot; openfile->current_y++)
-           openfile->current = openfile->current->next;
-       for (; openfile->current_y > mouse_y && openfile->current !=
-               openfile->fileage; openfile->current_y--)
-           openfile->current = openfile->current->prev;
-
-       openfile->current_x = actual_x(openfile->current->data,
+#ifdef DEBUG
+           fprintf(stderr, "mouse_y = %d, current_y = %d\n", mouse_y, openfile->current_y);
+#endif
+
+       if (ISSET(SOFTWRAP)) {
+           int i = 0;
+           for (openfile->current = openfile->edittop;
+                openfile->current->next && i < mouse_y;
+                openfile->current = openfile->current->next, i++) {
+               openfile->current_y = i;
+               i += strlenpt(openfile->current->data) / COLS;
+           }
+
+#ifdef DEBUG
+           fprintf(stderr, "do_mouse(): moving to current_y = %d, i %d\n", openfile->current_y, i);
+           fprintf(stderr, "            openfile->current->data = \"%s\"\n", openfile->current->data);
+#endif
+
+           if (i > mouse_y) {
+               openfile->current = openfile->current->prev;
+               openfile->current_x = actual_x(openfile->current->data, mouse_x + (mouse_y - openfile->current_y) * COLS);
+#ifdef DEBUG
+           fprintf(stderr, "do_mouse(): i > mouse_y, mouse_x = %d, current_x to = %d\n", mouse_x, openfile->current_x);
+#endif
+           } else {
+               openfile->current_x = actual_x(openfile->current->data, mouse_x);
+#ifdef DEBUG
+           fprintf(stderr, "do_mouse(): i <= mouse_y, mouse_x = %d, setting current_x to = %d\n", mouse_x, openfile->current_x);
+#endif
+           }
+
+           openfile->placewewant = xplustabs();
+
+       } else {
+           /* Move to where the click occurred. */
+           for (; openfile->current_y < mouse_y && openfile->current !=
+                  openfile->filebot; openfile->current_y++)
+               openfile->current = openfile->current->next;
+           for (; openfile->current_y > mouse_y && openfile->current !=
+                  openfile->fileage; openfile->current_y--)
+               openfile->current = openfile->current->prev;
+
+           openfile->current_x = actual_x(openfile->current->data,
                get_page_start(xplustabs()) + mouse_x);
-       openfile->placewewant = xplustabs();
+
+           openfile->placewewant = xplustabs();
+       }
 
 #ifndef NANO_TINY
        /* Clicking where the cursor is toggles the mark, as does