import { ParseMode } from '../public/core' ; import { register as registerCommand } from '../editor/commands' ; import { complete } from './autocomplete' ; import type { MathfieldPrivate } from './mathfield-private' ; import { onTypedText } from './keyboard-input' ; import { toggleKeystrokeCaption } from './keystroke-caption' ; registerCommand ( { undo : ( mathfield ) => { complete ( mathfield , 'accept' ) ; mathfield . undo ( ) ; return true ; } , redo : ( mathfield ) => { complete ( mathfield , 'accept' ) ; mathfield . redo ( ) ; return true ; } , scrollIntoView : ( mathfield ) => { mathfield . scrollIntoView ( ) ; return true ; } , scrollToStart : ( mathfield ) => { mathfield . field ! . scroll ( 0 , 0 ) ; return true ; } , scrollToEnd : ( mathfield ) => { const fieldBounds = mathfield . field ! . getBoundingClientRect ( ) ; mathfield . field ! . scroll ( fieldBounds . left - window . scrollX , 0 ) ; return true ; } , enterLatexMode : ( mathfield ) => { mathfield . switchMode ( 'latex' ) ; return true ; } , toggleKeystrokeCaption : toggleKeystrokeCaption , switchMode : ( mathfield , mode , prefix , suffix ) => { mathfield . switchMode ( mode , prefix , suffix ) ; return true ; } , insert : ( mathfield , s , options ) => mathfield . insert ( s , options ) , typedText : ( mathfield , text , options ) => { onTypedText ( mathfield , text , options ) ; return true ; } , commit : ( mathfield ) => { if ( typeof mathfield . options . onCommit === 'function' ) { mathfield . options . onCommit ( mathfield ) ; } return true ; } , } ) ; registerCommand ( { copyToClipboard : ( mathfield ) => { mathfield . focus ( ) ; if ( mathfield . model . selectionIsCollapsed ) { mathfield . select ( ) ; } document . execCommand ( 'copy' ) ; return false ; } , cutToClipboard : ( mathfield ) => { mathfield . focus ( ) ; document . execCommand ( 'cut' ) ; return true ; } , pasteFromClipboard : ( mathfield ) => { mathfield . focus ( ) ; document . execCommand ( 'paste' ) ; return true ; } , } , { target : 'mathfield' , category : 'clipboard' } ) ;