File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -294,9 +294,34 @@ function createListKeymap(schema: Schema): Record<string, any> {
294294 } ;
295295
296296 // Tab 和 Shift-Tab 操作
297- if ( schema . nodes . list_item ) {
298- keys [ "Tab" ] = sinkListItem ( schema . nodes . list_item ) ;
299- keys [ "Shift-Tab" ] = liftListItem ( schema . nodes . list_item ) ;
297+ {
298+ const sinkList = schema . nodes . list_item ? sinkListItem ( schema . nodes . list_item ) : null ;
299+ const liftList = schema . nodes . list_item ? liftListItem ( schema . nodes . list_item ) : null ;
300+
301+ keys [ "Tab" ] = ( state : any , dispatch : any ) => {
302+ // 优先尝试列表缩进
303+ if ( sinkList && sinkList ( state , dispatch ) ) {
304+ return true ;
305+ }
306+ // 非列表上下文:通过 execCommand 插入两个空格,走正常输入管道
307+ document . execCommand ( "insertText" , false , " " ) ;
308+ return true ;
309+ } ;
310+
311+ keys [ "Shift-Tab" ] = ( state : any , dispatch : any ) => {
312+ // 优先尝试列表取消缩进
313+ if ( liftList && liftList ( state , dispatch ) ) {
314+ return true ;
315+ }
316+ // 非列表上下文:删除行首的两个空格
317+ const { $from } = state . selection ;
318+ const lineText = $from . parent . textContent ;
319+ if ( lineText . startsWith ( " " ) && dispatch ) {
320+ const startOfNode = $from . pos - $from . parentOffset ;
321+ dispatch ( state . tr . delete ( startOfNode , startOfNode + 2 ) ) ;
322+ }
323+ return true ;
324+ } ;
300325 }
301326
302327 // 取消列表
You can’t perform that action at this time.
0 commit comments