FAILURE MAP
← Case archive

FA-7926 / Text editing / Open access

Text selection replacement: The caret is positioned using the deleted range length · case 01

The caret is positioned using the deleted range length.

Verified by executionVariant 1 · 8 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

The caret operation uses `hi + len(replacement)` where the contract requires `lo + len(replacement)`.

THE FAILURE

The caret operation uses `hi + len(replacement)` where the contract requires `lo + len(replacement)`.

Unsuccessful approach: Leaving the caret at insertion start makes subsequent typing precede the replacement.

Case contract

Composition is preserved; replace the normalized half-open selection and collapse both endpoints immediately after inserted text.

Why this case matters

A deterministic model of text selection replacement; this isolates one interface invariant without requiring a browser.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(text, anchor, focus, replacement, composing):
    if composing: return (text, anchor, focus)
    lo = min(anchor, focus)
    hi = max(anchor, focus)
    result = text[:lo] + replacement + text[hi:]
    caret = hi + len(replacement)
    return (result, caret, caret)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('composition', solve('abcdef', 1, 4, 'XY', True), ('abcdef', 1, 4))
check('forward', solve('abcdef', 1, 4, 'XY', False), ('aXYef', 3, 3))
check('backward', solve('abcdef', 4, 1, 'XY', False), ('aXYef', 3, 3))
check('insertion', solve('ab', 1, 1, 'XYZ', False), ('aXYZb', 4, 4))
check('delete', solve('abc', 0, 3, '', False), ('', 0, 0))
check('no selection', solve('abc', 2, 2, '', False), ('abc', 2, 2))
check('parameterized selected length', solve('a'*N, 0, N, 'X', False), ('X', 1, 1))
for repetition in range(N):
    check('repeat no selection', solve('abc', 2, 2, '', False), ('abc', 2, 2))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
composition['abcdef', 1, 4]['abcdef', 1, 4]Passed
forward['aXYef', 6, 6]['aXYef', 3, 3]Failed
backward['aXYef', 6, 6]['aXYef', 3, 3]Failed
insertion['aXYZb', 4, 4]['aXYZb', 4, 4]Passed
delete['', 3, 3]['', 0, 0]Failed
no selection['abc', 2, 2]['abc', 2, 2]Passed
parameterized selected length['X', 2, 2]['X', 1, 1]Failed
repeat no selection['abc', 2, 2]['abc', 2, 2]Passed

SHA-256 / 0a016a7aa5d722790b2583ea2cd93467123084014f1e0d94fb7691e027b52c9e

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(text, anchor, focus, replacement, composing):
    if composing: return (text, anchor, focus)
    lo = min(anchor, focus)
    hi = max(anchor, focus)
    result = text[:lo] + replacement + text[hi:]
    caret = lo
    return (result, caret, caret)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('composition', solve('abcdef', 1, 4, 'XY', True), ('abcdef', 1, 4))
check('forward', solve('abcdef', 1, 4, 'XY', False), ('aXYef', 3, 3))
check('backward', solve('abcdef', 4, 1, 'XY', False), ('aXYef', 3, 3))
check('insertion', solve('ab', 1, 1, 'XYZ', False), ('aXYZb', 4, 4))
check('delete', solve('abc', 0, 3, '', False), ('', 0, 0))
check('no selection', solve('abc', 2, 2, '', False), ('abc', 2, 2))
check('parameterized selected length', solve('a'*N, 0, N, 'X', False), ('X', 1, 1))
for repetition in range(N):
    check('repeat no selection', solve('abc', 2, 2, '', False), ('abc', 2, 2))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
composition['abcdef', 1, 4]['abcdef', 1, 4]Passed
forward['aXYef', 1, 1]['aXYef', 3, 3]Failed
backward['aXYef', 1, 1]['aXYef', 3, 3]Failed
insertion['aXYZb', 1, 1]['aXYZb', 4, 4]Failed
delete['', 0, 0]['', 0, 0]Passed
no selection['abc', 2, 2]['abc', 2, 2]Passed
parameterized selected length['X', 0, 0]['X', 1, 1]Failed
repeat no selection['abc', 2, 2]['abc', 2, 2]Passed

SHA-256 / 1012172de9d9583b5222f6edf434c4646264055fc077f1ff1ec18cf5997a5b23

HELD IN THE MEMBER ARCHIVE

The verified repair and its recorded checks are member-only.

This mechanism has 8 recorded checks per implementation. The open-access tier publishes the failure and the unsuccessful fix; the repaired source that passes every check, and the observations that prove it, are available to members.

Every case sharing this mechanism uses the same contract and the same repair, so this one record is held back for all of them.

Member access is invitation-based. Sign in with your invited account to inspect the repair.

Sign in to the archive ↗

Verification & scope

This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:38:16.617078+00:00.

Case digest / 692d76f4fdbaf9be892d96a2408040d75928a4842989315853380fd4c68900fe