8000 normalize pieces with new decoration by abhinayagarwal · Pull Request #47 · gluonhq/rich-text-area · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

normalize pieces with new decoration #47

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

Merged
merged 1 commit into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/com/gluonhq/richtext/model/Piece.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public TextDecoration getDecoration() {
}

Piece copy(int newStart, int newLength) {
return copy(newStart, newLength, decoration);
return new Piece(source, bufferType, newStart, newLength, decoration);
}

Piece copy(int newStart, int newLength, TextDecoration textDecoration) {
Expand Down
46 changes: 46 additions & 0 deletions src/test/java/com/gluonhq/richtext/model/PieceTableTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,28 @@ public void sameBlockDecorateWeightAndSize() {
);
}

@Test
@DisplayName("Same block multiple decoration across pieces")
public void sameBlockMultiDecorateSpanningMultiplePieces() {
PieceTable pt = new PieceTable(originalText + " One Two Three");
pt.decorate(14, 27, TextDecoration.builder().fontWeight(FontWeight.BOLD).build());
pt.decorate(18, 21, TextDecoration.builder().fontPosture(FontPosture.ITALIC).build());
Assertions.assertEquals("Original Text One Two Three", pt.getText());
Assertions.assertTrue(pt.pieces.stream()
.filter(piece -> piece.getText().equals("One "))
.anyMatch(piece -> piece.getDecoration().getFontWeight() == FontWeight.BOLD)
);
Assertions.assertTrue(pt.pieces.stream()
.filter(piece -> piece.getText().equals("Two"))
.anyMatch(piece -> piece.getDecoration().getFontWeight() == FontWeight.BOLD &&
piece.getDecoration().getFontPosture() == FontPosture.ITALIC)
);
Assertions.assertTrue(pt.pieces.stream()
.filter(piece -> piece.getText().equals(" Three"))
.anyMatch(piece -> piece.getDecoration().getFontWeight() == FontWeight.BOLD)
);
}

@Test
@DisplayName("Multi block decorate")
public void multiBlockDecorate() {
Expand Down Expand Up @@ -367,6 +389,30 @@ public void multiBlockDecorateSpanningMultiplePieces() {
);
}

@Test
@DisplayName("Multi block multiple decoration across pieces")
public void multiBlockMultiDecorateSpanningMultiplePieces() {
PieceTable pt = new PieceTable(originalText);
String insert = "Bigger ";
pt.insert(insert, 9); // 'Original Bigger Text'
pt.decorate(6, 18, TextDecoration.builder().fontWeight(FontWeight.BOLD).build());
pt.decorate(9, 15, TextDecoration.builder().fontPosture(FontPosture.ITALIC).build());
Assertions.assertEquals("Original Bigger Text", pt.getText());
Assertions.assertTrue(pt.pieces.stream()
.filter(piece -> piece.getText().equals("al "))
.anyMatch(piece -> piece.getDecoration().getFontWeight() == FontWeight.BOLD)
);
Assertions.assertTrue(pt.pieces.stream()
.filter(piece -> piece.getText().equals("Bigger"))
.anyMatch(piece -> piece.getDecoration().getFontWeight() == FontWeight.BOLD &&
piece.getDecoration().getFontPosture() == FontPosture.ITALIC)
);
Assertions.assertTrue(pt.pieces.stream()
.filter(piece -> piece.getText().equals("Te"))
.anyMatch(piece -> piece.getDecoration().getFontWeight() == FontWeight.BOLD)
);
}

@Test
@DisplayName("Multi block decorate weight and posture")
public void multiBlockDecorateWeightAndPosture() {
Expand Down
0