]> git.neil.brown.name Git - edlib.git/commitdiff
Page up/down now move cursor to EOF when appropriate.
authorNeilBrown <neil@brown.name>
Wed, 2 Dec 2015 00:02:14 +0000 (11:02 +1100)
committerNeilBrown <neil@brown.name>
Wed, 2 Dec 2015 00:02:14 +0000 (11:02 +1100)
emacs doesn't do this, but I think it looks better... maybe.

Signed-off-by: NeilBrown <neil@brown.name>
core.h
mode-emacs.c

diff --git a/core.h b/core.h
index 4e0b9723db18ee662a73d065f56bd3d05990ae96..c845b2b0f9e687962340194cf06677db4de39166 100644 (file)
--- a/core.h
+++ b/core.h
@@ -216,6 +216,11 @@ static inline int mark_ordered_or_same_pane(struct pane *p, struct mark *m1, str
        return mark_ordered(m1, m2) || mark_same_pane(p, m1, m2, NULL);
 }
 
+static inline int mark_ordered_not_same_pane(struct pane *p, struct mark *m1, struct mark *m2)
+{
+       return mark_ordered(m1, m2) && !mark_same_pane(p, m1, m2, NULL);
+}
+
 static inline int mark_ordered_not_same(struct doc *d, struct mark *m1, struct mark *m2)
 {
        return mark_ordered(m1, m2) && !mark_same(d, m1, m2);
index 61a7ff86650ba6df95674bf28e13d06ad7802084..bdf5d54379113ae5e8372ebb25dfab785f4bc36c 100644 (file)
@@ -84,8 +84,12 @@ REDEF_CMD(emacs_move)
 
        if (strcmp(mv->type, "Move-View-Large") == 0 && old_x >= 0) {
                /* Might have lost the cursor - place it at top or
-                * bottom of view
+                * bottom of view, but make sure it moves only in the
+                * right direction.
                 */
+               int ok;
+               struct mark *old_point = mark_at_point(cursor_pane,
+                                                      ci->mark, MARK_UNGROUPED);
                ci2.focus = cursor_pane;
                ci2.key = "Move-CursorXY";
                ci2.numeric = 1;
@@ -96,6 +100,25 @@ REDEF_CMD(emacs_move)
                else
                        ci2.y = cursor_pane->h - 1;
                key_handle_xy(&ci2);
+               if (mv->direction == 1)
+                       ok = mark_ordered_not_same_pane(cursor_pane, old_point, ci->mark);
+               else
+                       ok = mark_ordered_not_same_pane(cursor_pane, ci->mark, old_point);
+               if (!ok) {
+                       /* Try other end of pane */
+                       memset(&ci2, 0, sizeof(ci2));
+                       ci2.focus = cursor_pane;
+                       ci2.key = "Move-CursorXY";
+                       ci2.numeric = 1;
+                       ci2.x = old_x;
+                       ci2.mark = ci->mark;
+                       if (mv->direction != 1)
+                               ci2.y = 0;
+                       else
+                               ci2.y = cursor_pane->h - 1;
+                       key_handle_xy(&ci2);
+               }
+               mark_free(old_point);
        }
 
        pane_damaged(cursor_pane, DAMAGED_CURSOR);