Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #1953. TextView cursor position is not updating by mouse. #1954

Merged
merged 2 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions Terminal.Gui/Views/TextView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2332,15 +2332,15 @@ void UpdateWrapModel ([CallerMemberName] string caller = null)
/// <summary>
/// Invoke the <see cref="UnwrappedCursorPosition"/> event with the unwrapped <see cref="CursorPosition"/>.
/// </summary>
public virtual void OnUnwrappedCursorPosition ()
public virtual void OnUnwrappedCursorPosition (int? cRow = null, int? cCol = null)
{
var row = currentRow;
var col = currentColumn;
if (wordWrap) {
var row = cRow == null ? currentRow : cRow;
var col = cCol == null ? currentColumn : cCol;
if (cRow == null && cCol == null && wordWrap) {
row = wrapManager.GetModelLineFromWrappedLines (currentRow);
col = wrapManager.GetModelColFromWrappedLines (currentRow, currentColumn);
}
UnwrappedCursorPosition?.Invoke (new Point (col, row));
UnwrappedCursorPosition?.Invoke (new Point ((int)col, (int)row));
}

ustring GetSelectedRegion ()
Expand All @@ -2357,6 +2357,7 @@ ustring GetSelectedRegion ()
startCol = wrapManager.GetModelColFromWrappedLines (selectionStartRow, selectionStartColumn);
model = wrapManager.Model;
}
OnUnwrappedCursorPosition (cRow, cCol);
return GetRegion (startRow, startCol, cRow, cCol, model);
}

Expand Down
19 changes: 19 additions & 0 deletions UnitTests/TextViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6016,6 +6016,25 @@ This is the second line.
the
first

line.
This
is
the
secon
d
line.
", output);

Assert.True (tv.MouseEvent (new MouseEvent () { X = 0, Y = 3, Flags = MouseFlags.Button1Pressed }));
tv.Redraw (tv.Bounds);
Assert.Equal (new Point (0, 3), tv.CursorPosition);
Assert.Equal (new Point (12, 0), cp);
GraphViewTests.AssertDriverContentsWithFrameAre (@"
This
is
the
first

line.
This
is
Expand Down