Skip to content

fix: level sibling lines when rebasing a charwise block - #21

Merged
nemanjamalesija merged 1 commit into
mainfrom
fix/charwise-sibling-rebase
Jul 5, 2026
Merged

nemanjamalesija merged 1 commit into
mainfrom
fix/charwise-sibling-rebase

Conversation

@nemanjamalesija

Copy link
Copy Markdown
Owner

Refs #17, does not close it, waiting for reporter confirmation. Builds on the trailing comment fix branch, merge that one first.

A charwise yank that starts mid line drops the first line's leading whitespace, so the paste conversion has to guess the block's structure. The old guess always nested the inner lines under line 1, which over indented siblings:

yank 'bar()' + '    baz()' charwise, ]p gave
bar()
    baz()

rebase_charwise_block now checks whether the first line looks like a scope opener. Opener looking first lines (if x:, foo() {, tag openers) keep the nesting guess. Non opener first lines are rebased to the minimum inner indent so siblings land level. Blank first lines keep the old behavior since they carry no evidence either way.

Known tradeoff, stated in the doc comment: continuation constructs whose first line does not end in an opener token (aligned call arguments, method chains) are now leveled too. The structure is genuinely ambiguous once the first line's indent is gone.

Tests: four new regression cases including the reported sibling scenario and a blank first line guard. Full suite green.

A charwise yank that starts mid-line drops the first line's leading
whitespace, so rebase_charwise_block has to guess where that line sat
relative to the inner lines. The old guess treated every block that
never dedents below its first inner indent as an opener plus nested
body, which over-indented sibling statements by the block's original
base after the shift to the target indent.

Ask the scope-opener heuristics about the stripped first line instead:
opener-looking lines (trailing brace/colon, keyword openers, tag
openers) keep the nesting guess, while anything else is re-padded to
the minimum inner indent so siblings land level after the uniform
delta. The caller now passes its buffer through so the heuristics read
the right commentstring. Still a guess, but it matches the common yank
patterns far better.

Refs #17
@nemanjamalesija
nemanjamalesija deleted the branch main July 5, 2026 11:58
@nemanjamalesija
nemanjamalesija changed the base branch from fix/trailing-comment-scope-detection to main July 5, 2026 11:59
@nemanjamalesija
nemanjamalesija merged commit 1ac5ef4 into main Jul 5, 2026
6 checks passed
@nemanjamalesija
nemanjamalesija deleted the fix/charwise-sibling-rebase branch July 5, 2026 12:01
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