Hi, glad you are trying out the API.
This is just an over site on my part. There’s tons of API and I figured better to just start with a little and expand out instead of include everything. But yes consider
Editor#collapseNode public, I’ll document it soon. Basically collapse node should be pretty strait forward… works like in an outliner. It will “collapse” the node, hiding all of the nodes children in a fold at the end of the nodes line.
Editor#hideNodes is a bit different and not as well tested. I just wrote it for a specific case. But what it does is add folds to hide all nodes (it takes an array) passed into it. It hides them by adding folds (folds can be added anywhere, not just along hierarchy lines. Be happy make this public if/when someone needs it, but will probably leave private until then.
I’m not sure I follow. You mean the part of your code that’s doing
forEachNodeInRange? If you just want to get a single node from the selection you can do
range.startNode. That will return the node where the range starts. I don’t see your code trying to create a range… but if you want to create a range from a node you can do
I think the parts that’s tripping you up is that all of your changes are bracketed in
endUpdates (that’s a good thing) BUT also your call to
Editor#collapseNode is in that update group. And that creates a problem because until
endUpdates is called the
Editor won’t know about the changes you’ve made.
Editor#collapseNode out of the updates block and it should work better, though I’m not certain it’s doing what you want yet.
Anyway… I’m definitely rambling now. I’ve created an updated version of your script here which “might” do what you were trying to do. Please ask again if I didn’t answer all of your questions.