This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 140127 - on right-click actions are created before cursor is moved in text component
Summary: on right-click actions are created before cursor is moved in text component
Status: VERIFIED FIXED
Alias: None
Product: editor
Classification: Unclassified
Component: Actions/Menu/Toolbar (show other bugs)
Version: 6.x
Hardware: All All
: P2 blocker (vote)
Assignee: issues@editor
URL:
Keywords: SIMPLEFIX
Depends on:
Blocks:
 
Reported: 2008-07-15 16:08 UTC by Vladimir Voskresensky
Modified: 2008-07-17 04:42 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Suggested fix (1.80 KB, patch)
2008-07-16 10:14 UTC, Jan Becicka
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Vladimir Voskresensky 2008-07-15 16:08:23 UTC
When user right click in editor => editor actions are created and isEnabled method is called.
The problem is that when action asks text component about it's cursor position => it is always old position and not the
one where right click occurred.
That fact very significantly affects usability of some actions which are enabled/disabled based on cursor position.

As test case you can create simple action for editor, put cursor in the beginning of document and right click at the end
of document.  then see the output of 

public boolean isEnabled() {
   final JTextComponent target = JTextComponent.getFocusedComponent();
   int offset = target.getSelectionStart();
   System.err.println("call offset: " + offset);
   return true;
}
Comment 1 Jan Becicka 2008-07-16 10:14:39 UTC
Created attachment 64674 [details]
Suggested fix
Comment 2 Jan Becicka 2008-07-16 10:16:53 UTC
The problem is, that BaseCaret listener is registered after EditorUI, so the menu is created before caret update. I have
a trivial fix, but I have no idea if the fix is safe. Needs to be reviewed.
Comment 3 Vitezslav Stejskal 2008-07-16 10:37:38 UTC
I think this fix will result in NPE from BaseCaret.install, which expects EditorUI to have already been installed to the
component. The initialization of editor panes is pretty clumsy and we should clean it up one day. As a quick fix for
this I think we could re-post the popup menu's creation in EditorUI.showPopupMenuForPopupTrigger to the AWT thread. This
way all the other mouse listeners will have a chance to perform their tasks before the menu is shown. Thanks for the
patch anyway.
Comment 4 Vitezslav Stejskal 2008-07-16 12:24:03 UTC
http://hg.netbeans.org/main/rev/1c9438ecee00
Comment 5 Vladimir Voskresensky 2008-07-16 14:37:24 UTC
Thank you very much! Works great now
Comment 6 Petr Cyhelsky 2008-07-16 14:47:44 UTC
If you can verify that your issue was resolved, set it's state to verified please. Thanks in advance.
Comment 7 Vladimir Voskresensky 2008-07-16 14:50:01 UTC
sure, verified 
Comment 8 Quality Engineering 2008-07-17 04:42:30 UTC
Integrated into 'main-golden', available in NB_Trunk_Production #324 build
Changeset: http://hg.netbeans.org/main/rev/1c9438ecee00
User: Vita Stejskal <vstejskal@netbeans.org>
Log: #140127 (fixed): postponing popup menu creation