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

[Feature] Keyboard Shortcut for Hyperlink #1729

Merged
merged 3 commits into from
Mar 10, 2024

Conversation

CorreyL
Copy link
Contributor

@CorreyL CorreyL commented Jan 21, 2024

#1728

The Rich Text Editor already has common keyboard shortcuts such as:

  • Mod-B: Bold
  • Mod-I: Italics
  • Mod-U: Underline

(Where Mod is the term used to refer to cmd for Mac devices, and Ctrl for all others in the Tiptap documentation)

This PR adds Mod-K for adding a hyperlink when using the Rich Text Editor

hyperlink keyboard-shortcut

Will allow code changes in a subsequent commit to access the function
and utilize the same core logic
Use the conventional Ctrl+K keyboard shortcut for adding a hyperlink
const setLink = useCallback(() => {
const previousUrl = editor.getAttributes("link").href;
const url = window.prompt("URL", previousUrl);
const setLinkGlobal = (editor: Editor) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm open to changing the naming of this function if desired, I just decided to leave Toolbar.setLink as-is to keep the diff of this PR low for now.

Copy link
Owner

Choose a reason for hiding this comment

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

I actually don't mind if the code is refactored to be inside Toolbar, and within a useCallback. Would be neater that way. I can take it from here and make the necessary changes.

Thank you for this quick helpful fix.

return {
"Mod-k": () => {
setLinkGlobal(this.editor as Editor);
return true;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

addKeyboardShortcuts expects functions in this object to return a boolean

image

image

@AmruthPillai AmruthPillai merged commit a92528c into AmruthPillai:main Mar 10, 2024
Copy link

nx-cloud bot commented Mar 10, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 219e699. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 4 targets

Sent with 💌 from NxCloud.

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.

2 participants