@@ -368,7 +368,7 @@ public static void DeleteEndOfWord(ConsoleKeyInfo? key = null, object arg = null
368368 _singleton . _buffer . Remove ( _singleton . _current , 1 + endPoint - _singleton . _current ) ;
369369 if ( _singleton . _current >= _singleton . _buffer . Length )
370370 {
371- _singleton . _current = Math . Max ( 0 , _singleton . _buffer . Length - 1 ) ;
371+ _singleton . _current = Math . Max ( 0 , _singleton . _buffer . Length - 1 ) ;
372372 }
373373 _singleton . Render ( ) ;
374374 }
@@ -522,11 +522,11 @@ internal static IDisposable UseViCommandModeTables()
522522 _singleton . _dispatchTable = _viCmdKeyMap ;
523523 _singleton . _chordDispatchTable = _viCmdChordTable ;
524524
525- return new Disposable ( ( ) =>
526- {
527- _singleton . _dispatchTable = oldDispatchTable ;
528- _singleton . _chordDispatchTable = oldChordDispatchTable ;
529- } ) ;
525+ return new Disposable ( ( ) =>
526+ {
527+ _singleton . _dispatchTable = oldDispatchTable ;
528+ _singleton . _chordDispatchTable = oldChordDispatchTable ;
529+ } ) ;
530530 }
531531
532532 /// <summary>
@@ -540,11 +540,11 @@ internal static IDisposable UseViInsertModeTables()
540540 _singleton . _dispatchTable = _viInsKeyMap ;
541541 _singleton . _chordDispatchTable = _viInsChordTable ;
542542
543- return new Disposable ( ( ) =>
544- {
545- _singleton . _dispatchTable = oldDispatchTable ;
546- _singleton . _chordDispatchTable = oldChordDispatchTable ;
547- } ) ;
543+ return new Disposable ( ( ) =>
544+ {
545+ _singleton . _dispatchTable = oldDispatchTable ;
546+ _singleton . _chordDispatchTable = oldChordDispatchTable ;
547+ } ) ;
548548 }
549549
550550 private void ViIndicateCommandMode ( )
@@ -849,6 +849,38 @@ public static void DeletePreviousLines(ConsoleKeyInfo? key = null, object arg =
849849 }
850850 }
851851
852+ /// <summary>
853+ /// Delete from the current logical line to the n-th requested logical line in a multiline buffer
854+ /// </summary>
855+ private static void DeleteRelativeLines ( ConsoleKeyInfo ? key = null , object arg = null )
856+ {
857+ if ( TryGetArgAsInt ( arg , out var requestedLineNumber , 1 ) )
858+ {
859+ var currentLineIndex = _singleton . GetLogicalLineNumber ( ) - 1 ;
860+ var requestedLineIndex = requestedLineNumber - 1 ;
861+ if ( requestedLineIndex < 0 )
862+ {
863+ requestedLineIndex = 0 ;
864+ }
865+
866+ var logicalLineCount = _singleton . GetLogicalLineCount ( ) ;
867+ if ( requestedLineIndex >= logicalLineCount )
868+ {
869+ requestedLineIndex = logicalLineCount - 1 ;
870+ }
871+
872+ var requestedLineCount = requestedLineIndex - currentLineIndex ;
873+ if ( requestedLineCount < 0 )
874+ {
875+ DeletePreviousLines ( null , - requestedLineCount ) ;
876+ }
877+ else
878+ {
879+ DeleteNextLines ( null , requestedLineCount ) ;
880+ }
881+ }
882+ }
883+
852884 /// <summary>
853885 /// Deletes the previous word.
854886 /// </summary>
@@ -1106,39 +1138,54 @@ private static void ViChord(ConsoleKeyInfo? key = null, object arg = null)
11061138
11071139 if ( _singleton . _chordDispatchTable . TryGetValue ( PSKeyInfo . FromConsoleKeyInfo ( key . Value ) , out var secondKeyDispatchTable ) )
11081140 {
1109- var secondKey = ReadKey ( ) ;
1110- if ( secondKeyDispatchTable . TryGetValue ( secondKey , out var handler ) )
1141+ ViChordHandler ( secondKeyDispatchTable , arg ) ;
1142+ }
1143+ }
1144+
1145+ private static void ViChordHandler ( Dictionary < PSKeyInfo , KeyHandler > secondKeyDispatchTable , object arg = null )
1146+ {
1147+ var secondKey = ReadKey ( ) ;
1148+ if ( secondKeyDispatchTable . TryGetValue ( secondKey , out var handler ) )
1149+ {
1150+ _singleton . ProcessOneKey ( secondKey , secondKeyDispatchTable , ignoreIfNoAction : true , arg : arg ) ;
1151+ }
1152+ else if ( ! IsNumeric ( secondKey ) )
1153+ {
1154+ _singleton . ProcessOneKey ( secondKey , secondKeyDispatchTable , ignoreIfNoAction : true , arg : arg ) ;
1155+ }
1156+ else
1157+ {
1158+ var argBuffer = _singleton . _statusBuffer ;
1159+ argBuffer . Clear ( ) ;
1160+ _singleton . _statusLinePrompt = "digit-argument: " ;
1161+ while ( IsNumeric ( secondKey ) )
11111162 {
1112- _singleton . ProcessOneKey ( secondKey , secondKeyDispatchTable , ignoreIfNoAction : true , arg : arg ) ;
1163+ argBuffer . Append ( secondKey . KeyChar ) ;
1164+ _singleton . Render ( ) ;
1165+ secondKey = ReadKey ( ) ;
11131166 }
1114- else if ( ! IsNumeric ( secondKey ) )
1167+ int numericArg = int . Parse ( argBuffer . ToString ( ) ) ;
1168+ if ( secondKeyDispatchTable . TryGetValue ( secondKey , out handler ) )
11151169 {
1116- _singleton . ProcessOneKey ( secondKey , secondKeyDispatchTable , ignoreIfNoAction : true , arg : arg ) ;
1170+ _singleton . ProcessOneKey ( secondKey , secondKeyDispatchTable , ignoreIfNoAction : true , arg : numericArg ) ;
11171171 }
11181172 else
11191173 {
1120- var argBuffer = _singleton . _statusBuffer ;
1121- argBuffer . Clear ( ) ;
1122- _singleton . _statusLinePrompt = "digit-argument: " ;
1123- while ( IsNumeric ( secondKey ) )
1124- {
1125- argBuffer . Append ( secondKey . KeyChar ) ;
1126- _singleton . Render ( ) ;
1127- secondKey = ReadKey ( ) ;
1128- }
1129- int numericArg = int . Parse ( argBuffer . ToString ( ) ) ;
1130- if ( secondKeyDispatchTable . TryGetValue ( secondKey , out handler ) )
1131- {
1132- _singleton . ProcessOneKey ( secondKey , secondKeyDispatchTable , ignoreIfNoAction : true , arg : numericArg ) ;
1133- }
1134- else
1135- {
1136- Ding ( ) ;
1137- }
1138- argBuffer . Clear ( ) ;
1139- _singleton . ClearStatusMessage ( render : true ) ;
1174+ Ding ( ) ;
11401175 }
1176+ argBuffer . Clear ( ) ;
1177+ _singleton . ClearStatusMessage ( render : true ) ;
1178+ }
1179+ }
1180+
1181+ private static void ViDGChord ( ConsoleKeyInfo ? key = null , object arg = null )
1182+ {
1183+ if ( ! key . HasValue )
1184+ {
1185+ throw new ArgumentNullException ( nameof ( key ) ) ;
11411186 }
1187+
1188+ ViChordHandler ( _viChordDGTable , arg ) ;
11421189 }
11431190
11441191 private static bool IsNumeric ( PSKeyInfo key )
@@ -1247,7 +1294,7 @@ public static void ViInsertLine(ConsoleKeyInfo? key = null, object arg = null)
12471294 _singleton . MoveToBeginningOfPhrase ( ) ;
12481295 _singleton . _buffer . Insert ( _singleton . _current , '\n ' ) ;
12491296 //_singleton._current = Math.Max(0, _singleton._current - 1);
1250- _singleton . SaveEditItem ( EditItemInsertChar . Create ( '\n ' , _singleton . _current ) ) ;
1297+ _singleton . SaveEditItem ( EditItemInsertChar . Create ( '\n ' , _singleton . _current ) ) ;
12511298 _singleton . Render ( ) ;
12521299 ViInsertMode ( ) ;
12531300 }
0 commit comments