Skip to content

Commit

Permalink
Merge pull request #20 from DevItaliya22/feat_tab
Browse files Browse the repository at this point in the history
Added tab functionality in Editor
  • Loading branch information
harshsbhat authored Jan 11, 2025
2 parents 048e6fe + 56fc4db commit 125eecb
Showing 1 changed file with 39 additions and 25 deletions.
64 changes: 39 additions & 25 deletions src/components/editor/Tiptap.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,52 @@
import { useEditor, EditorContent } from "@tiptap/react";
import { useEditor, EditorContent, Editor } from "@tiptap/react";
import StarterKit from "@tiptap/starter-kit";
import Underline from "@tiptap/extension-underline";
import TextEditorMenuBar from "./TextEditorMenu";

import { EditorView } from "@tiptap/pm/view";

type TextEditorProps = {
onChange: (content: string) => void;
initialContent?: string;
};

onChange: (content: string) => void;
initialContent?: string;
};

export default function RichTextEditor({
onChange,
initialContent,
}: TextEditorProps) {
onChange,
initialContent,
}: TextEditorProps) {
const editor = useEditor({
extensions: [StarterKit, Underline],
content: initialContent,
onUpdate: ({ editor }) => {
onChange(editor.getHTML());
},
editorProps: {
attributes: {
class:
"cursor-text rounded-md border-2 shadow p-5 ring-offset-background focus-within:outline-none min-h-[50vh] sm:min-h-[70vh]",
},
handleKeyDown: (view:EditorView, event:KeyboardEvent) => {
if (event.key === 'Tab') {
event.preventDefault();

const { state } = view;
const { selection } = state;
const { from, to } = selection;
const spaces = ' ';
const transaction = state.tr.insertText(spaces, from, to);

const editor = useEditor({
extensions: [StarterKit, Underline],
content: initialContent,
onUpdate : ({editor}) => {
onChange(editor.getHTML())
},
editorProps: {
attributes: {
class: "cursor-text rounded-md border-2 shadow p-5 ring-offset-background focus-within:outline-none min-h-[50vh] sm:min-h-[70vh]"
view.dispatch(transaction);
return true;
}
return false;
},
},
immediatelyRender: false,
});

}
},
immediatelyRender: false
})
return (
<div className="h-full">
<TextEditorMenuBar editor={editor} />
<EditorContent editor={editor} className="h-full"/>
<EditorContent editor={editor} className="h-full" />
</div>
)
}
);
}

0 comments on commit 125eecb

Please sign in to comment.