Skip to content

Commit

Permalink
editor: Restore original cursor position after updates.
Browse files Browse the repository at this point in the history
Fix an occasional annoyance where the cursor would get
moved as a byproduct of updating another window, while
the cursor is active, leaving it on the other window
instead of in the original position. To fix this, simply
mark the original window as needing an update so that the
cursor is restored to the original position.
  • Loading branch information
InterLinked1 committed Apr 27, 2024
1 parent dca526e commit c74e6bb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions editor.c
Original file line number Diff line number Diff line change
Expand Up @@ -1782,6 +1782,8 @@ static int __editor(struct client *client, struct pollfd *pfds, uint32_t uid, st
wnoutrefresh(window);

curs_set(2); /* Show cursor in editor, extra visible */
client->cursor = 1;
client->cur_win = window;
doupdate();

for (;;) {
Expand Down Expand Up @@ -1833,9 +1835,11 @@ static int __editor(struct client *client, struct pollfd *pfds, uint32_t uid, st
goto redraw;
case KEY_ESCAPE:
curs_set(0);
client->cursor = 0;
SUB_MENU_PRE;
res = c = show_help_menu(client, pfds, HELP_EDITOR);
curs_set(2);
client->cursor = 1;
SUB_MENU_POST;
/* Nothing has happened to the window,
* so doupdate() on its own won't redraw it by default,
Expand Down Expand Up @@ -2196,12 +2200,14 @@ static int __editor(struct client *client, struct pollfd *pfds, uint32_t uid, st
}

done:
client->cur_win = NULL;
unpost_form(form);
free_form(form);
for (i = 0; i < NUM_FIELDS; i++) {
free_field(fields[i]);
}
delwin(window);
curs_set(0);
client->cursor = 0;
return res;
}
10 changes: 10 additions & 0 deletions evergreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ void client_set_status_nout(struct client *client, const char *s)
/* Write message to status bar (footer) */
mvwaddstr(client->win_footer, 0, STATUS_BAR_START_COL, s);
wnoutrefresh(client->win_footer);
if (client->cursor) {
/* Restore original cursor position,
* simply by updating whatever window the cursor was on before we moved it to update the status bar.
* The next call to doupdate() will make sure the cursor is restored,
* rather than lingering after the status text until the next screen update. */
if (client->cur_win) {
wnoutrefresh(client->cur_win);
}
}
}

static void client_clear_status(struct client *client)
Expand Down Expand Up @@ -288,6 +297,7 @@ static int client_term_init(struct client *client)
noecho();
keypad(stdscr, TRUE); /* Enable keypad for function key interpretation (escape sequences) */
curs_set(0); /* Disable cursor */
client->cursor = 0;
start_color(); /* Enable colors */

/* Since menus are by default white on black,
Expand Down
3 changes: 3 additions & 0 deletions evergreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
#include <time.h> /* struct tm */

#include <ncurses.h>
#include <form.h>
#include <menu.h>

#define KEY_ESCAPE 27
Expand Down Expand Up @@ -284,6 +285,7 @@ struct client {
WINDOW *win_folders; /*!< Folders pane */
WINDOW *win_main; /*!< Message pane */
WINDOW *win_footer; /*!< Footer */
WINDOW *cur_win; /*!< Current window */
/* Mailbox data and state */
struct mailbox *mailboxes; /*!< Mailboxes array */
int num_mailboxes; /*!< Number of mailboxes */
Expand All @@ -292,6 +294,7 @@ struct client {
unsigned int focus:1; /*!< Message pane focused (as opposed to folder pane) */
unsigned int idling:1; /*!< Currently IMAP idling */
unsigned int mouse_enable:1; /*!< Mouse currently enabled? */
unsigned int cursor:1; /*!< Cursor currently active? */
int menu_depth; /*!< Current depth of menus/submenus */
int resize_depth; /*!< Current resize depth */
time_t idlestart; /*!< Time IDLE started */
Expand Down

0 comments on commit c74e6bb

Please sign in to comment.