From 39298f8d8fe0637461ea415dd688eb6dc6bd9c5f Mon Sep 17 00:00:00 2001 From: Luke Street Date: Thu, 30 Apr 2026 22:31:24 -0600 Subject: [PATCH] Preserve focused element on pop --- src/dusk/ui/document.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/dusk/ui/document.cpp b/src/dusk/ui/document.cpp index b3eefc95ad..a27a111e31 100644 --- a/src/dusk/ui/document.cpp +++ b/src/dusk/ui/document.cpp @@ -35,8 +35,13 @@ Document::~Document() { void Document::show() { if (mDocument != nullptr) { - mDocument->Show(); - focus(); + // Attempt to preserve the previously focused element + mDocument->Show(Rml::ModalFlag::None, Rml::FocusFlag::Keep); + // If nothing is focused, let the document decide the initial focus + auto* leaf = mDocument->GetFocusLeafNode(); + if (leaf == nullptr || leaf == mDocument) { + focus(); + } } }