Code Completion CTRL+RETURN

General Discussion on RSyntaxTextArea.

Moderator: robert

Code Completion CTRL+RETURN

Postby Georg Raffer » Fri Oct 12, 2012 6:14 am

Hallo,
I am using the RSyntaxTextArea + code completion. The application is used to execute HQL statements.
The code completion works fine. For executing statements I use an ActionListener which listens on CTRL+RETURN.

But when I press CTRL+RETURN the code completion always tries to complete the current text.
Example:
from KiCOHeader;

cursor is after Ki an I press CTRL+RETURN, code completion always changes the statement to KiPhysicalStockCOHeader.
But code completion is registered to CTRL+' ':

AutoCompletion ac = new AutoCompletion(provider);
ac.setTriggerKey(KeyStroke.getKeyStroke(' ', InputEvent.CTRL_DOWN_MASK));

Can anybody please explain how the auto completion for CTRL+RETURN can be disabled?

bye, Georg
Georg Raffer
 

Re: Code Completion CTRL+RETURN

Postby robert » Sat Oct 13, 2012 2:00 pm

Hi Georg,

Ctrl+Enter is mapped to the "dumb complete word action." This action scans the document backwards from the caret position, and "auto-completes" the word at the caret position with the most recent one starting with the same prefix. This is added in RTADefaultInputMap. To remove this functionality, you need to either remove the DumbCompleteWordAction from the InputMap/ActionMap, or replace it with your own action to execute the HQL statements (the latter is probably cleaner). i.e.

java code:

class ExecuteStatementsAction extends AbstractAction {
...
}

...

InputMap im = textArea.getInputMap();
ActionMap am = textArea.getActionMap();

am.remove(RTextAreaEditorKit.rtaDumbCompleteWordAction);
int ctrl = textArea.getToolkit().getMenuShortcutKeyMask();
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, ctrl), "executeStatements");
am.put("executeStatements", new ExecuteStatementsAction());
User avatar
robert
 
Posts: 797
Joined: Sat May 10, 2008 5:16 pm

Re: Code Completion CTRL+RETURN

Postby Georg Raffer » Mon Oct 15, 2012 6:44 am

Hi Robert,
Thank you the solution works perfectly well for me.

bye, Georg
Georg Raffer
 


Return to Open Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron