From 157a32312bca0fe6b507c2b8a5aa417595b729de Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 13 Mar 2024 21:17:35 +0000 Subject: [PATCH 1/3] Fixes #3317. Listvew mouse event doesn't cause a SelectedItemChanged event to fire --- Terminal.Gui/Views/ListView.cs | 2 -- UnitTests/Views/ListViewTests.cs | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Terminal.Gui/Views/ListView.cs b/Terminal.Gui/Views/ListView.cs index 3e38092be3..36d9d64b33 100644 --- a/Terminal.Gui/Views/ListView.cs +++ b/Terminal.Gui/Views/ListView.cs @@ -802,8 +802,6 @@ public override bool MouseEvent (MouseEvent me) selected = top + me.Y; if (AllowsAll ()) { Source.SetMark (SelectedItem, !Source.IsMarked (SelectedItem)); - SetNeedsDisplay (); - return true; } OnSelectedChanged (); SetNeedsDisplay (); diff --git a/UnitTests/Views/ListViewTests.cs b/UnitTests/Views/ListViewTests.cs index 145caf85d0..2241c355f0 100644 --- a/UnitTests/Views/ListViewTests.cs +++ b/UnitTests/Views/ListViewTests.cs @@ -545,5 +545,24 @@ tem 2 tem 3 tem 4", output); } + + [Fact] + public void SelectedItemChanged_Event_Is_Also_Fired_With_AllowsMarking_True_By_Keyboard_Or_Mouse () + { + var itemChanged = 0; + var lv = new ListView (new List () { "Item1", "Item2", "Item3" }) { Width = 5, Height = 3, AllowsMarking = true }; + lv.SelectedItemChanged += (e) => itemChanged = e.Item; + + Assert.Equal (0, lv.SelectedItem); + Assert.Equal (lv.SelectedItem, itemChanged); + + Assert.True (lv.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers()))); + Assert.Equal (1, lv.SelectedItem); + Assert.Equal (lv.SelectedItem, itemChanged); + + Assert.True (lv.MouseEvent (new MouseEvent(){ X = 0, Y = 2, Flags = MouseFlags.Button1Clicked})); + Assert.Equal (2, lv.SelectedItem); + Assert.Equal (lv.SelectedItem, itemChanged); + } } } From 4eabd71b165f2c4d79b416d915ee80a57ddaa1a8 Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 13 Mar 2024 21:45:11 +0000 Subject: [PATCH 2/3] Reformat only for re-test the CI. --- Terminal.Gui/Views/ListView.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Terminal.Gui/Views/ListView.cs b/Terminal.Gui/Views/ListView.cs index 36d9d64b33..3ccdc03959 100644 --- a/Terminal.Gui/Views/ListView.cs +++ b/Terminal.Gui/Views/ListView.cs @@ -875,7 +875,7 @@ void RenderUstr (ConsoleDriver driver, ustring ustr, int col, int line, int widt /// public void Render (ListView container, ConsoleDriver driver, bool marked, int item, int col, int line, int width, int start = 0) { - var savedClip = container.ClipToBounds(); + var savedClip = container.ClipToBounds (); container.Move (col - start, line); var t = src? [item]; if (t == null) { From b1218d743699703e5d1d06ee6fef6e087c0f6e82 Mon Sep 17 00:00:00 2001 From: BDisp Date: Thu, 14 Mar 2024 11:29:16 +0000 Subject: [PATCH 3/3] Rename to Raised. --- UnitTests/Views/ListViewTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UnitTests/Views/ListViewTests.cs b/UnitTests/Views/ListViewTests.cs index 2241c355f0..f705dab25f 100644 --- a/UnitTests/Views/ListViewTests.cs +++ b/UnitTests/Views/ListViewTests.cs @@ -547,7 +547,7 @@ tem 3 } [Fact] - public void SelectedItemChanged_Event_Is_Also_Fired_With_AllowsMarking_True_By_Keyboard_Or_Mouse () + public void SelectedItemChanged_Event_Is_Also_Raised_With_AllowsMarking_True_By_Keyboard_Or_Mouse () { var itemChanged = 0; var lv = new ListView (new List () { "Item1", "Item2", "Item3" }) { Width = 5, Height = 3, AllowsMarking = true };