mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
Allow pasting text to the unfocused search.
This commit is contained in:
parent
612b81ee87
commit
12a78c1f45
2 changed files with 28 additions and 7 deletions
|
@ -3264,13 +3264,7 @@ void Widget::keyPressEvent(QKeyEvent *e) {
|
|||
} else {
|
||||
_inner->selectSkipPage(_scroll->height(), -1);
|
||||
}
|
||||
} else if (!(e->modifiers() & ~Qt::ShiftModifier)
|
||||
&& e->key() != Qt::Key_Shift
|
||||
&& !_openedFolder
|
||||
&& !_openedForum
|
||||
&& _search->isVisible()
|
||||
&& !_search->hasFocus()
|
||||
&& !e->text().isEmpty()) {
|
||||
} else if (redirectKeyToSearch(e)) {
|
||||
// This delay in search focus processing allows us not to create
|
||||
// _suggestions in case the event inserts some non-whitespace search
|
||||
// query while still show _suggestions animated, if it is a space.
|
||||
|
@ -3284,6 +3278,31 @@ void Widget::keyPressEvent(QKeyEvent *e) {
|
|||
}
|
||||
}
|
||||
|
||||
bool Widget::redirectKeyToSearch(QKeyEvent *e) const {
|
||||
if (_openedFolder
|
||||
|| _openedForum
|
||||
|| !_search->isVisible()
|
||||
|| _search->hasFocus()) {
|
||||
return false;
|
||||
}
|
||||
const auto character = !(e->modifiers() & ~Qt::ShiftModifier)
|
||||
&& (e->key() != Qt::Key_Shift)
|
||||
&& !e->text().isEmpty();
|
||||
if (character) {
|
||||
return true;
|
||||
} else if (e != QKeySequence::Paste) {
|
||||
return false;
|
||||
}
|
||||
const auto useSelectionMode = (e->key() == Qt::Key_Insert)
|
||||
&& (e->modifiers() == (Qt::CTRL | Qt::SHIFT))
|
||||
&& QGuiApplication::clipboard()->supportsSelection();
|
||||
const auto pasteMode = useSelectionMode
|
||||
? QClipboard::Selection
|
||||
: QClipboard::Clipboard;
|
||||
const auto data = QGuiApplication::clipboard()->mimeData(pasteMode);
|
||||
return data && data->hasText();
|
||||
}
|
||||
|
||||
void Widget::paintEvent(QPaintEvent *e) {
|
||||
if (controller()->contentOverlapped(this, e)) {
|
||||
return;
|
||||
|
|
|
@ -250,6 +250,8 @@ private:
|
|||
void updateSuggestions(anim::type animated);
|
||||
void processSearchFocusChange();
|
||||
|
||||
[[nodiscard]] bool redirectKeyToSearch(QKeyEvent *e) const;
|
||||
|
||||
MTP::Sender _api;
|
||||
|
||||
bool _dragInScroll = false;
|
||||
|
|
Loading…
Add table
Reference in a new issue