Skip to content

Conversation

@jramosg
Copy link

@jramosg jramosg commented Jan 23, 2026

Improve backspace and deleteForward functions for reader macro hash deletion

What has changed?

  • Enhanced backspace function in src/cursor-doc/paredit.ts: Added comprehensive logic to handle deletion behavior when interacting with reader macro tokens (#(, #{), distinguishing between empty and non-empty forms, and properly managing cursor positioning.

  • Enhanced deleteForward function in src/cursor-doc/paredit.ts: Added detection for invalid reader prefixes (junk # tokens) and reader macro start positions, allowing proper deletion of # characters in appropriate contexts.

  • Added comprehensive test suite: Implemented 12 new tests covering all hash character deletion scenarios for both backspace and delete-forward operations, ensuring robust behavior across different reader macro contexts.

The implementation correctly handles:

  • Empty reader macros (#(), #{}) - jumps over # instead of deleting
  • Non-empty reader macros (#(prn "hello"), #{:foo :bar}) - allows # deletion
  • Invalid reader syntax (#[...], junk # tokens) - allows # deletion
  • Proper cursor positioning and token boundary detection

Fixes #2766

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 change might have some side effects and tested those as well.
  • 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).

This update introduces several test cases to verify the behavior of
deleting `#()` forms and related constructs in the paredit sandbox.
These tests ensure that backspace and delete operations function as
expected, enhancing the reliability of the paredit functionality.
This update introduces tests for the deletion of hash characters (#)
in various contexts involving reader macros. The tests ensure that
hash characters are correctly deleted or preserved based on their
surrounding syntax, improving the robustness of the paredit
functionality.
Improve the backspace function to correctly manage deletion
behavior when interacting with reader macro tokens. This
includes special cases for empty reader macros and invalid
prefixes, ensuring a smoother editing experience in the
paredit sandbox.
Fixes # is not deleted in specific case
Fixes BetterThanTomorrow#2766
@netlify
Copy link

netlify bot commented Jan 23, 2026

Deploy Preview for calva-docs ready!

Name Link
🔨 Latest commit 53ed4f2
🔍 Latest deploy log https://app.netlify.com/projects/calva-docs/deploys/6975c042aa4357000839f913
😎 Deploy Preview https://deploy-preview-3002--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 project configuration.

Detect if the cursor is inside the '#' prefix of a reader macro token
before the opening delimiter. This improves the backspace behavior when
editing reader macros, ensuring a smoother user experience.
@jramosg jramosg changed the title Fix/# deletion 2766 Fix # deletion 2766 Jan 23, 2026
Updated the backspace function to simplify token type checks
by replacing the Set with an array for JUMP_TOKEN_TYPES. This
change improves readability and maintains functionality when
handling reader macro tokens.
Introduce a constant for open delimiters regex to improve code
readability and maintainability. Update backspace function to use
this constant for checking token boundaries within reader macros.
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