rich-text-area icon indicating copy to clipboard operation
rich-text-area copied to clipboard

edit / update / reopen

Open tonydroy opened this issue 9 months ago • 2 comments

I am experiencing a cluster of issues with restoring documents in the RichTextArea that I do not understand. In the 1.1.2 version I can reproduce the issues with a modified version of the FullFeaturedDemo.

Modifications: The document variable is no longer final and simplified to,

private Document document = new Document("this is\na test");

Buttons are created as follows,

Button updateDocButton = new Button("update doc");
        updateDocButton.setOnAction(e -> document = editor.getDocument() );

Button setDocumentButton = new Button("set doc");
 //       setDocumentButton.setOnAction(e -> editor.setDocument(document) );
        setDocumentButton.setOnAction(e -> editor.getActionFactory().open(document).execute(new ActionEvent()));

And the buttons are added to toolbar.

Behavior: I expect that I should be able to: open document (with the toolbar button) / edit / press update / press clear / press open or set -- and see my edited document again. Here is what I get:

  1. With the second (action factory) version of 'set' I can: open / add text to the very end / update / clear / set -- and, as expected, the edited text is restored.

  2. Still with the second (action factory) version of 'set': open / edit text not at the end / update / clear / set -- results in StringIndexOutOfBoundsException (PieceTable.java: 83).

  3. With the first (setDocument) version of 'set': open / edit / update / clear / set -- results in no visible change (the visible screen remains clear though I believe the RichTextArea document is in fact updated).

  4. With 'set' to the side: open / edit / update / and the open button again - reverts to the original version of document.

In any case, what I cannot do is create a document, save (perhaps to disk now with Serializable) reopen, edit, and expect it to save/open again.

FullFeaturedDemo.zip

tonydroy avatar May 07 '24 21:05 tonydroy

In the version of RichTextArea available on 5/27/24 I no longer see the crash associated with option (2). Options (3) and (4) are the same.

tonydroy avatar May 27 '24 18:05 tonydroy

Please test again with the most recent 1.1.4-SNAPSHOT version.

If you still find exceptions, please post them, with clear steps of how to reproduce.

Ideally, provide a SSCCE simple class, for instance using a simple class like BasicDocumentDemo.

As for the use of RichTextArea::setDocument, you are right, it doesn't work if you call it twice.

But if you check its Javadoc: https://github.com/gluonhq/rich-text-area/blob/main/rta/src/main/java/com/gluonhq/richtextarea/RichTextArea.java#L95

it wasn't intended to be used directly.

Most likely we need to make documentProperty readOnly, to enforce that (since this will be breaking API, it will need a major release though).

Edit: I've filed #341, and created a PR for it: #342

jperedadnr avatar Jun 21 '24 20:06 jperedadnr