Skip to content

Commit bec3e38

Browse files
authored
Fix ParStyle equals & indent (#943)
1 parent 14534d0 commit bec3e38

2 files changed

Lines changed: 23 additions & 9 deletions

File tree

richtextfx-demos/src/main/java/org/fxmisc/richtext/demo/richtext/Indent.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,21 @@ public class Indent
44
{
55
double width = 15;
66
int level = 1;
7+
8+
Indent() {}
9+
10+
Indent( int level )
11+
{
12+
if ( level > 0 ) this.level = level;
13+
}
14+
15+
Indent increase()
16+
{
17+
return new Indent( level+1 );
18+
}
19+
20+
Indent decrease()
21+
{
22+
return new Indent( level-1 );
23+
}
724
}

richtextfx-demos/src/main/java/org/fxmisc/richtext/demo/richtext/ParStyle.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,16 @@ public ParStyle(Optional<TextAlignment> alignment, Optional<Color> backgroundCol
7373

7474
@Override
7575
public int hashCode() {
76-
return Objects.hash(alignment, backgroundColor);
76+
return Objects.hash(alignment, backgroundColor, indent);
7777
}
7878

7979
@Override
8080
public boolean equals(Object other) {
8181
if(other instanceof ParStyle) {
8282
ParStyle that = (ParStyle) other;
8383
return Objects.equals(this.alignment, that.alignment) &&
84-
Objects.equals(this.backgroundColor, that.backgroundColor);
84+
Objects.equals(this.backgroundColor, that.backgroundColor) &&
85+
Objects.equals(this.indent, that.indent);
8586
} else {
8687
return false;
8788
}
@@ -134,16 +135,12 @@ public ParStyle updateIndent(Indent indent) {
134135
}
135136

136137
public ParStyle increaseIndent() {
137-
if ( indent.isPresent() ) indent.get().level++;
138-
else return updateIndent( new Indent() );
139-
return this;
138+
return updateIndent( indent.map( Indent::increase ).orElseGet( Indent::new ) );
140139
}
141140

142141
public ParStyle decreaseIndent() {
143-
if ( indent.isPresent() && --indent.get().level == 0 ) {
144-
return updateIndent( null );
145-
}
146-
return this;
142+
return updateIndent( indent.filter( in -> in.level > 1 )
143+
.map( Indent::decrease ).orElse( null ) );
147144
}
148145

149146
}

0 commit comments

Comments
 (0)