diff --git a/include/eepp/ui/doc/textposition.hpp b/include/eepp/ui/doc/textposition.hpp index 38beadfe9..c0da6071a 100644 --- a/include/eepp/ui/doc/textposition.hpp +++ b/include/eepp/ui/doc/textposition.hpp @@ -39,6 +39,14 @@ class EE_API TextPosition { return mLine > other.mLine || ( mLine == other.mLine && mColumn > other.mColumn ); } + bool operator<=( const TextPosition& other ) const { + return mLine <= other.mLine || ( mLine == other.mLine && mColumn <= other.mColumn ); + } + + bool operator>=( const TextPosition& other ) const { + return mLine >= other.mLine || ( mLine == other.mLine && mColumn >= other.mColumn ); + } + TextPosition operator+( const TextPosition& other ) const { return {mLine + other.line(), mColumn + other.column()}; } diff --git a/src/eepp/ui/doc/textdocument.cpp b/src/eepp/ui/doc/textdocument.cpp index 8adf64b12..7fe1b86a2 100644 --- a/src/eepp/ui/doc/textdocument.cpp +++ b/src/eepp/ui/doc/textdocument.cpp @@ -1452,7 +1452,7 @@ TextRange TextDocument::find( String text, TextPosition from, const bool& caseSe if ( restrictRange.isValid() ) { restrictRange = sanitizeRange( restrictRange.normalized() ); to = restrictRange.end(); - if ( from < restrictRange.start() || from > restrictRange.end() ) + if ( from < restrictRange.start() || from >= restrictRange.end() ) return TextRange(); } @@ -1479,7 +1479,10 @@ TextRange TextDocument::find( String text, TextPosition from, const bool& caseSe } if ( currentLine == textLines[i] ) { - initPos = TextPosition( i + 1, 0 ); + initPos = TextPosition( initPos.line() + 1, 0 ); + + if ( initPos >= restrictRange.end() ) + return TextRange(); } else { return find( text, range.end(), caseSensitive, wholeWord, type, restrictRange ); }