mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 03:00:46 +03:00
Merge pull request #1095 from syldrathecat/subtle-paste-fixes
Subtle corrections to paste behaviors
This commit is contained in:
commit
835fcf6325
3 changed files with 16 additions and 18 deletions
|
@ -188,8 +188,7 @@ Rectangle {
|
||||||
Keys.onShortcutOverride: event.accepted = (popup.opened && (event.key === Qt.Key_Escape || event.key === Qt.Key_Tab || event.key === Qt.Key_Enter || event.key === Qt.Key_Space))
|
Keys.onShortcutOverride: event.accepted = (popup.opened && (event.key === Qt.Key_Escape || event.key === Qt.Key_Tab || event.key === Qt.Key_Enter || event.key === Qt.Key_Space))
|
||||||
Keys.onPressed: {
|
Keys.onPressed: {
|
||||||
if (event.matches(StandardKey.Paste)) {
|
if (event.matches(StandardKey.Paste)) {
|
||||||
room.input.paste(false);
|
event.accepted = room.input.tryPasteAttachment(false);
|
||||||
event.accepted = true;
|
|
||||||
} else if (event.key == Qt.Key_Space) {
|
} else if (event.key == Qt.Key_Space) {
|
||||||
// close popup if user enters space after colon
|
// close popup if user enters space after colon
|
||||||
if (cursorPosition == completerTriggeredAt + 1)
|
if (cursorPosition == completerTriggeredAt + 1)
|
||||||
|
@ -361,11 +360,6 @@ Rectangle {
|
||||||
}
|
}
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
function onInsertText(text) {
|
|
||||||
messageInput.remove(messageInput.selectionStart, messageInput.selectionEnd);
|
|
||||||
messageInput.insert(messageInput.cursorPosition, text);
|
|
||||||
}
|
|
||||||
|
|
||||||
function onTextChanged(newText) {
|
function onTextChanged(newText) {
|
||||||
messageInput.text = newText;
|
messageInput.text = newText;
|
||||||
messageInput.cursorPosition = newText.length;
|
messageInput.cursorPosition = newText.length;
|
||||||
|
@ -401,7 +395,7 @@ Rectangle {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
acceptedButtons: Qt.MiddleButton
|
acceptedButtons: Qt.MiddleButton
|
||||||
cursorShape: Qt.IBeamCursor
|
cursorShape: Qt.IBeamCursor
|
||||||
onClicked: room.input.paste(true)
|
onPressed: (mouse) => mouse.accepted = room.input.tryPasteAttachment(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,8 +101,8 @@ InputVideoSurface::supportedPixelFormats(QAbstractVideoBuffer::HandleType type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
bool
|
||||||
InputBar::paste(bool fromMouse)
|
InputBar::tryPasteAttachment(bool fromMouse)
|
||||||
{
|
{
|
||||||
const QMimeData *md = nullptr;
|
const QMimeData *md = nullptr;
|
||||||
|
|
||||||
|
@ -113,14 +113,16 @@ InputBar::paste(bool fromMouse)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (md)
|
if (md)
|
||||||
insertMimeData(md);
|
return insertMimeData(md);
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
bool
|
||||||
InputBar::insertMimeData(const QMimeData *md)
|
InputBar::insertMimeData(const QMimeData *md)
|
||||||
{
|
{
|
||||||
if (!md)
|
if (!md)
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
nhlog::ui()->debug("Got mime formats: {}",
|
nhlog::ui()->debug("Got mime formats: {}",
|
||||||
md->formats().join(QStringLiteral(", ")).toStdString());
|
md->formats().join(QStringLiteral(", ")).toStdString());
|
||||||
|
@ -171,7 +173,7 @@ InputBar::insertMimeData(const QMimeData *md)
|
||||||
auto data = md->data(QStringLiteral("x-special/gnome-copied-files")).split('\n');
|
auto data = md->data(QStringLiteral("x-special/gnome-copied-files")).split('\n');
|
||||||
if (data.size() < 2) {
|
if (data.size() < 2) {
|
||||||
nhlog::ui()->warn("MIME format is malformed, cannot perform paste.");
|
nhlog::ui()->warn("MIME format is malformed, cannot perform paste.");
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 1; i < data.size(); ++i) {
|
for (int i = 1; i < data.size(); ++i) {
|
||||||
|
@ -181,10 +183,13 @@ InputBar::insertMimeData(const QMimeData *md)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (md->hasText()) {
|
} else if (md->hasText()) {
|
||||||
emit insertText(md->text());
|
return false;
|
||||||
} else {
|
} else {
|
||||||
nhlog::ui()->debug("formats: {}", md->formats().join(QStringLiteral(", ")).toStdString());
|
nhlog::ui()->debug("formats: {}", md->formats().join(QStringLiteral(", ")).toStdString());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -190,8 +190,8 @@ public slots:
|
||||||
[[nodiscard]] bool containsAtRoom() const { return containsAtRoom_; }
|
[[nodiscard]] bool containsAtRoom() const { return containsAtRoom_; }
|
||||||
|
|
||||||
void send();
|
void send();
|
||||||
void paste(bool fromMouse);
|
bool tryPasteAttachment(bool fromMouse);
|
||||||
void insertMimeData(const QMimeData *data);
|
bool insertMimeData(const QMimeData *data);
|
||||||
void updateState(int selectionStart, int selectionEnd, int cursorPosition, const QString &text);
|
void updateState(int selectionStart, int selectionEnd, int cursorPosition, const QString &text);
|
||||||
void openFileSelection();
|
void openFileSelection();
|
||||||
[[nodiscard]] bool uploading() const { return uploading_; }
|
[[nodiscard]] bool uploading() const { return uploading_; }
|
||||||
|
@ -212,7 +212,6 @@ private slots:
|
||||||
void removeRunUpload(MediaUpload *upload);
|
void removeRunUpload(MediaUpload *upload);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void insertText(QString text);
|
|
||||||
void textChanged(QString newText);
|
void textChanged(QString newText);
|
||||||
void uploadingChanged(bool value);
|
void uploadingChanged(bool value);
|
||||||
void containsAtRoomChanged();
|
void containsAtRoomChanged();
|
||||||
|
|
Loading…
Reference in a new issue