@@ -120,7 +120,7 @@ namespace hex::ui {
120120 auto oldPos = m_state.m_cursorPosition ;
121121
122122
123- if (isEmpty () || oldPos. m_line >= ( i64 )m_lines. size ( ))
123+ if (isEmpty () || oldPos < Coordinates ( 0 , 0 ))
124124 return ;
125125
126126 auto lindex = m_state.m_cursorPosition .m_line ;
@@ -163,7 +163,7 @@ namespace hex::ui {
163163
164164 auto oldPos = m_state.m_cursorPosition ;
165165
166- if (isEmpty () || oldPos. m_line >= ( i64 ) m_lines. size ( ))
166+ if (isEmpty () || oldPos > setCoordinates (- 1 , - 1 ))
167167 return ;
168168
169169 auto lindex = m_state.m_cursorPosition .m_line ;
@@ -184,11 +184,9 @@ namespace hex::ui {
184184 }
185185
186186 if (select) {
187- if (oldPos == m_interactiveSelection.m_end ) {
188- m_interactiveSelection.m_end = Coordinates (m_state.m_cursorPosition );
189- if (m_interactiveSelection.m_end == Invalid)
190- return ;
191- } else if (oldPos == m_interactiveSelection.m_start )
187+ if (oldPos == m_interactiveSelection.m_end )
188+ m_interactiveSelection.m_end = m_state.m_cursorPosition ;
189+ else if (oldPos == m_interactiveSelection.m_start )
192190 m_interactiveSelection.m_start = m_state.m_cursorPosition ;
193191 else {
194192 m_interactiveSelection.m_start = oldPos;
@@ -387,16 +385,17 @@ namespace hex::ui {
387385 auto &line = m_lines[at.m_line ];
388386 auto charIndex = lineCoordinatesToIndex (at);
389387
390- if (isWordChar (line.m_chars [charIndex])) {
391- while (charIndex > 0 && isWordChar (line.m_chars [charIndex - 1 ]))
392- --charIndex;
393- } else if (ispunct (line.m_chars [charIndex])) {
394- while (charIndex > 0 && ispunct (line.m_chars [charIndex - 1 ]))
395- --charIndex;
396- } else if (isspace (line.m_chars [charIndex])) {
397- while (charIndex > 0 && isspace (line.m_chars [charIndex - 1 ]))
398- --charIndex;
388+ bool found = false ;
389+ while (charIndex > 0 && isWordChar (line.m_chars [charIndex - 1 ])) {
390+ found = true ;
391+ --charIndex;
392+ }
393+ while (!found && charIndex > 0 && ispunct (line.m_chars [charIndex - 1 ])) {
394+ found = true ;
395+ --charIndex;
399396 }
397+ while (!found && charIndex > 0 && isspace (line.m_chars [charIndex - 1 ]))
398+ --charIndex;
400399 return getCharacterCoordinates (at.m_line , charIndex);
401400 }
402401
@@ -408,16 +407,18 @@ namespace hex::ui {
408407 auto &line = m_lines[at.m_line ];
409408 auto charIndex = lineCoordinatesToIndex (at);
410409
411- if (isWordChar (line.m_chars [charIndex])) {
412- while (charIndex < (i32 ) line.m_chars .size () && isWordChar (line.m_chars [charIndex]))
413- ++charIndex;
414- } else if (ispunct (line.m_chars [charIndex])) {
415- while (charIndex < (i32 ) line.m_chars .size () && ispunct (line.m_chars [charIndex]))
416- ++charIndex;
417- } else if (isspace (line.m_chars [charIndex])) {
418- while (charIndex < (i32 ) line.m_chars .size () && isspace (line.m_chars [charIndex]))
419- ++charIndex;
410+ bool found = false ;
411+ while (charIndex < (i32 ) line.m_chars .size () && isWordChar (line.m_chars [charIndex])) {
412+ found = true ;
413+ ++charIndex;
414+ }
415+ while (!found && charIndex < (i32 ) line.m_chars .size () && ispunct (line.m_chars [charIndex])) {
416+ found = true ;
417+ ++charIndex;
420418 }
419+ while (!found && charIndex < (i32 ) line.m_chars .size () && isspace (line.m_chars [charIndex]))
420+ ++charIndex;
421+
421422 return getCharacterCoordinates (at.m_line , charIndex);
422423 }
423424
@@ -429,17 +430,16 @@ namespace hex::ui {
429430 auto &line = m_lines[at.m_line ];
430431 auto charIndex = lineCoordinatesToIndex (at);
431432
432- if (isspace (line.m_chars [charIndex])) {
433- while (charIndex < (i32 ) line.m_chars .size () && isspace (line.m_chars [charIndex]))
434- ++charIndex;
435- }
436- if (isWordChar (line.m_chars [charIndex])) {
437- while (charIndex < (i32 ) line.m_chars .size () && (isWordChar (line.m_chars [charIndex])))
438- ++charIndex;
439- } else if (ispunct (line.m_chars [charIndex])) {
440- while (charIndex < (i32 ) line.m_chars .size () && (ispunct (line.m_chars [charIndex])))
441- ++charIndex;
433+ while (charIndex < (i32 ) line.m_chars .size () && isspace (line.m_chars [charIndex]))
434+ ++charIndex;
435+ bool found = false ;
436+ while (charIndex < (i32 ) line.m_chars .size () && (isWordChar (line.m_chars [charIndex]))) {
437+ found = true ;
438+ ++charIndex;
442439 }
440+ while (!found && charIndex < (i32 ) line.m_chars .size () && (ispunct (line.m_chars [charIndex])))
441+ ++charIndex;
442+
443443 return getCharacterCoordinates (at.m_line , charIndex);
444444 }
445445
@@ -451,17 +451,17 @@ namespace hex::ui {
451451 auto &line = m_lines[at.m_line ];
452452 auto charIndex = lineCoordinatesToIndex (at);
453453
454- if (isspace (line.m_chars [charIndex - 1 ])) {
455- while (charIndex > 0 && isspace (line.m_chars [charIndex - 1 ]))
456- --charIndex;
457- }
458- if (isWordChar (line.m_chars [charIndex - 1 ])) {
459- while (charIndex > 0 && isWordChar (line.m_chars [charIndex - 1 ]))
460- --charIndex;
461- } else if (ispunct (line.m_chars [charIndex - 1 ])) {
462- while (charIndex > 0 && ispunct (line.m_chars [charIndex - 1 ]))
463- --charIndex;
454+ bool found = false ;
455+ while (charIndex > 0 && isspace (line.m_chars [charIndex - 1 ]))
456+ --charIndex;
457+
458+ while (charIndex > 0 && isWordChar (line.m_chars [charIndex - 1 ])) {
459+ found = true ;
460+ --charIndex;
464461 }
462+ while (!found && charIndex > 0 && ispunct (line.m_chars [charIndex - 1 ]))
463+ --charIndex;
464+
465465 return getCharacterCoordinates (at.m_line , charIndex);
466466 }
467467
0 commit comments