screen: concentrate the setting of placewewant

Instead of saving the current value of placewewant, then setting the
new value, and then passing the old value to edit_redraw() in seven
different places, just let edit_redraw() do this saving and setting.

In the bargain placewewant is now only recalculated when it matters
-- when allow_update is TRUE -- and not when it's superfluous.
This commit is contained in:
Benno Schulenberg 2016-04-10 21:16:19 +02:00
parent dbe39901b2
commit aa1ae0a144
6 changed files with 18 additions and 31 deletions

View File

@ -146,7 +146,6 @@ void do_page_down(void)
void do_para_begin(bool allow_update)
{
filestruct *current_save = openfile->current;
const size_t pww_save = openfile->placewewant;
if (openfile->current != openfile->fileage) {
do {
@ -156,10 +155,9 @@ void do_para_begin(bool allow_update)
}
openfile->current_x = 0;
openfile->placewewant = 0;
if (allow_update)
edit_redraw(current_save, pww_save);
edit_redraw(current_save);
}
/* Move up to the beginning of the last beginning-of-paragraph line
@ -178,7 +176,6 @@ void do_para_begin_void(void)
void do_para_end(bool allow_update)
{
filestruct *const current_save = openfile->current;
const size_t pww_save = openfile->placewewant;
while (openfile->current != openfile->filebot &&
!inpar(openfile->current))
@ -194,14 +191,11 @@ void do_para_end(bool allow_update)
if (openfile->current != openfile->filebot) {
openfile->current = openfile->current->next;
openfile->current_x = 0;
openfile->placewewant = 0;
} else {
} else
openfile->current_x = strlen(openfile->current->data);
openfile->placewewant = xplustabs();
}
if (allow_update)
edit_redraw(current_save, pww_save);
edit_redraw(current_save);
}
/* Move down to the beginning of the last line of the current paragraph.
@ -219,7 +213,6 @@ void do_para_end_void(void)
* screen afterwards. */
void do_prev_word(bool allow_punct, bool allow_update)
{
size_t pww_save = openfile->placewewant;
filestruct *current_save = openfile->current;
bool seen_a_word = FALSE, step_forward = FALSE;
@ -256,11 +249,10 @@ void do_prev_word(bool allow_punct, bool allow_update)
/* Move one character forward again to sit on the start of the word. */
openfile->current_x = move_mbright(openfile->current->data,
openfile->current_x);
openfile->placewewant = xplustabs();
/* If allow_update is TRUE, update the screen. */
if (allow_update)
edit_redraw(current_save, pww_save);
edit_redraw(current_save);
}
/* Move to the previous word in the file, treating punctuation as part of a
@ -276,7 +268,6 @@ void do_prev_word_void(void)
* otherwise. */
bool do_next_word(bool allow_punct, bool allow_update)
{
size_t pww_save = openfile->placewewant;
filestruct *current_save = openfile->current;
bool started_on_word = is_word_mbchar(openfile->current->data +
openfile->current_x, allow_punct);
@ -309,11 +300,9 @@ bool do_next_word(bool allow_punct, bool allow_update)
break;
}
openfile->placewewant = xplustabs();
/* If allow_update is TRUE, update the screen. */
if (allow_update)
edit_redraw(current_save, pww_save);
edit_redraw(current_save);
/* Return whether we started on a word. */
return started_on_word;

View File

@ -1746,7 +1746,6 @@ int do_mouse(void)
#ifndef NANO_TINY
size_t current_x_save = openfile->current_x;
#endif
size_t pww_save = openfile->placewewant;
sameline = (mouse_y == openfile->current_y);
@ -1798,8 +1797,6 @@ int do_mouse(void)
get_page_start(xplustabs()) + mouse_x);
}
openfile->placewewant = xplustabs();
#ifndef NANO_TINY
/* Clicking where the cursor is toggles the mark, as does
* clicking beyond the line length with the cursor at the end of
@ -1811,7 +1808,7 @@ int do_mouse(void)
/* The cursor moved; clean the cutbuffer on the next cut. */
cutbuffer_reset();
edit_redraw(current_save, pww_save);
edit_redraw(current_save);
}
/* No more handling is needed. */

View File

@ -792,7 +792,7 @@ void edit_draw(filestruct *fileptr, const char *converted, int
int update_line(filestruct *fileptr, size_t index);
bool need_screen_update(size_t pww_save);
void edit_scroll(scroll_dir direction, ssize_t nlines);
void edit_redraw(filestruct *old_current, size_t pww_save);
void edit_redraw(filestruct *old_current);
void edit_refresh(void);
void edit_update(update_type location);
void total_redraw(void);

View File

@ -482,7 +482,6 @@ void go_looking(void)
{
filestruct *was_current = openfile->current;
size_t was_current_x = openfile->current_x;
size_t was_pww = openfile->placewewant;
int didfind;
findnextstr_wrap_reset();
@ -498,8 +497,7 @@ void go_looking(void)
openfile->current_x == was_current_x)
statusbar(_("This is the only occurrence"));
openfile->placewewant = xplustabs();
edit_redraw(was_current, was_pww);
edit_redraw(was_current);
search_replace_abort();
}
@ -1113,9 +1111,7 @@ void do_find_bracket(void)
/* If count is zero, we've found a matching bracket. Update
* the screen and get out. */
if (count == 0) {
size_t pww_save = openfile->placewewant;
openfile->placewewant = xplustabs();
edit_redraw(current_save, pww_save);
edit_redraw(current_save);
break;
}
} else {

View File

@ -1950,7 +1950,6 @@ void do_justify(bool full_justify)
filestruct *edittop_save = openfile->edittop;
filestruct *current_save = openfile->current;
size_t current_x_save = openfile->current_x;
size_t pww_save = openfile->placewewant;
size_t totsize_save = openfile->totsize;
#ifndef NANO_TINY
filestruct *mark_begin_save = openfile->mark_begin;
@ -2295,7 +2294,6 @@ void do_justify(bool full_justify)
openfile->edittop = edittop_save;
openfile->current = current_save;
openfile->current_x = current_x_save;
openfile->placewewant = pww_save;
openfile->totsize = totsize_save;
#ifndef NANO_TINY
if (openfile->mark_set) {
@ -2316,6 +2314,9 @@ void do_justify(bool full_justify)
/* Put the keystroke back into the queue. */
unget_kbinput(kbinput, meta_key, func_key);
/* Set the desired screen column (always zero, except at EOF). */
openfile->placewewant = xplustabs();
#ifndef NANO_TINY
/* Throw away the entire undo stack, to prevent a crash when
* the user tries to undo something in the justified text. */

View File

@ -2958,8 +2958,12 @@ void edit_scroll(scroll_dir direction, ssize_t nlines)
/* Update any lines between old_current and current that need to be
* updated. Use this if we've moved without changing any text. */
void edit_redraw(filestruct *old_current, size_t pww_save)
void edit_redraw(filestruct *old_current)
{
size_t was_pww = openfile->placewewant;
openfile->placewewant = xplustabs();
/* If the current line is offscreen, scroll until it's onscreen. */
if (openfile->current->lineno >= openfile->edittop->lineno + maxrows ||
openfile->current->lineno < openfile->edittop->lineno)
@ -2980,7 +2984,7 @@ void edit_redraw(filestruct *old_current, size_t pww_save)
#endif /* !NANO_TINY */
/* Update old_current and current if we've changed page. */
if (need_screen_update(0) || need_screen_update(pww_save)) {
if (need_screen_update(0) || need_screen_update(was_pww)) {
update_line(old_current, 0);
update_line(openfile->current, openfile->current_x);
}