Fix ctrl + end key handling, pos.y member should be calculated with _m_coordinate_to_caret method.

This commit is contained in:
beru 2019-02-24 09:53:36 +09:00
parent bf27549beb
commit 46ad9fd9f3

View File

@ -2394,6 +2394,7 @@ namespace nana {
auto origin = impl_->cview->origin(); auto origin = impl_->cview->origin();
auto pos = points_.caret; auto pos = points_.caret;
auto coord = _m_caret_to_coordinate(points_.caret, false); auto coord = _m_caret_to_coordinate(points_.caret, false);
auto coord_org = coord;
wchar_t key = arg.key; wchar_t key = arg.key;
@ -2405,7 +2406,6 @@ namespace nana {
//The number of charecters in the line of caret //The number of charecters in the line of caret
auto const text_length = textbase().getline(points_.caret.y).size(); auto const text_length = textbase().getline(points_.caret.y).size();
switch (key) { switch (key) {
case keyboard::os_arrow_left: case keyboard::os_arrow_left:
if (select_.move_to_end && (select_.a != select_.b) && (!arg.shift)) if (select_.move_to_end && (select_.a != select_.b) && (!arg.shift))
@ -2451,12 +2451,19 @@ namespace nana {
pos.y = 0; pos.y = 0;
break; break;
case keyboard::os_end: case keyboard::os_end:
//move the caret to the end of the line
pos.x = static_cast<decltype(pos.x)>(text_length);
//move the caret to the end of the text if Ctrl is pressed //move the caret to the end of the text if Ctrl is pressed
if (arg.ctrl) if (arg.ctrl) {
pos.y = static_cast<unsigned>((line_count - 1) * line_px); coord.y = static_cast<unsigned>((line_count - 1) * line_px);
//The number of charecters of the bottom line
auto const text_length = textbase().getline(std::max(0u, line_count - 1)).size();
//move the caret to the end of the line
pos.x = static_cast<decltype(pos.x)>(text_length);
}
else {
//move the caret to the end of the line
pos.x = static_cast<decltype(pos.x)>(text_length);
}
break; break;
case keyboard::os_pageup: case keyboard::os_pageup:
if (origin.y > 0) if (origin.y > 0)
@ -2476,10 +2483,12 @@ namespace nana {
break; break;
} }
if (pos == points_.caret) if (coord != coord_org)
{ {
auto pos_x = pos.x;
impl_->cview->move_origin(origin - impl_->cview->origin()); impl_->cview->move_origin(origin - impl_->cview->origin());
pos = _m_coordinate_to_caret(coord, false); pos = _m_coordinate_to_caret(coord, false);
pos.x = pos_x;
} }
if (pos != points_.caret) { if (pos != points_.caret) {