You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So, let's say I'm using a StyleClassedTextArea, and I want to change the background color of the user's current focus, based on where their caret is at the moment. I'm also doing other manipulations, so I have a function that receives a StyleSpans<Collection<String>> and is also expected to return a StyleSpans<Collection<String>> with the correct styles applied to it. This way, I can avoid multiple setStyle calls and just do it once after every processor adds or removes classes as necessary.
I'm using StyleSpans.subView(...) to scope my class additions / subtractions to a small range, but I'm not sure how to merge my changes back into the main collection after I've used mapStyles or overlay on the StyleSpans returned from the "master" StyleSpans.subView.
Here's some pseudo-code written in Kotlin if I'm not clear enough.
// Where's the caret at?val indexRange = getCurrentParagraphBasedOnEvilWizardry(textArea.selection)
// Get all the style spans in the documentval styleSpans = textArea.getStyleSpans(0, textArea.length -1)
// Remove old "focused" styling, because the user might not be on the same line anymoreval withoutFocus = styleSpans.mapStyles { /* removes "focused" class from each collection */ }
// OK, now I have a StyleSpan collection that no longer includes the "focused" class.// Let's get a subview containing just the stylespans that exist in indexRange.val subview = withoutFocus.subView(indexRange.start, indexRange.end)
// OK, now let's add the "focused" style.val newStyle =StyleSpans.singleton(/* ... */)
val withFocusSubview = subview.overlay(newStyle) { theirs, ours -> (theirs + ours) }
// OK, now we've got a StyleSpans that all have the "focused" class in them.// Now we need to go back to withoutFocus, and replace the stylespans contained within indexRange with the new ones.// Nonexistant method.return withoutFocus.replace(indexRange.start, indexRange.end, withFocusSubview);
I'm trying to avoid multiple calls to setStyle and having other components know about the textarea.
The text was updated successfully, but these errors were encountered:
Thanks. The :has-caret class might be what I need, but I'm on 0.6.10 for now. Is there also a way to style the background of paragraphs themselves in SNAPSHOT?
So, let's say I'm using a
StyleClassedTextArea
, and I want to change the background color of the user's current focus, based on where their caret is at the moment. I'm also doing other manipulations, so I have a function that receives aStyleSpans<Collection<String>>
and is also expected to return aStyleSpans<Collection<String>>
with the correct styles applied to it. This way, I can avoid multiplesetStyle
calls and just do it once after every processor adds or removes classes as necessary.I'm using
StyleSpans.subView(...)
to scope my class additions / subtractions to a small range, but I'm not sure how to merge my changes back into the main collection after I've usedmapStyles
oroverlay
on theStyleSpans
returned from the "master"StyleSpans.subView
.Here's some pseudo-code written in Kotlin if I'm not clear enough.
I'm trying to avoid multiple calls to
setStyle
and having other components know about the textarea.The text was updated successfully, but these errors were encountered: