selections can now start outside of a message

This means in the empty space under any available messages
This commit is contained in:
Rasmus Karlsson
2017-11-04 13:17:35 +01:00
parent e1a31785ef
commit 064daaa77a
3 changed files with 51 additions and 0 deletions
+35
View File
@@ -275,6 +275,41 @@ const Word *MessageRef::tryGetWordPart(QPoint point)
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)
{
if (this->wordParts.size() == 0) {