From 3851d17540ac7f94751d2a30e113da710d735c80 Mon Sep 17 00:00:00 2001 From: Untone Date: Fri, 11 Oct 2024 04:05:34 +0300 Subject: [PATCH] minor --- .../Editor/Toolbar/BlockquoteBubbleMenu.tsx | 2 +- .../Editor/Toolbar/EditorFloatingMenu.tsx | 7 ++++++- .../Editor/Toolbar/MicroBubbleMenu.tsx | 16 ++++++++++++---- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/components/Editor/Toolbar/BlockquoteBubbleMenu.tsx b/src/components/Editor/Toolbar/BlockquoteBubbleMenu.tsx index 6247c74e..e3953cd6 100644 --- a/src/components/Editor/Toolbar/BlockquoteBubbleMenu.tsx +++ b/src/components/Editor/Toolbar/BlockquoteBubbleMenu.tsx @@ -41,7 +41,7 @@ export const BlockquoteBubbleMenu = (props: Props) => { )} - + {(triggerRef: (el: HTMLElement) => void) => ( diff --git a/src/components/Editor/Toolbar/MicroBubbleMenu.tsx b/src/components/Editor/Toolbar/MicroBubbleMenu.tsx index 8060f0a1..9920776d 100644 --- a/src/components/Editor/Toolbar/MicroBubbleMenu.tsx +++ b/src/components/Editor/Toolbar/MicroBubbleMenu.tsx @@ -1,11 +1,12 @@ import type { Editor } from '@tiptap/core' +import { clsx } from 'clsx' import { Accessor, Show, createSignal, onCleanup, onMount } from 'solid-js' import { Icon } from '~/components/_shared/Icon' +import { useEditorContext } from '~/context/editor' import { InsertLinkForm } from './InsertLinkForm' +import { ToolbarControl } from './ToolbarControl' -import clsx from 'clsx' import styles from './MicroBubbleMenu.module.scss' -import ToolbarControl from './ToolbarControl' type MicroBubbleMenuProps = { editor: Accessor @@ -15,6 +16,7 @@ type MicroBubbleMenuProps = { export const MicroBubbleMenu = (props: MicroBubbleMenuProps) => { const [linkEditorOpen, setLinkEditorOpen] = createSignal(false) + const { editing } = useEditorContext() const handleOpenLinkForm = () => { const { from, to } = props.editor()!.state.selection @@ -29,9 +31,9 @@ export const MicroBubbleMenu = (props: MicroBubbleMenuProps) => { props.editor()?.chain().focus().setTextSelection(to).run() } - // handle ctrl+k to insert link const handleKeyDown = (event: KeyboardEvent) => { - if ( + // handle ctrl+k to insert link + if ( event.code === 'KeyK' && (event.metaKey || event.ctrlKey) && !props.editor()?.state.selection.empty @@ -39,6 +41,12 @@ export const MicroBubbleMenu = (props: MicroBubbleMenuProps) => { event.preventDefault() setLinkEditorOpen((prev) => !prev) } + + // handle shift+enter to change focus + if (event.code === 'Enter' && (event.metaKey || event.shiftKey)) { + event.preventDefault() + editing()?.commands.focus() + } } onMount(() => {