fix(history): keep the open detail row across paging and filtering
The inline detail panel was tracked by the filtered list index. The display list is rebuilt and re-sorted on every data change, sort switch or filter edit, so a stored index pointed at a different transaction after the rebuild, and a page reset was triggered by any change in the row count, bouncing the view back to page 1. - The open row is now tracked by a stable content key (txid, display type, address and the amount's exact bits) so the right row stays open across rebuilds. - The page resets and the open row collapses only when a filter input changes (type, sort or the full search text). A new or removed row is data and now just clamps the current page. - The open row is also cleared on page navigation and when the list empties, so a wallet switch does not resurrect an old expansion. Adds pure helpers rowKey/filterInputsChanged to transactions_tab_helpers.h. Tests: rowKey distinguishes each field and separates +0.0 from -0.0, and filterInputsChanged latches each input change but not the first frame. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -177,12 +177,13 @@ void RenderTransactionsTab(App* app)
|
||||
std::string txLoadingText = app->transactionRefreshProgressText();
|
||||
bool txLoading = !txLoadingText.empty();
|
||||
|
||||
// Expanded row index for inline detail
|
||||
static int s_expanded_row = -1;
|
||||
// Open inline detail, keyed by row identity (history::rowKey), NOT by list index: the display list is rebuilt
|
||||
// and re-sorted on every change, so an index would land on a different transaction. Empty = none open.
|
||||
static std::string s_expanded_key;
|
||||
|
||||
// Pagination state
|
||||
static int s_current_page = 0;
|
||||
static int s_prev_filter_hash = 0; // detect filter changes to reset page
|
||||
static history::FilterInputs s_prev_filter; // detect filter-input changes to reset page
|
||||
|
||||
// ================================================================
|
||||
// Summary Cards — Received | Sent | Mined
|
||||
@@ -550,12 +551,13 @@ void RenderTransactionsTab(App* app)
|
||||
int perPage = std::max(10, (int)schema::UI().drawElement("tabs.transactions", "rows-per-page").sizeOr(50.0f));
|
||||
int totalPages = std::max(1, (filtered_count + perPage - 1) / perPage);
|
||||
|
||||
// Reset page when filters change
|
||||
int filterHash = type_filter * 1000003 + s_sort_mode * 7919 + filtered_count * 31 + static_cast<int>(search_str.size());
|
||||
if (filterHash != s_prev_filter_hash) {
|
||||
// Reset page (and collapse the open row) only when a filter INPUT changes (type, sort, or the search text).
|
||||
// The row count is data: a new/removed row just clamps the page below instead of bouncing to page 1.
|
||||
if (history::filterInputsChanged(s_prev_filter, type_filter, s_sort_mode, search_str)) {
|
||||
s_current_page = 0;
|
||||
s_prev_filter_hash = filterHash;
|
||||
s_expanded_key.clear();
|
||||
}
|
||||
if (filtered_count == 0) s_expanded_key.clear(); // wallet switch / emptied list: don't resurrect an old expansion
|
||||
if (s_current_page >= totalPages) s_current_page = totalPages - 1;
|
||||
if (s_current_page < 0) s_current_page = 0;
|
||||
|
||||
@@ -582,7 +584,7 @@ void RenderTransactionsTab(App* app)
|
||||
ImGui::BeginDisabled(s_current_page == 0);
|
||||
if (TactileButton(ICON_MD_FIRST_PAGE "##txFirst", ImVec2(btnW, btnW), Type().iconSmall())) {
|
||||
s_current_page = 0;
|
||||
s_expanded_row = -1;
|
||||
s_expanded_key.clear();
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
|
||||
@@ -592,7 +594,7 @@ void RenderTransactionsTab(App* app)
|
||||
ImGui::BeginDisabled(s_current_page == 0);
|
||||
if (TactileButton(ICON_MD_CHEVRON_LEFT "##txPrev", ImVec2(btnW, btnW), Type().iconSmall())) {
|
||||
s_current_page--;
|
||||
s_expanded_row = -1;
|
||||
s_expanded_key.clear();
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
|
||||
@@ -619,7 +621,7 @@ void RenderTransactionsTab(App* app)
|
||||
ImGui::BeginDisabled(s_current_page >= totalPages - 1);
|
||||
if (TactileButton(ICON_MD_CHEVRON_RIGHT "##txNext", ImVec2(btnW, btnW), Type().iconSmall())) {
|
||||
s_current_page++;
|
||||
s_expanded_row = -1;
|
||||
s_expanded_key.clear();
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
|
||||
@@ -629,7 +631,7 @@ void RenderTransactionsTab(App* app)
|
||||
ImGui::BeginDisabled(s_current_page >= totalPages - 1);
|
||||
if (TactileButton(ICON_MD_LAST_PAGE "##txLast", ImVec2(btnW, btnW), Type().iconSmall())) {
|
||||
s_current_page = totalPages - 1;
|
||||
s_expanded_row = -1;
|
||||
s_expanded_key.clear();
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
}
|
||||
@@ -686,7 +688,8 @@ void RenderTransactionsTab(App* app)
|
||||
for (int fi = pageStart; fi < pageEnd; fi++) {
|
||||
size_t i = filtered_indices[fi];
|
||||
const auto& tx = display_txns[i];
|
||||
bool is_expanded = (s_expanded_row == static_cast<int>(i));
|
||||
const std::string rk = history::rowKey(tx.txid, tx.display_type, tx.address, tx.amount); // <= perPage rows/frame
|
||||
bool is_expanded = !s_expanded_key.empty() && s_expanded_key == rk;
|
||||
|
||||
ImGui::PushID(static_cast<int>(i));
|
||||
ImVec2 rowPos = ImGui::GetCursorScreenPos();
|
||||
@@ -832,7 +835,7 @@ void RenderTransactionsTab(App* app)
|
||||
// Click to expand/collapse + invisible button for interaction
|
||||
ImGui::InvisibleButton("##txRow", ImVec2(innerW, rowH));
|
||||
if (ImGui::IsItemClicked(0)) {
|
||||
s_expanded_row = is_expanded ? -1 : static_cast<int>(i);
|
||||
if (is_expanded) s_expanded_key.clear(); else s_expanded_key = rk;
|
||||
}
|
||||
|
||||
// Tooltip
|
||||
|
||||
Reference in New Issue
Block a user