import Editor from "../editor" ; import { AnyObject } from "../decorate" ; import getSelection from "./get-selection" ; import focusAt from "./focus-at" ; import getSelectedIdList from "./get-selected-id-list" ; const modifySelectionDecorate = ( editor , style ? , data ? ) => { let selection = getSelection ( editor ) ; if ( selection . isCollapsed ) { return ; } let start = selection . range [ 0 ] ; let end = selection . range [ 1 ] ; let idList = getSelectedIdList ( editor . article , start . id , end . id ) ; if ( idList . length === 0 ) return ; if ( idList . length === 1 ) { let component = editor . storeManage . getBlockById ( idList [ 0 ] ) ; component . modifyContentDecorate ( start . offset , end . offset - 1 , style , data ) ; return focusAt ( editor , start , end ) ; } let firstComponent = editor . storeManage . getBlockById ( idList [ 0 ] ) ; let lastComponent = editor . storeManage . getBlockById ( idList [ idList . length - 1 ] ) ; firstComponent . modifyContentDecorate ( start . offset , - 1 , style , data ) ; lastComponent . modifyContentDecorate ( 0 , end . offset - 1 , style , data ) ; for ( let i = 1 ; i < idList . length - 1 ; i ++ ) { let component = editor . storeManage . getBlockById ( idList [ i ] ) ; component . modifyContentDecorate ( 0 , - 1 , style , data ) ; } focusAt ( editor , start , end ) ; } ; export default modifySelectionDecorate ;