Giter Club home page Giter Club logo

Comments (6)

 avatar commented on May 13, 2024

(update: cleaned up comments)
if I apply a style using the method below, which relies on applying a style to a rang, I do not run into the problem above.

I apply a style to a range. Range is is defined by adding white space when needed ( if the caret happens to be at the end) or by coloring the character before the caret. (not the best behavior I admit).

       //if caret is at the end.. then add a white space
       if (richTextArea.getCaretPosition() == richTextArea.getLength()) {
           richTextArea.appendText(" ");
        }
       richTextArea.setStyle(richTextArea.getCaretPosition(), richTextArea.getCaretPosition()+1, style); 

Because this does not utilize the subscribe to change method, I can append styled documents and have them come in with their styles. The problem with it is that it is not as clean.

Would it be possible to add a method that will unsubscribe, or override caret style, append styled document, then revert caret style. Not sure what the best behavior is. What do you suggest? :/

from richtextfx.

TomasMikula avatar TomasMikula commented on May 13, 2024

Hi Maher,

subscribe returns a Subscription which you can use to unsubscribe (forever):

Subscription sub = area.plainTextChanges().subscribe(...);

// when no longer interested in changes
sub.unsubscribe();

To ignore changes temporarily, you can do this

InterceptableEventStream<PlainTextChange> changes =
        richTextArea.plainTextChanges().interceptable();

changes.subscribe(change -> {
    // handle the change
});

// ignore changes while inserting styled document
changes.muteWhile(() -> {
    richTextArea.insert(index, document);
});

or this

Indicator ignoreChanges = new Indicator();

richTextArea.plainTextChanges().subscribe(change -> {
    if(ignoreChanges.isOff()) {
        // handle the change
    }
});

// ignore changes while inserting styled document
ignoreChanges.onWhile(() -> {
    richTextArea.insert(index, document);
});

from richtextfx.

 avatar commented on May 13, 2024

Thanks!

On Tue, Apr 22, 2014 at 7:11 PM, TomasMikula [email protected]:

Hi Maher,

subscribe returns a Subscription which you can use to unsubscribe
(forever):

Subscription sub = area.plainTextChanges().subscribe(...);
// when no longer interested in changessub.unsubscribe();

To ignore changes temporarily, you can do this

InterceptableEventStream changes =
richTextArea.plainTextChanges().interceptable();
changes.subscribe(change -> {
// handle the change});
// ignore changes while inserting styled documentchanges.muteWhile(() -> {
richTextArea.insert(index, document);});

or this

Indicator ignoreChanges = new Indicator();
richTextArea.plainTextChanges().subscribe(change -> {
if(ignoreChanges.isOff()) {
// handle the change
}});
// ignore changes while inserting styled documentignoreChanges.onWhile(() -> {
richTextArea.insert(index, document);});


Reply to this email directly or view it on GitHubhttps://github.com//issues/46#issuecomment-41117645
.

from richtextfx.

 avatar commented on May 13, 2024

I tried the :

InterceptableEventStream changes =
richTextArea.plainTextChanges().interceptable();

changes.subscribe(change -> {
// handle the change
});

it worked, but the unsubscribe didn't. I can;t seem to unsubscribe.

The process is this:

I create a view port, which as a text area, and declare subscription
object: subtoChange.

Also a bunch of styling buttons are created.

When style parameter button is pressed. the subscription object gets
initialized.

So it happens the first time, and continues to be reset again, every time a
styling button is pressed.

   editor.subtoChange

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

and when I want to insert a styled document, I do this

        editor.subtoChange.unsubscribe();

editor.richTextArea.insert(editor.richTextArea.getCaretPosition(),
styledDoc);

do you see anything incorrect in the process?

On Tue, Apr 22, 2014 at 7:14 PM, Maher Elkhaldi [email protected]:

Thanks!

On Tue, Apr 22, 2014 at 7:11 PM, TomasMikula [email protected]:

Hi Maher,

subscribe returns a Subscription which you can use to unsubscribe
(forever):

Subscription sub = area.plainTextChanges().subscribe(...);
// when no longer interested in changessub.unsubscribe();

To ignore changes temporarily, you can do this

InterceptableEventStream changes =
richTextArea.plainTextChanges().interceptable();
changes.subscribe(change -> {
// handle the change});
// ignore changes while inserting styled documentchanges.muteWhile(() -> {
richTextArea.insert(index, document);});

or this

Indicator ignoreChanges = new Indicator();
richTextArea.plainTextChanges().subscribe(change -> {
if(ignoreChanges.isOff()) {
// handle the change
}});
// ignore changes while inserting styled documentignoreChanges.onWhile(() -> {
richTextArea.insert(index, document);});


Reply to this email directly or view it on GitHubhttps://github.com//issues/46#issuecomment-41117645
.

from richtextfx.

 avatar commented on May 13, 2024

on a second thought i think I know why.

I am inserting at the end of a document. so if my guess is correct, when
inserting, it pushes the caret (which has an older style) and inserts
inside. so when done inserting.. and I type again after the inserted
document, i will be typing within the old style.

Is my guess correct?

On Tue, Apr 22, 2014 at 8:32 PM, Maher Elkhaldi [email protected]:

I tried the :

InterceptableEventStream changes =
richTextArea.plainTextChanges().interceptable();

changes.subscribe(change -> {
// handle the change
});

it worked, but the unsubscribe didn't. I can;t seem to unsubscribe.

The process is this:

I create a view port, which as a text area, and declare subscription
object: subtoChange.

Also a bunch of styling buttons are created.

When style parameter button is pressed. the subscription object gets
initialized.

So it happens the first time, and continues to be reset again, every time
a styling button is pressed.

   editor.subtoChange

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

and when I want to insert a styled document, I do this

        editor.subtoChange.unsubscribe();

editor.richTextArea.insert(editor.richTextArea.getCaretPosition(),
styledDoc);

do you see anything incorrect in the process?

On Tue, Apr 22, 2014 at 7:14 PM, Maher Elkhaldi [email protected]:

Thanks!

On Tue, Apr 22, 2014 at 7:11 PM, TomasMikula [email protected]:

Hi Maher,

subscribe returns a Subscription which you can use to unsubscribe
(forever):

Subscription sub = area.plainTextChanges().subscribe(...);
// when no longer interested in changessub.unsubscribe();

To ignore changes temporarily, you can do this

InterceptableEventStream changes =
richTextArea.plainTextChanges().interceptable();
changes.subscribe(change -> {
// handle the change});
// ignore changes while inserting styled documentchanges.muteWhile(() -> {
richTextArea.insert(index, document);});

or this

Indicator ignoreChanges = new Indicator();
richTextArea.plainTextChanges().subscribe(change -> {
if(ignoreChanges.isOff()) {
// handle the change
}});
// ignore changes while inserting styled documentignoreChanges.onWhile(() -> {
richTextArea.insert(index, document);});


Reply to this email directly or view it on GitHubhttps://github.com//issues/46#issuecomment-41117645
.

from richtextfx.

TomasMikula avatar TomasMikula commented on May 13, 2024

Calling subscribe multiple times does not reset the subscription, but registers a new one every time. You only unsubscribe the latest one.

You shouldn't call subscribe multiple times, once is enough, when you set up the scene. If you subscribe on every button click, it means the subscription code will be executed many times on every change. This will eventually consume too much CPU as well as memory.

from richtextfx.

Related Issues (20)

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.