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
I want to expand my selection to a leaf but none of the available method on the change object is able target the leaves on a node (or maybe I missed it)
collapseTo{Edge}Of{Direction}Text is collapsing to the start of the text node so naturally I thought that there would be a collapseTo{Edge}Of{Direction}Leaf
I ended up creating my own function to get the range of a leaf to update my selection
I was wondering if there was a better way select a leaf other than calculate his range by adding the length of previous leaves on a text node
Here is a small snippet
const leafIndex = 3 ; //arbitrary leaf index that I want to select
const currentText = value.texts.get(0);
const leafIWantToSelect = value.texts.get(0).getLeaves().get(leafIndex);
const leavesBefore = value.texts.get(0).getLeaves().slice(0, leafIndex);
const textLengthBeforeLeaf = leavesBefore.reduce((a, leaf) => a + leaf.text.length, 0);
const selection = Range.create({
anchorKey: currentText.key,
focusKey: currentText.key,
anchorOffset:textLengthBeforeLeaf,
focusOffset: textLengthBeforeLeaf + leafIWantToSelect.text.length
});
const next = value.change().select(selection).focus();
@inkubux interesting use case, sounds like a reasonable thing to have to me! I'd accept a PR that implements them similarly to how the Text methods work.
I think Im running into a similar problem. I have text nodes that have many leaves (each leaf is a slice of the text that corresponds to a token in a query language).
When the user types, I trigger fuzzy autocompletion- which means I have to replace the content of the leaf with the new text. I couldn't find a good way to create a range around the leaf that I wanted to modify though.
My particular solution was to wrap each leaf with a mark. I added the text and offset to the data attribute on each mark . Then I used mark queries to build the range I needed. Something like editor.value.document.getMarksAtRange(editor.value.selection.toRange())
As of #3093 (which was just merged), I believe this issue is no longer applicable, because a lot has changed. I'm going through and closing out any potential issues that are not out of date with the overhaul. Thanks for understanding.
I want to expand my selection to a leaf but none of the available method on the change object is able target the leaves on a node (or maybe I missed it)
collapseTo{Edge}Of{Direction}Text is collapsing to the start of the text node so naturally I thought that there would be a collapseTo{Edge}Of{Direction}Leaf
I ended up creating my own function to get the range of a leaf to update my selection
I was wondering if there was a better way select a leaf other than calculate his range by adding the length of previous leaves on a text node
Here is a small snippet
I also have a jsfiddle with the code
[https://jsfiddle.net/fj9dvhom/917/](jsfiddle leaf playground)
Thanks a lof for your help
The text was updated successfully, but these errors were encountered: