From 8d2dffb7ed3b525411442909c9bd103c6c885f7d Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Wed, 2 Dec 2015 11:02:14 +1100 Subject: [PATCH] Page up/down now move cursor to EOF when appropriate. emacs doesn't do this, but I think it looks better... maybe. Signed-off-by: NeilBrown --- core.h | 5 +++++ mode-emacs.c | 25 ++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/core.h b/core.h index 4e0b9723..c845b2b0 100644 --- 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); diff --git a/mode-emacs.c b/mode-emacs.c index 61a7ff86..bdf5d543 100644 --- a/mode-emacs.c +++ b/mode-emacs.c @@ -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); -- 2.39.5