Skip to content
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 (2) #2751

Draft
wants to merge 10 commits into
base: dev
Choose a base branch
from

Conversation

pbwolf
Copy link
Contributor

@pbwolf pbwolf commented Mar 9, 2025

What has changed?

This branch experimentally restores multi-cursor reformatting with additional enhancements to formatPosition's cursor repositioning.

Issue 2748 Case 1 (The cursor jumped to the next line when it had been in whitespace that the reformatter revised) is resolved by making a distinct whitespace edit for each line instead of combining spaces and newlines into a single edit.

Issue 2748 Case 2 (The cursor, at the beginning of a blank line, did not move to the indentation tab-stop):

  • Case 2a, when the formatter should insert the necessary spaces, is resolved by passing an actual cursor position as the reference point to the formatter. If there is more than one cursor then one is chosen arbitrarily. The non-arbitrary technique of using the beginning of the form as the reference point did not recognize that the formatter might trim (not indent) blank lines other than the one with the reference point.
  • Case 2b, when the document already had enough indentation spaces but they were to the right of the cursor, is mitigated, for the single-cursor case only, by asynchronously imposing the formatter's newIndex as the selection if it is different from where the cursor floated to naturally.

Reformatting between two top-level forms, or performing a structural edit that changed a top-level form's delimiters, reformatted the whole document using an interface that did not specify a reference point. That occasioned a few other adjustments on this branch:

  • This branch resorts to whole-document formatting less often, by narrowing the post-structural-edit reformat radius to the form (not its enclosing list) if there is no enclosing list. Also, this branch formats a single-form document as a form, not a document.
  • This branch formats a document even if its first line was a comment.

Fixes #2748

My Calva PR Checklist

I have:

  • Read How to Contribute.
  • Directed this pull request at the dev branch. (Or have specific reasons to target some other branch.)
  • Made sure I have changed the PR base branch, so that it is not published. (Sorry for the nagging.)
  • Made sure there is an issue registered with a clear problem statement that this PR addresses, (created the issue if it was not present).
    • Updated the [Unreleased] entry in CHANGELOG.md, linking the issue(s) that the PR is addressing.
  • Figured if anything about the fix warrants tests on Mac/Linux/Windows/Remote/Whatever, and either tested it there if so, or mentioned it in the PR.
  • Added to or updated docs in this branch, if appropriate
  • Tests
    • Tested the particular change
    • Figured if the change might have some side effects and tested those as well.
  • Formatted all JavaScript and TypeScript code that was changed. (use the prettier extension or run npm run prettier-format)
  • Confirmed that there are no linter warnings or errors (use the eslint extension, run npm run eslint before creating your PR, or run npm run eslint-watch to eslint as you go).

Ping @PEZ, @bpringe, @corasaurus-hex, @Cyrik

Copy link

netlify bot commented Mar 9, 2025

Deploy Preview for calva-docs ready!

Name Link
🔨 Latest commit 7f9923d
🔍 Latest deploy log https://app.netlify.com/sites/calva-docs/deploys/67cdb0f2602f700008044d8e
😎 Deploy Preview https://deploy-preview-2751--calva-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@pbwolf pbwolf marked this pull request as draft March 9, 2025 15:23
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