From 7448e7825f5602b35ec0d6a11cb3195a939608b2 Mon Sep 17 00:00:00 2001 From: Per Bothner Date: Thu, 6 Jun 2019 21:18:09 -0700 Subject: [PATCH] Avoid code duplication relating to screen clearning in s_update. --- src/screen.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/screen.cpp b/src/screen.cpp index e42968f7c..62a863c5d 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -699,17 +699,21 @@ static void s_update(screen_t *scr, const wcstring &left_prompt, const wcstring } // Now actually output stuff. - for (; j < o_line.size(); j++) { + for (; ; j++) { + bool done = j >= o_line.size(); + // Clear the screen if we have not done so yet. // If we are about to output into the last column, clear the screen first. If we clear // the screen after we output into the last column, it can erase the last character due // to the sticky right cursor. If we clear the screen too early, we can defeat soft // wrapping. - if (j + 1 == (size_t)screen_width && should_clear_screen_this_line && - !has_cleared_screen) { + if (should_clear_screen_this_line && !has_cleared_screen + && (done || j + 1 == (size_t)screen_width)) { s_move(scr, current_width, (int)i); s_write_mbs(scr, clr_eos); has_cleared_screen = true; } + if (done) + break; perform_any_impending_soft_wrap(scr, current_width, (int)i); s_move(scr, current_width, (int)i); @@ -719,13 +723,6 @@ static void s_update(screen_t *scr, const wcstring &left_prompt, const wcstring current_width += width; } - // Clear the screen if we have not done so yet. - if (should_clear_screen_this_line && !has_cleared_screen) { - s_move(scr, current_width, (int)i); - s_write_mbs(scr, clr_eos); - has_cleared_screen = true; - } - bool clear_remainder = false; // Clear the remainder of the line if we need to clear and if we didn't write to the end of // the line. If we did write to the end of the line, the "sticky right edge" (as part of