Skip to content

Commit

Permalink
listen to skin tone changes, and test (#321)
Browse files Browse the repository at this point in the history
* listen to skin tone changes, and test

* fix test
  • Loading branch information
jperedadnr authored May 9, 2024
1 parent da373db commit 1a1ccd0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/
package com.gluonhq.richtextarea;

import com.gluonhq.emoji.EmojiSkinTone;
import com.gluonhq.richtextarea.model.Decoration;
import com.gluonhq.richtextarea.model.Document;
import com.gluonhq.richtextarea.model.ImageDecoration;
Expand Down Expand Up @@ -382,6 +383,7 @@ protected void invalidated() {
private final EventHandler<DragEvent> dndHandler = this::dndListener;

private final ChangeListener<Boolean> tableAllowedListener;
private final ChangeListener<EmojiSkinTone> skinToneChangeListener;

private final ResourceBundle resources;

Expand Down Expand Up @@ -597,6 +599,7 @@ protected RichTextAreaSkin(final RichTextArea control) {
};

tableAllowedListener = (obs, ov, nv) -> viewModel.setTableAllowed(nv);
skinToneChangeListener = (obs, ov, nv) -> refreshTextFlow();
caretChangeListener = (obs, ov, nv) -> viewModel.getParagraphWithCaret()
.ifPresent(paragraph -> Platform.runLater(paragraphListView::scrollIfNeeded));
internalCaretChangeListener = (obs, ov, nv) -> {
Expand Down Expand Up @@ -658,6 +661,7 @@ public void dispose() {
getSkinnable().widthProperty().removeListener(controlPrefWidthListener);
getSkinnable().focusedProperty().removeListener(focusListener);
getSkinnable().removeEventHandler(DragEvent.ANY, dndHandler);
getSkinnable().skinToneProperty().removeListener(skinToneChangeListener);
contextMenu.getItems().clear();
tableCellContextMenuItems = null;
tableContextMenuItems = null;
Expand Down Expand Up @@ -728,6 +732,7 @@ private void setup(Document document) {
getSkinnable().widthProperty().addListener(controlPrefWidthListener);
getSkinnable().focusedProperty().addListener(focusListener);
getSkinnable().addEventHandler(DragEvent.ANY, dndHandler);
getSkinnable().skinToneProperty().addListener(skinToneChangeListener);
refreshTextFlow();
requestLayout();
editableChangeListener(null); // sets up all related listeners
Expand Down
35 changes: 33 additions & 2 deletions rta/src/test/java/com/gluonhq/richtextarea/ui/RTATest.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@
import static javafx.scene.text.FontWeight.BOLD;
import static javafx.scene.text.FontWeight.NORMAL;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.testfx.api.FxAssert.verifyThat;
import static org.testfx.util.WaitForAsyncUtils.sleep;
import static org.testfx.util.WaitForAsyncUtils.waitForFxEvents;

@ExtendWith(ApplicationExtension.class)
Expand Down Expand Up @@ -365,7 +365,38 @@ public void emojiDemoTest(FxRobot robot) {
run(() -> richTextArea.getActionFactory().selectNone().execute(new ActionEvent()));
waitForFxEvents();

sleep(10, TimeUnit.SECONDS);
int noToneEmojis = 0;
int mediumDarkToneEmojis = 0;
for (int i = 0; i < 15; i++) {
ImageView imageView = robot.lookup(node -> node instanceof ImageView).nth(i).query();
Object emojiUnified = imageView.getProperties().get("emoji_unified");
assertNotNull(emojiUnified);
if ("1F471".equals(emojiUnified.toString())) {
noToneEmojis++;
}else if ("1F471-1F3FD".equals(emojiUnified.toString())) {
mediumDarkToneEmojis++;
}
}
assertEquals(1, noToneEmojis);
assertEquals(1, mediumDarkToneEmojis);

run(() -> richTextArea.setSkinTone(EmojiSkinTone.MEDIUM_SKIN_TONE));
waitForFxEvents();

noToneEmojis = 0;
mediumDarkToneEmojis = 0;
for (int i = 0; i < 15; i++) {
ImageView imageView = robot.lookup(node -> node instanceof ImageView).nth(i).query();
Object emojiUnified = imageView.getProperties().get("emoji_unified");
assertNotNull(emojiUnified);
if ("1F471".equals(emojiUnified.toString())) {
noToneEmojis++;
}else if ("1F471-1F3FD".equals(emojiUnified.toString())) {
mediumDarkToneEmojis++;
}
}
assertEquals(0, noToneEmojis);
assertEquals(2, mediumDarkToneEmojis);
}

private void run(Runnable runnable) {
Expand Down

0 comments on commit 1a1ccd0

Please sign in to comment.