Make moving between words more aware of whitespaces
This commit is contained in:
parent
f130d495c8
commit
5d87108b3d
1 changed files with 17 additions and 0 deletions
|
|
@ -409,10 +409,19 @@ TextPosition Editor::move(Movement move, TextPosition pos) const {
|
||||||
break;
|
break;
|
||||||
case Movement::kWordLeft:
|
case Movement::kWordLeft:
|
||||||
{
|
{
|
||||||
|
for(;;) {
|
||||||
|
TextPosition prevCharPos = this->move(Movement::kLeft, pos);
|
||||||
|
if(prevCharPos != TextPosition{0, 0} && std::isspace(fLines[prevCharPos.fParagraphIndex].fText[prevCharPos.fTextByteIndex]))
|
||||||
|
pos = prevCharPos;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (pos.fTextByteIndex == 0) {
|
if (pos.fTextByteIndex == 0) {
|
||||||
pos = this->move(Movement::kLeft, pos);
|
pos = this->move(Movement::kLeft, pos);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<bool>& words = fLines[pos.fParagraphIndex].fWordBoundaries;
|
const std::vector<bool>& words = fLines[pos.fParagraphIndex].fWordBoundaries;
|
||||||
assert(words.size() == fLines[pos.fParagraphIndex].fText.size());
|
assert(words.size() == fLines[pos.fParagraphIndex].fText.size());
|
||||||
do {
|
do {
|
||||||
|
|
@ -432,6 +441,14 @@ TextPosition Editor::move(Movement move, TextPosition pos) const {
|
||||||
do {
|
do {
|
||||||
++pos.fTextByteIndex;
|
++pos.fTextByteIndex;
|
||||||
} while (pos.fTextByteIndex < text.size() && !words[pos.fTextByteIndex]);
|
} while (pos.fTextByteIndex < text.size() && !words[pos.fTextByteIndex]);
|
||||||
|
|
||||||
|
for(;;) {
|
||||||
|
const std::string& text = fLines[pos.fParagraphIndex].fText;
|
||||||
|
if(pos.fTextByteIndex != text.size() && std::isspace(text[pos.fTextByteIndex]))
|
||||||
|
pos = this->move(Movement::kRight, pos);
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue