Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 24dbaa4

Browse files
committedDec 31, 2020
Supports 'diw' command.
1 parent 7e2b882 commit 24dbaa4

7 files changed

+586
-1
lines changed
 

‎PSReadLine/Cmdlets.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public class PSConsoleReadLineOptions
141141
public const int DefaultCompletionQueryItems = 100;
142142

143143
// Default includes all characters PowerShell treats like a dash - em dash, en dash, horizontal bar
144-
public const string DefaultWordDelimiters = @";:,.[]{}()/\|^&*-=+'""" + "\u2013\u2014\u2015";
144+
public const string DefaultWordDelimiters = @";:,.[]{}()/\|!?^&*-=+'""" + "\u2013\u2014\u2015";
145145

146146
/// <summary>
147147
/// When ringing the bell, what should be done?

‎PSReadLine/KeyBindings.vi.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ internal static ConsoleColor AlternateBackground(ConsoleColor bg)
4545
private static Dictionary<PSKeyInfo, KeyHandler> _viChordYTable;
4646
private static Dictionary<PSKeyInfo, KeyHandler> _viChordDGTable;
4747

48+
private static Dictionary<PSKeyInfo, KeyHandler> _viChordTextObjectsTable;
49+
4850
private static Dictionary<PSKeyInfo, Dictionary<PSKeyInfo, KeyHandler>> _viCmdChordTable;
4951
private static Dictionary<PSKeyInfo, Dictionary<PSKeyInfo, KeyHandler>> _viInsChordTable;
5052

@@ -231,6 +233,7 @@ private void SetDefaultViBindings()
231233
{ Keys.ucG, MakeKeyHandler( DeleteEndOfBuffer, "DeleteEndOfBuffer") },
232234
{ Keys.ucE, MakeKeyHandler( ViDeleteEndOfGlob, "ViDeleteEndOfGlob") },
233235
{ Keys.H, MakeKeyHandler( BackwardDeleteChar, "BackwardDeleteChar") },
236+
{ Keys.I, MakeKeyHandler( ViChordDeleteTextObject, "ChordViTextObject") },
234237
{ Keys.J, MakeKeyHandler( DeleteNextLines, "DeleteNextLines") },
235238
{ Keys.K, MakeKeyHandler( DeletePreviousLines, "DeletePreviousLines") },
236239
{ Keys.L, MakeKeyHandler( DeleteChar, "DeleteChar") },
@@ -289,6 +292,11 @@ private void SetDefaultViBindings()
289292
{ Keys.Percent, MakeKeyHandler( ViYankPercent, "ViYankPercent") },
290293
};
291294

295+
_viChordTextObjectsTable = new Dictionary<PSKeyInfo, KeyHandler>
296+
{
297+
{ Keys.W, MakeKeyHandler(ViHandleTextObject, "WordTextObject")},
298+
};
299+
292300
_viChordDGTable = new Dictionary<PSKeyInfo, KeyHandler>
293301
{
294302
{ Keys.G, MakeKeyHandler( DeleteRelativeLines, "DeleteRelativeLines") },

‎PSReadLine/StringBuilderCharacterExtensions.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ public static bool InWord(this StringBuilder buffer, int i, string wordDelimiter
3434
return Character.IsInWord(buffer[i], wordDelimiters);
3535
}
3636

37+
/// <summary>
38+
/// Returns true if the character at the specified position is
39+
/// at the end of the buffer
40+
/// </summary>
41+
/// <param name="buffer"></param>
42+
/// <param name="i"></param>
43+
/// <returns></returns>
44+
public static bool IsAtEndOfBuffer(this StringBuilder buffer, int i)
45+
{
46+
return i >= (buffer.Length - 1);
47+
}
48+
3749
/// <summary>
3850
/// Returns true if the character at the specified position is
3951
/// a unicode whitespace character.
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
using System;
2+
using System.Text;
3+
4+
namespace Microsoft.PowerShell
5+
{
6+
internal static partial class StringBuilderTextObjectExtensions
7+
{
8+
/// <summary>
9+
/// Returns the position of the beginning of the current word as delimited by white space and delimiters
10+
/// This method differs from <see cref="ViFindPreviousWordPoint(string)" />:
11+
/// When the cursor location is on the first character of a word, <see cref="ViFindPreviousWordPoint(string)" />
12+
/// returns the position of the previous word, whereas this method returns the cursor location.
13+
///
14+
/// When the cursor location is in a word, both methods return the same result.
15+
///
16+
/// This method supports VI "iw" text object.
17+
/// </summary>
18+
public static int ViFindBeginningOfWordObjectBoundary(this StringBuilder buffer, int position, string wordDelimiters)
19+
{
20+
// cursor may be past the end of the buffer when calling this method
21+
// this may happen if the cursor is at the beginning of a new line
22+
23+
var i = Math.Min(position, buffer.Length - 1);
24+
25+
// if starting on a word consider a text object as a sequence of characters excluding the delimiters
26+
// otherwise, consider a word as a sequence of delimiters
27+
28+
var delimiters = wordDelimiters + '\n';
29+
if (buffer.InWord(i, wordDelimiters))
30+
{
31+
delimiters += " \t";
32+
}
33+
if (delimiters.IndexOf(buffer[i]) == -1 && buffer.IsWhiteSpace(i))
34+
{
35+
delimiters = " \t";
36+
}
37+
38+
var isTextObjectChar = buffer.InWord(i, wordDelimiters)
39+
? (Func<char, bool>)(c => delimiters.IndexOf(c) == -1)
40+
: c => delimiters.IndexOf(c) != -1
41+
;
42+
43+
var beginning = i;
44+
while (i >= 0 && isTextObjectChar(buffer[i]))
45+
{
46+
beginning = i--;
47+
}
48+
49+
return beginning;
50+
}
51+
52+
/// <summary>
53+
/// Finds the position of the beginning of the next word object starting from the specified position.
54+
/// If positioned on the last word in the buffer, returns buffer length + 1.
55+
/// This method supports VI "iw" text-object.
56+
/// iw: "inner word", select words. White space between words is counted too.
57+
/// </summary>
58+
public static int ViFindBeginningOfNextWordObjectBoundary(this StringBuilder buffer, int position, string wordDelimiters)
59+
{
60+
// cursor may be past the end of the buffer when calling this method
61+
// this may happen if the cursor is at the beginning of a new line
62+
63+
var i = Math.Min(position, buffer.Length - 1);
64+
65+
// always skip the first newline character
66+
67+
if (buffer[i] == '\n' && i < buffer.Length - 1)
68+
{
69+
// try to skip a second newline characters
70+
// to replicate vim behaviour
71+
72+
++i;
73+
}
74+
75+
// if starting on a word consider a text object as a sequence of characters excluding the delimiters
76+
// otherwise, consider a word as a sequence of delimiters
77+
78+
var delimiters = wordDelimiters;
79+
80+
if (buffer.InWord(i, wordDelimiters))
81+
{
82+
delimiters += " \t\n";
83+
}
84+
if (buffer.IsWhiteSpace(i))
85+
{
86+
delimiters = " \t";
87+
}
88+
89+
var isTextObjectChar = buffer.InWord(i, wordDelimiters)
90+
? (Func<char, bool>)(c => delimiters.IndexOf(c) == -1)
91+
: c => delimiters.IndexOf(c) != -1
92+
;
93+
94+
// try to skip a second newline characters
95+
// to replicate vim behaviour
96+
97+
if (buffer[i] == '\n' && i < buffer.Length - 1)
98+
{
99+
++i;
100+
}
101+
102+
// skip to next non word characters
103+
104+
while (i < buffer.Length && isTextObjectChar(buffer[i]))
105+
{
106+
++i;
107+
}
108+
109+
// make sure end includes the starting position
110+
111+
return Math.Max(i, position);
112+
}
113+
}
114+
}

‎PSReadLine/TextObjects.Vi.cs

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace Microsoft.PowerShell
5+
{
6+
public partial class PSConsoleReadLine
7+
{
8+
internal enum TextObjectOperation
9+
{
10+
None,
11+
Change,
12+
Delete,
13+
}
14+
15+
internal enum TextObjectSpan
16+
{
17+
None,
18+
Around,
19+
Inner,
20+
}
21+
22+
private TextObjectOperation _textObjectOperation = TextObjectOperation.None;
23+
private TextObjectSpan _textObjectSpan = TextObjectSpan.None;
24+
25+
private readonly IDictionary<TextObjectOperation, IDictionary<TextObjectSpan, KeyHandler>> _textObjectHandlers
26+
= new Dictionary<TextObjectOperation, IDictionary<TextObjectSpan, KeyHandler>>
27+
{
28+
{
29+
TextObjectOperation.Delete,
30+
new Dictionary<TextObjectSpan, KeyHandler>
31+
{
32+
{TextObjectSpan.Inner, MakeKeyHandler(ViDeleteInnerWord, "ViDeleteInnerWord")}
33+
}
34+
}
35+
};
36+
37+
private void ViChordDeleteTextObject(ConsoleKeyInfo? key = null, object arg = null)
38+
{
39+
_textObjectOperation = TextObjectOperation.Delete;
40+
ViChordTextObject(key, arg);
41+
}
42+
43+
private void ViChordTextObject(ConsoleKeyInfo? key = null, object arg = null)
44+
{
45+
if (!key.HasValue)
46+
{
47+
ResetTextObjectState();
48+
throw new ArgumentNullException(nameof(key));
49+
}
50+
51+
_textObjectSpan = GetRequestedTextObjectSpan(key.Value);
52+
53+
// handle text object
54+
55+
var textObjectKey = ReadKey();
56+
if (_viChordTextObjectsTable.TryGetValue(textObjectKey, out _))
57+
{
58+
_singleton.ProcessOneKey(textObjectKey, _viChordTextObjectsTable, ignoreIfNoAction: true, arg: arg);
59+
}
60+
else
61+
{
62+
ResetTextObjectState();
63+
Ding();
64+
}
65+
}
66+
67+
private TextObjectSpan GetRequestedTextObjectSpan(ConsoleKeyInfo key)
68+
{
69+
if (key.KeyChar == 'i')
70+
{
71+
return TextObjectSpan.Inner;
72+
}
73+
else if (key.KeyChar == 'a')
74+
{
75+
return TextObjectSpan.Around;
76+
}
77+
else
78+
{
79+
System.Diagnostics.Debug.Assert(false);
80+
throw new NotSupportedException();
81+
}
82+
}
83+
84+
private static void ViHandleTextObject(ConsoleKeyInfo? key = null, object arg = null)
85+
{
86+
if (
87+
!_singleton._textObjectHandlers.TryGetValue(_singleton._textObjectOperation, out var textObjectHandler) ||
88+
!textObjectHandler.TryGetValue(_singleton._textObjectSpan, out var handler)
89+
)
90+
{
91+
ResetTextObjectState();
92+
Ding();
93+
return;
94+
}
95+
96+
handler.Action(key, arg);
97+
}
98+
99+
private static void ResetTextObjectState()
100+
{
101+
_singleton._textObjectOperation = TextObjectOperation.None;
102+
_singleton._textObjectSpan = TextObjectSpan.None;
103+
}
104+
105+
private static void ViDeleteInnerWord(ConsoleKeyInfo? key = null, object arg = null)
106+
{
107+
var delimiters = _singleton.Options.WordDelimiters;
108+
109+
if (!TryGetArgAsInt(arg, out var numericArg, 1))
110+
return;
111+
112+
if (_singleton._buffer.Length == 0)
113+
{
114+
if (numericArg > 1)
115+
{
116+
Ding();
117+
}
118+
return;
119+
}
120+
121+
// unless at the end of the buffer a single delete word should not delete backwards
122+
// so if the cursor is on an empty line, do nothing
123+
124+
if (
125+
numericArg == 1 &&
126+
_singleton._current < _singleton._buffer.Length &&
127+
_singleton._buffer.IsLogigalLineEmpty(_singleton._current)
128+
)
129+
{
130+
return;
131+
}
132+
133+
var start = _singleton._buffer.ViFindBeginningOfWordObjectBoundary(_singleton._current, delimiters);
134+
var end = _singleton._current;
135+
136+
// attempting to find a valid position for multiple words
137+
// if no valid position is found, this is a no-op
138+
139+
{
140+
while (numericArg-- > 0 && end < _singleton._buffer.Length)
141+
{
142+
end = _singleton._buffer.ViFindBeginningOfNextWordObjectBoundary(end, delimiters);
143+
}
144+
145+
// attempting to delete too many words should ding
146+
147+
if (numericArg > 0)
148+
{
149+
Ding();
150+
return;
151+
}
152+
}
153+
154+
if (end > 0 && _singleton._buffer.IsAtEndOfBuffer(end - 1) && _singleton._buffer.InWord(end - 1, delimiters))
155+
{
156+
_singleton._shouldAppend = true;
157+
}
158+
159+
_singleton.RemoveTextToClipboard(start, end - start);
160+
_singleton.AdjustCursorPosition(start);
161+
_singleton.Render();
162+
}
163+
164+
/// <summary>
165+
/// Attempt to set the cursor at the specified position.
166+
/// </summary>
167+
/// <param name="position"></param>
168+
/// <returns></returns>
169+
private int AdjustCursorPosition(int position)
170+
{
171+
// this method might prove useful in a more general case
172+
173+
if (_buffer.Length == 0)
174+
{
175+
_current = 0;
176+
return 0;
177+
}
178+
179+
var maxPosition = _buffer[_buffer.Length - 1] == '\n'
180+
? _buffer.Length
181+
: _buffer.Length - 1
182+
;
183+
184+
var newCurrent = Math.Min(position, maxPosition);
185+
186+
var beginning = GetBeginningOfLinePos(newCurrent);
187+
188+
if (newCurrent < _buffer.Length && _buffer[newCurrent] == '\n' && (newCurrent + ViEndOfLineFactor > beginning))
189+
{
190+
newCurrent += ViEndOfLineFactor;
191+
}
192+
193+
_current = newCurrent;
194+
195+
return newCurrent;
196+
}
197+
}
198+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
using Microsoft.PowerShell;
2+
using System.Text;
3+
using Xunit;
4+
5+
namespace Test
6+
{
7+
public sealed class StringBuilderTextObjectExtensionsTests
8+
{
9+
[Fact]
10+
public void StringBuilderTextObjectExtensions_ViFindBeginningOfWordObjectBoundary()
11+
{
12+
const string wordDelimiters = PSConsoleReadLineOptions.DefaultWordDelimiters;
13+
14+
var buffer = new StringBuilder("Hello, world!\ncruel world.\none\n\n\n\n\ntwo\n three four.");
15+
Assert.Equal(0, buffer.ViFindBeginningOfWordObjectBoundary(1, wordDelimiters));
16+
}
17+
18+
[Fact]
19+
public void StringBuilderTextObjectExtensions_ViFindBeginningOfWordObjectBoundary_whitespace()
20+
{
21+
const string wordDelimiters = PSConsoleReadLineOptions.DefaultWordDelimiters;
22+
23+
var buffer = new StringBuilder("Hello, world!");
24+
Assert.Equal(6, buffer.ViFindBeginningOfWordObjectBoundary(7, wordDelimiters));
25+
}
26+
27+
[Fact]
28+
public void StringBuilderTextObjectExtensions_ViFindBeginningOfWordObjectBoundary_backwards()
29+
{
30+
const string wordDelimiters = PSConsoleReadLineOptions.DefaultWordDelimiters;
31+
32+
var buffer = new StringBuilder("Hello!\nworld!");
33+
Assert.Equal(5, buffer.ViFindBeginningOfWordObjectBoundary(6, wordDelimiters));
34+
}
35+
36+
[Fact]
37+
public void StringBuilderTextObjectExtensions_ViFindBeginningOfWordObjectBoundary_end_of_buffer()
38+
{
39+
const string wordDelimiters = PSConsoleReadLineOptions.DefaultWordDelimiters;
40+
41+
var buffer = new StringBuilder("Hello, world!");
42+
Assert.Equal(12, buffer.ViFindBeginningOfWordObjectBoundary(buffer.Length, wordDelimiters));
43+
}
44+
45+
[Fact]
46+
public void StringBuilderTextObjectExtensions_ViFindBeginningOfNextWordObjectBoundary()
47+
{
48+
const string wordDelimiters = PSConsoleReadLineOptions.DefaultWordDelimiters;
49+
50+
var buffer = new StringBuilder("Hello, world!\ncruel world.\none\n\n\n\n\ntwo\n three four.");
51+
52+
// Words |Hello|,| |world|!|\n|cruel |world|.|\n|one\n\n|\n\n|\n|two|\n |three| |four|.|
53+
// Pos 01234 5 6 78901 2 _3 456789 01234 5 _6 789_0_1 _2_3 _4 567 _89 01234 5 6789 0
54+
// Pos 0 1 2 3 4 5
55+
56+
// system under test
57+
58+
Assert.Equal(5, buffer.ViFindBeginningOfNextWordObjectBoundary(0, wordDelimiters));
59+
Assert.Equal(6, buffer.ViFindBeginningOfNextWordObjectBoundary(5, wordDelimiters));
60+
Assert.Equal(7, buffer.ViFindBeginningOfNextWordObjectBoundary(6, wordDelimiters));
61+
Assert.Equal(12, buffer.ViFindBeginningOfNextWordObjectBoundary(7, wordDelimiters));
62+
Assert.Equal(13, buffer.ViFindBeginningOfNextWordObjectBoundary(12, wordDelimiters));
63+
Assert.Equal(19, buffer.ViFindBeginningOfNextWordObjectBoundary(13, wordDelimiters));
64+
Assert.Equal(20, buffer.ViFindBeginningOfNextWordObjectBoundary(19, wordDelimiters));
65+
Assert.Equal(25, buffer.ViFindBeginningOfNextWordObjectBoundary(20, wordDelimiters));
66+
Assert.Equal(26, buffer.ViFindBeginningOfNextWordObjectBoundary(25, wordDelimiters));
67+
Assert.Equal(30, buffer.ViFindBeginningOfNextWordObjectBoundary(26, wordDelimiters));
68+
Assert.Equal(32, buffer.ViFindBeginningOfNextWordObjectBoundary(30, wordDelimiters));
69+
Assert.Equal(34, buffer.ViFindBeginningOfNextWordObjectBoundary(32, wordDelimiters));
70+
Assert.Equal(38, buffer.ViFindBeginningOfNextWordObjectBoundary(34, wordDelimiters));
71+
Assert.Equal(40, buffer.ViFindBeginningOfNextWordObjectBoundary(38, wordDelimiters));
72+
Assert.Equal(45, buffer.ViFindBeginningOfNextWordObjectBoundary(40, wordDelimiters));
73+
Assert.Equal(46, buffer.ViFindBeginningOfNextWordObjectBoundary(45, wordDelimiters));
74+
Assert.Equal(50, buffer.ViFindBeginningOfNextWordObjectBoundary(46, wordDelimiters));
75+
}
76+
}
77+
}

‎test/TextObjects.Vi.Tests.cs

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
using Microsoft.PowerShell;
2+
using Xunit;
3+
4+
namespace Test
5+
{
6+
public partial class ReadLine
7+
{
8+
[SkippableFact]
9+
public void ViTextObject_diw()
10+
{
11+
TestSetup(KeyMode.Vi);
12+
13+
Test("\"hello, \ncruel world!\"", Keys(
14+
_.DQuote,
15+
"hello, world!", _.Enter,
16+
"cruel world!", _.DQuote,
17+
_.Escape,
18+
19+
// move cursor to the 'o' in 'world'
20+
"gg9l",
21+
22+
// delete text object
23+
"diw",
24+
CheckThat(() => AssertLineIs("\"hello, !\ncruel world!\"")),
25+
CheckThat(() => AssertCursorLeftIs(8)),
26+
27+
// delete
28+
"diw",
29+
CheckThat(() => AssertLineIs("\"hello, \ncruel world!\"")),
30+
CheckThat(() => AssertCursorLeftIs(7))
31+
));
32+
}
33+
34+
[SkippableFact]
35+
public void ViTextObject_diw_digit_arguments()
36+
{
37+
TestSetup(KeyMode.Vi);
38+
39+
Test("\"hello, world!\"", Keys(
40+
_.DQuote,
41+
"hello, world!", _.Enter,
42+
"cruel world!", _.DQuote,
43+
_.Escape,
44+
45+
// move cursor to the 'o' in 'world'
46+
"gg9l",
47+
48+
// delete text object
49+
"diw",
50+
CheckThat(() => AssertLineIs("\"hello, !\ncruel world!\"")),
51+
CheckThat(() => AssertCursorLeftIs(8)),
52+
53+
// delete multiple text objects (spans multiple lines)
54+
"3diw",
55+
CheckThat(() => AssertLineIs("\"hello, world!\"")),
56+
CheckThat(() => AssertCursorLeftIs(8))
57+
));
58+
}
59+
60+
61+
[SkippableFact]
62+
public void ViTextObject_diw_noop()
63+
{
64+
TestSetup(KeyMode.Vi);
65+
66+
TestMustDing("\"hello, world!\ncruel world!\"", Keys(
67+
_.DQuote,
68+
"hello, world!", _.Enter,
69+
"cruel world!", _.DQuote,
70+
_.Escape,
71+
72+
// move cursor to the 'o' in 'world'
73+
"gg9l",
74+
75+
// attempting to delete too many words must ding
76+
"1274diw"
77+
));
78+
}
79+
80+
[SkippableFact]
81+
public void ViTextObject_diw_empty_line()
82+
{
83+
TestSetup(KeyMode.Vi);
84+
85+
var continuationPrefixLength = PSConsoleReadLineOptions.DefaultContinuationPrompt.Length;
86+
87+
Test("\"\nhello, world!\n\noh, bitter world!\n\"", Keys(
88+
_.DQuote, _.Enter,
89+
"hello, world!", _.Enter,
90+
_.Enter,
91+
"oh, bitter world!", _.Enter,
92+
_.DQuote, _.Escape,
93+
94+
// move cursor to the second line
95+
"ggjj",
96+
97+
// deleting single word cannot move backwards to previous line (noop)
98+
"diw",
99+
CheckThat(() => AssertLineIs("\"\nhello, world!\n\noh, bitter world!\n\""))
100+
));
101+
}
102+
103+
[SkippableFact]
104+
public void ViTextObject_diw_end_of_buffer()
105+
{
106+
TestSetup(KeyMode.Vi);
107+
108+
var continuationPrefixLength = PSConsoleReadLineOptions.DefaultContinuationPrompt.Length;
109+
110+
Test("", Keys(
111+
_.DQuote,
112+
"hello, world!", _.Enter,
113+
"cruel world!", _.DQuote,
114+
_.Escape,
115+
116+
// move to end of buffer
117+
"G$",
118+
119+
// delete text object (deletes backwards)
120+
"diw", CheckThat(() => AssertLineIs("\"hello, world!\ncruel world")),
121+
"diw", CheckThat(() => AssertLineIs("\"hello, world!\ncruel ")),
122+
"diw", CheckThat(() => AssertLineIs("\"hello, world!\ncruel")),
123+
"diw", CheckThat(() => AssertLineIs("\"hello, world!\n")),
124+
"diw", CheckThat(() => AssertLineIs("\"hello, world")),
125+
"diw", CheckThat(() => AssertLineIs("\"hello, ")),
126+
"diw", CheckThat(() => AssertLineIs("\"hello,")),
127+
"diw", CheckThat(() => AssertLineIs("\"hello")),
128+
"diw", CheckThat(() => AssertLineIs("\"")),
129+
"diw", CheckThat(() => AssertLineIs(""))
130+
));
131+
}
132+
133+
[SkippableFact]
134+
public void ViTextObject_diw_empty_buffer()
135+
{
136+
TestSetup(KeyMode.Vi);
137+
Test("", Keys(_.Escape, "diw"));
138+
TestMustDing("", Keys(_.Escape, "d2iw"));
139+
}
140+
141+
[SkippableFact]
142+
public void ViTextObject_diw_new_lines()
143+
{
144+
TestSetup(KeyMode.Vi);
145+
146+
var continuationPrefixLength = PSConsoleReadLineOptions.DefaultContinuationPrompt.Length;
147+
148+
Test("\"\ntwo\n\"", Keys(
149+
_.DQuote, _.Enter,
150+
"one", _.Enter,
151+
_.Enter, _.Enter,
152+
_.Enter, _.Enter,
153+
_.Enter,
154+
"two", _.Enter, _.DQuote,
155+
_.Escape,
156+
157+
// move to the beginning of 'one'
158+
"gg0j",
159+
160+
// delete text object
161+
"2diw",
162+
CheckThat(() => AssertLineIs("\"\n\n\n\n\ntwo\n\"")),
163+
164+
"ugg0j", // currently undo does not move the cursor to the correct position
165+
// delete multiple text objects (spans multiple lines)
166+
"3diw",
167+
CheckThat(() => AssertLineIs("\"\n\n\ntwo\n\"")),
168+
169+
"ugg0j", // currently undo does not move the cursor to the correct position
170+
// delete multiple text objects (spans multiple lines)
171+
"4diw",
172+
CheckThat(() => AssertLineIs("\"\ntwo\n\""))
173+
));
174+
}
175+
}
176+
}

0 commit comments

Comments
 (0)
Please sign in to comment.