Skip to content

Get exact LinesCount!#349

Closed
muraee wants to merge 1 commit intoFXMisc:masterfrom
intecsoft:master
Closed

Get exact LinesCount!#349
muraee wants to merge 1 commit intoFXMisc:masterfrom
intecsoft:master

Conversation

@muraee
Copy link
Copy Markdown

@muraee muraee commented Aug 23, 2016

  • new method getParagraphLinesCount, returns an integer of linesCount in a specific Paragraph using its index as parameter.
  • getCaretBoundsOnScreen method in class StyledTextArea is now public, used to determine if the caret is outside the screen or not.

                  - getCaretBoundsOnScreen method is now public.
@muraee muraee changed the title new Features! Get exact LinesCount! Aug 23, 2016
@JordanMartinez
Copy link
Copy Markdown
Contributor

What exactly is "linesCount" ? Is that the number of Text objects stored a TextFlow's list of children? I'm not familiar with that API.

@muraee
Copy link
Copy Markdown
Author

muraee commented Aug 24, 2016

@JordanMartinez a paragraph represents a Text (or TextField) object in a TextFlow (CodeArea), but still a TextField can store more than one line that is not necessarily separated by \n in case of WrapText.
Using this new method you can get the linesCount for each Paragraph (Text object) and the sum would be linesCount for the whole TextFlow (CodeArea).

@JordanMartinez
Copy link
Copy Markdown
Contributor

Oo! I can see why that would be very helpful.

Putting it into my own words... If you have a really long line of text, and the wrap text feature is on, and the StyledTextArea (or one of its flavors) is not wide enough to display the entire long line, then this feature would tell you how many lines it takes to display that entire long line.

Using this new method you can get the linesCount for each Paragraph (Text object) and the sum would be linesCount for the whole TextFlow (CodeArea) (emphasis mine).

But wouldn't this only work for the content that is actually displayed? I may be misunderstanding you, but since most of the document isn't displayed, you still wouldn't be able to know how many lines it takes to display the entire document. Each line itself is a TextFlow; CodeArea is a VirtualFlow with many TextFlow objects (cells) as needed to display the content that fits within the viewport.

@muraee
Copy link
Copy Markdown
Author

muraee commented Aug 24, 2016

Yes that is exactly what I meant.
I am not sure if I can get the linesCount of the text that is not displayed, but still it is very helpful to track any new lines inserted in StyledTextArea when the wrapText feature is on.
That was the case when I needed this feature, as I wanted the CodeArea Height to fit its content instead of scrolling to see the rest.

@JordanMartinez
Copy link
Copy Markdown
Contributor

@TomasMikula any comments here? This PR has been open for a while now...

@ghost
Copy link
Copy Markdown

ghost commented Dec 7, 2016

Consider also a getLineCount() that iterates over the paragraphs to compute the total sum of lines for the text area. Another possibility for the API might look like:

Paragraph p = textArea.getParagraph(getCaretParagraph());
long pLines = p.getLineCount();
long tLines = textArea.getLineCount();

// Seems like behaviour that belongs to the paragraph.
pLines = textArea.getParagraphLineCount(getCaretParagraph());

The implementation for textArea.getLineCount() becomes trivial:

long totalLines = 0;

for( final Paragraph p : getParagraphs() ) {
  totalLines += p.getLineCount();
}

return totalLines;

As far as I can tell, this PR implies:

  public int countLines( final StyleClassedTextArea textArea ) {
    int total = 0;

    for( int i = textArea.getParagraphs().size() - 1; i >= 0; i-- ) {
      total += textArea.getParagraphLinesCount( i );
    }

    return total;
  }

Not nearly as elegant as:

textArea.getLineCount()

However, this would lead the developers to thinking that it is an accurate line count, which might not be possible to calculate quickly. At least not without extensive documentation that, on this PR, is lacking.

@sherzfel
Copy link
Copy Markdown

This branch returns either 1 is wrapText is false or if wrapText is true it returns the number of signs. Am I doing something wrong or has this branch an error?

@JordanMartinez
Copy link
Copy Markdown
Contributor

Both features of this PR have been implemented in other PRs. The only one that hasn't is the one that @davejarvis mentioned: area.getLineCount(), which would return the sum of all paragraph's lineCounts. @davejarvis if you still want that feature, please open a new issue. It won't take long to resolve, but there may be a few other factors we need to take into consideration.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants