Skip to content

CMD + K to trigger link dialog #4347

Closed
Closed

Description

@zurfyx

Ctrl/CMD + K is a common convention to toggle link

Activity

  1. added
    enhancement
    good first issue
    on Apr 18, 2023
  2. AnuragBalhra commented on Apr 19, 2023

    @AnuragBalhra
    Contributor

    Sounds like a good first issue, I can pick it up if no one else is working on it yet.

  3. Nantris commented on Apr 20, 2023

    @Nantris

    @AnuragBalhra are you planning to work on this? Do you know how the Ctrl/Cmd+B are handled for Bold for an example of how to add this?

  4. AnuragBalhra commented on Apr 22, 2023

    @AnuragBalhra
    Contributor

    Yes I'm starting to work on this.
    I don't already know how to do it but I'll try to investigate how it's done for Ctrl/Cmd+B. If someone already knows any documentation/references about how they are implemented, that would be really helpful.

  5. evskorobogatij commented on Jun 6, 2023

    @evskorobogatij

    I do

    import React, { useCallback, useEffect } from 'react'
    import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'
    import { $isLinkNode, TOGGLE_LINK_COMMAND } from '@lexical/link'
    import { useUnit } from 'effector-react'
    import { changeLastKeyInfo } from 'components/Editor/models/keys'
    
    export const HotKeyPlugins = () => {
      const [editor] = useLexicalComposerContext()
    
      const handleChangeLastKeyInfo = useUnit(changeLastKeyInfo)
    
      const insertLink = useCallback(() => {
        editor.dispatchCommand(TOGGLE_LINK_COMMAND, 'https://')
      }, [editor])
    
      const handleKeyPress = useCallback(
        (e: KeyboardEvent) => {
          const { code, ctrlKey, altKey, shiftKey } = e
          handleChangeLastKeyInfo({ code, ctrlKey, altKey, shiftKey })
          if (ctrlKey && code === 'KeyK') {
            insertLink()
            e.preventDefault()
          }
        },
        [handleChangeLastKeyInfo],
      )
    
      useEffect(() => {
        window.addEventListener('keydown', handleKeyPress)
        return () => {
          window.removeEventListener('keydown', handleKeyPress)
        }
      }, [handleKeyPress])
    
      return <></>
    }
    
    
  6. acywatson commented on Jul 4, 2023

    @acywatson
    Contributor

    Closed by #4413

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementgood first issueplayground

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions