RichTextFX icon indicating copy to clipboard operation
RichTextFX copied to clipboard

Q: Any missing APIs in JavaFX which are needed for this project?

Open andy-goryachev-oracle opened this issue 2 years ago • 16 comments

Greetings.

I am collecting requests for missing/incomplete APIs needed for implementing a rich text editor, see https://bugs.openjdk.org/browse/JDK-8300569

I searched through your issue tracker and added all the JBS tickets mentioned (hopefully, all of them), but there exists a possibility that you might need other APIs for which no JBS ticket has been created.

You can respond here or in JBS ticket.

Thanks.

-andy

andy-goryachev-oracle avatar Jan 25 '23 23:01 andy-goryachev-oracle

@Xiaobaishushu25 please post as a separate issue, thank you.

Jugen avatar Jan 26 '23 12:01 Jugen

Not sure whether this is out of scope (but if it is, it can be deleted), but my wishlist is to have font-metrics, line metrics access in javafx canvas/graphicscontext. Such as https://docs.oracle.com/javase/7/docs/technotes/guides/2d/spec/j2d-fonts.html. Current limitation is that one cannot justify text or do multiline text, mixed font text measurements in canvas/graphicscontext.

mambastudio avatar Jan 26 '23 20:01 mambastudio

Thank you @mambastudio . We already have https://bugs.openjdk.org/browse/JDK-8090775 for this problem.

Personally, I used a single static Text/TextFlow instance for that purpose.

andy-goryachev-oracle avatar Jan 26 '23 20:01 andy-goryachev-oracle

Problems that occur in implementations of functions implementing syntax highlighting

Syntax highlighting implementations often use regular expressions for lexical analysis, but may not be able to use the standard API java.util.regex.Pattern as a regular expression engine for the following reasons.

  • Potential StackOverFlow risk due to the use of recursive calls in implementations when there is group repetition in the grammar definition.

https://bugs.openjdk.org/browse/JDK-6882582

yososs avatar Jan 27 '23 08:01 yososs

Standardize VirtualFlow for use in text editors (TextArea).

  • Many text editor libraries have their own implementations, but appear to have few functional features.
  • javafx's standard control TextArea, without VirtualFlow, is not good at handling large text.

yososs avatar Jan 27 '23 08:01 yososs

Lack of a clever edit buffer implementation.

  • javafx's standard controls TextField and TextArea are worse at handling large text than Swing's GapContent due to their naive implementation.
  • The choice of editing buffer algorithm will be a feature of each text editor engine, but we feel that standardization of the interface and default implementation should be considered.

At least the text buffer of JavaFX standard control should be able to handle text with a length equal to or greater than that of Swing. Solving this problem would reduce the need for third-party libraries for his RichTextArea engine, but would improve the reputation of JavaFX technology.

yososs avatar Jan 27 '23 08:01 yososs

Enhanced wrap text mode variation

The importance of these wrap rules may be perceived differently in languages that separate words with whitespace and those that do not (CJK).

overflow-wrap: anywhere;
line-break: strict;
hyphens: manual;
hyphens: auto;

  • https://developer.mozilla.org/docs/Web/CSS/overflow-wrap

  • https://developer.mozilla.org/docs/Web/CSS/line-break

  • https://developer.mozilla.org/docs/Web/CSS/hyphens

  • Soft hyphen support for TextFlow - JBS

yososs avatar Jan 27 '23 09:01 yososs

Lack of API and CSS rules to specify letter spacing for Text

yososs avatar Jan 27 '23 13:01 yososs

Standardize VirtualFlow for use in text editors (TextArea).

  • Many text editor libraries have their own implementations, but appear to have few functional features.
  • javafx's standard control TextArea, without VirtualFlow, is not good at handling large text.

This looks very useful; looking forward to making it happen

leewyatt avatar Jan 30 '23 15:01 leewyatt

I don't think APIs is the way to think of it. A better approach is to determine what are the desirable features of a text component and then work from there.

The Swing JTextComponent is a good model to use, especially its separation of view and model and the ability to work with both and interchange between them, for instance methods such as modelToView and viewToModel are indispensable for developers who want to manipulate the view based on the text.

So a good first step is to have feature parity with JTextComponent.

Further features that would be useful are things like paragraph decorations, such as the margins RichTextFX uses and the decorations that Gluon's RichTextArea uses.

Support for arbitrary Nodes positioned within the text is useful and parity with the text features offered by HTML such as word spacing, letter spacing, line spacing, alignments, indentations, fonts and so on.

Another useful feature would be support for CSS styling (as RichTextFX does) and allow for arbitrary pseudo classes to be assigned to text. Give the developer access to each text component so that styling can be overridden.

Scalability should be a primary concern, I had a user tell me that the RichTextFX text component was slowing down, I later found out that the person had 200,000 words in the component.

An undomanager should be a core feature with a simple interface for both the end user and developer, this includes having access to the undos available.

Finally, accurate positioning of the text within a scrollpane is needed, so I should be able to have a text position, get the view position then move the view to the exact location of the text.

garybentley avatar Feb 14 '23 00:02 garybentley

Gary:

Thank you so much for a very detailed list! As we all know, it is a very long list.

Could you clarify a few points please?

So a good first step is to have feature parity with JTextComponent. What is missing, specifically?

Further features that would be useful are things like paragraph decorations, such as the margins RichTextFX uses and the decorations that Gluon's RichTextArea uses. What kinds of decorations? Are these decorations applied to the whole paragraph or individual text runs?

Thanks again. -andy

