2018-01-04 23:50:30 +01:00
|
|
|
#pragma once
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2023-09-23 17:09:56 +02:00
|
|
|
#include <cstddef>
|
2022-11-16 00:32:15 +01:00
|
|
|
#include <cstdint>
|
2018-08-11 17:35:46 +02:00
|
|
|
#include <tuple>
|
2018-04-03 02:55:32 +02:00
|
|
|
#include <utility>
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-01-04 23:50:30 +01:00
|
|
|
namespace chatterino {
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-01-04 23:50:30 +01:00
|
|
|
struct SelectionItem {
|
2023-09-23 17:09:56 +02:00
|
|
|
size_t messageIndex{0};
|
|
|
|
size_t charIndex{0};
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2022-11-16 00:32:15 +01:00
|
|
|
SelectionItem() = default;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2023-09-23 17:09:56 +02:00
|
|
|
SelectionItem(size_t _messageIndex, size_t _charIndex)
|
2022-11-16 00:32:15 +01:00
|
|
|
: messageIndex(_messageIndex)
|
|
|
|
, charIndex(_charIndex)
|
2018-01-04 23:50:30 +01:00
|
|
|
{
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-01-16 00:26:04 +01:00
|
|
|
bool operator<(const SelectionItem &b) const
|
|
|
|
{
|
2018-08-11 17:35:46 +02:00
|
|
|
return std::tie(this->messageIndex, this->charIndex) <
|
|
|
|
std::tie(b.messageIndex, b.charIndex);
|
2018-01-16 00:26:04 +01:00
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-01-16 00:26:04 +01:00
|
|
|
bool operator>(const SelectionItem &b) const
|
2018-01-04 23:50:30 +01:00
|
|
|
{
|
2018-12-02 17:49:15 +01:00
|
|
|
return !this->operator==(b) && b.operator<(*this);
|
2018-01-04 23:50:30 +01:00
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-01-16 00:26:04 +01:00
|
|
|
bool operator==(const SelectionItem &b) const
|
2018-01-04 23:50:30 +01:00
|
|
|
{
|
2018-01-16 00:26:04 +01:00
|
|
|
return this->messageIndex == b.messageIndex &&
|
|
|
|
this->charIndex == b.charIndex;
|
2018-01-04 23:50:30 +01:00
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-05-17 12:16:13 +02:00
|
|
|
bool operator!=(const SelectionItem &b) const
|
|
|
|
{
|
|
|
|
return this->operator==(b);
|
|
|
|
}
|
2018-01-04 23:50:30 +01:00
|
|
|
};
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-01-04 23:50:30 +01:00
|
|
|
struct Selection {
|
|
|
|
SelectionItem start;
|
|
|
|
SelectionItem end;
|
2018-04-15 15:09:31 +02:00
|
|
|
SelectionItem selectionMin;
|
|
|
|
SelectionItem selectionMax;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-04-03 02:55:32 +02:00
|
|
|
Selection() = default;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-01-04 23:50:30 +01:00
|
|
|
Selection(const SelectionItem &start, const SelectionItem &end)
|
|
|
|
: start(start)
|
|
|
|
, end(end)
|
2018-04-15 15:09:31 +02:00
|
|
|
, selectionMin(start)
|
|
|
|
, selectionMax(end)
|
2018-01-04 23:50:30 +01:00
|
|
|
{
|
2018-04-15 15:09:31 +02:00
|
|
|
if (selectionMin > selectionMax)
|
|
|
|
{
|
|
|
|
std::swap(this->selectionMin, this->selectionMax);
|
2018-01-04 23:50:30 +01:00
|
|
|
}
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-01-04 23:50:30 +01:00
|
|
|
bool isEmpty() const
|
|
|
|
{
|
2018-01-16 00:26:04 +01:00
|
|
|
return this->start == this->end;
|
2018-01-04 23:50:30 +01:00
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-01-04 23:50:30 +01:00
|
|
|
bool isSingleMessage() const
|
|
|
|
{
|
2018-04-15 15:09:31 +02:00
|
|
|
return this->selectionMin.messageIndex ==
|
|
|
|
this->selectionMax.messageIndex;
|
2018-01-04 23:50:30 +01:00
|
|
|
}
|
2022-11-16 00:32:15 +01:00
|
|
|
|
|
|
|
// Shift all message selection indices `offset` back
|
2023-09-23 17:09:56 +02:00
|
|
|
void shiftMessageIndex(size_t offset)
|
2022-11-16 00:32:15 +01:00
|
|
|
{
|
|
|
|
if (offset > this->selectionMin.messageIndex)
|
|
|
|
{
|
|
|
|
this->selectionMin.messageIndex = 0;
|
2023-06-18 14:09:11 +02:00
|
|
|
this->selectionMin.charIndex = 0;
|
2022-11-16 00:32:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->selectionMin.messageIndex -= offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (offset > this->selectionMax.messageIndex)
|
|
|
|
{
|
|
|
|
this->selectionMax.messageIndex = 0;
|
2023-06-18 14:09:11 +02:00
|
|
|
this->selectionMax.charIndex = 0;
|
2022-11-16 00:32:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->selectionMax.messageIndex -= offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (offset > this->start.messageIndex)
|
|
|
|
{
|
|
|
|
this->start.messageIndex = 0;
|
2023-06-18 14:09:11 +02:00
|
|
|
this->start.charIndex = 0;
|
2022-11-16 00:32:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->start.messageIndex -= offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (offset > this->end.messageIndex)
|
|
|
|
{
|
|
|
|
this->end.messageIndex = 0;
|
2023-06-18 14:09:11 +02:00
|
|
|
this->end.charIndex = 0;
|
2022-11-16 00:32:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->end.messageIndex -= offset;
|
|
|
|
}
|
|
|
|
}
|
2018-01-04 23:50:30 +01:00
|
|
|
};
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-10-06 13:43:21 +02:00
|
|
|
struct DoubleClickSelection {
|
2022-11-16 00:32:15 +01:00
|
|
|
uint32_t originalStart{0};
|
|
|
|
uint32_t originalEnd{0};
|
|
|
|
uint32_t origMessageIndex{0};
|
|
|
|
bool selectingLeft{false};
|
|
|
|
bool selectingRight{false};
|
2018-10-06 13:43:21 +02:00
|
|
|
SelectionItem origStartItem;
|
|
|
|
SelectionItem origEndItem;
|
|
|
|
};
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-01-16 00:26:04 +01:00
|
|
|
} // namespace chatterino
|