Skip to content

discard: Preserve transformed additions inside replacements - #457

Closed
halfline wants to merge 6 commits into
mainfrom
publish/transformed-addition-scope-20260823T171401Z
Closed

discard: Preserve transformed additions inside replacements#457
halfline wants to merge 6 commits into
mainfrom
publish/transformed-addition-scope-20260823T171401Z

Conversation

@halfline

Copy link
Copy Markdown
Owner

The discard replacement workflow saves transformed selected lines in a batch
and reverses those saved alternatives from the live worktree.

When an added line belongs to a larger old-to-new replacement, rollback can
treat its transformed wording as a separate insertion and remove it. Git may
also align replacement wording with deleted baseline text, leaving no
selectable addition row. For selected added lines inside a larger replacement,
fallback expansion can widen the selection to the complete replacement and
restore unrelated baseline content.

This pull request keeps transformed additions live during rollback,
materializes baseline-matching wording as selectable addition rows, and binds
non-empty partial selections of the added side to their resolved worktree
coordinates. Selecting the complete added side continues to use the established
whole-replacement behavior.

The functional regressions exercise the original Markdown shape, wording that
matches deleted baseline text, the full 31-line CastKMS document, growing and
shrinking replacement payloads, the complete-added-side boundary, and saved
batch replay.

Validation:

  • uv run pytest -n auto
  • uv run ruff check src tests scripts
  • uv run python scripts/check_translations.py
  • uv run python scripts/check_dead_code.py
  • uv run python scripts/check_type_hygiene.py
  • uv run mypy

The discard replacement workflow saves selected replacement text in a batch
and reverses that selection from the live worktree.

Users lose transformed wording when a selected addition extends beyond the
deleted side of a mixed replacement. The rollback treats that wording as an
independent insertion even though it belongs to the replacement already in
progress.

This commit begins preserving transformed additions by recognizing a selected
addition in a mixed replacement run and excluding its rewritten row from the
live-worktree rollback.

The next commit will exercise the retained wording before later commits
preserve its selectable identity and exact selection scope.
The discard replacement workflow retains transformed additions that extend
mixed replacement runs in the live worktree.

The functional suite does not demonstrate the multiline Markdown shape that
exposed the rollback failure. A regression could therefore remove neighboring
replacement content without detection.

This commit continues validating transformed additions with a selected
sentence beyond the deleted side of a replacement and verifies that the
surrounding list remains live.

Subsequent commits will preserve selected wording when it matches deleted
baseline text and when it occupies part of a larger added side.
The discard replacement workflow retains transformed trailing additions by
mapping their rewritten diff rows into saved batch ownership.

Git can align transformed wording with a deleted baseline line and render the
new occurrence as unchanged context. Users then cannot save the replacement
because the rewritten occurrence has no selectable addition row.

This commit continues preserving transformed additions by masking the
rewritten span while Git constructs the diff and restoring its exact bytes on
the resulting addition rows.

Subsequent commits will exercise that alignment case before preserving exact
added-line scope within larger replacements.
The discard replacement workflow retains transformed trailing additions even
when Git could align their wording with deleted baseline content.

The functional suite does not lock down that alignment case across batch
creation and later application. A regression could make the transformed
occurrence unselectable or alter the saved alternative during replay.

This commit continues regression validation by reproducing the baseline-text
collision and asserting the live file, saved batch, and replayed result.

The next code commit will preserve selected added lines that occupy only part
of a larger replacement run.
The discard replacement workflow retains transformed trailing additions and
keeps their rewritten rows selectable when the wording matches baseline text.

Users who transform selected added lines inside a larger replacement can still
lose neighboring working text because the fallback widens those lines to the
entire replacement.

This commit addresses that by keeping a non-empty selection bound to its
resolved worktree coordinates when unselected added lines remain in the same
replacement. The existing snapshot-bound buffer builder now performs that
rewrite, so its dead-code exception is no longer needed.

The final commit will exercise the full document shape, line-count changes,
the complete-added-side boundary, and saved-batch replay.
The discard replacement workflow keeps a non-empty selection of added lines
bound to its worktree coordinates when other added lines remain in the same
replacement. Selecting every added line retains the whole-replacement
behavior.

The functional suite lacks the full document shape that exposed selection
widening. It also does not pin line-count changes or the complete added side
across later batch application.

This commit completes regression validation by reproducing the 31-line
replacement, exercising selections that grow or shrink, and asserting the
complete-added-side behavior through batch creation and replay.

Discarding transformed added lines now preserves their intended scope across
ordinary wording, baseline matches, and partial added-side selections.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant