[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: |
Sun, 11 Mar 2018 17:54:44 +0100 |
From: Benno Schulenberg <address@hidden>
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 back at the center.
---
src/global.c | 4 ++++
src/move.c | 15 +++++++++++++--
src/nano.c | 7 +++++++
src/proto.h | 2 ++
src/winio.c | 5 +++--
5 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/src/global.c b/src/global.c
index b86014c5..300cb586 100644
--- a/src/global.c
+++ b/src/global.c
@@ -111,6 +111,10 @@ WINDOW *bottomwin = NULL;
int editwinrows = 0;
/* How many rows does the edit window take up? */
+int placement_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. */
filestruct *cutbottom = NULL;
diff --git a/src/move.c b/src/move.c
index 2613fd20..d9dfc5aa 100644
--- a/src/move.c
+++ b/src/move.c
@@ -559,10 +559,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)
{
- adjust_viewport(CENTERING);
+ if (placement_mode == 0)
+ adjust_viewport(CENTERING);
+ else if (placement_mode == 1) {
+ /* Simulate the cursor being on the top row, then scroll there.
*/
+ openfile->current_y = 0;
+ adjust_viewport(STATIONARY);
+ } else {
+ /* Simulate the cursor being on the bottom row, then scroll
there. */
+ openfile->current_y = editwinrows - 1;
+ adjust_viewport(STATIONARY);
+ }
total_refresh();
}
#endif
diff --git a/src/nano.c b/src/nano.c
index ad959256..e07f7cd6 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -1702,6 +1702,8 @@ int do_input(bool allow_funcs)
puddle[depth] = '\0';
do_output(puddle, depth, FALSE);
+ placement_mode = -1;
+
/* Empty the input buffer. */
free(puddle);
puddle = NULL;
@@ -1748,6 +1750,11 @@ int do_input(bool allow_funcs)
#ifdef ENABLE_WRAPPING
filestruct *was_next = openfile->current->next;
#endif
+ if (shortcut->func == do_center)
+ placement_mode = (placement_mode + 1) % 3;
+ else
+ placement_mode = -1;
+
#ifndef NANO_TINY
filestruct *was_current = openfile->current;
size_t was_x = openfile->current_x;
diff --git a/src/proto.h b/src/proto.h
index 9b179427..fe617c09 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -96,6 +96,8 @@ extern WINDOW *edit;
extern WINDOW *bottomwin;
extern int editwinrows;
+extern int placement_mode;
+
extern filestruct *cutbuffer;
extern filestruct *cutbottom;
extern partition *filepart;
diff --git a/src/winio.c b/src/winio.c
index 9257fe79..34b966ed 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -3256,9 +3256,10 @@ void adjust_viewport(update_type manner)
if (manner == STATIONARY)
goal = openfile->current_y;
- else if (manner == CENTERING)
+ else if (manner == CENTERING) {
goal = editwinrows / 2;
- else if (!current_is_above_screen())
+// placement_mode = 0;
+ } else if (!current_is_above_screen())
goal = editwinrows - 1;
openfile->edittop = openfile->current;
--
2.16.2