Skip to content
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

Closed
IMurdocI opened this issue Mar 31, 2015 · 11 comments
Closed

Spacebar scrolls the scrollpane #134

IMurdocI opened this issue Mar 31, 2015 · 11 comments

Comments

@IMurdocI
Copy link

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!

@TomasMikula
Copy link
Member

Hi! Does it also add a space to the editor or not?

@IMurdocI
Copy link
Author

hey,
Yes, space is also added to the Editor!

@TomasMikula
Copy link
Member

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();
    }
});

@IMurdocI
Copy link
Author

great, thank you very much for the help.
Should have thought of the event.consume myself.

@TomasMikula
Copy link
Member

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.

@TomasMikula TomasMikula reopened this Mar 31, 2015
@TomasMikula
Copy link
Member

I'm not sure whether that will work for characters like .,:;+-=_(){}[]\/?!@#$%^&*~, but should be useful anyway.

@IMurdocI
Copy link
Author

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)!

@TomasMikula
Copy link
Member

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 KEY_PRESSED handler on Z or any other character. CodeArea handles KEY_TYPED for Z, but not KEY_PRESSED for Z.

@TomasMikula
Copy link
Member

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.

@IMurdocI
Copy link
Author

okay, seems like a good start solution!

@TomasMikula
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants