Comments (6)
(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.
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.
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.
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.
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.
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)
- SetPlaceholder is invalid and does not display placeholders HOT 6
- After adding inner margins to CodeArea, VirtualizedScrollPanel displays abnormally HOT 6
- ScrollPanel embedded with VirtualizedScrollPanel's rolling solution HOT 2
- Is there a built-in and universal code keyword highlighted? HOT 1
- 'Variables' in rich text HOT 2
- getTotalAreaWidthEstimate() HOT 1
- How to refresh/redraw the area? HOT 2
- Question: what is the best practice for frequently changed text? HOT 5
- Question: How to keep the selection when append text? HOT 2
- GenericStyledArea adding inappropriate character when using a different keyboard setup HOT 3
- Question: InlineCssTextArea for appending 100 000 lines HOT 2
- How to set the size of tab in CodeArea? HOT 2
- StyleClassedTextArea + PageUp/PageDown -> NoSuchElementException + IndexOutOfBoundsException HOT 3
- Question: xml highlighter gives StackOverflowError HOT 2
- Question: How to move selected code right/left using Tab/Shift+Tab? HOT 3
- Question: How to show vertical lines in CodeArea for indentations? HOT 6
- Question: How to set selection color via code or CSS? HOT 4
- Question: how I can use InlineCssTextField with multiple color and pattern text please HOT 3
- Question: codeArea.removeSelection delayed display HOT 1
- CodeArea seems to intercept the input method, preventing it from being passed to other TextFields.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from richtextfx.