mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
selections can now start outside of a message
This means in the empty space under any available messages
This commit is contained in:
parent
e1a31785ef
commit
064daaa77a
|
@ -275,6 +275,41 @@ const Word *MessageRef::tryGetWordPart(QPoint point)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// XXX(pajlada): This is probably not the optimal way to calculate this
|
||||||
|
int MessageRef::getLastCharacterIndex() const
|
||||||
|
{
|
||||||
|
// find out in which line the cursor is
|
||||||
|
int lineNumber = 0, lineStart = 0, lineEnd = 0;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < this->wordParts.size(); i++) {
|
||||||
|
const WordPart &part = this->wordParts[i];
|
||||||
|
|
||||||
|
if (part.getLineNumber() != lineNumber) {
|
||||||
|
lineStart = i;
|
||||||
|
lineNumber = part.getLineNumber();
|
||||||
|
}
|
||||||
|
|
||||||
|
lineEnd = i + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// count up to the cursor
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < lineStart; i++) {
|
||||||
|
const WordPart &part = this->wordParts[i];
|
||||||
|
|
||||||
|
index += part.getWord().isImage() ? 2 : part.getText().length() + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = lineStart; i < lineEnd; i++) {
|
||||||
|
const WordPart &part = this->wordParts[i];
|
||||||
|
|
||||||
|
index += part.getCharacterLength();
|
||||||
|
}
|
||||||
|
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
int MessageRef::getSelectionIndex(QPoint position)
|
int MessageRef::getSelectionIndex(QPoint position)
|
||||||
{
|
{
|
||||||
if (this->wordParts.size() == 0) {
|
if (this->wordParts.size() == 0) {
|
||||||
|
|
|
@ -30,6 +30,7 @@ public:
|
||||||
bool updateBuffer = false;
|
bool updateBuffer = false;
|
||||||
|
|
||||||
const Word *tryGetWordPart(QPoint point);
|
const Word *tryGetWordPart(QPoint point);
|
||||||
|
int getLastCharacterIndex() const;
|
||||||
int getSelectionIndex(QPoint position);
|
int getSelectionIndex(QPoint position);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "widgets/channelview.hpp"
|
#include "widgets/channelview.hpp"
|
||||||
#include "channelmanager.hpp"
|
#include "channelmanager.hpp"
|
||||||
#include "colorscheme.hpp"
|
#include "colorscheme.hpp"
|
||||||
|
#include "debug/log.hpp"
|
||||||
#include "messages/limitedqueuesnapshot.hpp"
|
#include "messages/limitedqueuesnapshot.hpp"
|
||||||
#include "messages/message.hpp"
|
#include "messages/message.hpp"
|
||||||
#include "messages/messageref.hpp"
|
#include "messages/messageref.hpp"
|
||||||
|
@ -760,6 +761,20 @@ void ChannelView::mousePressEvent(QMouseEvent *event)
|
||||||
if (!tryGetMessageAt(event->pos(), message, relativePos, messageIndex)) {
|
if (!tryGetMessageAt(event->pos(), message, relativePos, messageIndex)) {
|
||||||
setCursor(Qt::ArrowCursor);
|
setCursor(Qt::ArrowCursor);
|
||||||
|
|
||||||
|
auto messages = this->getMessagesSnapshot();
|
||||||
|
if (messages.getLength() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start selection at the last message at its last index
|
||||||
|
auto lastMessageIndex = messages.getLength() - 1;
|
||||||
|
auto lastMessage = messages[lastMessageIndex];
|
||||||
|
auto lastCharacterIndex = lastMessage->getLastCharacterIndex();
|
||||||
|
|
||||||
|
SelectionItem selectionItem(lastMessageIndex, lastCharacterIndex);
|
||||||
|
this->setSelection(selectionItem, selectionItem);
|
||||||
|
this->selecting = true;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue