import Editor from "../editor" ; import Inline from "../components/inline" ; import Character from "../components/character" ; import focusAt from "../selection/focus-at" ; import { getCursorPosition , Cursor } from "../selection/util" ; import ContentCollection from "../components/content-collection" ; import { getUtf8TextLengthFromJsOffset } from "../util/text-util" ; const input = ( editor , charOrInline , start , event ? ) => { try { let block = editor . storeManage . getBlockById ( start . id ) ; let offset = start . offset ; let startPosition = getCursorPosition ( editor . mountedWindow , start ) ; if ( ! startPosition ) return ; let startNode = startPosition . node ; if ( block instanceof ContentCollection && charOrInline === " " && ( startPosition . index <= 0 || startPosition . index >= getUtf8TextLengthFromJsOffset ( startNode . nodeValue ) - 1 ) ) { charOrInline = new Character ( charOrInline ) ; } if ( start . offset === 0 || startNode . nodeName === "BR" || startNode . nodeName === "IMG" || typeof charOrInline !== "string" || startPosition . index === 0 || startPosition . index >= getUtf8TextLengthFromJsOffset ( startNode . nodeValue ) - 1 || ( ! event && typeof charOrInline === "string" ) || event ?. defaultPrevented ) { event ?. preventDefault ( ) ; let operator = block . add ( offset , charOrInline ) ; focusAt ( editor , operator ?. [ 0 ] || start , operator ?. [ 1 ] ) ; return ; } charOrInline = typeof charOrInline === "string" ? charOrInline . replace ( /\n/g , "" ) : charOrInline ; editor . articleManage . stopUpdate ( ) ; block . add ( offset , charOrInline ) ; editor . articleManage . startUpdate ( ) ; } catch ( e ) { console . warn ( e ) ; } } ; export default input ;