MCPcopy Create free account
hub / github.com/bigcode-project/jupytercoder / distanceIterator

Function distanceIterator

src/diff.js:715–754  ·  view source on GitHub ↗
(start, minLine, maxLine)

Source from the content-addressed store, hash-verified

713 // by distance from a given start position. I.e. for [0, 4], with
714 // start of 2, this will iterate 2, 3, 1, 4, 0.
715 function distanceIterator (start, minLine, maxLine) {
716 var wantForward = true,
717 backwardExhausted = false,
718 forwardExhausted = false,
719 localOffset = 1;
720 return function iterator() {
721 if (wantForward && !forwardExhausted) {
722 if (backwardExhausted) {
723 localOffset++;
724 } else {
725 wantForward = false;
726 } // Check if trying to fit beyond text length, and if not, check it fits
727 // after offset location (or desired location on first iteration)
728
729
730 if (start + localOffset <= maxLine) {
731 return localOffset;
732 }
733
734 forwardExhausted = true;
735 }
736
737 if (!backwardExhausted) {
738 if (!forwardExhausted) {
739 wantForward = true;
740 } // Check if trying to fit before text beginning, and if not, check it fits
741 // before offset location
742
743
744 if (minLine <= start - localOffset) {
745 return -localOffset++;
746 }
747
748 backwardExhausted = true;
749 return iterator();
750 } // We tried to fit hunk before text beginning and beyond text length, then
751 // hunk can't fit on the text. Return undefined
752
753 };
754 }
755
756 function applyPatch(source, uniDiff) {
757 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

Callers 1

applyPatchFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected