MCPcopy Index your code
hub / github.com/nodejs/node / adjustIntersectingElement

Function adjustIntersectingElement

test/fixtures/snapshot/typescript.js:38504–38570  ·  view source on GitHub ↗
(element, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta)

Source from the content-addressed store, hash-verified

38502 return false;
38503 }
38504 function adjustIntersectingElement(element, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta) {
38505 ts.Debug.assert(element.end >= changeStart, "Adjusting an element that was entirely before the change range");
38506 ts.Debug.assert(element.pos <= changeRangeOldEnd, "Adjusting an element that was entirely after the change range");
38507 ts.Debug.assert(element.pos <= element.end);
38508 // We have an element that intersects the change range in some way. It may have its
38509 // start, or its end (or both) in the changed range. We want to adjust any part
38510 // that intersects such that the final tree is in a consistent state. i.e. all
38511 // children have spans within the span of their parent, and all siblings are ordered
38512 // properly.
38513 // We may need to update both the 'pos' and the 'end' of the element.
38514 // If the 'pos' is before the start of the change, then we don't need to touch it.
38515 // If it isn't, then the 'pos' must be inside the change. How we update it will
38516 // depend if delta is positive or negative. If delta is positive then we have
38517 // something like:
38518 //
38519 // -------------------AAA-----------------
38520 // -------------------BBBCCCCCCC-----------------
38521 //
38522 // In this case, we consider any node that started in the change range to still be
38523 // starting at the same position.
38524 //
38525 // however, if the delta is negative, then we instead have something like this:
38526 //
38527 // -------------------XXXYYYYYYY-----------------
38528 // -------------------ZZZ-----------------
38529 //
38530 // In this case, any element that started in the 'X' range will keep its position.
38531 // However any element that started after that will have their pos adjusted to be
38532 // at the end of the new range. i.e. any node that started in the 'Y' range will
38533 // be adjusted to have their start at the end of the 'Z' range.
38534 //
38535 // The element will keep its position if possible. Or Move backward to the new-end
38536 // if it's in the 'Y' range.
38537 var pos = Math.min(element.pos, changeRangeNewEnd);
38538 // If the 'end' is after the change range, then we always adjust it by the delta
38539 // amount. However, if the end is in the change range, then how we adjust it
38540 // will depend on if delta is positive or negative. If delta is positive then we
38541 // have something like:
38542 //
38543 // -------------------AAA-----------------
38544 // -------------------BBBCCCCCCC-----------------
38545 //
38546 // In this case, we consider any node that ended inside the change range to keep its
38547 // end position.
38548 //
38549 // however, if the delta is negative, then we instead have something like this:
38550 //
38551 // -------------------XXXYYYYYYY-----------------
38552 // -------------------ZZZ-----------------
38553 //
38554 // In this case, any element that ended in the 'X' range will keep its position.
38555 // However any element that ended after that will have their pos adjusted to be
38556 // at the end of the new range. i.e. any node that ended in the 'Y' range will
38557 // be adjusted to have their end at the end of the 'Z' range.
38558 var end = element.end >= changeRangeOldEnd ?
38559 // Element ends after the change range. Always adjust the end pos.
38560 element.end + delta :
38561 // Element ends in the change range. The element will keep its position if

Callers 2

visitNodeFunction · 0.85
visitArrayFunction · 0.85

Calls 2

assertMethod · 0.80
minMethod · 0.45

Tested by

no test coverage detected