1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 12:57:35 +00:00

LibGUI: Don't destroy columns after selecting already opened one

This commit is contained in:
Karol Kosek 2022-12-28 01:58:05 +01:00 committed by Andreas Kling
parent e673fc4183
commit 7e52daa542

View file

@ -313,8 +313,14 @@ void ColumnsView::mousedown_event(MouseEvent& event)
auto index = index_at_event_position_in_column(position, *column); auto index = index_at_event_position_in_column(position, *column);
if (index.is_valid() && !(event.modifiers() & Mod_Ctrl)) { if (index.is_valid() && !(event.modifiers() & Mod_Ctrl)) {
if (model()->row_count(index)) if (model()->row_count(index)) {
push_column(index); auto is_index_already_open = m_columns.first_matching([&](auto& column) { return column.parent_index == index; }).has_value();
if (is_index_already_open) {
set_cursor(index, SelectionUpdate::Set);
} else {
push_column(index);
}
}
return; return;
} }
@ -405,7 +411,14 @@ void ColumnsView::move_cursor(CursorMovement movement, SelectionUpdate selection
case CursorMovement::Left: case CursorMovement::Left:
new_index = cursor_parent; new_index = cursor_parent;
break; break;
case CursorMovement::Right: case CursorMovement::Right: {
// Don't reset columns if one already exists.
auto maybe_column = m_columns.first_matching([&](auto& column) { return model.parent_index(column.parent_index) == cursor_index(); });
if (maybe_column.has_value()) {
new_index = maybe_column->parent_index;
break;
}
new_index = model.index(0, m_model_column, cursor_index()); new_index = model.index(0, m_model_column, cursor_index());
if (model.is_within_range(new_index)) { if (model.is_within_range(new_index)) {
if (model.is_within_range(cursor_index())) if (model.is_within_range(cursor_index()))
@ -413,6 +426,7 @@ void ColumnsView::move_cursor(CursorMovement movement, SelectionUpdate selection
update(); update();
} }
break; break;
}
default: default:
break; break;
} }