import Editor from "../editor" ; import focusAt from "../selection/focus-at" ; import getSelectedIdList from "../selection/get-selected-id-list" ; import { Cursor } from "../selection/util" ; const deleteSelection = ( editor , start , end ? ) => { if ( ! end || ( start . id === end . id && start . offset === end . offset ) ) { return ; } let idList = getSelectedIdList ( editor . article , start . id , end . id ) ; if ( idList . length === 0 ) return ; if ( idList . length === 1 ) { let block = editor . storeManage . getBlockById ( idList [ 0 ] ) ; let operator = block . remove ( start . offset , end . offset ) ; return focusAt ( editor , operator ?. [ 0 ] || start , operator ?. [ 1 ] ) ; } let headBlock = editor . storeManage . getBlockById ( idList [ 0 ] ) ; let tailBlock = editor . storeManage . getBlockById ( idList [ idList . length - 1 ] ) ; headBlock . remove ( start . offset , - 1 ) ; for ( let i = 1 ; i < idList . length - 1 ; i ++ ) { editor . storeManage . getBlockById ( idList [ i ] ) . removeSelf ( ) ; } tailBlock . remove ( 0 , end . offset ) ; tailBlock . sendTo ( headBlock ) ; return focusAt ( editor , { id : headBlock . id , offset : start . offset , } ) ; } ; export default deleteSelection ;