-
Notifications
You must be signed in to change notification settings - Fork 236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spacebar scrolls the scrollpane #134
Comments
Hi! Does it also add a space to the editor or not? |
hey, |
Thanks. Scroll by spacebar is probably the desired behavior of the ScrollPane. The problem probably is that the event is not consumed by the CodeArea. There are a two events fired when a character key is pressed: KEY_PRESSED and KEY_TYPED. CodeArea handles the KEY_TYPED event and inserts a space character, but does not handle the KEY_PRESSED event, so it propagates up and is handled by the ScrollPane as a command to scroll down. This is an interesting problem that questions the design of key handling in JavaFX. Luckily for you, there is a simple workaround: you can add an event handler to CodeArea that consumes the KEY_PRESSED event for space: codeArea.addEventHandler(KeyEvent.KEY_PRESSED, event -> {
if(event.getCode() == KeyCode.SPACE) {
event.consume();
}
}); |
great, thank you very much for the help. |
Seems like I can solve this in RichTextFX, by checking whether a KEY_PRESSED event isLetterKey(), isDigitKey() or isWhitespaceKey() and only consume it in that case, otherwise let it bubble up. I will leave this open so that I don't forget about it. |
I'm not sure whether that will work for characters like |
by just consuming the event only when spacebar is pressed (as you mentioned in your second post) everything works fine, all characters and whitespaces (space/tab)! |
Thanks for confirming. It is not a general solution, though, because the problem would re-appear for someone who puts a CodeArea as a child of a node that, for example, uses |
My proposed more general solution would work for letters (A-Z), digits (0-9) and whitespace characters, but not for other special characters as mentioned above. |
okay, seems like a good start solution! |
I asked about a general solution on the JavaFX mailing list, with no answer so far, so I proceeded with a fix the way I proposed above. |
Hello,
I'm using the the CodeEditor as an editabele object on Pane that is inside a scrollpane. (see it like a TextField in MS Word).
I have the issue, that when pressing the spacebar inside the CodeEditor, my Scrollpane scrolls down, without me adding any code that may change the vvalue of the scrollpane!
The text was updated successfully, but these errors were encountered: