Skip to content

Use transform_region() for prettify/unprettify#1645

Merged
rolandwalker merged 1 commit intomainfrom
RW/use-transform-region-for-prettify-bindings
Feb 28, 2026
Merged

Use transform_region() for prettify/unprettify#1645
rolandwalker merged 1 commit intomainfrom
RW/use-transform-region-for-prettify-bindings

Conversation

@rolandwalker
Copy link
Contributor

@rolandwalker rolandwalker commented Feb 27, 2026

Description

This method is built in to prompt_toolkit, and simpler. The position of the cursor in the transformed text is still not precise, as expected. (It wasn't precise before.)

xref #1646 covers the bot's main issue.

Checklist

  • I added this contribution to the changelog.md file.
  • I added my name to the AUTHORS file (or it's already there).
  • To lint and format the code, I ran
    uv run ruff check && uv run ruff format && uv run mypy --install-types .

@rolandwalker rolandwalker self-assigned this Feb 27, 2026
@github-actions
Copy link

  1. High: parse failures now wipe the entire query buffer
  • In key_bindings.py and key_bindings.py, transform_region(...) is called unconditionally when buffer is non-empty.
  • handle_prettify_binding() / handle_unprettify_binding() return "" on parse failure (main.py, main.py).
  • Before this PR, empty result was explicitly ignored, preserving user text; now failed prettify/unprettify can replace the whole buffer with empty text (data loss regression).
  • Action: keep old guard behavior by only applying transformed text when result is non-empty (or change handlers to return original input on parse failure).
  1. Missing regression tests for failure/edge behavior
  • Current coverage in test_main.py and test_main.py only checks successful formatting.
  • Add tests for invalid SQL and multi-statement input verifying Ctrl-X p/u does not clear buffer and that toolbar error is set. This would have caught the regression above.

No new security issue found in this diff.

This method is built in to prompt_toolkit, and simpler.  The position
of the cursor in the transformed text is still not precise, as expected.
(It wasn't precise before.)
@rolandwalker rolandwalker force-pushed the RW/use-transform-region-for-prettify-bindings branch from 9694842 to be9ff95 Compare February 28, 2026 11:28
@rolandwalker rolandwalker merged commit 1c58bfb into main Feb 28, 2026
8 checks passed
@rolandwalker rolandwalker deleted the RW/use-transform-region-for-prettify-bindings branch February 28, 2026 11:32
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.

2 participants