Skip to content

Commit 8289b0f

Browse files
committed
Fix StyledTextArea#setParagraphStyle.
1 parent 7a7df5b commit 8289b0f

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

richtextfx/src/main/java/org/fxmisc/richtext/EditableStyledDocument.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.reactfx.EventStream;
2222
import org.reactfx.EventStreams;
2323
import org.reactfx.Guard;
24+
import org.reactfx.util.Lists;
2425
import org.reactfx.value.SuspendableVar;
2526
import org.reactfx.value.Val;
2627
import org.reactfx.value.Var;
@@ -360,13 +361,30 @@ public void setStyleSpans(int paragraph, int from, StyleSpans<? extends S> style
360361
}
361362
}
362363

364+
public void setParagraphStyle(int parIdx, PS style) {
365+
ensureValidParagraphIndex(parIdx);
366+
Paragraph<S, PS> par = paragraphs.get(parIdx);
367+
int len = par.length();
368+
int start = position(parIdx, 0).toOffset();
369+
int end = start + len;
370+
371+
try(Guard commitOnClose = beginStyleChange(start, end)) {
372+
Paragraph<S, PS> q = par.setParagraphStyle(style);
373+
paragraphs.set(parIdx, q);
374+
}
375+
}
376+
363377

364378
/* ********************************************************************** *
365379
* *
366380
* Private and package private methods *
367381
* *
368382
* ********************************************************************** */
369383

384+
private void ensureValidParagraphIndex(int parIdx) {
385+
Lists.checkIndex(parIdx, paragraphs.size());
386+
}
387+
370388
private void ensureValidRange(int start, int end) {
371389
ensureValidRange(start, end, length());
372390
}

richtextfx/src/main/java/org/fxmisc/richtext/StyledTextArea.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -712,8 +712,8 @@ public void setStyleSpans(int paragraph, int from, StyleSpans<? extends S> style
712712
* Sets style for the whole paragraph.
713713
*/
714714
public void setParagraphStyle(int paragraph, PS paragraphStyle) {
715-
if (paragraph >= 0 && paragraph < paragraphs.size()) {
716-
paragraphs.set(paragraph, paragraphs.get(paragraph).setParagraphStyle(paragraphStyle));
715+
try(Guard g = omniSuspendable.suspend()) {
716+
content.setParagraphStyle(paragraph, paragraphStyle);
717717
}
718718
}
719719

0 commit comments

Comments
 (0)