Account for the last position in wxMSW wxTextCtrl

There is a valid position after the last character of the text in
wxTextCtrl, e.g. position 0 in the empty control, so account for it and,
notably, don't return -1 from XYToPosition(0, 0) when the control is
empty.

This fixes a regression in a69ab2907c.
This commit is contained in:
Vadim Zeitlin
2017-08-25 01:42:51 +02:00
parent de9b6fdc9e
commit e74fb5effe
2 changed files with 13 additions and 14 deletions

View File

@@ -1486,13 +1486,12 @@ long wxTextCtrl::XYToPosition(long x, long y) const
// Line is identified by a character position!
long lineLength = ::SendMessage(GetHwnd(), EM_LINELENGTH, charIndex, 0);
// For all lines but last one we need to adjust the length
// to include new line character (only one because both CR and LF
// are virtually "displayed" at the same position).
if ( y < GetNumberOfLines() - 1 )
lineLength += 1;
if ( x >= lineLength )
// Notice that x == lineLength is still valid because it corresponds either
// to the position of the LF at the end of any line except the last one or
// to the last position, which is the position after the last character,
// for the last line.
if ( x > lineLength )
return -1;
return charIndex + x;