Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

feat(ui): Adds keyboard shortcut for insert link

widal0010f137013ec7d
diff --git a/public/components/common/form/CommentEditor.tsx b/public/components/common/form/CommentEditor.tsx
index 1f9903719..28d2ac90a 100644
--- a/public/components/common/form/CommentEditor.tsx
+++ b/public/components/common/form/CommentEditor.tsx
@@ -443,6 +443,23 @@ const Tiptap: React.FunctionComponent<CommentEditorProps> = (props) => {
editor.chain().focus().insertContent(`<a href="${urlWithProtocol}" target="_blank" rel="noopener nofollow">${text}</a>`).run()
}
+ // Handle keyboard shortcuts
+ const handleKeyDown = (event: KeyboardEvent) => {
+ if (!editor) return
+
+ const isMac = navigator.userAgent.toUpperCase().indexOf("MAC") >= 0
+ const isCmdK = (isMac && event.metaKey && event.key === "k") || (!isMac && event.ctrlKey && event.key === "k")
+
+ if (isCmdK) {
+ event.preventDefault()
+ // Get the text that was highlighted when the user pressed Cmd+K
+ const { from, to } = editor.state.selection
+ const selectedText = editor.state.doc.textBetween(from, to)
+ setSelectedText(selectedText)
+ setIsLinkModalOpen(true)
+ }
+ }
+
const extensions = isRawMarkdownMode
? [
// Minimal extensions for markdown mode
@@ -586,6 +603,18 @@ const Tiptap: React.FunctionComponent<CommentEditorProps> = (props) => {
}
}, [editor])
+ // Add keyboard event listener for shortcuts
+ useEffect(() => {
+ if (editor) {
+ const editorElement = editor.view.dom
+ editorElement.addEventListener("keydown", handleKeyDown)
+
+ return () => {
+ editorElement.removeEventListener("keydown", handleKeyDown)
+ }
+ }
+ }, [editor])
+
return (
<ValidationContext.Consumer>
{(ctx) => (