-
-
Notifications
You must be signed in to change notification settings - Fork 226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multicursor reformatting #2741
Multicursor reformatting #2741
Conversation
✅ Deploy Preview for calva-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
src/calva-fmt/src/format.ts
Outdated
/** whitespace and substance. Pre-format and re-formatted text can be expressed | ||
* as a series of SpacedUnit. The substance parts can be aligned and then | ||
* changes in size can be translated to TextEdits. | ||
*/ | ||
type SpacedUnit = [spaces: string, stuff: string]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is pretty awesome stuff! Looks lik some of it could be extracted into a module that doesn't need vscode and thus we could unit have unit tests?
Not sure if there's something else but the conflicts to fix here? I have been running with this branch for a few days and it is awesome. Don't think I've noticed anything that doesn't work. |
Thank you for the notes. I aim to merge dev's recent advances and extract some unit-testable parts |
Procedures that calculate whitespace adjustments are extracted to a new module and demonstrated with tests that check the text and cursor positions in the results. The cursor-position tests motivated some changes to the model of VS Code's implicit cursor adjustment after edits above or to the left of the cursor. The implicit behavior is described in passing on the VS Code Extension API reference page (https://code.visualstudio.com/api/references/vscode-api#TextEditorEdit) as "Although the equivalent text [insertion] can be made with replace, insert will produce a different resulting selection (it will get moved)." |
Thanks, @pbwolf! This is such a QOL change for me. You don't mention it in the PR, but also the format-current-form command is now multi-cursor. |
What has changed?
All commands that manipulate the document via DocumentModel are potentially affected, even commands that are not multicursor-capable. The single-cursor reformatting code path is just the base case of the multi-cursor code path, so it should be regarded as all-new despite the same underlying clj-format.
Extending auto-reformatting to multiple cursors changed the calculation of the region(s) to reformat. It may be that the region that gets reformatted after some commands will be benignly different from before, e.g., more extensive.
I did not add reformatting to the multicursor section of the paredit documentation, since it is not controlled by a setting.
Details:
Fixes #2738, #2737
My Calva PR Checklist
I have:
dev
branch. (Or have specific reasons to target some other branch.)published
. (Sorry for the nagging.)[Unreleased]
entry inCHANGELOG.md
, linking the issue(s) that the PR is addressing.npm run prettier-format
)npm run eslint
before creating your PR, or runnpm run eslint-watch
to eslint as you go).Ping @PEZ, @bpringe, @corasaurus-hex, @Cyrik