Fix double click to select full words (#5243)
Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
#include "messages/layouts/MessageLayout.hpp"
|
||||
|
||||
#include "Application.hpp"
|
||||
#include "controllers/accounts/AccountController.hpp"
|
||||
#include "messages/MessageBuilder.hpp"
|
||||
#include "messages/MessageElement.hpp"
|
||||
#include "mocks/EmptyApplication.hpp"
|
||||
#include "singletons/Emotes.hpp"
|
||||
#include "singletons/Fonts.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
#include "singletons/Theme.hpp"
|
||||
#include "singletons/WindowManager.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <QDebug>
|
||||
#include <QString>
|
||||
|
||||
#include <memory>
|
||||
|
||||
using namespace chatterino;
|
||||
|
||||
namespace {
|
||||
|
||||
class MockApplication : mock::EmptyApplication
|
||||
{
|
||||
public:
|
||||
MockApplication()
|
||||
: settings(this->settingsDir.filePath("settings.json"))
|
||||
, fonts(this->settings)
|
||||
, windowManager(this->paths_)
|
||||
{
|
||||
}
|
||||
Theme *getThemes() override
|
||||
{
|
||||
return &this->theme;
|
||||
}
|
||||
|
||||
Fonts *getFonts() override
|
||||
{
|
||||
return &this->fonts;
|
||||
}
|
||||
|
||||
WindowManager *getWindows() override
|
||||
{
|
||||
return &this->windowManager;
|
||||
}
|
||||
|
||||
Settings settings;
|
||||
Theme theme;
|
||||
Fonts fonts;
|
||||
WindowManager windowManager;
|
||||
};
|
||||
|
||||
constexpr int WIDTH = 300;
|
||||
|
||||
class MessageLayoutTest
|
||||
{
|
||||
public:
|
||||
// "aaaaaaaa bbbbbbbb cccccccc"
|
||||
MessageLayoutTest(const QString &text)
|
||||
{
|
||||
MessageBuilder builder;
|
||||
builder.append(
|
||||
std::make_unique<TextElement>(text, MessageElementFlag::Text));
|
||||
this->layout = std::make_unique<MessageLayout>(builder.release());
|
||||
this->layout->layout(WIDTH, 1, MessageElementFlag::Text, false);
|
||||
}
|
||||
|
||||
MockApplication mockApplication;
|
||||
std::unique_ptr<MessageLayout> layout;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(TextElement, BasicCase)
|
||||
{
|
||||
auto test = MessageLayoutTest("abc");
|
||||
|
||||
// Simulate we are clicking on the first word
|
||||
auto point = QPoint(WIDTH / 20, test.layout->getHeight() / 2);
|
||||
|
||||
const auto *hoveredElement = test.layout->getElementAt(point);
|
||||
ASSERT_NE(hoveredElement, nullptr);
|
||||
|
||||
const auto [wordStart, wordEnd] =
|
||||
test.layout->getWordBounds(hoveredElement, point);
|
||||
|
||||
EXPECT_EQ(wordStart, 0);
|
||||
EXPECT_EQ(wordEnd, 3);
|
||||
}
|
||||
Reference in New Issue
Block a user