Skip to content

Commit ab7d667

Browse files
committed
merge
2 parents eb8cb44 + 524be85 commit ab7d667

8 files changed

+117
-54
lines changed

Terminal.Gui/Terminal.Gui.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<InformationalVersion>1.9</InformationalVersion>
1616
</PropertyGroup>
1717
<ItemGroup>
18+
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="3.1.6" />
1819
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="all" />
1920
<PackageReference Include="NStack.Core" Version="1.0.7" />
2021
<InternalsVisibleTo Include="UnitTests" />

Terminal.Gui/Views/TextField.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,10 @@ private void ContextMenu_KeyChanged (Key obj)
235235

236236
private void HistoryText_ChangeText (HistoryText.HistoryTextItem obj)
237237
{
238-
Text = ustring.Make (obj.Lines [obj.CursorPosition.Y]);
238+
if (obj == null)
239+
return;
240+
241+
Text = ustring.Make (obj?.Lines [obj.CursorPosition.Y]);
239242
CursorPosition = obj.CursorPosition.X;
240243
Adjust ();
241244
}

Terminal.Gui/Views/TextView.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ public int GetModelColFromWrappedLines (int line, int col)
851851
var firstLine = wrappedModelLines.IndexOf (r => r.ModelLine == modelLine);
852852
int modelCol = 0;
853853

854-
for (int i = firstLine; i <= line; i++) {
854+
for (int i = firstLine; i <= Math.Min (line, wrappedModelLines.Count - 1); i++) {
855855
var wLine = wrappedModelLines [i];
856856

857857
if (i < line) {
@@ -1165,7 +1165,7 @@ public class TextView : View {
11651165
/// Unlike the <see cref="TextChanged"/> event, this event is raised whenever the user types or
11661166
/// otherwise changes the contents of the <see cref="TextView"/>.
11671167
/// </remarks>
1168-
public Action<ContentsChangedEventArgs> ContentsChanged;
1168+
public event Action<ContentsChangedEventArgs> ContentsChanged;
11691169

11701170
/// <summary>
11711171
/// Invoked with the unwrapped <see cref="CursorPosition"/>.
@@ -1432,7 +1432,7 @@ private void HistoryText_ChangeText (HistoryText.HistoryTextItem obj)
14321432
}
14331433

14341434
UpdateWrapModel ();
1435-
1435+
14361436
Adjust ();
14371437
OnContentsChanged ();
14381438
}
@@ -1830,14 +1830,14 @@ public bool LoadFile (string path)
18301830
try {
18311831
SetWrapModel ();
18321832
res = model.LoadFile (path);
1833+
historyText.Clear (Text);
18331834
ResetPosition ();
18341835
} catch (Exception) {
18351836
throw;
18361837
} finally {
18371838
UpdateWrapModel ();
18381839
SetNeedsDisplay ();
18391840
Adjust ();
1840-
OnContentsChanged ();
18411841
}
18421842
return res;
18431843
}
@@ -1850,9 +1850,9 @@ public bool LoadFile (string path)
18501850
public void LoadStream (Stream stream)
18511851
{
18521852
model.LoadStream (stream);
1853+
historyText.Clear (Text);
18531854
ResetPosition ();
18541855
SetNeedsDisplay ();
1855-
OnContentsChanged ();
18561856
}
18571857

18581858
/// <summary>

UICatalog/UICatalog.cs

+3-6
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public UICatalogTopLevel ()
178178
"About UI Catalog", () => MessageBox.Query ("About UI Catalog", _aboutMessage.ToString(), "_Ok"), null, null, Key.CtrlMask | Key.A),
179179
}),
180180
});
181-
181+
182182
Capslock = new StatusItem (Key.CharMask, "Caps", null);
183183
Numlock = new StatusItem (Key.CharMask, "Num", null);
184184
Scrolllock = new StatusItem (Key.CharMask, "Scroll", null);
@@ -189,9 +189,6 @@ public UICatalogTopLevel ()
189189
Visible = true,
190190
};
191191
StatusBar.Items = new StatusItem [] {
192-
Capslock,
193-
Numlock,
194-
Scrolllock,
195192
new StatusItem(Key.Q | Key.CtrlMask, "~CTRL-Q~ Quit", () => {
196193
if (_selectedScenario is null){
197194
// This causes GetScenarioToRun to return null
@@ -201,7 +198,7 @@ public UICatalogTopLevel ()
201198
_selectedScenario.RequestStop();
202199
}
203200
}),
204-
new StatusItem(Key.F10, "~F10~ Hide/Show Status Bar", () => {
201+
new StatusItem(Key.F10, "~F10~ Status Bar", () => {
205202
StatusBar.Visible = !StatusBar.Visible;
206203
LeftPane.Height = Dim.Fill(StatusBar.Visible ? 1 : 0);
207204
RightPane.Height = Dim.Fill(StatusBar.Visible ? 1 : 0);
@@ -284,7 +281,7 @@ void LoadedHandler ()
284281
miIsMouseDisabled.Checked = Application.IsMouseDisabled;
285282
miHeightAsBuffer.Checked = Application.HeightAsBuffer;
286283
DriverName.Title = $"Driver: {Driver.GetType ().Name}";
287-
OS.Title = $"OS: {Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment.OperatingSystem}";
284+
OS.Title = $"OS: {Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment.OperatingSystem} {Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment.OperatingSystemVersion}";
288285

289286
if (_selectedScenario != null) {
290287
_selectedScenario = null;

UICatalog/UICatalog.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<DefineConstants>TRACE;DEBUG_IDISPOSABLE</DefineConstants>
2020
</PropertyGroup>
2121
<ItemGroup>
22-
<PackageReference Include="CsvHelper" Version="30.0.0" />
22+
<PackageReference Include="CsvHelper" Version="30.0.1" />
2323
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="3.1.6" />
2424
</ItemGroup>
2525
<ItemGroup>

UnitTests/TextFieldTests.cs

+15
Original file line numberDiff line numberDiff line change
@@ -1281,5 +1281,20 @@ public void ScrollOffset_Initialize ()
12811281
Assert.Equal (0, tf.ScrollOffset);
12821282
Assert.Equal (16, tf.CursorPosition);
12831283
}
1284+
1285+
[Fact]
1286+
public void HistoryText_IsDirty_ClearHistoryChanges ()
1287+
{
1288+
var text = "Testing";
1289+
var tf = new TextField (text);
1290+
1291+
Assert.Equal (text, tf.Text);
1292+
tf.ClearHistoryChanges ();
1293+
Assert.False (tf.IsDirty);
1294+
1295+
Assert.True (tf.ProcessKey (new KeyEvent (Key.A, new KeyModifiers ())));
1296+
Assert.Equal ($"{text}A", tf.Text);
1297+
Assert.True (tf.IsDirty);
1298+
}
12841299
}
12851300
}

0 commit comments

Comments
 (0)