(ctx, node, startPoint, endPoint)
| 140 | } |
| 141 | |
| 142 | function _findBestMatch(ctx, node, startPoint, endPoint) { |
| 143 | if (!(node instanceof Element)) return null; |
| 144 | var softMatch = null, displaceMatchCount = 0, scanLimit = 10; |
| 145 | var newSet = ctx.idMap.get(node), nodeMatchCount = newSet?.size || 0; |
| 146 | if (node.id && !newSet) return null; |
| 147 | var cursor = startPoint; |
| 148 | while (cursor && cursor !== endPoint) { |
| 149 | var oldSet = ctx.idMap.get(cursor); |
| 150 | if (_isSoftMatch(cursor, node)) { |
| 151 | if (oldSet && newSet && [...oldSet].some(id => newSet.has(id))) return cursor; |
| 152 | if (!oldSet) { |
| 153 | if (scanLimit > 0 && cursor.isEqualNode(node)) return cursor; |
| 154 | if (!softMatch) softMatch = cursor; |
| 155 | } |
| 156 | } |
| 157 | displaceMatchCount += oldSet?.size || 0; |
| 158 | if (displaceMatchCount > nodeMatchCount) break; |
| 159 | if (cursor.contains(document.activeElement)) break; |
| 160 | if (--scanLimit < 1 && nodeMatchCount === 0) break; |
| 161 | cursor = cursor.nextSibling; |
| 162 | } |
| 163 | if (softMatch && _matchesUpcomingSibling(ctx, softMatch, node)) return null; |
| 164 | return softMatch; |
| 165 | } |
| 166 | |
| 167 | function _matchesUpcomingSibling(ctx, oldElt, startNode) { |
| 168 | if (ctx.futureMatches.has(oldElt)) return true; |
no test coverage detected