Skip to content

Commit

Permalink
Merge pull request #3321 from BDisp/v1_listview-selecteditemchanged-m…
Browse files Browse the repository at this point in the history
…arks-click.fix_3317

Fixes #3317. v1-Listvew mouse event doesn't cause a SelectedItemChanged event to fire
  • Loading branch information
tig authored Mar 16, 2024
2 parents 26c06d7 + b1218d7 commit 214ff12
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
4 changes: 1 addition & 3 deletions Terminal.Gui/Views/ListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand Down Expand Up @@ -877,7 +875,7 @@ void RenderUstr (ConsoleDriver driver, ustring ustr, int col, int line, int widt
/// <inheritdoc/>
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) {
Expand Down
19 changes: 19 additions & 0 deletions UnitTests/Views/ListViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -545,5 +545,24 @@ tem 2
tem 3
tem 4", output);
}

[Fact]
public void SelectedItemChanged_Event_Is_Also_Raised_With_AllowsMarking_True_By_Keyboard_Or_Mouse ()
{
var itemChanged = 0;
var lv = new ListView (new List<string> () { "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);
}
}
}

0 comments on commit 214ff12

Please sign in to comment.