Support whole-word caret movement in ui::edit
This commit is contained in:
parent
922daee6d2
commit
8ca5ab3f25
1 changed files with 26 additions and 4 deletions
|
|
@ -196,19 +196,41 @@ namespace psemek::ui
|
||||||
{
|
{
|
||||||
if (e.key == SDLK_LEFT)
|
if (e.key == SDLK_LEFT)
|
||||||
{
|
{
|
||||||
if (caret_ > 0)
|
if (ctrl_down_)
|
||||||
{
|
{
|
||||||
--caret_;
|
std::size_t start = caret_;
|
||||||
|
while (start > 0 && std::isspace(text_[start - 1])) --start;
|
||||||
|
while (start > 0 && !std::isspace(text_[start - 1])) --start;
|
||||||
|
caret_ = start;
|
||||||
reset_caret();
|
reset_caret();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (caret_ > 0)
|
||||||
|
{
|
||||||
|
--caret_;
|
||||||
|
reset_caret();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (e.key == SDLK_RIGHT)
|
else if (e.key == SDLK_RIGHT)
|
||||||
{
|
{
|
||||||
if (caret_ < text_.size())
|
if (ctrl_down_)
|
||||||
{
|
{
|
||||||
++caret_;
|
std::size_t end = caret_;
|
||||||
|
while (end < text_.size() && !std::isspace(text_[end])) ++end;
|
||||||
|
while (end < text_.size() && std::isspace(text_[end])) ++end;
|
||||||
|
caret_ = end;
|
||||||
reset_caret();
|
reset_caret();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (caret_ < text_.size())
|
||||||
|
{
|
||||||
|
++caret_;
|
||||||
|
reset_caret();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (e.key == SDLK_HOME)
|
else if (e.key == SDLK_HOME)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue