|
1 | 1 | import {parsePatch} from './parse'; |
| 2 | +import distanceIterator from '../util/distance-iterator'; |
2 | 3 |
|
3 | 4 | export function applyPatch(source, uniDiff, options = {}) { |
4 | 5 | if (typeof uniDiff === 'string') { |
@@ -51,49 +52,6 @@ export function applyPatch(source, uniDiff, options = {}) { |
51 | 52 | return true; |
52 | 53 | } |
53 | 54 |
|
54 | | - function distanceIterator(toPos, minLine, maxLine) { |
55 | | - let wantForward = true, |
56 | | - backwardExhausted = false, |
57 | | - forwardExhausted = false, |
58 | | - localOffset = 1; |
59 | | - |
60 | | - return function iterator() { |
61 | | - if (wantForward && !forwardExhausted) { |
62 | | - if (backwardExhausted) { |
63 | | - localOffset++; |
64 | | - } else { |
65 | | - wantForward = false; |
66 | | - } |
67 | | - |
68 | | - // Check if trying to fit beyond text length, and if not, check it fits |
69 | | - // after offset location (or desired location on first iteration) |
70 | | - if (toPos + localOffset <= maxLine) { |
71 | | - return localOffset; |
72 | | - } |
73 | | - |
74 | | - forwardExhausted = true; |
75 | | - } |
76 | | - |
77 | | - if (!backwardExhausted) { |
78 | | - if (!forwardExhausted) { |
79 | | - wantForward = true; |
80 | | - } |
81 | | - |
82 | | - // Check if trying to fit before text beginning, and if not, check it fits |
83 | | - // before offset location |
84 | | - if (minLine <= toPos - localOffset) { |
85 | | - return -localOffset++; |
86 | | - } |
87 | | - |
88 | | - backwardExhausted = true; |
89 | | - return iterator(); |
90 | | - } |
91 | | - |
92 | | - // We tried to fit hunk before text beginning and beyond text lenght, then |
93 | | - // hunk can't fit on the text. Return undefined |
94 | | - }; |
95 | | - } |
96 | | - |
97 | 55 | // Search best fit offsets for each hunk based on the previous ones |
98 | 56 | for (let i = 0; i < hunks.length; i++) { |
99 | 57 | let hunk = hunks[i], |
|
0 commit comments