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

Cycle through headings on Ctrl+H #110

Closed

Conversation

double-beep
Copy link
Contributor

@double-beep double-beep commented Apr 11, 2022

  • Toggle code blocks and headings when Ctrl + M and Ctrl + H are pressed respectively.
  • Cycle through headings on Ctrl + H.

Closes #45, closes #105

@netlify
Copy link

netlify bot commented Apr 11, 2022

Deploy Preview for nifty-lalande-39c157 ready!

Name Link
🔨 Latest commit ad2a6f8
🔍 Latest deploy log https://app.netlify.com/sites/nifty-lalande-39c157/deploys/62541ecf486f9f000954f45d
😎 Deploy Preview https://deploy-preview-110--nifty-lalande-39c157.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 settings.

Copy link
Collaborator

@b-kelly b-kelly left a comment

Choose a reason for hiding this comment

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

Thank you for the PR! I'll give this a lookover soon, but in the meanwhile, could you add some unit tests in as well? I believe we have some existing command unit tests you could use as inspiration. If not, I can add a few for you to base yours off of.

@double-beep
Copy link
Contributor Author

@b-kelly I have already added an e2e test for Ctrl + H - do I need to add more tests?

Copy link
Collaborator

@b-kelly b-kelly left a comment

Choose a reason for hiding this comment

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

Left a few comments on the approach. I'd also like to add this functionality to markdown mode as well.

Regarding unit vs e2e tests - we'd like to prefer unit tests whenever possible, especially for functionality that doesn't need a view to run (as is the case here with the state commands). Unit tests are much faster and can be made much more complex / complete.

@@ -96,6 +96,51 @@ function toggleBlockType(
};
}

const headingInfo = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like this causes the header cycling state to be shared across different heading nodes. Something to note, this will also cause state to be shared across editor instances, across heading nodes.

time: 0,
};

export function cycleThroughHeadings(nodeType: NodeType) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Add /** */ docs to all new + exported functions


export function cycleThroughHeadings(nodeType: NodeType) {
return (state: EditorState, dispatch: (tr: Transaction) => void) => {
const delay = Date.now() - headingInfo.time;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd prefer to not check for delays in our underlying code. I think this is to support successive presses causing cycling, but single presses causing toggle? If that's something we'd like to pursue, let's move that logic into the keybind file instead

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.

Heading selection UX improvements Toggle heading shortcut broken in rich text mode
2 participants