Skip to content

Commit

Permalink
fix demo for cut command (#4313)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdbch authored Aug 11, 2023
1 parent a922f09 commit afaa87f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions demos/src/Commands/Cut/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,25 @@ import ListItem from '@tiptap/extension-list-item'
import TextStyle from '@tiptap/extension-text-style'
import { EditorContent, useEditor } from '@tiptap/react'
import StarterKit from '@tiptap/starter-kit'
import React from 'react'
import React, { useCallback } from 'react'

const MenuBar = ({ editor }) => {
if (!editor) {
return null
}

const onCutToStart = useCallback(() => {
editor.chain().cut({ from: editor.state.selection.$from.pos, to: editor.state.selection.$to.pos }, 1).run()
}, [editor])

const onCutToEnd = useCallback(() => {
editor.chain().cut({ from: editor.state.selection.$from.pos, to: editor.state.selection.$to.pos }, editor.state.doc.nodeSize - 2).run()
}, [editor])

return (
<>
<button onClick={() => editor.chain().cut({ from: editor.state.selection.$from.pos, to: editor.state.selection.$to.pos }, 1)}>Cut content to start of document</button>
<button onClick={() => editor.chain().cut({ from: editor.state.selection.$from.pos, to: editor.state.selection.$to.pos }, editor.state.doc.nodeSize - 2)}>Cut content to end of document</button>
<button onClick={onCutToStart}>Cut content to start of document</button>
<button onClick={onCutToEnd}>Cut content to end of document</button>
</>
)
}
Expand Down

0 comments on commit afaa87f

Please sign in to comment.