Skip to content

Loading (by replacing) a document with a ReadOnlyStyledDocument doesn't display text #123

@JordanMartinez

Description

@JordanMartinez

In previous versions (I believe before 6.0), I could save and load a document's text and style using XML. To do so, I simulated the same process used by the InlineCssTextArea's "subDocument()" method.

My method:

  1. Creates all the StyledTexts in a Paragraph
  2. Creates a Paragraph using the resulting list of StyledTexts
  3. Creates a ReadOnlyStyledDocument (ROSD) using the resulting list of Paragraphs
  4. Replaces the object's document with the newly created ROSD
  5. Deletes the last newline character in the text

Since then, I've encountered a problem that I believe relates to which LineTerminator I use, but I'm not entirely sure. Once the new document is displayed, I don't see the actual text (screenshot below). I only see the white background with their scrollbars correctly sized to the text it should display. Scrolling works fine, but I only see a white background. Typing in anything / selecting the text that should be there doesn't do anything.
Update: scrolling down a ways (1/3 to 1/2 of document's length) once the document is loaded will sometimes correct the problem.

I'm pretty sure this is a breaking change due to the new releases that can be quickly solved, but I wasn't sure what I should change to solve it.

selection_008

Below is my code for achieving this, written in Groovy.

def paragraphList = []
for (paragraph in document.Paragraph) {
    def newParagraph
    if (paragraph.@text != null) {
        // println "Encountered situation 1: line has content, but not user_inputted content"
        newParagraph = new Paragraph(paragraph.@text, "", LineTerminator.LF)
    } else {
        // println "Encountered situation 2: line has content & user_inputted text"
        def segments = []
        for (styledText in paragraph.StyledText) {
            segments << new StyledText(styledText.@text, styledText.@style)
        }
        newParagraph = new Paragraph(segments as List<StyledText>, LineTerminator.LF)
    }
    // println "Adding a new paragraph to list of Paragraphs"
    def value = paragraph.@index as int
    paragraphList.putAt(value - 1, newParagraph)
}
paragraphList.eachWithIndex { paragraph, index ->
    // replace all null values with a new Paragraph containing no text
    if (paragraph == null) {
    paragraphList[index] = new Paragraph("", "", LineTerminator.LF)
    }
}
// println "Replacing with newly created Document"
// Pressing enter isn't registered when I use "replace(new ROSD(arguments...))." I have to use replace(0,0,new ROSD)
this.replace(0, 0, new ReadOnlyStyledDocument(paragraphList as List<Paragraph>, ReadOnlyStyledDocument.ParagraphsPolicy.COPY))
// after replacing with loaded Doc, need to delete the last line.
// This is the line that exists when first created and doc gets inserted before it. Using ".replace(0, 1, ...)" doesn't work
def lastcharacter = getText().size()
deleteText(lastcharacter - 1, lastcharacter)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions