aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/guiTable.cpp39
1 files changed, 30 insertions, 9 deletions
diff --git a/src/guiTable.cpp b/src/guiTable.cpp
index ed5b0d87b..b327782e2 100644
--- a/src/guiTable.cpp
+++ b/src/guiTable.cpp
@@ -560,14 +560,31 @@ void GUITable::setSelected(s32 index)
m_sel_column = 0;
m_sel_doubleclick = false;
- --index;
+ --index; // Switch from 1-based indexing to 0-based indexing
s32 rowcount = m_rows.size();
-
- if (index >= rowcount)
+ if (rowcount == 0) {
+ return;
+ } else if (index < 0) {
+ index = 0;
+ } else if (index >= rowcount) {
index = rowcount - 1;
- while (index >= 0 && m_rows[index].visible_index < 0)
- --index;
+ }
+
+ // If the selected row is not visible, open its ancestors to make it visible
+ if (m_rows[index].visible_index < 0) {
+ std::set<s32> opened_trees;
+ getOpenedTrees(opened_trees);
+ s32 indent = m_rows[index].indent;
+ for (s32 j = index - 1; j >= 0; --j) {
+ if (m_rows[j].indent < indent) {
+ opened_trees.insert(j);
+ indent = m_rows[j].indent;
+ }
+ }
+ setOpenedTrees(opened_trees);
+ }
+
if (index >= 0) {
m_selected = m_rows[index].visible_index;
assert(m_selected >= 0 && m_selected < (s32) m_visible_rows.size());
@@ -596,11 +613,11 @@ void GUITable::setDynamicData(const DynamicData &dyndata)
m_keynav_time = dyndata.keynav_time;
m_keynav_buffer = dyndata.keynav_buffer;
- m_scrollbar->setPos(dyndata.scrollpos);
-
setSelected(dyndata.selected);
m_sel_column = 0;
m_sel_doubleclick = false;
+
+ m_scrollbar->setPos(dyndata.scrollpos);
}
const c8* GUITable::getTypeName() const
@@ -1091,7 +1108,9 @@ void GUITable::getOpenedTrees(std::set<s32> &opened_trees) const
void GUITable::setOpenedTrees(const std::set<s32> &opened_trees)
{
- s32 old_selected = getSelected();
+ s32 old_selected = -1;
+ if (m_selected >= 0)
+ old_selected = m_visible_rows[m_selected];
std::vector<s32> parents;
std::vector<s32> closed_parents;
@@ -1143,7 +1162,9 @@ void GUITable::setOpenedTrees(const std::set<s32> &opened_trees)
updateScrollBar();
- setSelected(old_selected);
+ // m_selected must be updated since it is a visible row index
+ if (old_selected >= 0)
+ m_selected = m_rows[old_selected].visible_index;
}
void GUITable::openTree(s32 to_open)