From 889827aadb8a13add162b91981c5b125fe0be919 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Mon, 14 Feb 2022 21:59:49 +0100 Subject: [PATCH] desktop: don't update notes field when executing command User report: when switching focus between windows, the cursor position gets lost. This is due to a note-edit command being fired, which then overwrites the notes tab. To prevent this, don't update the notes field when placing a command. Moreover, generally don't update the dive selection when placing a command as that also rewrites all the values. Should this be extended to other fields? Fixes #3365 Signed-off-by: Berthold Stoeger --- CHANGELOG.md | 1 + commands/command_base.cpp | 2 -- commands/command_edit.cpp | 3 ++- desktop-widgets/tab-widgets/maintab.cpp | 7 +++---- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a90125b3..46f66907a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +- desktop: Don't lose cursor position in notes when switching between windows [#3369] - Uemis support: fix the ability disconnect/reconnect the Zurich when its filesystem is full - libdivecomputer: add support for latest BLE hardware in OSTC dive computers diff --git a/commands/command_base.cpp b/commands/command_base.cpp index 1110699a9..ad571089f 100644 --- a/commands/command_base.cpp +++ b/commands/command_base.cpp @@ -112,5 +112,3 @@ bool placingCommand() } } // namespace Command - - diff --git a/commands/command_edit.cpp b/commands/command_edit.cpp index e6e5f8e8e..32c8b889a 100644 --- a/commands/command_edit.cpp +++ b/commands/command_edit.cpp @@ -156,7 +156,8 @@ void EditBase::undo() // Send signals. DiveField id = fieldId(); emit diveListNotifier.divesChanged(stdToQt(dives), id); - setSelection(selectedDives, current); + if (!placingCommand()) + setSelection(selectedDives, current); } // We have to manually instantiate the constructors of the EditBase class, diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index 49170525d..06f44b7ef 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -248,7 +248,7 @@ void MainTab::divesChanged(const QVector &dives, DiveField field) ui.depth->setText(get_depth_string(current_dive->maxdepth, true)); if (field.rating) ui.rating->setCurrentStars(current_dive->rating); - if (field.notes) + if (field.notes && !Command::placingCommand()) updateNotes(current_dive); if (field.datetime) { updateDateTime(current_dive); @@ -306,11 +306,10 @@ static bool isHtml(const QString &s) void MainTab::updateNotes(const struct dive *d) { QString tmp(d->notes); - if (isHtml(tmp)) { + if (isHtml(tmp)) ui.notes->setHtml(tmp); - } else { + else ui.notes->setPlainText(tmp); - } } void MainTab::updateDateTime(const struct dive *d)