From d6791a836b887d8de79af6a2b2b2385d5ebc27b3 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Tue, 20 Aug 2013 20:08:56 -0700 Subject: [PATCH] Include the autosuggestion in history if it was truncated https://github.com/fish-shell/fish-shell/issues/650 --- reader.cpp | 4 ++-- screen.cpp | 6 +++++- screen.h | 5 ++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/reader.cpp b/reader.cpp index 907a6aab2..96d7bc44d 100644 --- a/reader.cpp +++ b/reader.cpp @@ -3517,9 +3517,9 @@ const wchar_t *reader_readline(void) data->search_buff.append(data->command_line); data->history_search = history_search_t(*data->history, data->search_buff, HISTORY_SEARCH_TYPE_CONTAINS); - /* Skip the autosuggestion as history */ + /* Skip the autosuggestion as history unless it was truncated */ const wcstring &suggest = data->autosuggestion; - if (! suggest.empty()) + if (! suggest.empty() && ! data->screen.autosuggestion_is_truncated) { data->history_search.skip_matches(wcstring_list_t(&suggest, 1 + &suggest)); } diff --git a/screen.cpp b/screen.cpp index 9cae7d360..8c8438346 100644 --- a/screen.cpp +++ b/screen.cpp @@ -1035,7 +1035,7 @@ struct screen_layout_t wcstring autosuggestion; /* Whether the prompts get their own line or not */ - bool prompts_get_own_line; + bool prompts_get_own_line; }; /* Given a vector whose indexes are offsets and whose values are the widths of the string if truncated at that offset, return the offset that fits in the given width. Returns width_by_offset.size() - 1 if they all fit. The first value in width_by_offset is assumed to be 0. */ @@ -1245,6 +1245,9 @@ void s_write(screen_t *s, /* Compute a layout */ const screen_layout_t layout = compute_layout(s, screen_width, left_prompt, right_prompt, explicit_command_line, autosuggestion, indent); + /* Determine whether, if we have an autosuggestion, it was truncated */ + s->autosuggestion_is_truncated = ! autosuggestion.empty() && autosuggestion != layout.autosuggestion; + /* Clear the desired screen */ s->desired.resize(0); s->desired.cursor.x = s->desired.cursor.y = 0; @@ -1402,6 +1405,7 @@ screen_t::screen_t() : last_right_prompt_width(), actual_width(SCREEN_WIDTH_UNINITIALIZED), soft_wrap_location(INVALID_LOCATION), + autosuggestion_is_truncated(false), need_clear_lines(false), need_clear_screen(false), actual_lines_before_reset(0), diff --git a/screen.h b/screen.h index 1dcb34bd7..0307fdd7d 100644 --- a/screen.h +++ b/screen.h @@ -140,6 +140,9 @@ class screen_t /** If we support soft wrapping, we can output to this location without any cursor motion. */ screen_data_t::cursor_t soft_wrap_location; + + /** Whether the last-drawn autosuggestion (if any) is truncated, or hidden entirely */ + bool autosuggestion_is_truncated; /** This flag is set to true when there is reason to suspect that @@ -155,7 +158,7 @@ class screen_t /** If we need to clear, this is how many lines the actual screen had, before we reset it. This is used when resizing the window larger: if the cursor jumps to the line above, we need to remember to clear the subsequent lines. */ size_t actual_lines_before_reset; - + /** These status buffers are used to check if any output has occurred other than from fish's main loop, in which case we need to redraw.