license import * as monacoEditor from "monaco-editor" ; /**
 * These are monaco commands. So far we use them in codelens actions (see codelensProvider)
 */ export default class Commands { insertNotes : string = "" ; setClef : string = "" ; setKey : string = "" ; setTime : string = "" ; showMakelily : ( tool : string , cb ? : ( ly : string ) => void ) => void ; constructor ( showMakelily ) { this . showMakelily = showMakelily ; } clear ( ) { this . insertNotes = "" ; this . setClef = "" ; this . setKey = "" ; this . setTime = "" ; } init ( editor ) { function moveToStartOfNextLine ( lineIdx ) { editor . setPosition ( { column : 1 , lineNumber : lineIdx + 2 , } ) ; } function replaceLine ( lineIdx , ly ) { const model = editor . getModel ( ) ; if ( ! model ) { return ; } const whitespace = model . getLinesContent ( ) [ lineIdx ] . match ( /^\s*/ ) ; const whitespacePrefix = whitespace ? whitespace [ 0 ] : "" ; const range = new monacoEditor . Range ( lineIdx + 1 , 1 , lineIdx + 2 , 1 ) ; const op = { forceMoveMarkers : false , range , text : `${ whitespacePrefix }${ ly }` , } ; editor . executeEdits ( "hacklily" , [ op ] ) ; } this . setClef = editor . addCommand ( Number . MAX_VALUE , ( internal , lineIdx ) : void => { moveToStartOfNextLine ( lineIdx ) ; this . showMakelily ( "clef" , ( ly ) => { replaceLine ( lineIdx , ly ) ; } ) ; } , "" ) || "" ; this . setKey = editor . addCommand ( Number . MAX_VALUE , ( internal , lineIdx ) : void => { moveToStartOfNextLine ( lineIdx ) ; this . showMakelily ( "key" , ( ly ) => { replaceLine ( lineIdx , ly ) ; } ) ; } , "" ) || "" ; this . setTime = editor . addCommand ( Number . MAX_VALUE , ( internal , lineIdx ) : void => { moveToStartOfNextLine ( lineIdx ) ; this . showMakelily ( "time" , ( ly ) => { replaceLine ( lineIdx , ly ) ; } ) ; } , "" ) || "" ; this . insertNotes = editor . addCommand ( Number . MAX_VALUE , ( internal , lineIdx ) : void => { moveToStartOfNextLine ( lineIdx ) ; this . showMakelily ( "notes" ) ; } , "" ) || "" ; } }