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 694078e

Browse files
committedDec 18, 2020
Supports for 'diw' command
1 parent 2ba2b7c commit 694078e

File tree

6 files changed

+579
-1
lines changed

6 files changed

+579
-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: 9 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") },
@@ -255,6 +258,7 @@ private void SetDefaultViBindings()
255258
{ Keys.E, MakeKeyHandler( ViReplaceEndOfWord, "ViReplaceEndOfWord") },
256259
{ Keys.ucE, MakeKeyHandler( ViReplaceEndOfGlob, "ViReplaceEndOfGlob") },
257260
{ Keys.H, MakeKeyHandler( BackwardReplaceChar, "BackwardReplaceChar") },
261+
{ Keys.I, MakeKeyHandler( BackwardReplaceChar, "BackwardReplaceChar") },
258262
{ Keys.L, MakeKeyHandler( ReplaceChar, "ReplaceChar") },
259263
{ Keys.Space, MakeKeyHandler( ReplaceChar, "ReplaceChar") },
260264
{ Keys._0, MakeKeyHandler( ViBackwardReplaceLine, "ViBackwardReplaceLine") },
@@ -289,6 +293,11 @@ private void SetDefaultViBindings()
289293
{ Keys.Percent, MakeKeyHandler( ViYankPercent, "ViYankPercent") },
290294
};
291295

296+
_viChordTextObjectsTable = new Dictionary<PSKeyInfo, KeyHandler>
297+
{
298+
{ Keys.W, MakeKeyHandler(ViHandleTextObject, "WordTextObject")},
299+
};
300+
292301
_viChordDGTable = new Dictionary<PSKeyInfo, KeyHandler>
293302
{
294303
{ Keys.G, MakeKeyHandler( DeleteRelativeLines, "DeleteRelativeLines") },
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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+
var startedAtBeginningOfLine =
66+
i == 0 ||
67+
buffer[i - 1] == '\n'
68+
;
69+
70+
// if starting on a word consider a text object as a sequence of characters excluding the delimiters
71+
// otherwise, consider a word as a sequence of delimiters
72+
73+
var delimiters = wordDelimiters;
74+
75+
if (buffer.InWord(i, wordDelimiters))
76+
{
77+
delimiters += " \t\n";
78+
}
79+
if (buffer.IsWhiteSpace(i))
80+
{
81+
delimiters = " \t";
82+
}
83+
84+
var isTextObjectChar = buffer.InWord(i, wordDelimiters)
85+
? (Func<char, bool>)(c => delimiters.IndexOf(c) == -1)
86+
: c => delimiters.IndexOf(c) != -1
87+
;
88+
89+
// if starting on a newline
90+
91+
if (buffer[i] == '\n' && i < buffer.Length - 1)
92+
{
93+
// try to skip two newline characters
94+
// to replicate vim behaviour
95+
96+
++i;
97+
98+
if (buffer[i] == '\n' && i < buffer.Length - 1)
99+
{
100+
++i;
101+
}
102+
}
103+
104+
// skip to next non word characters
105+
106+
while (i < buffer.Length && isTextObjectChar(buffer[i]))
107+
{
108+
++i;
109+
}
110+
111+
// when starting the search on a newline
112+
// skip one space character
113+
// replicate vim behaviour
114+
115+
if (startedAtBeginningOfLine && (i < buffer.Length && buffer.IsVisibleBlank(i)) && i < buffer.Length - 1)
116+
{
117+
++i;
118+
}
119+
120+
// make sure end includes the starting position
121+
122+
return Math.Max(i, position);
123+
}
124+
}
125+
}

