@@ -444,6 +444,11 @@ void TextCursor::setFormat(FormatId id, FormatValue val)
444
444
445
445
bool TextCursor::movePosition (TextCursor::MoveOperation op, TextCursor::MoveMode mode, int count)
446
446
{
447
+ auto isWordBoundaryCharacter = [this ](bool lettersOrDigits) -> bool {
448
+ Char c = currentCharacter ();
449
+ return c.isSpace () || lettersOrDigits != (c.isLetter () || c.isDigit ());
450
+ };
451
+
447
452
for (int i = 0 ; i < count; i++) {
448
453
switch (op) {
449
454
case TextCursor::MoveOperation::Left:
@@ -534,26 +539,29 @@ bool TextCursor::movePosition(TextCursor::MoveOperation op, TextCursor::MoveMode
534
539
535
540
break ;
536
541
537
- case TextCursor::MoveOperation::WordLeft:
542
+ case TextCursor::MoveOperation::WordLeft: {
538
543
if (m_column > 0 ) {
539
544
--m_column;
540
545
while (m_column > 0 && currentCharacter ().isSpace ()) {
541
546
--m_column;
542
547
}
543
- while (m_column > 0 && !currentCharacter ().isSpace ()) {
548
+ bool isWordOrDigit = currentCharacter ().isLetter () || currentCharacter ().isDigit ();
549
+ while (m_column > 0 && !isWordBoundaryCharacter (isWordOrDigit)) {
544
550
--m_column;
545
551
}
546
- if (currentCharacter (). isSpace ( )) {
552
+ if (isWordBoundaryCharacter (isWordOrDigit )) {
547
553
++m_column;
548
554
}
549
555
}
550
- break ;
556
+ }
557
+ break ;
551
558
552
559
case TextCursor::MoveOperation::NextWord: {
553
560
size_t cols = columns ();
554
561
if (m_column < cols) {
555
562
++m_column;
556
- while (m_column < cols && !currentCharacter ().isSpace ()) {
563
+ bool isWordOrDigit = currentCharacter ().isLetter () || currentCharacter ().isDigit ();
564
+ while (m_column < cols && !isWordBoundaryCharacter (isWordOrDigit)) {
557
565
++m_column;
558
566
}
559
567
while (m_column < cols && currentCharacter ().isSpace ()) {
@@ -593,7 +601,9 @@ void TextCursor::selectWord()
593
601
// handle double-clicking inside a word
594
602
size_t startPosition = m_column;
595
603
596
- while (m_column > 0 && currentCharacter ().isSpace () == selectSpaces) {
604
+ bool parseLetters = (currentCharacter ().isLetter () || currentCharacter ().isDigit ());
605
+ while (m_column > 0 && currentCharacter ().isSpace () == selectSpaces
606
+ && parseLetters == (currentCharacter ().isLetter () || currentCharacter ().isDigit ())) {
597
607
--m_column;
598
608
}
599
609
@@ -604,7 +614,8 @@ void TextCursor::selectWord()
604
614
m_selectColumn = m_column;
605
615
606
616
m_column = startPosition;
607
- while (m_column < curLine ().columns () && currentCharacter ().isSpace () == selectSpaces) {
617
+ while (m_column < curLine ().columns () && currentCharacter ().isSpace () == selectSpaces
618
+ && parseLetters == (currentCharacter ().isLetter () || currentCharacter ().isDigit ())) {
608
619
++m_column;
609
620
}
610
621
0 commit comments