Fix split focusing being broken in certain circumstances when the "Show input when it's empty" setting was disabled (#3838)

Co-authored-by: Kasia <zneix@zneix.eu>
This commit is contained in:
pajlada
2022-06-26 18:53:09 +02:00
committed by GitHub
parent 8bdfbf7b87
commit 6599009e79
13 changed files with 151 additions and 57 deletions
+42 -24
View File
@@ -91,7 +91,8 @@ Split::Split(QWidget *parent)
{
this->setMouseTracking(true);
this->view_->setPausable(true);
this->view_->setFocusPolicy(Qt::FocusPolicy::NoFocus);
this->view_->setFocusProxy(this->input_->ui_.textEdit);
this->setFocusProxy(this->input_->ui_.textEdit);
this->vbox_->setSpacing(0);
this->vbox_->setMargin(1);
@@ -112,9 +113,6 @@ Split::Split(QWidget *parent)
});
this->updateInputPlaceholder();
this->view_->mouseDown.connect([this](QMouseEvent *) {
this->giveFocus(Qt::MouseFocusReason);
});
this->view_->selectionChanged.connect([this]() {
if (view_->hasSelection())
{
@@ -150,28 +148,33 @@ Split::Split(QWidget *parent)
this->input_->textChanged.connect([=](const QString &newText) {
if (getSettings()->showEmptyInput)
{
// We always show the input regardless of the text, so we can early out here
return;
}
if (newText.length() == 0)
if (newText.isEmpty())
{
this->input_->hide();
}
else if (this->input_->isHidden())
{
// Text updated and the input was previously hidden, show it
this->input_->show();
}
});
getSettings()->showEmptyInput.connect(
[this](const bool &showEmptyInput, auto) {
if (!showEmptyInput && this->input_->getInputText().length() == 0)
if (showEmptyInput)
{
this->input_->hide();
this->input_->show();
}
else
{
this->input_->show();
if (this->input_->getInputText().isEmpty())
{
this->input_->hide();
}
}
},
this->signalHolder_);
@@ -207,9 +210,11 @@ Split::Split(QWidget *parent)
});
this->input_->ui_.textEdit->focused.connect([this] {
// Forward textEdit's focused event
this->focused.invoke();
});
this->input_->ui_.textEdit->focusLost.connect([this] {
// Forward textEdit's focusLost event
this->focusLost.invoke();
});
this->input_->ui_.textEdit->imagePasted.connect(
@@ -640,7 +645,7 @@ IndirectChannel Split::getIndirectChannel()
return this->channel_;
}
ChannelPtr Split::getChannel()
ChannelPtr Split::getChannel() const
{
return this->channel_.get();
}
@@ -757,16 +762,6 @@ void Split::updateLastReadMessage()
this->view_->updateLastReadMessage();
}
void Split::giveFocus(Qt::FocusReason reason)
{
this->input_->ui_.textEdit->setFocus(reason);
}
bool Split::hasFocus() const
{
return this->input_->ui_.textEdit->hasFocus();
}
void Split::paintEvent(QPaintEvent *)
{
// color the background of the chat
@@ -828,11 +823,6 @@ void Split::leaveEvent(QEvent *event)
this->handleModifiers(QGuiApplication::queryKeyboardModifiers());
}
void Split::focusInEvent(QFocusEvent *event)
{
this->giveFocus(event->reason());
}
void Split::handleModifiers(Qt::KeyboardModifiers modifiers)
{
if (modifierStatus != modifiers)
@@ -1278,3 +1268,31 @@ void Split::drag()
}
} // namespace chatterino
QDebug operator<<(QDebug dbg, const chatterino::Split &split)
{
auto channel = split.getChannel();
if (channel)
{
dbg.nospace() << "Split(" << (void *)&split
<< ", channel:" << channel->getName() << ")";
}
else
{
dbg.nospace() << "Split(" << (void *)&split << ", no channel)";
}
return dbg;
}
QDebug operator<<(QDebug dbg, const chatterino::Split *split)
{
if (split != nullptr)
{
return operator<<(dbg, *split);
}
dbg.nospace() << "Split(nullptr)";
return dbg;
}