Giter Club home page Giter Club logo

richtextfx's Introduction

RichTextFX

RichTextFX provides a memory-efficient text area for JavaFX that allows the developer to style ranges of text, display custom objects in-line (no more HTMLEditor), and override specific default behaviors only where necessary.

The library does not follow the model-view-controller paradigm, which prevents access to view-specific APIs (e.g., obtaining caret/selection/character bounds, programmic scrolling, and such).

Use the library as a foundation for building rich text editors and code editors that offer syntax highlighting. Being a foundation, many features will not be implemented in this project (such as language-specific syntax highlighters, search-and-replace, hyperlink support, and similar). Rather, developers may implement these features then submit the work as a PR to the richtextfx-demos package.

For further details about RichTextFX, its design principles, how it works, and applying CSS styling, see the wiki.

JFXCentral

Demos

Standalone applications that demonstrate RichTextFX features may be found in the RichTextFX demos directory.

Table of Contents

Who uses RichTextFX?

Let us know if you use RichTextFX in your project!

Features

  • Assign arbitrary styles to arbitrary ranges of text. A style can be an object, a CSS string, or a style class string.
  • Display line numbers or, more generally, any graphic in front of each paragraph. Can be used to show breakpoint toggles on each line of code.
  • Support for displaying other Nodes in-line.
  • Positioning a popup window relative to the caret or selection. Useful e.g. to position an autocompletion box.
  • Getting the character index under the mouse when the mouse stays still over the text for a specified period of time. Useful for displaying tooltips depending on the word under the mouse.
  • Overriding the default behavior only where necessary without overriding any other part.

Flavors

The following explains the different rich text area classes. The first one is the base class from which all others extend: it needs further customization before it can be used but provides all aspects of the project's features. The later ones extend this base class in various ways to provide out-of-box functionality for specific use cases. Most will use one of these subclasses.

GenericStyledArea

GenericStyledArea allows one to inline custom objects into the area alongside of text. As such, it uses generics and functional programming to accomplish this task in a completely type-safe way.

It has the following parameter types:

  • PS, the paragraph style. This can be used for text alignment or setting the background color for the entire paragraph. A paragraph is either one line when text wrap is off or a long text displayed over multiple lines in a narrow viewport when text wrap is on.
  • SEG, the segment object. This specifies what immutable object to store in the model part of the area: text, hyperlinks, images, emojis, or any combination thereof.
  • S, the segment style. This can be used for text and object styling. Usually, this will be a CSS style or CSS style class.

Functional programming via lambdas specify how to apply styles, how to create a Node for a given segment, and how to operate on a given segment (e.g., getting its length, combining it with another segment, etc.).

GenericStyledArea is used in the Rich-text demo.

See the wiki for a basic pattern that one must follow to implement custom objects correctly.

StyledTextArea

StyledTextArea<PS, S>, or one of its subclasses below, is the area you will most likely use if you don't need to display custom objects in your area.

It extends GenericStyledArea<PS, StyledText<S>, S>>. StyledText is simply a text (String) and a style object (S). A slightly-enhanced JavaFX Text node is used to display the StyledText<S>, so you can style it using its CSS properties and additional RichTextFX-specific CSS (see the wiki for more details).

It properly handles the aforementioned functional programming to properly display and operate on StyledText<S> objects.

The style object (S) can either be a CSS String (-fx-fill: red;), a CSS styleclass (.red { -fx-fill: red; }), or an object that handles this in a different way. Since most will use either the CSS String or CSS style class approach, there are two subclasses that already handle this correctly.

InlineCssTextArea

InlineCssTextArea uses the Node#setStyle(String cssStyle) method to style Text objects:

area.setStyle(from, to, "-fx-font-weight: bold;");

StyleClassedTextArea

StyleClassedTextArea uses the Node#setStyleClass(String styleClass) method to style Text objects. You can define the style classes in your stylesheet.

example.css:

.red { -fx-fill: red; }

Example.java:

area.setStyleClass(from, to, "red");

This renders the text in the range (from, to) in red.

CodeArea

CodeArea is a variant of StyleClassedTextArea that uses a fixed width font by default, making it a convenient base for source code editors. CodeArea is used in the Java Keywords demo.

Requirements

JDK11 or higher is required. (Can still be compiled with JDK9 if needed)

Download

Stable release

Current stable release is 0.11.2 which is ONLY compatible with Java 11 and UP.

Maven coordinates

Group ID Artifact ID Version
org.fxmisc.richtext richtextfx 0.11.2

Maven Central

Gradle example

dependencies {
    compile group: 'org.fxmisc.richtext', name: 'richtextfx', version: '0.11.2'
}

Sbt example

libraryDependencies += "org.fxmisc.richtext" % "richtextfx" % "0.11.2"

Manual download

Download the JAR file or the fat JAR file (including dependencies) and place it on your classpath.

Snapshot releases

Snapshot releases are deployed to Sonatype snapshot repository.

Maven coordinates

Group ID Artifact ID Version
org.fxmisc.richtext richtextfx 1.0.0-SNAPSHOT

Gradle example

repositories {
    maven {
        url 'https://oss.sonatype.org/content/repositories/snapshots/'
    }
}

dependencies {
    compile group: 'org.fxmisc.richtext', name: 'richtextfx', version: '1.0.0-SNAPSHOT'
}

Sbt example

resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"

libraryDependencies += "org.fxmisc.richtext" % "richtextfx" % "1.0.0-SNAPSHOT"

License

Dual-licensed under BSD 2-Clause License and GPLv2 with the Classpath Exception.

richtextfx's People

Contributors

afester avatar alexp11223 avatar amjdhsn avatar cemartins avatar chrisf-london avatar creativeartie avatar devcharly avatar finanzer avatar gaeqs avatar grigoriliev avatar iamgio avatar jeffreyguenther avatar jformdesigner avatar jordanmartinez avatar jugen avatar mewesk avatar neilccbrown avatar prat-man avatar rationalityfrontline avatar rohitawate avatar scientificware avatar shoaniki avatar skyaphid avatar svkreml avatar terjedahl avatar theandreim avatar tomasmikula avatar uzielsilva avatar veita avatar zev-g avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

richtextfx's Issues

Saving Content to file.

Hi Tomas,
I am trying export the text to a text file, how do I save a rtf file with styling?
Thanks,
Maher

ENTER key behavior

Hi Tomas, I noticed that when I hit the ENTER key somewhere in a paragraph that ends with a new line (so hitting Enter before the paragraph's end), the caret jumps to the new line position at the end. If the last position of the paragraph is not an new line, then hitting enter anywhere before behaves as expected. Is this by design?

Feature request: set text range background

Hi Tomas,
Would it be possible to look into adding a couple of method to set and apply a background color to selected ranges within text?

The functionality I am hoping to achieve is to store the ranges selected by the user for a given text string and give them the option to show/hide background color for those ranges.

For example:
myRange = textAreaCSS.getSelection();
myRange.setBackground(Color c);
myRange.showBackground(true);

Thanks for your help with this.
Best regards,
Maher

Question: Saving a file.

Hi Tomas,
I am trying to save the content (text and styles) to an external "text" file. So that the user can save and open their work. I am playing with the idea of making a preamble-like text body which has CSS styles, then range starts and ends, then then the plain text.

How does RichTextFX track styles, what is the data structure it uses? I am asking so that maybe there is something that already does what I am trying to do.
Best,
Maher

Paragraph Questions.

Hi Tomas,

To confirm, a paragraph is collection of styled texts that is separated from others by a new line before it and after it. right?

Would it be possible to provide a method to get Paragraph at caret?

Probably outside your scope, not sure. but do you plan to provide paragraph alignment options?

Thanks,
Maher

Starting a style at certain position in text (with having an index range)..

Hi Tomas,
I could not find a way to assign a style at the caret location. Is there one? What is available now requires an range.

For example, user clicks, then assigns a style. Then whatever is written afterward will inherit the new style.

Since the current method requires a range, I currently get the caret position, then append a dummy white space (in case the caret is at the end), then use the position of the caret and increment by 1 (as a range) to assign style, then remove the white space.

Thanks,
Maher

Copy/cut has unexpected behavior

When copying/cutting text in the rich text example, and others, I noticed that it only copies/cuts the text itself but nothing else, also the entire pasted block of text takes on the style wherever the caret was sitting.

I used all the copy methods and got the same results (ctr+c, toolbar button, and right-click>copy), so I assume they all use the same method to copy/paste.

I think both the styles and text should be copied into the clipboard, and should allow for pasting into separate RichTextFX nodes if possible.

Paragraph-level styles

To support rich-text editors, it should be possible to assign paragraph-level styles, such as alignment, heading, ...

EasyBind once more

Hi Tomas

it seems that EasyBind SNAPSHOT 1.0.0 is out of sync with the RichText implementation once more.

java.lang.NoSuchMethodError: org.fxmisc.easybind.EasyBind.map(Ljavafx/beans/value/ObservableValue;Ljava/util/function/Function;
at org.fxmisc.richtext.StyledTextArea.(StyledTextArea.java:269)

greetings
Roel

Enhancement: Style Match

Hi Tomas, I am trying to implement a search for similar text.
I can find similar strings, but I am trying to find a way to match the style. I am doing ths:

public static ArrayList<IndexRange> getIndexRangesOfStyledDocInTextArea(StyledDocument styledDocToFind, InlineCssTextArea richTextArea) {
    ArrayList<IndexRange> ranges = new ArrayList<>();

    String textBody = richTextArea.getText();

    int start = 0;
    while (true) {
        int found = textBody.indexOf(styledDocToFind.getText(), start);
        if (found != -1) {
            // Found a similar string, now lets match the style -- do whatever here

            IndexRange range = new IndexRange(found, found + styledDocToFind.length());

            StyledDocument foundDoc = richTextArea.getDocument().subSequence(range);
            StyleSpans foundSpans = foundDoc.getStyleSpans(0);
            StyleSpans givenSpans = styledDocToFind.getStyleSpans(0);

            int foundSpanCount = foundSpans.getSpanCount();
            int givenSpanCount = givenSpans.getSpanCount();

            boolean match = true;//assume we found it
            for (int i = 0; i < foundSpanCount; i++) {
                if (foundSpans.getStyleSpan(i).getStyle() != givenSpans.getStyleSpan(i).getStyle()) {
                    match = false;
                    break;
                }
            }

            //if assumptions hold true then..
            if (match) {
                ranges.add(range);
            }

        }
        if (found == -1) {
            break;
        }
        start = found + 2;  // move start up for next iteration
    }

    return ranges;
}

But I can't seem to get it. How do you suggest I find an exact match (string+ style)?

Out of bounds error on applying style to a selection

I was applying a style to a selection. after this selection there was a couple of new lines.. so I guess it has to do with the line terminator?

Exception in thread "JavaFX Application Thread" java.lang.IndexOutOfBoundsException: 6 not in [0, 6)
at org.fxmisc.richtext.Paragraph.subSequence(Paragraph.java:229)
at org.fxmisc.richtext.Paragraph.restyle(Paragraph.java:262)
at org.fxmisc.richtext.EditableStyledDocument.setStyleSpans(EditableStyledDocument.java:257)
at org.fxmisc.richtext.StyledTextArea.setStyleSpans(StyledTextArea.java:522)
at TextComponentElements.TextEditor.applySizeToSelection(TextEditor.java:1336)
at TextComponentElements.TextEditor.applySize(TextEditor.java:1321)
at TextComponentElements.TextEditor$32.handle(TextEditor.java:889)
at TextComponentElements.TextEditor$32.handle(TextEditor.java:885)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:204)
at javafx.scene.Scene$ClickGenerator.postProcess(Scene.java:3456)
at javafx.scene.Scene$ClickGenerator.access$8300(Scene.java:3387)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3755)
at javafx.scene.Scene$MouseHandler.access$1800(Scene.java:3471)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1695)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2486)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:314)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:243)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:345)
at com.sun.glass.ui.View.handleMouseEvent(View.java:526)
at com.sun.glass.ui.View.notifyMouse(View.java:898)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$300(WinApplication.java:39)
at com.sun.glass.ui.win.WinApplication$4$1.run(WinApplication.java:112)
at java.lang.Thread.run(Thread.java:744)

Type error in MyListView

I'm trying to keep up with your work. When I try to build the control, I get an error on line 90 of MyListView.java. Type mismatch: cannot convert from capture#16-of ? extends ListCell to null. I'm not familiar with VirtualFlow. Do you know what the issue might be?

"OutOfBoundsException" When hitting Enter

Hi Tomas, I changed my code to match the method you gave me before. See code below and the generated error. This is the full stack trace of the error:

The steps are:

Click in text area, apply a font size,.. things work fine..
Then hit Enter.. the error comes up.

I isolated the code that triggers the error, which is this:

public void doTheCaretStyleChange(TextEditorViewPort port, StyleInfo style) {
port.viewPortRichText.plainTextChanges().subscribe(change -> {
int from = change.getPosition();
int length = change.getInserted().length();
port.viewPortRichText.setStyle(from, from + length, style.completeInLineCSS.get());
});
}

-Error----------------------------------------------------------------------------------

Exception in thread "JavaFX Application Thread" java.lang.IndexOutOfBoundsException: 11 not in [0, 11)
at org.fxmisc.richtext.Paragraph.subSequence(Paragraph.java:229)
at org.fxmisc.richtext.Paragraph.restyle(Paragraph.java:249)
at org.fxmisc.richtext.EditableStyledDocument.setStyle(EditableStyledDocument.java:200)
at org.fxmisc.richtext.StyledTextArea.setStyle(StyledTextArea.java:477)
at TextComponentElements.TextEditor.lambda$doTheCaretStyleChange$0(TextEditor.java:804)
at TextComponentElements.TextEditor$$Lambda$99/699487773.accept(Unknown Source)
at org.reactfx.EventStreamBase.lambda$emit$0(EventStreamBase.java:10)
at org.reactfx.EventStreamBase$$Lambda$53/2124890648.accept(Unknown Source)
at org.reactfx.ListHelper$MultiElemHelper.forEach(ListHelper.java:118)
at org.reactfx.ListHelper.forEach(ListHelper.java:29)
at org.reactfx.EventStreamBase.emit(EventStreamBase.java:10)
at org.reactfx.InterceptableEventStreamImpl$1.consume(InterceptableEventStreamImpl.java:17)
at org.reactfx.PausedConsumer.feedToPrevious(InterceptableEventStreamImpl.java:149)
at org.reactfx.StackedConsumer.unstack(InterceptableEventStreamImpl.java:106)
at org.reactfx.InterceptableEventStreamImpl.unstack(InterceptableEventStreamImpl.java:81)
at org.reactfx.InterceptableEventStreamImpl.lambda$stack$50(InterceptableEventStreamImpl.java:74)
at org.reactfx.InterceptableEventStreamImpl$$Lambda$45/982926558.close(Unknown Source)
at org.reactfx.Hold.lambda$multi$33(Hold.java:23)
at org.reactfx.Hold$$Lambda$47/1800471081.close(Unknown Source)
at org.fxmisc.richtext.StyledTextArea.replaceText(StyledTextArea.java:563)
at org.fxmisc.richtext.TextEditingArea.replaceText(TextEditingArea.java:231)
at org.fxmisc.richtext.EditActions.replaceSelection(EditActions.java:144)
at org.fxmisc.richtext.behavior.CodeAreaBehavior.callAction(CodeAreaBehavior.java:213)
at org.fxmisc.richtext.behavior.CodeAreaBehavior.callAction(CodeAreaBehavior.java:140)
at com.sun.javafx.scene.control.behavior.BehaviorBase.callActionForEvent(BehaviorBase.java:222)
at org.fxmisc.richtext.behavior.CodeAreaBehavior.callActionForEvent(CodeAreaBehavior.java:134)
at com.sun.javafx.scene.control.behavior.BehaviorBase$1.handle(BehaviorBase.java:136)
at com.sun.javafx.scene.control.behavior.BehaviorBase$1.handle(BehaviorBase.java:133)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:204)
at javafx.scene.Scene$KeyHandler.process(Scene.java:3949)
at javafx.scene.Scene$KeyHandler.access$2100(Scene.java:3896)
at javafx.scene.Scene.impl_processKeyEvent(Scene.java:2036)
at javafx.scene.Scene$ScenePeerListener.keyEvent(Scene.java:2493)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:170)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:123)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(GlassViewEventHandler.java:197)
at com.sun.glass.ui.View.handleKeyEvent(View.java:517)
at com.sun.glass.ui.View.notifyKey(View.java:927)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$300(WinApplication.java:39)
at com.sun.glass.ui.win.WinApplication$4$1.run(WinApplication.java:112)
at java.lang.Thread.run(Thread.java:744)

Can't change background properties of an InlineCssTextArea

Is it possible to set the background colour and/or opacity of an InlineCssTextArea? I can't seem to find a way to do this anywhere. I originally had a TextArea in my project and switched it for an InlineCssTextArea for rich text support, but the CSS I used before no longer works. If this is not supported, is there a chance of it being added any time soon?

I'm using the newest JAR, 1.0.0-20140327. Thanks in advance.

Undo has strange behaviour

I've been messing around with the demos provided. In the rich text demo, after typing a few lines and adding a little bit of styling I tested out the undo button (on the toolbar and using "ctr+z"). The behavior was very strange. Some lines I created did not get undone and it seemed like areas of the text were getting deleted in strange places.

Enhancement: provide IndexRange for Paragraph

Would it be possible to provide indexRange for a given paragraph. This is the use case:

I have a paragraph with multiple styled text objects, each has its own. I need to change one style parameter, for example size.

I am using the styles.mapStyles method. then I apply styles to the whole text area at a given range.

I need a way to know where the given paragraph starts or end in reference to the text area. I tried to figure it out but I could not reach a solution.

Style-aware undo/redo

Current implementation of undo/redo works with plain text, which means the style information is lost when you undo and/or redo edits.

Undo Issues.

Hi Tomas,
When I undo a a step (applying a style or typing text), the strings come in correctly, but the styles do not. I am trying to figure out what styles it assigns to the text, but can't figure out a consistent pattern yet. Is this working as expected on your end?

Would this have to do with the Subscribe method?

IndexRange of style span

Hi Tomas, I have been testing this. it seems there is an issue.

In "word", if you make wo red, and detect the span index range, it will be correct,
"wo" is a range, and "rd" is a range.

but if you apply a color again to "or", so coloring should be like "w" "or" "d", and you click in "or", the span will only detect the O (from previously applied style.

Can you reproduce this?
I am using the richTextArea.getStyleRangeAtPosition(caretpos);

IndexRange and Replace Text

Question on the : inLineCSS.replaceText(indexRange, anotherString)

When I do a replace Text on a certain range, where the new inserted text length is shorter or longer than the text being replaced, Will CodeArea update the indexeRanges of successive text ranges that come after it and push them further down or up?

Override PopUp Location/ stop it from updating based on a boolean condition.

Hi Tomas,
Would it be possible to add a location override for the pop up?

This is my use case:

I am using the PopOver from controlsFX, and I like the detachable feature. So, I would like to be able to do something like this:

-If the popover is detached.. then only update content inside.. but not the position. So in this case, override the position and keep it to last moved location. So something like..
PopOver popOver = new PopOver();
richTextArea.setPopupAtCaret(popOver);
if(popOver.isDetached()){
richTextArea.setPopUpAutoLayout(false);
}
else{
richTextArea.setPopUpAutoLayout(true);
}

-If it is not detached, then update the content as well as the position. This is the default current situation.

What do you think?
Best,
Maher

MouseEvents on InLineCssTextArea

Hi Tomas,
I am trying to listen to mouse events in the inlineCSS text area, but it does not seem to trigger any event. Can you verify on your end?
Thanks,
Maher

Error when hitting ENTER within styled text

Hi Tomas,
I do the following:
-apply style to a selection of text. (all works fine and as expected). but if..:
-I go to the very end of the text (caret position is at the very end)
-Hit Enter,

I get this:
Exception in thread "JavaFX Application Thread" java.lang.IndexOutOfBoundsException
at org.fxmisc.richtext.skin.ParagraphGraphic.setCaretPosition(ParagraphGraphic.java:142)
at org.fxmisc.richtext.skin.StyledTextAreaSkin.lambda$refreshCaret$62(StyledTextAreaSkin.java:304)
at org.fxmisc.richtext.skin.StyledTextAreaSkin$$Lambda$91/1775390474.accept(Unknown Source)
at org.fxmisc.richtext.skin.MyListView.lambda$show$68(MyListView.java:55)
at org.fxmisc.richtext.skin.MyListView$$Lambda$92/380188793.accept(Unknown Source)
at org.fxmisc.richtext.skin.MyListView.lambda$null$69(MyListView.java:64)
at org.fxmisc.richtext.skin.MyListView$$Lambda$94/1788109869.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl$6$1.run(PlatformImpl.java:301)
at com.sun.javafx.application.PlatformImpl$6$1.run(PlatformImpl.java:298)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$6.run(PlatformImpl.java:298)
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.access$300(WinApplication.java:39)
at com.sun.glass.ui.win.WinApplication$4$1.run(WinApplication.java:112)
at java.lang.Thread.run(Thread.java:744)

IndexOutOfBoundsException when using positionCaret

Hi,

first of, thank you for creating this awesome project, it has helped me quite a lot! I am working on an application which displays relatively large XML files (>4000 lines) and use your component for syntax highlighting.

However, for some time now, I've run into some seemingly random exceptions when trying to move the caret to a position in the text. I get "IndexOutOfBoundsException" although the index I'm trying to jump to is perfectly within the length of the text. Additionally, the indices causing the exceptions always changing.

Here is a snippet which does the trick for me:
https://gist.github.com/kleino/33f918937db512d224e7

Question on white space.

Hi Tomas, Just a quick question in case you have any tips, How does CodeArea handle white spaces generated by tabs? I am mainly concerned about the "size" of the space. I tried to print the location of the caret, the position (column) updates by one increment whether I hit a character key, a space-bar, or a tab. If I want to rebuild the same content (more like port it ) to another Code Area, how do you suggest I keep track of the white space types (how they were generated) or their sizes? Or does java8 handle the size of the white space on its own? Thanks for your help :) Maher

ENTER key + typing..

Hi Tomas can you do the following:

-type some text.

-hit Enter in the middle of the text..

-now start typing where you hit enter. (position A)..

what I get is that anything I type gets first inserted at position A, but soon after it starts appending the text to the end of the text area.. and sometimes filckers between position A and the end of the paragraph.

Can you confirm?

Question About getText()

Hi Tomas,
Thanks for pushing the updates. I am working on my editor version from another end. Will go back to the text styling component soon. I have question about the getText() method: Basically, what does it return?

Can I use this to setText of another InLineCSSTextArea or a Paragraph and expect the styles to come in as well?

I could not find information on this in the docs. please forgive me if you have mentioned it somewhere already :)
Thanks,
Maher

EasyBind not valid

Hi Tomas,

it seems that EasyBind SNAPSHOT 1.0.0 is out of sync with the RichText implementation. The function EasyBind.supply() is missing in the latest Version.

greetings,
Roel

TextWrap Not Working.

Hi Tomas,
The richTextArea text wrapping property does not seem to work here. Can you verify that? I used the latest JAR.
Maher

API to set/get multiple style ranges at once

Being able to set multiple style ranges in one call can lead to significant performance improvement compared to multiple setStyle(...) calls each of which sets the style for a single range. This would be useful primarily for automatic syntax highlighting, where the style ranges for the whole text become available all at once (once parsing is finished).

Being able to get back all the styles in a given range comes in handy e.g. when creating a rich-text editor that wants to update its toolbar state according to the styles used in the selected range, or to change one aspect (e.g. font size) of the styles in the selected range, while keeping all other aspects unchanged.

CSS color not working on InLineCssTextArea

Hi Tomas, The InlineCssTextArea text do not seem to update its color based on the the passed CSS style string. Other properties work fine (font, size, weight, etc).

The same CSS style string works on the regular javafx TextArea.

This is what I am using for color:
"-fx-text-fill: " + getColor() + " ;"

getColor() return a color value for sure (it works fine on TextArea).

Using latest JAR 20140122
Thanks,
Maher

Add an inline style to a text segment

Is possible to add an inline style to substring? Right now, setStyle(String style) styles the whole control.

Can we get a method like?

setStyle(int from, int to, String style)

Text moves when paragraphsize exceedes the editorwindow.

First off all, a great project:

But, i've got a problem.
Wenn the current paragraphheight exceedes the editorwindow, moving the caret makes the text hop up and down .
The behaviour is reproducible in the sample implementation.
Just type a large text in one paragraph until the srollbar is shown.

NPE at javafx.scene.text.Text.getSpanBounds(Text.java:292)

Just tried to use the CodeArea inside a JFXtras-labs 8 window control. Unfortunately I get the following error:

Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
    at javafx.scene.text.Text.getSpanBounds(Text.java:292)
    at javafx.scene.text.Text.impl_computeGeomBounds(Text.java:1146)
    at javafx.scene.Node.updateGeomBounds(Node.java:3526)

JavaFX TextArea and Text nodes do work.

The error does not occur if I prevent layout calls via setManaged(false).

What I do exactly:

CodeArea textArea = new CodeArea();
textArea.replaceText("my code");

Window w = new Window("CodeEditor");
w.setPreferredSize(400,300);

// content pane is a regular stack pane
w.getContentPane().getChildren().add(textArea);

rootPane.getChildren().add(w);

I'm testing on OS X, JDK 8-b129 and the CodeAreaFX from commit b8846ca3e1fba8e4829ee3d015b305b2bf99380c

Method to get style range at the current position.

Hi Tomas,
I came across this use case. I can make a method for it, but I thought of letting you know in case you think it is worth integrating as a general purpose method.

The method would the range(start and end) of the style at a current position.

steps would something like this:
get the style at the caret position
get the boundaries of the style from the caret position: start range of style (left of caret) and end range of the style (right of caret).

Once I get that range, I can then apply additional styling. not only for that location, but for the whole range of characters to its left and right of it.

Support background color for a range of text

Hi Tomas,
I am in the process of implementing a highlighting method.
I am doing this simple code. I verified all values, they are all fine.

tempStype = "-fx-background-color: yellow;" ;
indexRange =richText.getSelection();
richText.setStyle(indexRange.getStart(), indexRange.getEnd(), tempStyle);

I notice a change in the range style, but the background is not affected. Is it broken? Can you verify?

Style At Caret Vs that of Insert(StyledDocument).

Hi Tomas,
I have the following scenario:

I create a text, style it, then save it to a clip board as a styled document.

Then i apply a different style at the caret. using:

    richTextArea.plainTextChanges().subscribe(change -> {
            int from = change.getPosition();
            int length = change.getInserted().length();
            richTextArea.setStyle(from, from + length, style);
    });

After this step, if I try to insert the styledDocument that I saved previously, it will come in using the last style applied at the caret, not its own style. So this is similar to inserting plain text.

I guess this is as expected, since the text area is subscribing to change, and any change will take in the style last applied.
I tried to do something like

        StyleSpans spans = styledDoc.getStyleSpans(0);
        richTextArea.plainTextChanges().subscribe(change -> {
            int from = change.getPosition();
            int length = change.getInserted().length();
            richTextArea.setStyleSpans(richTextArea.getCaretPosition(), spans);
        });
        richTextArea.insert(richTextArea.getCaretPosition(), styledDoc);

but with no luck. I also tried to set the subscribe to null.. but I gt an error.
is there a way to override that subscription or stop it in the event when i am inserting a styled document?

Saving to RFT. Where do I start?

Hi Tomas,
I now have a breakdown of the styled document data: string, CSS styles, and their starts and end positions. Is there a way to convert this data to an RFT file? Can you directly to a starting point to started search from?
Thanks,
Maher

Enhancement: Popup positioning.

Hi Tomas,
Thanks for adding the popup property. Would be possible to add an alignment or offset methods for that position?

Example use case: selecting a range of text. In some situations, it would make sense to have the pop up centered in the selected range horizontally, and maybe indented down a few lines vertically.. I am not sure how feasible it is to implement. but thought I'll make a suggestion.
Thanks,
Maher

Paragraphs and assembling a document.

Hi Tomas,

I am trying to achieve this functionality:

Assemble a document from other styledDocuments (text with different styles). For this, I am using the append method. This works fine, but I would like to be able to swap an appended text by another one at any point. So I was thinking maybe paragraphs is the way to go. But it does not seem to take a styledDocument.

The use case is this:
User needs to assemble document from different parts.
User needs to swap document parts (blocks of text) or change their order, etc.

Any thoughts?
Maher

Q: How to apply multiple styles at the same time ?

Hello,
I am trying to make a simple XML editor. This is the part of the code where I am trying to style the main CodeArea of the app, to have code highlight:

public static void setCurCodeArea(CodeArea newCodeArea) {

        newCodeArea.textProperty().addListener(new ChangeListener<String>() {
            @Override
            public void changed(ObservableValue<? extends String> observable, String oldText, String newText) {

                StyleSpansBuilder<Collection<String>> spansBuilder = new StyleSpansBuilder<>();

                //make the "<" and ">" blue
                Pattern arrows = Pattern.compile("\\<|\\>");
                addSpanStyle(spansBuilder, newText, arrows, "arrow");

                //make text between <>  brown
                Pattern tags = Pattern.compile("\\<(.*?)\\>");
                addSpanStyle(spansBuilder, newText, tags, "tag");

                newCodeArea.setStyleSpans(0, spansBuilder.create());
            }
        });

        curCodeArea = newCodeArea;
    }

    private static void addSpanStyle(StyleSpansBuilder<Collection<String>> spansBuilder, String newText, Pattern pattern, String spanClass) {
        Matcher matcher = pattern.matcher(newText);
        int lastKwEnd = 0;
        while (matcher.find()) {
            spansBuilder.add(Collections.emptyList(), matcher.start() - lastKwEnd);
            spansBuilder.add(Collections.singleton(spanClass), matcher.end() - matcher.start());
            lastKwEnd = matcher.end();
        }
        spansBuilder.add(Collections.emptyList(), newText.length() - lastKwEnd);
    }

And this is part of the exception StackTrace.

Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -2968
    at java.lang.String.substring(String.java:1918)
    at org.fxmisc.richtext.StyledText.subSequence(StyledText.java:59)
    at org.fxmisc.richtext.Paragraph.subSequence(Paragraph.java:153)
    at org.fxmisc.richtext.Paragraph.restyle(Paragraph.java:180)
    at org.fxmisc.richtext.EditableStyledDocument.setStyleSpans(EditableStyledDocument.java:281)
    at org.fxmisc.richtext.StyledTextArea.setStyleSpans(StyledTextArea.java:444)
    at xmltool.UIBean$1.changed(UIBean.java:37)
    at xmltool.UIBean$1.changed(UIBean.java:23)
    at com.sun.javafx.binding.ExpressionHelper$SingleChange.fireValueChangedEvent(ExpressionHelper.java:176)
    at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:80)
    at org.reactfx.inhibeans.binding.ObjectBinding.release(ObjectBinding.java:45)
    at org.reactfx.inhibeans.binding.ObjectBinding$$Lambda$69/1971275683.close(Unknown Source)
    at org.reactfx.Hold.lambda$multi$34(Hold.java:23)
    at org.reactfx.Hold$$Lambda$75/1047103664.close(Unknown Source)
    at org.fxmisc.richtext.StyledTextArea.replaceText(StyledTextArea.java:496)
    at org.fxmisc.richtext.EditActions.replaceText(EditActions.java:127)
    at xmltool.MainController.fileOpenByString(MainController.java:126)
    at xmltool.utils.UIHelperUtil.loadOpenFiles(UIHelperUtil.java:130)
    at xmltool.utils.UIHelperUtil.restoreState(UIHelperUtil.java:118)
    at xmltool.Main.initialization(Main.java:93)
    at xmltool.Main.start(Main.java:85)
    at com.sun.javafx.application.LauncherImpl$8.run(LauncherImpl.java:837)
    at com.sun.javafx.application.PlatformImpl$7.run(PlatformImpl.java:335)
    at com.sun.javafx.application.PlatformImpl$6$1.run(PlatformImpl.java:301)
    at com.sun.javafx.application.PlatformImpl$6$1.run(PlatformImpl.java:298)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl$6.run(PlatformImpl.java:298)
    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.access$300(WinApplication.java:39)
    at com.sun.glass.ui.win.WinApplication$4$1.run(WinApplication.java:112)
    ... 1 more

I guess I am not applying the multiple styles in a proper way...

Dependency issue with reactfx

I ran into an issue with my CodeArea not working when built from another machine. I think i've tracked it down to the reactfx snapshot dependency being pulled in. There was a commit to that project yesterday which of course built a new snapshot. I'm still trying to get my gradle project to pull in an older snapshot but I figure there is probably a breaking change that will need to be addressed here.

Caret Position

Hi,

First of all, nice control you got there !
I have an issue when a type the "tab" character. The caret doesn't move, but the text gets indented like it should be.

Olivier Allouch

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.