‎PSReadLine/TextObjects.Vi.cs

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
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+
41+
if (!key.HasValue)
42+
{
43+
ResetTextObjectState();
44+
throw new ArgumentNullException(nameof(key));
45+
}
46+
47+
_textObjectSpan = GetRequestedTextObjectSpan(key.Value);
48+
49+
// handle text object
50+
51+
var textObjectKey = ReadKey();
52+
if (_viChordTextObjectsTable.TryGetValue(textObjectKey, out _))
53+
{
54+
_singleton.ProcessOneKey(textObjectKey, _viChordTextObjectsTable, ignoreIfNoAction: true, arg: arg);
55+
}
56+
else
57+
{
58+
ResetTextObjectState();
59+
Ding();
60+
}
61+
}
62+
63+
private TextObjectSpan GetRequestedTextObjectSpan(ConsoleKeyInfo key)
64+
{
65+
if (key.KeyChar == 'i')
66+
{
67+
return TextObjectSpan.Inner;
68+
}
69+
else if (key.KeyChar == 'a')
70+
{
71+
return TextObjectSpan.Around;
72+
}
73+
else
74+
{
75+
System.Diagnostics.Debug.Assert(false);
76+
throw new NotSupportedException();
77+
}
78+
}
79+
80+
private static void ViHandleTextObject(ConsoleKeyInfo? key = null, object arg = null)
81+
{
82+
if (
83+
!_singleton._textObjectHandlers.TryGetValue(_singleton._textObjectOperation, out var textObjectHandler) ||
84+
!textObjectHandler.TryGetValue(_singleton._textObjectSpan, out var handler)
85+
)
86+
{
87+
ResetTextObjectState();
88+
Ding();
89+
return;
90+
}
91+
92+
handler.Action(key, arg);
93+
}
94+
95+
private static void ResetTextObjectState()
96+
{
97+
_singleton._textObjectOperation = TextObjectOperation.None;
98+
_singleton._textObjectSpan = TextObjectSpan.None;
99+
}
100+
101+
private static void ViDeleteInnerWord(ConsoleKeyInfo? key = null, object arg = null)
102+
{
103+
var delimiters = _singleton.Options.WordDelimiters;
104+
105+
if (TryGetArgAsInt(arg, out var numericArg, 1))
106+
{
107+
if (_singleton._buffer.Length == 0)
108+
{
109+
if (numericArg > 1)
110+
{
111+
Ding();
112+
}
113+
return;
114+
}
115+
116+
// unless at the end of the buffer a single delete word should not delete backwards
117+
// so if the cursor is on an empty line, do nothing
118+
119+
if (
120+
numericArg == 1 &&
121+
_singleton._current < _singleton._buffer.Length &&
122+
_singleton._buffer.IsLogigalLineEmpty(_singleton._current)
123+
)
124+
{
125+
return;
126+
}
127+
128+
var start = _singleton._buffer.ViFindBeginningOfWordObjectBoundary(_singleton._current, delimiters);
129+
var end = _singleton._current;
130+
131+
// attempting to find a valid position for multiple words
132+
// if no valid position is found, this is a no-op
133+
134+
{
135+
while (numericArg-- > 0 && end < _singleton._buffer.Length)
136+
{
137+
end = _singleton._buffer.ViFindBeginningOfNextWordObjectBoundary(end, delimiters);
138+
}
139+
140+
// attempting to delete too many words should ding
141+
142+
if (numericArg > 0)
143+
{
144+
Ding();
145+
return;
146+
}
147+
}
148+
149+
_singleton.RemoveTextToClipboard(start, end - start);
150+
_singleton.AdjustCursorPosition(start);
151+
_singleton.Render();
152+
}
153+
}
154+
155+
/// <summary>
156+
/// Attempt to set the cursor at the specified position.
157+
/// </summary>
158+
/// <param name="position"></param>
159+
/// <returns></returns>
160+
private int AdjustCursorPosition(int position)
161+
{
162+
// this method might prove useful in a more general case
163+
164+
if (_buffer.Length == 0)
165+
{
166+
_current = 0;
167+
return 0;
168+
}
169+
170+
var maxPosition = _buffer[_buffer.Length - 1] == '\n'
171+
? _buffer.Length
172+
: _buffer.Length - 1
173+
;
174+
175+
var newCurrent = Math.Min(position, maxPosition);
176+
177+
var beginning = GetBeginningOfLinePos(newCurrent);
178+
179+
if (newCurrent < _buffer.Length && _buffer[newCurrent] == '\n' && (newCurrent + ViEndOfLineFactor > beginning))
180+
{
181+
newCurrent += ViEndOfLineFactor;
182+
}
183+
184+
_current = newCurrent;
185+
186+
return newCurrent;
187+
}
188+
}
189+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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(14, buffer.ViFindBeginningOfNextWordObjectBoundary(13, wordDelimiters));
64+
Assert.Equal(20, buffer.ViFindBeginningOfNextWordObjectBoundary(14, wordDelimiters));
65+
Assert.Equal(25, buffer.ViFindBeginningOfNextWordObjectBoundary(20, wordDelimiters));
66+
Assert.Equal(26, buffer.ViFindBeginningOfNextWordObjectBoundary(25, wordDelimiters));
67+
Assert.Equal(27, buffer.ViFindBeginningOfNextWordObjectBoundary(26, wordDelimiters));
68+
Assert.Equal(30, buffer.ViFindBeginningOfNextWordObjectBoundary(27, wordDelimiters));
69+
Assert.Equal(32, buffer.ViFindBeginningOfNextWordObjectBoundary(30, wordDelimiters));
70+
Assert.Equal(34, buffer.ViFindBeginningOfNextWordObjectBoundary(32, wordDelimiters));
71+
Assert.Equal(35, buffer.ViFindBeginningOfNextWordObjectBoundary(34, wordDelimiters));
72+
Assert.Equal(38, buffer.ViFindBeginningOfNextWordObjectBoundary(35, wordDelimiters));
73+
Assert.Equal(40, buffer.ViFindBeginningOfNextWordObjectBoundary(38, wordDelimiters));
74+
Assert.Equal(45, buffer.ViFindBeginningOfNextWordObjectBoundary(40, wordDelimiters));
75+
Assert.Equal(46, buffer.ViFindBeginningOfNextWordObjectBoundary(45, wordDelimiters));
76+
Assert.Equal(50, buffer.ViFindBeginningOfNextWordObjectBoundary(46, wordDelimiters));
77+
}
78+
}
79+
}

‎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.