From: Gary Bentley @.> Date: Monday, February 13, 2023 at 16:37 To: FXMisc/RichTextFX @.> Cc: Andy Goryachev @.>, Author @.> Subject: [External] : Re: [FXMisc/RichTextFX] Q: Any missing APIs in JavaFX which are needed for this project? (Issue #1167)

I don't think APIs is the way to think of it. A better approach is to determine what are the desirable features of a text component and then work from there.

The Swing JTextComponent is a good model to use, especially its separation of view and model and the ability to work with both and interchange between them, for instance methods such as modelToView and viewToModel are indispensable for developers who want to manipulate the view based on the text.

So a good first step is to have feature parity with JTextComponent.

Further features that would be useful are things like paragraph decorations, such as the margins RichTextFX uses and the decorations that Gluon's RichTextArea uses.

Support for arbitrary Nodes positioned within the text is useful and parity with the text features offered by HTML such as word spacing, letter spacing, line spacing, alignments, indentations, fonts and so on.

Another useful feature would be support for CSS styling (as RichTextFX does) and allow for arbitrary pseudo classes to be assigned to text. Give the developer access to each text component so that styling can be overridden.

Scalability should be a primary concern, I had a user tell me that the RichTextFX text component was slowing down, I later found out that the person had 200,000 words in the component.

An undomanager should be a core feature with a simple interface for both the end user and developer, this includes having access to the undos available.

Finally, accurate positioning of the text within a scrollpane is needed, so I should be able to have a text position, get the view position then move the view to the exact location of the text.

— Reply to this email directly, view it on GitHubhttps://urldefense.com/v3/__https:/github.com/FXMisc/RichTextFX/issues/1167*issuecomment-1428921893__;Iw!!ACWV5N9M2RV99hQ!L6E37FU0YXilbbOwJH-0ylLuVye_mIzFjUkk6oaFH7QcKUgPZkcoThGmAeUe_wedfVQcdMrg0Y4tfoO30Q0mdWqDoSzHyQ$, or unsubscribehttps://urldefense.com/v3/__https:/github.com/notifications/unsubscribe-auth/AZQ34ZHJ5AFCCFO36KC63LLWXLHU5ANCNFSM6AAAAAAUG4REWI__;!!ACWV5N9M2RV99hQ!L6E37FU0YXilbbOwJH-0ylLuVye_mIzFjUkk6oaFH7QcKUgPZkcoThGmAeUe_wedfVQcdMrg0Y4tfoO30Q0mdWp0RTlCMA$. You are receiving this because you authored the thread.Message ID: @.***>

andy-goryachev-oracle avatar Feb 17 '23 22:02 andy-goryachev-oracle

Hi Andy,

Glad I could help.

So for JTextComponent, I would say that any new text component should have the same features as that supported by JTextComponent. If you compare javafx/TextArea and swing/JTextComponent they have very different approaches. For TextArea there is a presumption that the user wants a scrollpane wrapper, but this isn't always true so instead TextFlow has to be used.

Features I think TextFlow needs (or any text component, note this list isn't exhaustive because the features I desire are limited to a specific use case, that is a person editing text only in a single component, other uses of RichTextFX say have different use cases and feature needs):

  • Access to the view or model and being able to move between the two.
  • Control of the caret visual properties such as color and shape. Similarly for the selection, there is some control in TextInputControl but that is purely for text.
  • TextFlow uses Nodes to represent it's model but there is no associated "document model" thus it makes managing the underlying information difficult. See javax.swing.text.Document, org.fxmisc.richtextfx.model.StyledDocument and com.gluonhq.richtextarea.model.Document for more details.
  • TextFlow doesn't allow for a first line indent. You would be amazed at the number of authors who want this feature.
  • Printing support, javafx.print assumes that you want to print the Node as is but text needs formatting and pagination that is related to the text.
  • There is no way to define how the caret should be moved around the text (or Nodes for TextFlow). In TextInputControl there is nextWord/previousWord but they seem to assume what a word is, presumably based on a default locale BreakIterator (but I don't know). So I would need to override this behavior in the sub-class rather than providing a way to let the component know how I would like caret movement to occur.
  • On a broader point being able to set a locale for Node would be useful.
  • There is no way in TextFlow to provide key/action mappings. This becomes a complex area for rich text, for example turning a number of selected Nodes into something suitable for cut/copy/paste is not straight forward.
  • Position tracking, in Swing this was provided by the Document model, see https://docs.oracle.com/en/java/javase/19/docs/api/java.desktop/javax/swing/text/AbstractDocument.html#createPosition(int) this type of thing is vital for being reactive to the user making changes to the model, especially when you can then map that position to the view.

This isn't an exhaustive list however, it's only my view of the features I think JTextComponent has and I wish TextFlow had.

For the decorations/margins, I think both paragraph and text run decorations are desirable. Consider a code text area, it would be useful to select a piece of text and assign "something" to it and then have a decoration be applied to the text and thus it be visually marked. However this would be useful at any level of granularity, from the entire document all the way down to each node or even single text characters.

My own preferred way of handling any new text component would be to have a "document" class that models the content and then I provide to the text component a way of converting each element within the document to a visual Node. RichTextFX sort of takes that approach which works very well but it may not be suitable for all use cases, for example rendering HTML elements.

garybentley avatar Feb 18 '23 02:02 garybentley

very good points, thank you @garybentley I am getting these issues digested and reflected in https://bugs.openjdk.org/browse/JDK-8300569

andy-goryachev-oracle avatar Feb 21 '23 16:02 andy-goryachev-oracle

I don't know if this would be valid but I think adding an emoji panel that would be attached to the editor or making it optional as well becuase emoji are custome and it's a lot of work to implement and having them adhere to most mobile key boards have.

kinsleykajiva avatar Mar 31 '24 17:03 kinsleykajiva

adding an emoji panel

is this the right ticket for this comment?

but if we speak of emoji support in javafx it is still incomplete, see https://bugs.openjdk.org/browse/JDK-8309565

andy-goryachev-oracle avatar Apr 01 '24 15:04 andy-goryachev-oracle

ok noted then .

kinsleykajiva avatar Apr 02 '24 07:04 kinsleykajiva