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

request: add index range property to styled text #33

Closed
ghost opened this issue Apr 10, 2014 · 8 comments
Closed

request: add index range property to styled text #33

ghost opened this issue Apr 10, 2014 · 8 comments

Comments

@ghost
Copy link

ghost commented Apr 10, 2014

Hi Tomas, Would it be possible to add an index range property to the styled text objects?
Maher

@TomasMikula
Copy link
Member

Hi Maher,

thanks for asking, but this is not possible. The reason is that StyledTexts are moved around as text is inserted and deleted to and from text area. Imagine a text area with 1 million StyledTexts and insert one character at position 0. You would have to update all 1 million ranges. Another nice property about StyledTexts as they are is immutability. Immutability enables, for example, that the same StyledText instance can be in two different text areas at two different positions at the same time.

@ghost
Copy link
Author

ghost commented Apr 10, 2014

Thanks! What is immutability?
On Apr 10, 2014 2:10 PM, "TomasMikula" notifications@github.com wrote:

Hi Maher,

thanks for asking, but this is not possible. The reason is that
StyledTexts are moved around as text is inserted and deleted to and from
text area. Imagine a text area with 1 million StyledTexts and insert one
character at position 0. You would have to update all 1 million ranges.
Another nice property about StyledTexts as they are is immutability.

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

@ghost
Copy link
Author

ghost commented Apr 10, 2014

Oh ok. Got it :)
Sorry ... Not sleeping.
On Apr 10, 2014 2:12 PM, "Maher Elkhaldi" m.s.khaldi@gmail.com wrote:

Thanks! What is immutability?
On Apr 10, 2014 2:10 PM, "TomasMikula" notifications@github.com wrote:

Hi Maher,

thanks for asking, but this is not possible. The reason is that
StyledTexts are moved around as text is inserted and deleted to and from
text area. Imagine a text area with 1 million StyledTexts and insert one
character at position 0. You would have to update all 1 million ranges.
Another nice property about StyledTexts as they are is immutability.

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

@ghost
Copy link
Author

ghost commented Apr 11, 2014

Hi Tomas, I made a subclass of StyledText with range info, and a method to
update the the range info for these ranges. When invoking the method upon
typing into the text area, things get really slow as you said. Now I invoke
it only when a style is applied, which makes sense. The speed is almost the
same.

How about adding an index range property that only updates when it gets
called by the user? Is there such a thing?

On Thu, Apr 10, 2014 at 2:14 PM, Maher Elkhaldi m.s.khaldi@gmail.comwrote:

Oh ok. Got it :)
Sorry ... Not sleeping.
On Apr 10, 2014 2:12 PM, "Maher Elkhaldi" m.s.khaldi@gmail.com wrote:

Thanks! What is immutability?
On Apr 10, 2014 2:10 PM, "TomasMikula" notifications@github.com wrote:

Hi Maher,

thanks for asking, but this is not possible. The reason is that
StyledTexts are moved around as text is inserted and deleted to and from
text area. Imagine a text area with 1 million StyledTexts and insert one
character at position 0. You would have to update all 1 million ranges.
Another nice property about StyledTexts as they are is immutability.

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

@TomasMikula
Copy link
Member

Hi Maher,

I don't think it's a good idea for StyledText to know its position within text area. What is your use case? Maybe we can come up with an alternative solution.

@ghost
Copy link
Author

ghost commented Apr 11, 2014

Hi Tomas,
I ran into this when I tried to apply a size to a collection of styled
texts.

For example: Maher (in bold) and sami (in normal). These technically two
different styled texts.

Now i want to increase the size of "er sa". This requires that u get the
style for each styledtext and its range.

So i get the style from Maher, build a new one with a new size, then apply
it based in the selection.. Which starts at er.
And to make sure that I apply the style only to er not the whole selection.
I need to know where the styled text ends so that I do the same process for
sami, which has a different style base all together

To do that, I made a method that rebuilds a collection if all styled texts
with their ranges every time I apply a style-- change the segments in a
paragraph.

This way I can apply specific styling parameters to any selection in text
and update the specific property of each styletext segment correctly.

That was part of my question about how the data is structured and what
happens when I apply a style to a text. I figured since it splits a segment
into other segments.. Then I need to get the started and ends of each
segment when the structure changes..which is when a style is applied.

Might be over engineered as a solution. But I am not a programmer.. More
like a guy wrestling with java on a daily basis to make a prototype :D
On Apr 10, 2014 7:37 PM, "TomasMikula" notifications@github.com wrote:

Hi Maher,

I don't think it's a good idea for StyledText to know its position within
text area. What is your use case? Maybe we can come up with an alternative
solution.

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

@TomasMikula
Copy link
Member

You should do something like this:

IndexRange range = area.getSelection();
StyleSpans<String> styles = area.getStyleSpans(range);
StyleSpans<String> newStyles = styles.mapStyles(css -> css + "-fx-font-size: 32pt;");
area.setStyleSpans(range.getStart(), newStyles);

@ghost
Copy link
Author

ghost commented Apr 11, 2014

oh my God!
this is why you're you!

On Thu, Apr 10, 2014 at 8:08 PM, TomasMikula notifications@github.comwrote:

You should do something like this:

IndexRange range = area.getSelection();StyleSpans styles = area.getStyleSpans(range);StyleSpans newStyles = styles.mapStyles(css -> css + "-fx-font-size: 32pt;");area.setStyleSpans(range.getStart(), newStyles);

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

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