Improve the "double click word selection" method of textbox to follow some other rules other than white space.

This commit is contained in:
Eduardo Roeder 2018-11-03 15:43:08 -03:00
parent 7651b430eb
commit 64bd9b7491

View File

@ -25,7 +25,8 @@
#include <algorithm>
#include <map>
namespace nana{ namespace widgets
namespace nana {
namespace widgets
{
namespace skeletons
{
@ -1632,14 +1633,20 @@ namespace nana{ namespace widgets
select_.a = select_.b = points_.caret;
const auto& line = impl_->textbase.getline(select_.b.y);
if (select_.a.x < line.size() && !std::isalnum(line[select_.a.x]) && line[select_.a.x] != '_') {
++select_.b.x;
}
else {
// Expand the selection forward to the word's end.
while (select_.b.x < line.size() && !std::iswspace(line[select_.b.x]))
while (select_.b.x < line.size() && !std::iswspace(line[select_.b.x]) && (std::isalnum(line[select_.b.x]) || line[select_.b.x] == '_'))
++select_.b.x;
// Expand the selection backward to the word's start.
while (select_.a.x > 0 && !std::iswspace(line[select_.a.x - 1]))
while (select_.a.x > 0 && !std::iswspace(line[select_.a.x - 1]) && (std::isalnum(line[select_.a.x - 1]) || line[select_.a.x - 1] == '_'))
--select_.a.x;
}
select_.mode_selection = selection::mode::method_selected;
impl_->try_refresh = sync_graph::refresh;
return true;