Skip to content

Commit

Permalink
dialogs/TextInputDialog: move history commit code to CommitHistory()
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Sep 23, 2024
1 parent 3601bff commit 3bc9545
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
38 changes: 22 additions & 16 deletions src/dialogs/TextInputDialog.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,34 @@ using std::string_view_literals::operator""sv;
/** max items stored in the history list */
static constexpr std::size_t wrln_max_history_length = 32;

inline void
TextInputDialog::CommitHistory() noexcept
{
if (history == nullptr)
return;

if (!value.empty()) {
/* update the current history entry */
*hcurrent = value;
} else {
/* the line was empty - remove the current history entry */
history->erase(hcurrent);
}

auto history_length = history->size();
while (history_length > wrln_max_history_length) {
history->pop_front();
--history_length;
}
}

inline void
TextInputDialog::SetReady() noexcept
{
assert(!ready);
ready = true;

/* update history */
if (history) {
if (!value.empty()) {
/* update the current history entry */
*hcurrent = value;
} else {
/* the line was empty - remove the current history entry */
history->erase(hcurrent);
}

auto history_length = history->size();
while (history_length > wrln_max_history_length) {
history->pop_front();
--history_length;
}
}
CommitHistory();

if (continuation)
continuation.resume();
Expand Down
1 change: 1 addition & 0 deletions src/dialogs/TextInputDialog.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ private:
return std::move(value);
}

void CommitHistory() noexcept;
void SetReady() noexcept;

/** returns the screen column where the cursor is located */
Expand Down

0 comments on commit 3bc9545

Please sign in to comment.