From ee15b9989bb6d129fee1d12c18c65f8d581fa62b Mon Sep 17 00:00:00 2001 From: cxl Date: Wed, 25 Jan 2017 10:22:37 +0000 Subject: [PATCH] TabBar: TabBar::MiddleDown fix (thanks cbpporter) git-svn-id: svn://ultimatepp.org/upp/trunk@10753 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/TabBar/TabBar.cpp | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/uppsrc/TabBar/TabBar.cpp b/uppsrc/TabBar/TabBar.cpp index a72a63f57..79975177c 100644 --- a/uppsrc/TabBar/TabBar.cpp +++ b/uppsrc/TabBar/TabBar.cpp @@ -2133,21 +2133,23 @@ void TabBar::RightDown(Point p, dword keyflags) void TabBar::MiddleDown(Point p, dword keyflags) { - if (highlight >= 0) - { - Value v = tabs[highlight].key; - ValueArray vv; - vv.Add(v); - if (!CancelClose(v) && ! CancelCloseSome(vv)) { - Value v = tabs[highlight].key; - // 2014/03/06 - FIRST the callbacks, THEN remove the tab - // otherwise keys in WhenCloseSome() are invalid - WhenClose(v); - WhenCloseSome(vv); - TabClosed(v); - Close(highlight); - } - } + if (highlight >= 0) + { + Value v = tabs[highlight].key; + ValueArray vv; + vv.Add(v); + int highlightBack = highlight; + if (!CancelClose(v) && ! CancelCloseSome(vv)) { + // highlight can be changed by the prompt. When reading "v", it can be invalid. I use the value from before the prompt to fix it + Value v = tabs[highlightBack].key; + // 2014/03/06 - FIRST the callbacks, THEN remove the tab + // otherwise keys in WhenCloseSome() are invalid + WhenClose(v); + WhenCloseSome(vv); + TabClosed(v); + Close(highlightBack); + } + } } void TabBar::MiddleUp(Point p, dword keyflags)