Skip to content

Commit 67f09a4

Browse files
authored
Refactor 'SelfInsert' to avoid duplicate logic (#1510)
1 parent 9e6c6b9 commit 67f09a4

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

PSReadLine/BasicEditing.cs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,20 @@ public static void SelfInsert(ConsoleKeyInfo? key = null, object arg = null)
3131
{
3232
if (count <= 0)
3333
return;
34-
if (count > 1)
35-
{
36-
var toInsert = new string(keyChar, count);
37-
if (_singleton._visualSelectionCommandCount > 0)
38-
{
39-
_singleton.GetRegion(out var start, out var length);
40-
Replace(start, length, toInsert);
41-
}
42-
else
43-
{
44-
Insert(toInsert);
45-
}
46-
return;
47-
}
34+
}
35+
else
36+
{
37+
count = 1;
4838
}
4939

5040
if (_singleton._visualSelectionCommandCount > 0)
5141
{
5242
_singleton.GetRegion(out var start, out var length);
53-
Replace(start, length, new string(keyChar, 1));
43+
Replace(start, length, new string(keyChar, count));
44+
}
45+
else if (count > 1)
46+
{
47+
Insert(new string(keyChar, count));
5448
}
5549
else
5650
{

0 commit comments

Comments
 (0)