import * as FirstCharacterMotion from "../motion/FirstCharacterMotion" ; import * as LastCharacterInLineMotion from "../motion/LastCharacterInLineMotion" ; import * as RightMotion from "../motion/RightMotion" ; import { AbstractInsertTextAction } from "./AbstractInsertTextAction" ; /**
 * a A i I
 */ export class InsertTextAction extends AbstractInsertTextAction { public Motion : IMotion ; constructor ( m ? ) { super ( ) ; if ( m === undefined ) { this . Motion = null ; } else { this . Motion = m ; } } public GetActionType ( ) { return ActionType . Insert ; } public Execute ( editor , vim ) { let p = editor . GetCurrentPosition ( ) ; if ( this . Motion != null ) { p = this . Motion . CalculateEnd ( editor , vim , p ) ; } if ( this . insertText !== null ) { editor . Insert ( p , this . insertText ) ; editor . SetPosition ( this . calcPositionAfterInsert ( p ) ) ; } else { vim . ApplyInsertMode ( p ) ; let text = editor . ReadLineAtCurrentPosition ( ) ; this . insertModeInfo = { DocumentLineCount : editor . GetLastLineNum ( ) + 1 , Position : p . Copy ( ) , BeforeText : text . substring ( 0 , p . Char ) , AfterText : text . substring ( p . Char ) , } ; } } } /**
 * a
 */ export function AppendTextAfterCursor ( num ) { let m = new RightMotion . RightMotion ( ) ; m . Count = 1 ; return new InsertTextAction ( m ) ; } /**
 * A
 */ export function AppendTextAtEndOfLine ( num ) { let m = new LastCharacterInLineMotion . LastCharacterInLineMotion ( ) ; return new InsertTextAction ( m ) ; } /**
 * i
 */ export function InsertTextBeforeCursor ( num ) { return new InsertTextAction ( ) ; } /**
 * I
 */ export function InsertTextBeforeFirstNonBlankInLine ( num ) { let m = new FirstCharacterMotion . FirstCharacterMotion ( ) ; m . Target = FirstCharacterMotion . Target . Current ; return new InsertTextAction ( m ) ; }