Skip to content
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

Exception: Cannot construct a Paragraph with StyleSpans object that contains no StyleSpan objects #696

Closed
JFormDesigner opened this issue Mar 1, 2018 · 2 comments · Fixed by #697

Comments

@JFormDesigner
Copy link
Contributor

I'm getting the below exception with current master branch of RichTextFX in Markdown Writer FX, but it works fine with RichTextFX 0.8.2.

Was able to find the commit that causes the exception: PR #685
Before this PR was merged, it worked. After merging, it fails.

The exception assumes a problem on my side, but I have no idea how to fix this.

I'm having a StyleClassedTextArea and using a StyleSpansBuilder<Collection<String>> to build style spans for the whole text.

Any ideas?

Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException:
 Cannot construct a Paragraph with StyleSpans object that contains no StyleSpan objects
	at org.fxmisc.richtext.model.Paragraph.<init>(Paragraph.java:124)
	at org.fxmisc.richtext.model.Paragraph.restyle(Paragraph.java:325)
	at org.fxmisc.richtext.model.GenericEditableStyledDocumentBase.lambda$11(GenericEditableStyledDocumentBase.java:170)
	at org.fxmisc.richtext.model.ReadOnlyStyledDocument.lambda$14(ReadOnlyStyledDocument.java:366)
	at org.reactfx.util.Tuple2.map(Tuple2.java:31)
	at org.fxmisc.richtext.model.ReadOnlyStyledDocument.lambda$12(ReadOnlyStyledDocument.java:365)
	at org.reactfx.util.Tuple2.map(Tuple2.java:31)
	at org.fxmisc.richtext.model.ReadOnlyStyledDocument.replace(ReadOnlyStyledDocument.java:364)
	at org.fxmisc.richtext.model.ReadOnlyStyledDocument.replace(ReadOnlyStyledDocument.java:354)
	at org.fxmisc.richtext.model.GenericEditableStyledDocumentBase.setStyleSpans(GenericEditableStyledDocumentBase.java:164)
	at org.fxmisc.richtext.model.SimpleEditableStyledDocument.setStyleSpans(SimpleEditableStyledDocument.java:1)
	at org.fxmisc.richtext.GenericStyledArea.setStyleSpans(GenericStyledArea.java:1138)
	at org.markdownwriterfx.editor.MarkdownSyntaxHighlighter.highlight(MarkdownSyntaxHighlighter.java:278)
	at org.markdownwriterfx.editor.MarkdownSyntaxHighlighter.highlight(MarkdownSyntaxHighlighter.java:198)
	at org.markdownwriterfx.editor.MarkdownEditorPane.applyHighlighting(MarkdownEditorPane.java:299)
	at org.markdownwriterfx.editor.MarkdownEditorPane.textChanged(MarkdownEditorPane.java:273)
	at org.markdownwriterfx.editor.MarkdownEditorPane.lambda$0(MarkdownEditorPane.java:100)
	at org.reactfx.value.ChangeListenerWrapper.accept(Val.java:786)
	at org.reactfx.util.AbstractReducingStreamNotifications.lambda$head$0(NotificationAccumulator.java:248)
	at org.reactfx.ObservableBase.notifyObservers(ObservableBase.java:68)
	at org.reactfx.SuspendableBase.resume(SuspendableBase.java:64)
	at org.reactfx.CloseableOnceGuard.close(Guard.java:49)
	at org.reactfx.MultiGuard.close(Guard.java:83)
	at org.reactfx.Suspendable$1.resumeSource(Suspendable.java:118)
	at org.reactfx.Suspendable$1.suspendSource(Suspendable.java:104)
	at org.reactfx.util.NonAccumulativeStreamNotifications.lambda$head$0(NotificationAccumulator.java:134)
	at org.reactfx.ObservableBase.notifyObservers(ObservableBase.java:68)
	at org.reactfx.ObservableBase.notifyObservers(ObservableBase.java:57)
	at org.reactfx.ProperEventStream.emit(ProperEventStream.java:18)
	at org.reactfx.EventStreams$3.lambda$observeInputs$0(EventStreams.java:105)
	at org.reactfx.value.ChangeListenerWrapper.accept(Val.java:786)
	at org.reactfx.util.AbstractReducingStreamNotifications.lambda$head$0(NotificationAccumulator.java:248)
	at org.reactfx.ObservableBase.notifyObservers(ObservableBase.java:68)
	at org.reactfx.ObservableBase.notifyObservers(ObservableBase.java:57)
	at org.reactfx.value.ValBase.invalidate(ValBase.java:32)
	at org.reactfx.SuspendableBoolean.release(SuspendableBoolean.java:24)
	at org.reactfx.CloseableOnceGuard.close(Guard.java:49)
	at org.reactfx.Suspendable.suspendWhile(Suspendable.java:49)
	at org.fxmisc.richtext.model.GenericEditableStyledDocumentBase.update(GenericEditableStyledDocumentBase.java:228)
	at org.reactfx.util.Tuple3.exec(Tuple3.java:43)
	at org.fxmisc.richtext.model.GenericEditableStyledDocumentBase.replace(GenericEditableStyledDocumentBase.java:135)
	at org.fxmisc.richtext.model.SimpleEditableStyledDocument.replace(SimpleEditableStyledDocument.java:1)
	at org.fxmisc.richtext.GenericStyledArea.replace(GenericStyledArea.java:1187)
	at org.fxmisc.richtext.GenericStyledArea.replaceText(GenericStyledArea.java:1174)
	at org.fxmisc.richtext.EditActions.replaceText(EditActions.java:148)
	at org.markdownwriterfx.editor.MarkdownEditorPane.setMarkdown(MarkdownEditorPane.java:225)
	at org.markdownwriterfx.FileEditor.load(FileEditor.java:267)
	at org.markdownwriterfx.FileEditor.activated(FileEditor.java:216)
	at org.markdownwriterfx.FileEditor.lambda$5(FileEditor.java:97)
	at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
	at java.security.AccessController.doPrivileged(Native Method)
	at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
	at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
	at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
	at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
	at java.lang.Thread.run(Thread.java:748)
@JFormDesigner
Copy link
Contributor Author

Was able to build a minimal app that reproduces the problem. Running the below app immediately throws the above exception:

import java.util.Collection;
import java.util.Collections;
import org.fxmisc.richtext.StyleClassedTextArea;
import org.fxmisc.richtext.model.StyleSpansBuilder;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class StyleSpansIssue extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        StyleClassedTextArea textArea = new StyleClassedTextArea();
        textArea.replaceText("* a\n\n");

        StyleSpansBuilder<Collection<String>> spansBuilder = new StyleSpansBuilder<>();
        spansBuilder.add(Collections.singleton("cls1"), 1);
        spansBuilder.add(Collections.singleton("cls2"), 3);
        spansBuilder.add(Collections.emptyList(), 1);
        textArea.setStyleSpans(0, spansBuilder.create());

        Scene scene = new Scene(new StackPane(textArea), 600, 400);
        primaryStage.setScene(scene);
        primaryStage.setTitle("StyleSpansIssue");
        primaryStage.show();
    }
}

@Bibek1998
Copy link

I want to make certain lines/paragraphs of codearea editablitiy false how to do it ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants