From aa09fd237526b2de5c7c100de48114a26dcec6d8 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Sat, 9 May 2020 11:46:32 -0700 Subject: [PATCH] Refactor 'SelfInsert' to avoid duplicate logic --- PSReadLine/BasicEditing.cs | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/PSReadLine/BasicEditing.cs b/PSReadLine/BasicEditing.cs index bbfbd39ec..6bd212e68 100644 --- a/PSReadLine/BasicEditing.cs +++ b/PSReadLine/BasicEditing.cs @@ -31,26 +31,20 @@ public static void SelfInsert(ConsoleKeyInfo? key = null, object arg = null) { if (count <= 0) return; - if (count > 1) - { - var toInsert = new string(keyChar, count); - if (_singleton._visualSelectionCommandCount > 0) - { - _singleton.GetRegion(out var start, out var length); - Replace(start, length, toInsert); - } - else - { - Insert(toInsert); - } - return; - } + } + else + { + count = 1; } if (_singleton._visualSelectionCommandCount > 0) { _singleton.GetRegion(out var start, out var length); - Replace(start, length, new string(keyChar, 1)); + Replace(start, length, new string(keyChar, count)); + } + else if (count > 1) + { + Insert(new string(keyChar, count)); } else {