nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Nano-devel] [PATCH 2/2] scrolling: make the centering function behave l


From: Benno Schulenberg
Subject: [Nano-devel] [PATCH 2/2] scrolling: make the centering function behave like in Emacs
Date: Wed, 4 May 2016 22:20:16 +0200

One strike centers the cursor line, a second strike puts it at the top
of the screen, and a third strike at the bottom.  A fourth strike puts
it at the center again.
---
 src/global.c |  3 +++
 src/move.c   | 15 +++++++++++++--
 src/nano.c   |  7 +++++++
 src/proto.h  |  1 +
 4 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/src/global.c b/src/global.c
index 3add8aa..9d703af 100644
--- a/src/global.c
+++ b/src/global.c
@@ -76,6 +76,9 @@ int editwinrows = 0;
        /* How many rows does the edit window take up? */
 int maxrows = 0;
        /* How many usable lines there are (due to soft wrapping). */
+int center_mode = -1;
+       /* Whether to center the cursor line (0), put it at the top (1),
+        * or at the bottom (2). */
 
 filestruct *cutbuffer = NULL;
        /* The buffer where we store cut text. */
diff --git a/src/move.c b/src/move.c
index b9429f8..5d92285 100644
--- a/src/move.c
+++ b/src/move.c
@@ -534,10 +534,21 @@ void do_scroll_down(void)
     do_down(TRUE);
 }
 
-/* Scroll the line with the cursor to the center of the screen. */
+/* Scroll the line with the cursor to the center of the screen, or
+ * to the top, or to the bottom. */
 void do_center(void)
 {
-    edit_update(CENTERING);
+    if (center_mode == 0)
+       edit_update(CENTERING);
+    else if (center_mode == 1)
+       /* Start the viewport at the line where the cursor is. */
+       openfile->edittop = openfile->current;
+    else {
+       /* Simulate the cursor being on the bottom line, then make
+        * it scroll there. */
+       openfile->current_y = editwinrows - 1;
+       edit_update(STATIONARY);
+    }
     refresh_needed = TRUE;
 }
 #endif
diff --git a/src/nano.c b/src/nano.c
index 152f809..b9f704b 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -1678,6 +1678,8 @@ int do_input(bool allow_funcs)
 
                free(output);
 
+               center_mode = -1;
+
                /* Empty the input buffer. */
                kbinput_len = 0;
                free(kbinput);
@@ -1696,6 +1698,11 @@ int do_input(bool allow_funcs)
                )
                preserve = TRUE;
 
+           if (s->scfunc == do_center)
+               center_mode = (center_mode + 1) % 3;
+           else
+               center_mode = -1;
+
            if (s->scfunc == NULL) {
                statusbar("Internal error: shortcut without function!");
                return ERR;
diff --git a/src/proto.h b/src/proto.h
index fce5661..dd83bc6 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -54,6 +54,7 @@ extern WINDOW *edit;
 extern WINDOW *bottomwin;
 extern int editwinrows;
 extern int maxrows;
+extern int center_mode;
 
 extern filestruct *cutbuffer;
 extern filestruct *cutbottom;
-- 
2.8.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]