aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Selection.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/Selection.h')
-rw-r--r--src/Selection.h44
1 files changed, 25 insertions, 19 deletions
diff --git a/src/Selection.h b/src/Selection.h
index c0d785870..7f3fd937b 100644
--- a/src/Selection.h
+++ b/src/Selection.h
@@ -11,10 +11,11 @@
namespace Scintilla::Internal {
class SelectionPosition {
- Sci::Position position;
- Sci::Position virtualSpace;
+ Sci::Position position = Sci::invalidPosition;
+ Sci::Position virtualSpace = 0;
public:
- explicit SelectionPosition(Sci::Position position_= Sci::invalidPosition, Sci::Position virtualSpace_=0) noexcept : position(position_), virtualSpace(virtualSpace_) {
+ constexpr SelectionPosition() noexcept = default;
+ constexpr explicit SelectionPosition(Sci::Position position_, Sci::Position virtualSpace_=0) noexcept : position(position_), virtualSpace(virtualSpace_) {
PLATFORM_ASSERT(virtualSpace < 800000000);
if (virtualSpace < 0)
virtualSpace = 0;
@@ -24,13 +25,20 @@ public:
virtualSpace = 0;
}
void MoveForInsertDelete(bool insertion, Sci::Position startChange, Sci::Position length, bool moveForEqual) noexcept;
- bool operator ==(const SelectionPosition &other) const noexcept {
- return position == other.position && virtualSpace == other.virtualSpace;
+ [[nodiscard]] constexpr bool operator ==(const SelectionPosition &other) const noexcept {
+ return (position == other.position) && (virtualSpace == other.virtualSpace);
}
- bool operator <(const SelectionPosition &other) const noexcept;
- bool operator >(const SelectionPosition &other) const noexcept;
- bool operator <=(const SelectionPosition &other) const noexcept;
- bool operator >=(const SelectionPosition &other) const noexcept;
+ [[nodiscard]] constexpr bool operator !=(const SelectionPosition &other) const noexcept {
+ return (position != other.position) || (virtualSpace != other.virtualSpace);
+ }
+ [[nodiscard]] constexpr bool operator <(const SelectionPosition &other) const noexcept {
+ if (position == other.position)
+ return virtualSpace < other.virtualSpace;
+ return position < other.position;
+ }
+ [[nodiscard]] bool operator >(const SelectionPosition &other) const noexcept;
+ [[nodiscard]] bool operator <=(const SelectionPosition &other) const noexcept;
+ [[nodiscard]] bool operator >=(const SelectionPosition &other) const noexcept;
Sci::Position Position() const noexcept {
return position;
}
@@ -61,9 +69,8 @@ public:
struct SelectionSegment {
SelectionPosition start;
SelectionPosition end;
- SelectionSegment() noexcept : start(), end() {
- }
- SelectionSegment(SelectionPosition a, SelectionPosition b) noexcept {
+ constexpr SelectionSegment() noexcept = default;
+ constexpr SelectionSegment(SelectionPosition a, SelectionPosition b) noexcept {
if (a < b) {
start = a;
end = b;
@@ -96,15 +103,14 @@ struct SelectionRange {
SelectionPosition caret;
SelectionPosition anchor;
- SelectionRange() noexcept : caret(), anchor() {
- }
- explicit SelectionRange(SelectionPosition single) noexcept : caret(single), anchor(single) {
+ constexpr SelectionRange() noexcept = default;
+ constexpr explicit SelectionRange(SelectionPosition single) noexcept : caret(single), anchor(single) {
}
- explicit SelectionRange(Sci::Position single) noexcept : caret(single), anchor(single) {
+ constexpr explicit SelectionRange(Sci::Position single) noexcept : caret(single), anchor(single) {
}
- SelectionRange(SelectionPosition caret_, SelectionPosition anchor_) noexcept : caret(caret_), anchor(anchor_) {
+ constexpr SelectionRange(SelectionPosition caret_, SelectionPosition anchor_) noexcept : caret(caret_), anchor(anchor_) {
}
- SelectionRange(Sci::Position caret_, Sci::Position anchor_) noexcept : caret(caret_), anchor(anchor_) {
+ constexpr SelectionRange(Sci::Position caret_, Sci::Position anchor_) noexcept : caret(caret_), anchor(anchor_) {
}
bool Empty() const noexcept {
return anchor == caret;
@@ -158,7 +164,7 @@ public:
enum class SelTypes { none, stream, rectangle, lines, thin };
SelTypes selType;
- Selection();
+ Selection(); // Allocates so may throw.
bool IsRectangular() const noexcept;
Sci::Position MainCaret() const noexcept;
Sci::Position MainAnchor() const noexcept;