From f73c056713c3812c1a852c32460dd6764f004eb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Wed, 9 Mar 2022 12:11:06 -0300 Subject: [PATCH] Multiline search crash fix. --- include/eepp/ui/doc/textposition.hpp | 8 ++++++++ src/eepp/ui/doc/textdocument.cpp | 7 +++++-- 2 files changed, 13 insertions(+), 2 deletions(-) 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 ); }