fix: adding back enter key extension with mentions (#3499)

This commit is contained in:
M. Palanikannan 2024-01-31 18:06:12 +05:30 committed by GitHub
parent 21bc668a56
commit 70172f8e3d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 39 additions and 12 deletions

View File

@ -10,6 +10,11 @@ export interface CustomMentionOptions extends MentionOptions {
} }
export const CustomMention = Mention.extend<CustomMentionOptions>({ export const CustomMention = Mention.extend<CustomMentionOptions>({
addStorage(this) {
return {
mentionsOpen: false,
};
},
addAttributes() { addAttributes() {
return { return {
id: { id: {

View File

@ -14,6 +14,7 @@ export const Suggestion = (suggestions: IMentionSuggestion[]) => ({
return { return {
onStart: (props: { editor: Editor; clientRect: DOMRect }) => { onStart: (props: { editor: Editor; clientRect: DOMRect }) => {
props.editor.storage.mentionsOpen = true;
reactRenderer = new ReactRenderer(MentionList, { reactRenderer = new ReactRenderer(MentionList, {
props, props,
editor: props.editor, editor: props.editor,
@ -45,10 +46,18 @@ export const Suggestion = (suggestions: IMentionSuggestion[]) => ({
return true; return true;
} }
const navigationKeys = ["ArrowUp", "ArrowDown", "Enter"];
if (navigationKeys.includes(props.event.key)) {
// @ts-ignore // @ts-ignore
return reactRenderer?.ref?.onKeyDown(props); reactRenderer?.ref?.onKeyDown(props);
event?.stopPropagation();
return true;
}
return false;
}, },
onExit: () => { onExit: (props: { editor: Editor; event: KeyboardEvent }) => {
props.editor.storage.mentionsOpen = false;
popup?.[0].destroy(); popup?.[0].destroy();
reactRenderer?.destroy(); reactRenderer?.destroy();
}, },

View File

@ -4,13 +4,16 @@ export const EnterKeyExtension = (onEnterKeyPress?: () => void) =>
Extension.create({ Extension.create({
name: "enterKey", name: "enterKey",
addKeyboardShortcuts() { addKeyboardShortcuts(this) {
return { return {
Enter: () => { Enter: () => {
if (!this.editor.storage.mentionsOpen) {
if (onEnterKeyPress) { if (onEnterKeyPress) {
onEnterKeyPress(); onEnterKeyPress();
} }
return true; return true;
}
return false;
}, },
"Shift-Enter": ({ editor }) => "Shift-Enter": ({ editor }) =>
editor.commands.first(({ commands }) => [ editor.commands.first(({ commands }) => [

View File

@ -1,5 +1,3 @@
import { EnterKeyExtension } from "src/ui/extensions/enter-key-extension"; import { EnterKeyExtension } from "src/ui/extensions/enter-key-extension";
export const LiteTextEditorExtensions = (onEnterKeyPress?: () => void) => [ export const LiteTextEditorExtensions = (onEnterKeyPress?: () => void) => [EnterKeyExtension(onEnterKeyPress)];
// EnterKeyExtension(onEnterKeyPress),
];

View File

@ -10,7 +10,7 @@ import { TActivityOperations } from "../root";
import { TIssueComment } from "@plane/types"; import { TIssueComment } from "@plane/types";
// icons // icons
import { Globe2, Lock } from "lucide-react"; import { Globe2, Lock } from "lucide-react";
import { useWorkspace } from "hooks/store"; import { useMention, useWorkspace } from "hooks/store";
const fileService = new FileService(); const fileService = new FileService();
@ -43,6 +43,8 @@ export const IssueCommentCreate: FC<TIssueCommentCreate> = (props) => {
const workspaceStore = useWorkspace(); const workspaceStore = useWorkspace();
const workspaceId = workspaceStore.getWorkspaceBySlug(workspaceSlug as string)?.id as string; const workspaceId = workspaceStore.getWorkspaceBySlug(workspaceSlug as string)?.id as string;
const { mentionHighlights, mentionSuggestions } = useMention();
// refs // refs
const editorRef = useRef<any>(null); const editorRef = useRef<any>(null);
// react hook form // react hook form
@ -61,7 +63,14 @@ export const IssueCommentCreate: FC<TIssueCommentCreate> = (props) => {
}; };
return ( return (
<div> <div
// onKeyDown={(e) => {
// if (e.key === "Enter" && !e.shiftKey) {
// e.preventDefault();
// // handleSubmit(onSubmit)(e);
// }
// }}
>
<Controller <Controller
name="access" name="access"
control={control} control={control}
@ -72,6 +81,7 @@ export const IssueCommentCreate: FC<TIssueCommentCreate> = (props) => {
render={({ field: { value, onChange } }) => ( render={({ field: { value, onChange } }) => (
<LiteTextEditorWithRef <LiteTextEditorWithRef
onEnterKeyPress={(e) => { onEnterKeyPress={(e) => {
console.log("yo");
handleSubmit(onSubmit)(e); handleSubmit(onSubmit)(e);
}} }}
cancelUploadImage={fileService.cancelUpload} cancelUploadImage={fileService.cancelUpload}
@ -86,6 +96,8 @@ export const IssueCommentCreate: FC<TIssueCommentCreate> = (props) => {
onChange={(comment_json: Object, comment_html: string) => { onChange={(comment_json: Object, comment_html: string) => {
onChange(comment_html); onChange(comment_html);
}} }}
mentionSuggestions={mentionSuggestions}
mentionHighlights={mentionHighlights}
commentAccessSpecifier={ commentAccessSpecifier={
showAccessSpecifier showAccessSpecifier
? { accessValue: accessValue ?? "INTERNAL", onAccessChange, showAccessSpecifier, commentAccess } ? { accessValue: accessValue ?? "INTERNAL", onAccessChange, showAccessSpecifier, commentAccess }