-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add
createEmptyParagraphEnd
command
- Loading branch information
Showing
5 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/extensions/core/extra-editor-commands/commands/create-empty-paragraph-end.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { RawCommands } from '@tiptap/core' | ||
import { TextSelection } from '@tiptap/pm/state' | ||
|
||
/** | ||
* Augment the official `@tiptap/core` module with extra commands so that the compiler knows about | ||
* them. For this to work externally, a wildcard export needs to be added to the root `index.ts`. | ||
*/ | ||
declare module '@tiptap/core' { | ||
interface Commands<ReturnType> { | ||
createEmptyParagraphEnd: { | ||
/** | ||
* Creates an empty paragraph at the end of the document. | ||
*/ | ||
createEmptyParagraphEnd: () => ReturnType | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Creates an empty paragraph at the end of the document. | ||
* | ||
* last node before creating the paragraph, using the build int fn | ||
*/ | ||
function createEmptyParagraphEnd(): ReturnType<RawCommands['createEmptyParagraphEnd']> { | ||
return ({ state, tr, chain, dispatch }) => { | ||
// Check if the transaction should be dispatched | ||
// ref: https://tiptap.dev/api/commands#dry-run-for-commands | ||
if (dispatch) { | ||
return chain() | ||
.command(() => { | ||
tr.setSelection( | ||
TextSelection.create( | ||
tr.doc, | ||
state.doc.content.size, | ||
state.doc.content.size, | ||
), | ||
) | ||
|
||
return true | ||
}) | ||
.createParagraphNear() | ||
.run() | ||
} | ||
|
||
return true | ||
} | ||
} | ||
|
||
export { createEmptyParagraphEnd } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters