@@ -368,7 +368,7 @@ public static void DeleteEndOfWord(ConsoleKeyInfo? key = null, object arg = null
368
368
_singleton . _buffer . Remove ( _singleton . _current , 1 + endPoint - _singleton . _current ) ;
369
369
if ( _singleton . _current >= _singleton . _buffer . Length )
370
370
{
371
- _singleton . _current = Math . Max ( 0 , _singleton . _buffer . Length - 1 ) ;
371
+ _singleton . _current = Math . Max ( 0 , _singleton . _buffer . Length - 1 ) ;
372
372
}
373
373
_singleton . Render ( ) ;
374
374
}
@@ -522,11 +522,11 @@ internal static IDisposable UseViCommandModeTables()
522
522
_singleton . _dispatchTable = _viCmdKeyMap ;
523
523
_singleton . _chordDispatchTable = _viCmdChordTable ;
524
524
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
+ } ) ;
530
530
}
531
531
532
532
/// <summary>
@@ -540,11 +540,11 @@ internal static IDisposable UseViInsertModeTables()
540
540
_singleton . _dispatchTable = _viInsKeyMap ;
541
541
_singleton . _chordDispatchTable = _viInsChordTable ;
542
542
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
+ } ) ;
548
548
}
549
549
550
550
private void ViIndicateCommandMode ( )
@@ -849,6 +849,38 @@ public static void DeletePreviousLines(ConsoleKeyInfo? key = null, object arg =
849
849
}
850
850
}
851
851
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
+
852
884
/// <summary>
853
885
/// Deletes the previous word.
854
886
/// </summary>
@@ -1106,39 +1138,54 @@ private static void ViChord(ConsoleKeyInfo? key = null, object arg = null)
1106
1138
1107
1139
if ( _singleton . _chordDispatchTable . TryGetValue ( PSKeyInfo . FromConsoleKeyInfo ( key . Value ) , out var secondKeyDispatchTable ) )
1108
1140
{
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 ) )
1111
1162
{
1112
- _singleton . ProcessOneKey ( secondKey , secondKeyDispatchTable , ignoreIfNoAction : true , arg : arg ) ;
1163
+ argBuffer . Append ( secondKey . KeyChar ) ;
1164
+ _singleton . Render ( ) ;
1165
+ secondKey = ReadKey ( ) ;
1113
1166
}
1114
- else if ( ! IsNumeric ( secondKey ) )
1167
+ int numericArg = int . Parse ( argBuffer . ToString ( ) ) ;
1168
+ if ( secondKeyDispatchTable . TryGetValue ( secondKey , out handler ) )
1115
1169
{
1116
- _singleton . ProcessOneKey ( secondKey , secondKeyDispatchTable , ignoreIfNoAction : true , arg : arg ) ;
1170
+ _singleton . ProcessOneKey ( secondKey , secondKeyDispatchTable , ignoreIfNoAction : true , arg : numericArg ) ;
1117
1171
}
1118
1172
else
1119
1173
{
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 ( ) ;
1140
1175
}
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 ) ) ;
1141
1186
}
1187
+
1188
+ ViChordHandler ( _viChordDGTable , arg ) ;
1142
1189
}
1143
1190
1144
1191
private static bool IsNumeric ( PSKeyInfo key )
@@ -1247,7 +1294,7 @@ public static void ViInsertLine(ConsoleKeyInfo? key = null, object arg = null)
1247
1294
_singleton . MoveToBeginningOfPhrase ( ) ;
1248
1295
_singleton . _buffer . Insert ( _singleton . _current , '\n ' ) ;
1249
1296
//_singleton._current = Math.Max(0, _singleton._current - 1);
1250
- _singleton . SaveEditItem ( EditItemInsertChar . Create ( '\n ' , _singleton . _current ) ) ;
1297
+ _singleton . SaveEditItem ( EditItemInsertChar . Create ( '\n ' , _singleton . _current ) ) ;
1251
1298
_singleton . Render ( ) ;
1252
1299
ViInsertMode ( ) ;
1253
1300
}
0 commit comments