Repository navigation
fix: preserve relative indent when pasting multi-line charwise blocks (]p/[p) - #14
Merged
Merged
Conversation
Charwise selections (e.g. `^v...y`) drop the first line's leading whitespace but keep the inner lines' absolute indent. ]p / [p then shifted every line by a single delta, which over-indented the inner lines by the block's original base indent -- visible in JSX/TSX where copying a `<Foo>...</Foo>` block and pasting it landed the children and closing tag too deep. When a block dedents back below its first inner line (a closing tag or brace), reconstruct the first line's base from the block's minimum inner indent before shifting, so the block's relative structure is preserved. Blocks that never dedent (e.g. `if x:` + body) keep the first line at column 0, matching previous behaviour. Fixes #11
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #11.
The real bug
Cause
A charwise selection (e.g.
^v...y) drops the first line's leading whitespace, but the inner lines keep their absolute indent. The]p/[ppath then shifted every line by a single delta computed from the first line — so the inner lines got the block's original base indent counted twice. (Vim's native]phas the same flaw; smart-paste should do better.)"Copying the whole line" worked because that's a linewise yank, which keeps the first line's indent and goes through a different path.
Fix
When a block dedents back below its first inner line (a closing tag/brace — the normal shape of a JSX element,
{},()block), the first line is an opener whose true base equals the block's minimum inner indent. Reconstruct it to that base before shifting, so the block's relative structure is preserved.Blocks that never dedent (e.g.
if x:+ body, where the first line genuinely sits at column 0) keep the first line at 0 — existing behavior is unchanged.After:
Tests
indent_spec.lua: unit tests for the newrebase_charwise_block(dedenting block, non-dedenting block, single line).charwise_paste_spec.lua:]pof a multi-line block from a mid-line charwise selection now matches the original structure instead of over-indenting.All existing specs and integration checks pass.