Skip to content

Commit

Permalink
editor: clicking embed in draft will now select it instead of navigat…
Browse files Browse the repository at this point in the history
…ing to original document
  • Loading branch information
iskaktoltay committed Sep 7, 2023
1 parent 1f53823 commit f0b9f9d
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions frontend/packages/app/src/editor/embed-block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ function InlineContentView({inline}: {inline: InlineContent[]}) {
return (
<span
className={isHyperdocsScheme(content.href) ? 'hm-link' : 'link'}
key={index}
onClick={() => {
openUrl(content.href, true)
}}
Expand Down Expand Up @@ -132,12 +133,13 @@ function EmbedPresentation({
editor,
}: {
block: BlockNoteBlock<typeof hmBlockSchema>
editor?: BlockNoteEditor<typeof hmBlockSchema>
editor: BlockNoteEditor<typeof hmBlockSchema>
}) {
let spawn = useNavigate('spawn')
let embed = useEmbed(block.props.ref)
let content = <Spinner />
const selected = useSelected(block, editor)

if (embed.content) {
content = (
<>
Expand All @@ -163,6 +165,9 @@ function EmbedPresentation({
paddingVertical="$2"
borderRadius="$4"
onPress={() => {
if (editor?.isEditable) {
return
}
let [documentId, version, blockId] = getIdsfromUrl(block.props.ref)
if (documentId) {
spawn({
Expand Down Expand Up @@ -220,14 +225,14 @@ function StaticEmbedPresentation({block}: {block: EmbedBlockType}) {

function useSelected(
block: BlockNoteBlock<HMBlockSchema>,
editor?: BlockNoteEditor<HMBlockSchema>,
editor: BlockNoteEditor<HMBlockSchema>,
) {
const [selected, setSelected] = useState(false)
const tiptapEditor = editor._tiptapEditor
const selection = tiptapEditor.state.selection

useEffect(() => {
if (editor) {
const tiptapEditor = editor?._tiptapEditor
const selection = tiptapEditor?.state.selection
const selectedNode = getBlockInfoFromPos(
tiptapEditor.state.doc,
tiptapEditor.state.selection.from,
Expand All @@ -243,7 +248,7 @@ function useSelected(
}
}
}
}, [editor?._tiptapEditor])
}, [selection])

return selected
}
Expand Down

0 comments on commit f0b9f9d

Please sign in to comment.