Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undo Issues. #51

Closed
ghost opened this issue Apr 30, 2014 · 6 comments
Closed

Undo Issues. #51

ghost opened this issue Apr 30, 2014 · 6 comments

Comments

@ghost
Copy link

ghost commented Apr 30, 2014

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?

@TomasMikula
Copy link
Member

This probably has to do with plainTextChanges.subscribe(). Every undo and redo generates a text change and triggers whatever you do in subscribe (applying style in your case). So this is unlikely an undo issue.

@ghost
Copy link
Author

ghost commented Apr 30, 2014

Is there a way I can mute the subscription while doing an undo? Is there
like an undoListener? I guess I can do it by listening to the keyevents.

On Wed, Apr 30, 2014 at 9:03 AM, TomasMikula [email protected]:

Closed #51 #51.


Reply to this email directly or view it on GitHubhttps://github.com//issues/51
.

@TomasMikula
Copy link
Member

I'm afraid listening to key events yourself is currently the only way. You can open an issue on UndoFX to be able to observe whether UndoManager is actively performing a change (undo or redo).

@TomasMikula
Copy link
Member

In your subscription, you can now do the following test

if(area.getUndoManager().isPerformingAction()) {
    return;
} else {
    // handle the change
}

@ghost
Copy link
Author

ghost commented Apr 30, 2014

I'll give it a shot now

@ghost
Copy link
Author

ghost commented Apr 30, 2014

Great! works just fine!. To confirm, this is the code I have now.

richTextArea.plainTextChanges().subscribe(change -> {
        if (richTextArea.getUndoManager().isPerformingAction()) {
            return;
        } else {
            int from = change.getPosition();
            int length = change.getInserted().length();
            richTextArea.setStyle(from, from + length, styleToUse.get());
        }
    });

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

No branches or pull requests

1 participant