@@ -237,14 +237,11 @@ public static void DeleteToEnd(ConsoleKeyInfo? key = null, object arg = null)
237237 var length = endPosition - startPosition + 1 ;
238238 if ( length > 0 )
239239 {
240- _clipboard . Record ( _singleton . _buffer , startPosition , length ) ;
241- _singleton . SaveEditItem ( EditItemDelete . Create (
242- _clipboard ,
243- _singleton . _current ,
240+ _singleton . RemoveTextToViRegister (
241+ startPosition ,
242+ length ,
244243 DeleteToEnd ,
245- arg ) ) ;
246-
247- _singleton . _buffer . Remove ( _singleton . _current , length ) ;
244+ arg ) ;
248245
249246 // the cursor will go back one character, unless at the beginning of the line
250247 var endOfLineCursorPos = GetEndOfLogicalLinePos ( _singleton . _current ) - 1 ;
@@ -282,14 +279,12 @@ public static void DeleteWord(ConsoleKeyInfo? key = null, object arg = null)
282279
283280 private static void DeleteToEndPoint ( object arg , int endPoint , Action < ConsoleKeyInfo ? , object > instigator )
284281 {
285- _singleton . SaveToClipboard ( _singleton . _current , endPoint - _singleton . _current ) ;
286- _singleton . SaveEditItem ( EditItemDelete . Create (
287- _clipboard ,
282+ _singleton . RemoveTextToViRegister (
288283 _singleton . _current ,
284+ endPoint - _singleton . _current ,
289285 instigator ,
290- arg
291- ) ) ;
292- _singleton . _buffer . Remove ( _singleton . _current , endPoint - _singleton . _current ) ;
286+ arg ) ;
287+
293288 if ( _singleton . _current >= _singleton . _buffer . Length )
294289 {
295290 _singleton . _current = Math . Max ( 0 , _singleton . _buffer . Length - 1 ) ;
@@ -301,14 +296,12 @@ private static void DeleteBackwardToEndPoint(object arg, int endPoint, Action<Co
301296 {
302297 int deleteLength = _singleton . _current - endPoint ;
303298
304- _singleton . SaveToClipboard ( endPoint , deleteLength ) ;
305- _singleton . SaveEditItem ( EditItemDelete . Create (
306- _clipboard ,
299+ _singleton . RemoveTextToViRegister (
307300 endPoint ,
301+ deleteLength ,
308302 instigator ,
309- arg
310- ) ) ;
311- _singleton . _buffer . Remove ( endPoint , deleteLength ) ;
303+ arg ) ;
304+
312305 _singleton . _current = endPoint ;
313306 _singleton . Render ( ) ;
314307 }
@@ -324,21 +317,8 @@ public static void ViDeleteGlob(ConsoleKeyInfo? key = null, object arg = null)
324317 {
325318 endPoint = _singleton . ViFindNextGlob ( endPoint ) ;
326319 }
327- int length = endPoint - _singleton . _current ;
328320
329- _singleton . SaveToClipboard ( _singleton . _current , length ) ;
330- _singleton . SaveEditItem ( EditItemDelete . Create (
331- _clipboard ,
332- _singleton . _current ,
333- ViDeleteGlob ,
334- arg
335- ) ) ;
336- _singleton . _buffer . Remove ( _singleton . _current , length ) ;
337- if ( _singleton . _current >= _singleton . _buffer . Length )
338- {
339- _singleton . _current = Math . Max ( 0 , _singleton . _buffer . Length - 1 ) ;
340- }
341- _singleton . Render ( ) ;
321+ DeleteToEndPoint ( arg , endPoint , ViDeleteGlob ) ;
342322 }
343323
344324 /// <summary>
@@ -358,19 +338,8 @@ public static void DeleteEndOfWord(ConsoleKeyInfo? key = null, object arg = null
358338 Ding ( ) ;
359339 return ;
360340 }
361- _singleton . SaveToClipboard ( _singleton . _current , 1 + endPoint - _singleton . _current ) ;
362- _singleton . SaveEditItem ( EditItemDelete . Create (
363- _clipboard ,
364- _singleton . _current ,
365- DeleteEndOfWord ,
366- arg
367- ) ) ;
368- _singleton . _buffer . Remove ( _singleton . _current , 1 + endPoint - _singleton . _current ) ;
369- if ( _singleton . _current >= _singleton . _buffer . Length )
370- {
371- _singleton . _current = Math . Max ( 0 , _singleton . _buffer . Length - 1 ) ;
372- }
373- _singleton . Render ( ) ;
341+
342+ DeleteToEndPoint ( arg , 1 + endPoint , DeleteEndOfWord ) ;
374343 }
375344
376345 /// <summary>
@@ -385,19 +354,7 @@ public static void ViDeleteEndOfGlob(ConsoleKeyInfo? key = null, object arg = nu
385354 endPoint = _singleton . ViFindGlobEnd ( endPoint ) ;
386355 }
387356
388- _singleton . SaveToClipboard ( _singleton . _current , 1 + endPoint - _singleton . _current ) ;
389- _singleton . SaveEditItem ( EditItemDelete . Create (
390- _clipboard ,
391- _singleton . _current ,
392- ViDeleteEndOfGlob ,
393- arg
394- ) ) ;
395- _singleton . _buffer . Remove ( _singleton . _current , 1 + endPoint - _singleton . _current ) ;
396- if ( _singleton . _current >= _singleton . _buffer . Length )
397- {
398- _singleton . _current = Math . Max ( 0 , _singleton . _buffer . Length - 1 ) ;
399- }
400- _singleton . Render ( ) ;
357+ DeleteToEndPoint ( arg , 1 + endPoint , ViDeleteEndOfGlob ) ;
401358 }
402359
403360 /// <summary>
@@ -724,10 +681,12 @@ public static void DeleteLineToFirstChar(ConsoleKeyInfo? key = null, object arg
724681 {
725682 var i = GetFirstNonBlankOfLogicalLinePos ( _singleton . _current ) ;
726683
727- _singleton . SaveToClipboard ( i , _singleton . _current - i ) ;
728- _singleton . SaveEditItem ( EditItemDelete . Create ( _clipboard , i , DeleteLineToFirstChar ) ) ;
684+ _singleton . RemoveTextToViRegister (
685+ i ,
686+ _singleton . _current - i ,
687+ DeleteLineToFirstChar ,
688+ arg ) ;
729689
730- _singleton . _buffer . Remove ( i , _singleton . _current - i ) ;
731690 _singleton . _current = i ;
732691 _singleton . Render ( ) ;
733692 }
@@ -775,7 +734,7 @@ private static int DeleteLineImpl(int lineIndex, int lineCount)
775734
776735 var deleteText = _singleton . _buffer . ToString ( range . Offset , range . Count ) ;
777736
778- _clipboard . LinewiseRecord ( deleteText ) ;
737+ _viRegister . LinewiseRecord ( deleteText ) ;
779738
780739 var deletePosition = range . Offset ;
781740 var anchor = _singleton . _current ;
@@ -890,14 +849,12 @@ public static void BackwardDeleteWord(ConsoleKeyInfo? key = null, object arg = n
890849 Ding ( ) ;
891850 return ;
892851 }
893- _clipboard . Record ( _singleton . _buffer , deletePoint , _singleton . _current - deletePoint ) ;
894- _singleton . SaveEditItem ( EditItemDelete . Create (
895- _clipboard ,
852+ _singleton . RemoveTextToViRegister (
896853 deletePoint ,
854+ _singleton . _current - deletePoint ,
897855 BackwardDeleteWord ,
898- arg
899- ) ) ;
900- _singleton . _buffer . Remove ( deletePoint , _singleton . _current - deletePoint ) ;
856+ arg ) ;
857+
901858 _singleton . _current = deletePoint ;
902859 _singleton . Render ( ) ;
903860 }
@@ -923,14 +880,12 @@ public static void ViBackwardDeleteGlob(ConsoleKeyInfo? key = null, object arg =
923880 Ding ( ) ;
924881 return ;
925882 }
926- _clipboard . Record ( _singleton . _buffer , deletePoint , _singleton . _current - deletePoint ) ;
927- _singleton . SaveEditItem ( EditItemDelete . Create (
928- _clipboard ,
883+ _singleton . RemoveTextToViRegister (
929884 deletePoint ,
885+ _singleton . _current - deletePoint ,
930886 BackwardDeleteWord ,
931- arg
932- ) ) ;
933- _singleton . _buffer . Remove ( deletePoint , _singleton . _current - deletePoint ) ;
887+ arg ) ;
888+
934889 _singleton . _current = deletePoint ;
935890 _singleton . Render ( ) ;
936891 }
@@ -966,10 +921,12 @@ private static void DeleteRange(int first, int last, Action<ConsoleKeyInfo?, obj
966921 {
967922 int length = last - first + 1 ;
968923
969- _singleton . SaveToClipboard ( first , length ) ;
970- _singleton . SaveEditItem ( EditItemDelete . Create ( _clipboard , first , action ) ) ;
924+ _singleton . RemoveTextToViRegister (
925+ first ,
926+ length ,
927+ action ) ;
928+
971929 _singleton . _current = first ;
972- _singleton . _buffer . Remove ( first , length ) ;
973930 _singleton . Render ( ) ;
974931 }
975932
0 commit comments