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.
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; }
Created attachment 64674 [details] Suggested fix
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.
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.
http://hg.netbeans.org/main/rev/1c9438ecee00
Thank you very much! Works great now
If you can verify that your issue was resolved, set it's state to verified please. Thanks in advance.
sure, verified
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