fix(hashline-edit): correct offset advancement and fuzzy index mapping in merge expand

- Track matchedLen separately for stripped continuation token matches
- Map fuzzy index back to original string position via character-by-character
  scan that skips operator chars, fixing positional correctness
This commit is contained in:
YeonGyu-Kim 2026-02-22 14:50:59 +09:00
parent 9390f98f01
commit ac81e1d7cd

View File

@ -78,18 +78,28 @@ export function maybeExpandSingleLineMerge(
let orderedMatch = true
for (const part of parts) {
let idx = merged.indexOf(part, offset)
let matchedLen = part.length
if (idx === -1) {
const stripped = stripTrailingContinuationTokens(part)
if (stripped !== part) {
idx = merged.indexOf(stripped, offset)
if (idx !== -1) matchedLen = stripped.length
}
}
if (idx === -1) {
const mergeStripped = stripMergeOperatorChars(merged.slice(offset))
const segment = merged.slice(offset)
const segmentStripped = stripMergeOperatorChars(segment)
const partStripped = stripMergeOperatorChars(part)
const fuzzyIdx = mergeStripped.indexOf(partStripped)
const fuzzyIdx = segmentStripped.indexOf(partStripped)
if (fuzzyIdx !== -1) {
idx = offset + fuzzyIdx
let strippedPos = 0
let originalPos = 0
while (strippedPos < fuzzyIdx && originalPos < segment.length) {
if (!/[|&?]/.test(segment[originalPos])) strippedPos += 1
originalPos += 1
}
idx = offset + originalPos
matchedLen = part.length
}
}
if (idx === -1) {
@ -97,7 +107,7 @@ export function maybeExpandSingleLineMerge(
break
}
indices.push(idx)
offset = idx + part.length
offset = idx + matchedLen
}
const expanded: string[] = []