Try to stay near the same line in modes if the current one is removed.
authornicm <nicm@openbsd.org>
Sun, 6 Oct 2024 09:30:22 +0000 (09:30 +0000)
committernicm <nicm@openbsd.org>
Sun, 6 Oct 2024 09:30:22 +0000 (09:30 +0000)
usr.bin/tmux/mode-tree.c

index 0bd42b3..0a90515 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: mode-tree.c,v 1.70 2024/10/01 10:10:29 nicm Exp $ */
+/* $OpenBSD: mode-tree.c,v 1.71 2024/10/06 09:30:22 nicm Exp $ */
 
 /*
  * Copyright (c) 2017 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -356,8 +356,13 @@ mode_tree_set_current(struct mode_tree_data *mtd, uint64_t tag)
                        mtd->offset = 0;
                return (1);
        }
-       mtd->current = 0;
-       mtd->offset = 0;
+       if (mtd->current >= mtd->line_size) {
+               mtd->current = mtd->line_size - 1;
+               if (mtd->current > mtd->height - 1)
+                       mtd->offset = mtd->current - mtd->height + 1;
+               else
+                       mtd->offset = 0;
+       }
        return (0);
 }