Bug #1598

TabBar middle mouse tab close bug

Added by cbpporter cbpporter about 7 years ago. Updated about 7 years ago.

Status:ApprovedStart date:01/03/2017
Priority:NormalDue date:
Assignee:Miroslav Fidler% Done:

0%

Category:IDESpent time:-
Target version:-

Description

Using the middle mouse in TabCtrl closes a tab, as expected.

But, tab closing + CancelCloseis often used for prompt ("Are you sure you want to close the file?").

If the callbacks are used to prompt the user with a GUI, the mouse movements of the user will inadvertently change the highlight that TabCtrl thinks it has and the highlight will be different before the prompt and after.

Fix with comments detailing issue:

void TabBar::MiddleDown(Point p, dword keyflags)
{
    if (highlight >= 0)
    {
        Value v = tabs[highlight].key;
        ValueArray vv;
        vv.Add(v);
        // highlight has some value here
        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);
        }
    }
}

Without fix: can crash.

History

#1 Updated by Miroslav Fidler about 7 years ago

  • Status changed from New to Approved

Also available in: Atom PDF