This repository has been archived by the owner on Nov 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(comment-editor): sends comment when pressing Enter
resolve #326 Press 'Enter' t osend comment. Press 'Shift-Enter' to add new line.
- Loading branch information
Showing
7 changed files
with
89 additions
and
18 deletions.
There are no files selected for viewing
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
40 changes: 40 additions & 0 deletions
40
packages/legacy-editor/src/extensions/extensions/comment/comment.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,40 @@ | ||
import { Extension } from '@tiptap/core' | ||
import { meta, CommentOptions, CommentAttributes } from './meta' | ||
|
||
export const Comment = Extension.create<CommentOptions, CommentAttributes>({ | ||
name: meta.name, | ||
|
||
addKeyboardShortcuts() { | ||
const handleShiftEnter = (): boolean => | ||
this.editor.commands.first(({ commands }) => [ | ||
() => commands.newlineInCode(), | ||
() => commands.createParagraphNear(), | ||
() => commands.liftEmptyBlock(), | ||
() => commands.splitBlock() | ||
]) | ||
|
||
const handleEnter = (): boolean => { | ||
if (this.options.onSendComment) { | ||
this.options.onSendComment() | ||
} | ||
return true | ||
} | ||
|
||
return { | ||
Enter: handleEnter, | ||
'Shift-Enter': handleShiftEnter | ||
} | ||
}, | ||
|
||
addCommands() { | ||
return { | ||
insertBlockAt: | ||
(content, position) => | ||
({ chain }) => { | ||
return position === undefined | ||
? chain().insertContent(content).run() | ||
: chain().insertContentAt(position, content).run() | ||
} | ||
} | ||
} | ||
}) |
1 change: 1 addition & 0 deletions
1
packages/legacy-editor/src/extensions/extensions/comment/index.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 @@ | ||
export * from './comment' |
12 changes: 12 additions & 0 deletions
12
packages/legacy-editor/src/extensions/extensions/comment/meta.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,12 @@ | ||
import { ExtensionMeta } from '../../common' | ||
|
||
export interface CommentOptions { | ||
onSendComment?: () => void | ||
} | ||
|
||
export interface CommentAttributes {} | ||
|
||
export const meta: ExtensionMeta = { | ||
name: 'comment', | ||
extensionType: 'extension' | ||
} |
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