diff --git a/include/eepp/ui/doc/textrange.hpp b/include/eepp/ui/doc/textrange.hpp index 56694de29..fe6b731c2 100644 --- a/include/eepp/ui/doc/textrange.hpp +++ b/include/eepp/ui/doc/textrange.hpp @@ -185,18 +185,20 @@ class EE_API TextRanges : public std::vector { } bool exists( const TextRange& range ) const { - for ( const auto& r : *this ) - if ( range == r ) - return true; - return false; + if ( !mIsSorted ) + return std::find( begin(), end(), range ) != end(); + return std::binary_search( begin(), end(), range ); } size_t findIndex( const TextRange& range ) const { - for ( size_t i = 0; i < size(); ++i ) { - if ( ( *this )[i] == range ) - return i; + if ( !mIsSorted ) { + auto it = std::find( begin(), end(), range ); + return it != end() ? std::distance( begin(), it ) : static_cast( -1 ); + } else { + auto it = std::lower_bound( begin(), end(), range ); + return ( it != end() && *it == range ) ? std::distance( begin(), it ) + : static_cast( -1 ); } - return 0; } bool hasSelection() const { @@ -216,15 +218,17 @@ class EE_API TextRanges : public std::vector { bool merge() { if ( size() <= 1 ) return false; - size_t oldSize = size(); - TextRanges newRanges; - newRanges.emplace_back( ( *this )[0] ); - for ( size_t i = 1; i < size(); ++i ) - if ( !newRanges.exists( ( *this )[i] ) ) - newRanges.emplace_back( ( *this )[i] ); - *this = newRanges; - sort(); - return oldSize != size(); + + if ( !mIsSorted ) + sort(); + + auto it = std::unique( begin(), end(), + []( const TextRange& a, const TextRange& b ) { return a == b; } ); + + bool merged = it != end(); + erase( it, end() ); + + return merged; } std::string toString() const { diff --git a/src/eepp/ui/uicodeeditor.cpp b/src/eepp/ui/uicodeeditor.cpp index 51275fe7c..1c233ebdc 100644 --- a/src/eepp/ui/uicodeeditor.cpp +++ b/src/eepp/ui/uicodeeditor.cpp @@ -1411,8 +1411,13 @@ Uint32 UICodeEditor::onMouseDown( const Vector2i& position, const Uint32& flags TextRange range( mDoc->getSelection().start(), textScreenPos ); range.normalize(); range = mDoc->sanitizeRange( range ); - for ( Int64 i = range.start().line(); i < range.end().line(); ++i ) - mDoc->addSelection( { i, range.start().column() } ); + TextRanges ranges; + ranges.reserve( range.end().line() - range.start().line() + 1 ); + for ( Int64 i = range.start().line(); i < range.end().line(); ++i ) { + TextPosition pos{ i, range.start().column() }; + ranges.push_back( TextRange{ pos, pos } ); + } + mDoc->addSelections( std::move( ranges ) ); } else if ( input->isModState( KEYMOD_SHIFT ) ) { mDoc->selectTo( textScreenPos ); } else if ( input->isModState( KEYMOD_CTRL ) && diff --git a/src/tools/ecode/version.hpp b/src/tools/ecode/version.hpp index 5a73c77d8..86cf362c5 100644 --- a/src/tools/ecode/version.hpp +++ b/src/tools/ecode/version.hpp @@ -8,7 +8,7 @@ using namespace EE; #define ECODE_MAJOR_VERSION 0 #define ECODE_MINOR_VERSION 6 -#define ECODE_PATCH_LEVEL 3 +#define ECODE_PATCH_LEVEL 4 /* ECODE_COMMIT_NUMBER 9999 is used for official releases, nightly builds (pre-releases) will * contain the number of commits after the last official release */