Include the autosuggestion in history if it was truncated

https://github.com/fish-shell/fish-shell/issues/650
This commit is contained in:
ridiculousfish 2013-08-20 20:08:56 -07:00
parent 69c6b007aa
commit d6791a836b
3 changed files with 11 additions and 4 deletions

View file

@ -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));
}

View file

@ -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),

View file

@ -140,6 +140,9 @@ public:
/** 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 @@ public:
/** 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.