File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -328,6 +328,34 @@ export default function DocumentPage() {
328328 class : 'min-h-full' ,
329329 spellcheck : 'false' ,
330330 } ,
331+ handleKeyDown : ( view , event ) => {
332+ if ( event . key === 'Tab' ) {
333+ if ( event . shiftKey ) {
334+ const { state } = view ;
335+ const { from } = state . selection ;
336+ const $from = state . doc . resolve ( from ) ;
337+ const startOfLine = $from . start ( $from . depth ) ;
338+ const textBeforeCursor = state . doc . textBetween ( startOfLine , from ) ;
339+
340+ if ( textBeforeCursor . endsWith ( ' ' ) ) {
341+ const deleteFrom = Math . max ( startOfLine , from - 2 ) ;
342+ view . dispatch ( state . tr . deleteRange ( deleteFrom , from ) ) ;
343+
344+ return true ;
345+ } else if ( textBeforeCursor . endsWith ( ' ' ) ) {
346+ view . dispatch ( state . tr . deleteRange ( from - 1 , from ) ) ;
347+
348+ return true ;
349+ }
350+ } else {
351+ view . dispatch ( view . state . tr . insertText ( ' ' ) ) ;
352+
353+ return true ;
354+ }
355+ }
356+
357+ return false ;
358+ } ,
331359 } ,
332360 immediatelyRender : false ,
333361 shouldRerenderOnTransaction : false ,
Original file line number Diff line number Diff line change @@ -39,9 +39,6 @@ import {
3939 Superscript ,
4040 TableKit ,
4141 TableOfContents ,
42- TableCell ,
43- TableHeader ,
44- TableRow ,
4542 TextAlign ,
4643 TextStyle ,
4744 TrailingNode ,
@@ -318,32 +315,7 @@ export const ExtensionKit = ({ provider }: ExtensionKitProps) => [
318315 enableEmoticons : true ,
319316 suggestion : emojiSuggestion ,
320317 } ) ,
321- TextAlign . extend ( {
322- addKeyboardShortcuts ( ) {
323- return {
324- Tab : ( ) => {
325- return this . editor . commands . insertContent ( ' ' ) ;
326- } ,
327- 'Shift-Tab' : ( ) => {
328- const { state } = this . editor ;
329- const { from } = state . selection ;
330- const $from = state . doc . resolve ( from ) ;
331- const startOfLine = $from . start ( $from . depth ) ;
332- const textBeforeCursor = state . doc . textBetween ( startOfLine , from ) ;
333-
334- if ( textBeforeCursor . endsWith ( ' ' ) ) {
335- const deleteFrom = Math . max ( startOfLine , from - 2 ) ;
336-
337- return this . editor . commands . deleteRange ( { from : deleteFrom , to : from } ) ;
338- } else if ( textBeforeCursor . endsWith ( ' ' ) ) {
339- return this . editor . commands . deleteRange ( { from : from - 1 , to : from } ) ;
340- }
341-
342- return false ;
343- } ,
344- } ;
345- } ,
346- } ) . configure ( {
318+ TextAlign . configure ( {
347319 types : [ 'heading' , 'paragraph' ] ,
348320 } ) ,
349321 Subscript ,
@@ -353,9 +325,6 @@ export const ExtensionKit = ({ provider }: ExtensionKitProps) => [
353325 resizable : true ,
354326 } ,
355327 } ) ,
356- TableCell ,
357- TableHeader ,
358- TableRow ,
359328 Typography ,
360329 Placeholder . configure ( {
361330 includeChildren : true ,
You can’t perform that action at this time.
0 commit comments