Skip to content

Conversation

@alizaberger
Copy link
Collaborator

@alizaberger alizaberger commented Mar 11, 2025

Describe your changes

Fixes the issue described in this meta post. In markdown mode, the code block button surrounds one character extra than the user's selection. This PR corrects that, cleans up the code, and adds comments to make it more understandable.

PR Checklist

  • All new/changed functionality includes unit and (optionally) e2e tests as appropriate
  • All new/changed functions have /** ... */ docs
  • I've added the bug/enhancement and other labels as appropriate

Environment(s) tested

  • Browser [e.g. chrome, safari]

@alizaberger alizaberger added bug Something isn't working commonmark Relates to commonmark round-tripping or syntax labels Mar 11, 2025
@netlify
Copy link

netlify bot commented Mar 11, 2025

Deploy Preview for stacks-editor ready!

Name Link
🔨 Latest commit 7fc2701
🔍 Latest deploy log https://app.netlify.com/sites/stacks-editor/deploys/67d1c2455e39910008e16feb
😎 Deploy Preview https://deploy-preview-393--stacks-editor.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.

const from = state.selection.from;
let to = state.selection.to;

// check if we need to unwrap
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is already done in the calling function

Copy link
Collaborator

@threefjefff threefjefff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good, tests look good, some potential for additional cleanup.

to += (formattingText.length * 2) + preceedingNewlineNeeded.length;

// set the selection to the text inside the code fences, skipping the leading newline
if (dispatch) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we're editing code here, can we also do a check for is dispatch is defined earlier in the code? We can skip a lot of pointless transaction building if we establish early whether or not this action is valid, and that seems possible by the time we've got to let tr = state.tr;

From here:

To be able to query whether a command is applicable for a given state, without actually executing it, the dispatch argument is optional—commands should simply return true without doing anything when they are applicable but no dispatch argument is given

Copy link
Contributor

@dancormier dancormier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested and this works well. It's nice to see this bug get fixed while simplifying the code.

Only minor suggestion is to give npm run format which will resolve the CI lint failure. I'll get you an approval asap once the pipeline succeeds.

Other than that, this seems good to go IMO! Thanks for the bug fix

@alizaberger alizaberger merged commit 994162e into main Mar 12, 2025
5 checks passed
@alizaberger alizaberger deleted the aberger/markdown-code-block-off-by-one branch March 12, 2025 17:23
This was referenced Apr 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working commonmark Relates to commonmark round-tripping or syntax

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants