@@ -11,7 +11,32 @@ public partial class PSConsoleReadLine
11
11
internal sealed class ViRegister
12
12
{
13
13
private readonly PSConsoleReadLine _singleton ;
14
- private string _text ;
14
+ private string _localText ;
15
+ private string Text
16
+ {
17
+ get
18
+ {
19
+ if ( _singleton . Options . ViClipboardMode == ViClipboardMode . ViRegister )
20
+ {
21
+ return _localText ;
22
+ }
23
+ else
24
+ {
25
+ return Internal . Clipboard . GetText ( ) ;
26
+ }
27
+ }
28
+ set
29
+ {
30
+ if ( _singleton . Options . ViClipboardMode == ViClipboardMode . ViRegister )
31
+ {
32
+ _localText = value ;
33
+ }
34
+ else
35
+ {
36
+ Internal . Clipboard . SetText ( value ) ;
37
+ }
38
+ }
39
+ }
15
40
16
41
/// <summary>
17
42
/// Initialize a new instance of the <see cref="ViRegister" /> class.
@@ -29,7 +54,7 @@ public ViRegister(PSConsoleReadLine singleton)
29
54
/// Returns whether this register is empty.
30
55
/// </summary>
31
56
public bool IsEmpty
32
- => String . IsNullOrEmpty ( _text ) ;
57
+ => String . IsNullOrEmpty ( Text ) ;
33
58
34
59
/// <summary>
35
60
/// Returns whether this register contains
@@ -41,7 +66,7 @@ public bool IsEmpty
41
66
/// Gets the raw text contained in the register
42
67
/// </summary>
43
68
public string RawText
44
- => _text ;
69
+ => Text ;
45
70
46
71
/// <summary>
47
72
/// Records the entire buffer in the register.
@@ -67,7 +92,7 @@ public void Record(StringBuilder buffer, int offset, int count)
67
92
System . Diagnostics . Debug . Assert ( offset + count <= buffer . Length ) ;
68
93
69
94
HasLinewiseText = false ;
70
- _text = buffer . ToString ( offset , count ) ;
95
+ Text = buffer . ToString ( offset , count ) ;
71
96
}
72
97
73
98
/// <summary>
@@ -77,7 +102,7 @@ public void Record(StringBuilder buffer, int offset, int count)
77
102
public void LinewiseRecord ( string text )
78
103
{
79
104
HasLinewiseText = true ;
80
- _text = text ;
105
+ Text = text ;
81
106
}
82
107
83
108
public int PasteAfter ( StringBuilder buffer , int position )
@@ -89,7 +114,7 @@ public int PasteAfter(StringBuilder buffer, int position)
89
114
90
115
if ( HasLinewiseText )
91
116
{
92
- var text = _text ;
117
+ var text = Text ;
93
118
94
119
if ( text [ 0 ] != '\n ' )
95
120
{
@@ -127,8 +152,9 @@ public int PasteAfter(StringBuilder buffer, int position)
127
152
position += 1 ;
128
153
}
129
154
130
- InsertAt ( buffer , _text , position , position ) ;
131
- position += _text . Length - 1 ;
155
+ var text = Text ;
156
+ InsertAt ( buffer , text , position , position ) ;
157
+ position += text . Length - 1 ;
132
158
133
159
return position ;
134
160
}
@@ -145,7 +171,7 @@ public int PasteBefore(StringBuilder buffer, int position)
145
171
146
172
position = Math . Max ( 0 , Math . Min ( position , buffer . Length - 1 ) ) ;
147
173
148
- var text = _text ;
174
+ var text = Text ;
149
175
150
176
if ( text [ 0 ] == '\n ' )
151
177
{
@@ -184,8 +210,9 @@ public int PasteBefore(StringBuilder buffer, int position)
184
210
}
185
211
else
186
212
{
187
- InsertAt ( buffer , _text , position , position ) ;
188
- return position + _text . Length - 1 ;
213
+ var text = Text ;
214
+ InsertAt ( buffer , text , position , position ) ;
215
+ return position + text . Length - 1 ;
189
216
}
190
217
}
191
218
0 commit comments