From 3b7bfc84155dbd7c727122ecec340f384bdf355b Mon Sep 17 00:00:00 2001 From: Paul Kulchenko Date: Sun, 24 Jan 2016 17:51:27 -0800 Subject: [PATCH] Fixed setting editor focus when switching from commandbar on OSX (fixes #577). --- src/editor/commands.lua | 11 ++++++++++- src/editor/editor.lua | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/editor/commands.lua b/src/editor/commands.lua index 8695659694..81ac45cdc6 100644 --- a/src/editor/commands.lua +++ b/src/editor/commands.lua @@ -950,7 +950,16 @@ ide.editorApp:Connect(wx.wxEVT_SET_FOCUS, function(event) if ide.infocus and (class == 'wxAuiToolBar' or class == 'wxFrame') then -- check if the window is shown before returning focus to it, -- as it may lead to a recursion in event handlers on OSX (wxwidgets 2.9.5). - pcall(function() if ide:IsWindowShown(ide.infocus) then ide.infocus:SetFocus() end end) + pcall(function() + if ide:IsWindowShown(ide.infocus) then + ide.infocus:SetFocus() + -- if switching to the editor, then also call SetSTCFocus, + -- otherwise the cursor is not shown in the editor on OSX. + if ide.infocus:GetClassInfo():GetClassName() == "wxStyledTextCtrl" then + ide.infocus:DynamicCast("wxStyledTextCtrl"):SetSTCFocus(true) + end + end + end) return end diff --git a/src/editor/editor.lua b/src/editor/editor.lua index 3b42c23eaf..6d235d34aa 100644 --- a/src/editor/editor.lua +++ b/src/editor/editor.lua @@ -172,6 +172,10 @@ function SetEditorSelection(selection) if editor then editor:SetFocus() editor:SetSTCFocus(true) + -- when the active editor is changed while the focus is away from the application + -- (as happens on OSX when the editor is selected from the command bar) + -- the focus stays on wxAuiToolBar component, so need to explicitly switch it. + if ide.osname == "Macintosh" and ide.infocus then ide.infocus = editor end local id = editor:GetId() FileTreeMarkSelected(openDocuments[id] and openDocuments[id].filePath or '')