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

Method to get style range at the current position. #26

Closed
ghost opened this issue Mar 20, 2014 · 4 comments
Closed

Method to get style range at the current position. #26

ghost opened this issue Mar 20, 2014 · 4 comments

Comments

@ghost
Copy link

ghost commented Mar 20, 2014

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.

@TomasMikula TomasMikula changed the title Method suggestion. Method to get style range at the current position. Mar 20, 2014
@TomasMikula
Copy link
Member

Hi Maher,

I could add such a method, I'm just not quite convinced about its general usefulness.

The use-case you mention can get more tricky. Imagine, for example, that you have the word
anti-oxidants
with caret positioned in the "oxidants" part. Imagine that you want to turn off the bold face. The method you suggest would return the range for the part "-oxidants" (since anti has a different style), thus resulting in
anti-oxidants
instead of
anti-oxidants.

@ghost
Copy link
Author

ghost commented Apr 5, 2014

Hi Tomas, sorry writing late. This is a use case that would benefit from such a method. I managed to make a sketchy method that does the detection.

Use case description:
Precondition: Have a number of saved CSS styles.
Purpose: iterate through the styles over text.

Steps:
Step0: save styles to a "gallery".
Step1: make a text selection ... or click somewhere in text and the code will detect the span based on the caret position.
Step2: scroll the mouse wheel , which will change the style of the selected text or the detected span as per the saved styles.

@TomasMikula
Copy link
Member

You should now be able to use

IndexRange range = area.getStyleRangeAtPosition(area.getCaretPosition());
area.setStyle(range.getStart(), range.getEnd(), newStyle);

@ghost
Copy link
Author

ghost commented Apr 14, 2014

Thanks :)
I will remove my patchy method now and that one liner of yours!

On Mon, Apr 14, 2014 at 2:49 PM, TomasMikula notifications@github.comwrote:

You should now be able to use

IndexRange range = area.getStyleRangeAtPosition(area.getCaretPosition());area.setStyle(range.getStart(), range.getEnd(), newStyle);


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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant