Fixed bug removing \n and added ability to use "ctrl"+"enter" for LB
Fixes #34
This commit is contained in:
parent
4959bc9634
commit
7cc4928826
@ -562,7 +562,7 @@ public final class ChatScene implements EventListener, Restorable {
|
|||||||
// KeyPressed will be called before the char has been added to the text, hence
|
// KeyPressed will be called before the char has been added to the text, hence
|
||||||
// this is needed for the first char
|
// this is needed for the first char
|
||||||
if (messageTextArea.getText().length() == 1 && e != null) checkPostConditions(e);
|
if (messageTextArea.getText().length() == 1 && e != null) checkPostConditions(e);
|
||||||
|
|
||||||
// This is needed for the messageTA context menu
|
// This is needed for the messageTA context menu
|
||||||
else if (e == null) checkPostConditions(false);
|
else if (e == null) checkPostConditions(false);
|
||||||
}
|
}
|
||||||
@ -585,14 +585,23 @@ public final class ChatScene implements EventListener, Restorable {
|
|||||||
*/
|
*/
|
||||||
@FXML
|
@FXML
|
||||||
private void checkPostConditions(KeyEvent e) {
|
private void checkPostConditions(KeyEvent e) {
|
||||||
final var messagePosted = settings.isEnterToSend() && e.getCode() == KeyCode.ENTER
|
final var enterPressed = e.getCode() == KeyCode.ENTER;
|
||||||
|| !settings.isEnterToSend() && e.getCode() == KeyCode.ENTER && e.isControlDown();
|
final var messagePosted = enterPressed ? settings.isEnterToSend() ? !e.isControlDown() : e.isControlDown() : false;
|
||||||
if (messagePosted) {
|
if (messagePosted) {
|
||||||
|
|
||||||
// Removing an inserted line break if added by pressing enter
|
// Removing an inserted line break if added by pressing enter
|
||||||
final var text = messageTextArea.getText();
|
final var text = messageTextArea.getText();
|
||||||
final var caretPosition = messageTextArea.getCaretPosition();
|
final var textPosition = messageTextArea.getCaretPosition() - 1;
|
||||||
if (text.charAt(caretPosition - 1) == '\n') messageTextArea.setText(new StringBuilder(text).deleteCharAt(caretPosition - 1).toString());
|
if (!e.isControlDown() && !text.isEmpty() && text.charAt(textPosition) == '\n')
|
||||||
|
messageTextArea.setText(new StringBuilder(text).deleteCharAt(textPosition).toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
// if control is pressed, the enter press is originally invalidated. Here it'll
|
||||||
|
// be inserted again
|
||||||
|
else if (enterPressed && e.isControlDown()) {
|
||||||
|
var caretPosition = messageTextArea.getCaretPosition();
|
||||||
|
messageTextArea.setText(new StringBuilder(messageTextArea.getText()).insert(caretPosition, '\n').toString());
|
||||||
|
messageTextArea.positionCaret(++caretPosition);
|
||||||
}
|
}
|
||||||
checkPostConditions(messagePosted);
|
checkPostConditions(messagePosted);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user