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
|
|
@ -195,6 +195,16 @@ namespace psemek::ui
|
|||
if (e.down && editing_)
|
||||
{
|
||||
if (e.key == SDLK_LEFT)
|
||||
{
|
||||
if (ctrl_down_)
|
||||
{
|
||||
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();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (caret_ > 0)
|
||||
{
|
||||
|
|
@ -202,7 +212,18 @@ namespace psemek::ui
|
|||
reset_caret();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (e.key == SDLK_RIGHT)
|
||||
{
|
||||
if (ctrl_down_)
|
||||
{
|
||||
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();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (caret_ < text_.size())
|
||||
{
|
||||
|
|
@ -210,6 +231,7 @@ namespace psemek::ui
|
|||
reset_caret();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (e.key == SDLK_HOME)
|
||||
{
|
||||
caret_ = 0;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue