LibLine: Avoid returning reference to cached suggestion

This caused a dangling reference down the line, which lead to funny
things like the following:
    > cd Bui[tab]
    > cd Bui^@^@

By returning a direct reference to the suggestion in question, we can be
sure that the referenced object is alive until the next suggestion
cycle.
This commit is contained in:
Ali Mohammad Pur 2023-12-22 00:44:24 +03:30 committed by Andreas Kling
parent 64616d3997
commit db34ee357d
Notes: sideshowbarker 2024-07-17 22:55:25 +09:00

View File

@ -76,9 +76,10 @@ void SuggestionManager::previous()
CompletionSuggestion const& SuggestionManager::suggest()
{
m_last_shown_suggestion = m_suggestions[m_next_suggestion_index];
auto const& suggestion = m_suggestions[m_next_suggestion_index];
m_selected_suggestion_index = m_next_suggestion_index;
return m_last_shown_suggestion;
m_last_shown_suggestion = suggestion;
return suggestion;
}
void SuggestionManager::set_current_suggestion_initiation_index(size_t index)