From f2803283b8591ff36fe474b4502e0ef7a8b10c87 Mon Sep 17 00:00:00 2001 From: George Peden Date: Fri, 12 Sep 2025 11:26:39 -0700 Subject: [PATCH] Fix B-spline keyboard focus issue (#23859) (#23860) * Fix B-spline keyboard focus issue (#23859) - Restore keyboard focus after command restart in changeConstructionMethode() - Fixes M key mode switching and R toggle periodic functionality - Uses direct MDI view focus restoration instead of private ensureFocus() method Fixes issue where keyboard shortcuts stop working after first mode switch. * Address Copilot feedback: Add null check for activeDocument() - Use ternary operator for cleaner null safety - Prevents potential crash if activeDocument() returns null - More idiomatic C++ code style * Improve variable scope per @chennes feedback - Use if-with-initialization to scope doc and mdi variables - Variables now only exist where needed instead of leaking into function scope - More idiomatic C++ code style --- src/Mod/Sketcher/Gui/DrawSketchHandlerBSpline.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerBSpline.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerBSpline.h index f13bca80e9..918419574f 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerBSpline.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerBSpline.h @@ -747,6 +747,13 @@ private: tryAutoRecomputeIfNotSolve(sketchgui->getSketchObject()); Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Add Sketch B-Spline")); + // Restore keyboard focus after command restart + if (Gui::Document* doc = Gui::Application::Instance->activeDocument()) { + if (Gui::MDIView* mdi = doc->getActiveView()) { + mdi->setFocus(); + } + } + // Add the necessary alignment geometries and constraints for (size_t i = 0; i < geoIds.size(); ++i) { addGeometry(points[i], geoIds[i], i == 0);