import { Position } from "../VimStyle" ; /**
 * p P
 */ export class PutRegisterAction implements IAction { public IsPrev : boolean ; public RegisterKey : Key ; public Count : number ; constructor ( ) { this . IsPrev = false ; this . RegisterKey = null ; } public GetActionType ( ) { return ActionType . Edit ; } public Execute ( editor , vim ) { let item ; if ( this . RegisterKey == null ) { item = vim . Register . GetUnName ( ) ; } else { item = vim . Register . Get ( this . RegisterKey ) ; } if ( item == null ) { return ; } let content = item . Body ; let cp = editor . GetCurrentPosition ( ) ; if ( item . Type === RegisterType . Text ) { if ( this . IsPrev ) { editor . InsertTextAtCurrentPosition ( item . Body ) ; editor . SetPosition ( cp ) ; return ; } let np = new Position ( ) ; np . Char = cp . Char + 1 ; np . Line = cp . Line ; editor . Insert ( np , content ) ; editor . SetPosition ( np ) ; return ; } else { let np = new Position ( ) ; np . Char = 0 ; if ( this . IsPrev ) { np . Line = cp . Line ; } else { np . Line = cp . Line + 1 ; if ( cp . Line === editor . GetLastLineNum ( ) ) { content = "\n" + content . substring ( 0 , content . length - 1 ) ; let lp = editor . GetLastPosition ( ) ; editor . Insert ( lp , content ) ; editor . SetPosition ( np ) ; return ; } } editor . Insert ( np , content ) ; editor . SetPosition ( np ) ; } } } /**
 * p
 */ export function PutRegisterAfterCursorPosition ( num ) { let a = new PutRegisterAction ( ) ; a . Count = num === 0 ? 1 : num ; return a ; } /**
 * P
 */ export function PutRegisterBeforeCursorPosition ( num ) { let a = new PutRegisterAction ( ) ; a . IsPrev = true ; a . Count = num === 0 ? 1 : num ; return a ; }