From 6b592808ae47b0fbf9fc4c146b114b2178dea4b2 Mon Sep 17 00:00:00 2001 From: RadRussianRus Date: Fri, 26 Aug 2022 22:30:07 +0300 Subject: [PATCH] [Option][GUI] Disable edit by Up --- Telegram/Resources/langs/rewrites/en.json | 1 + .../SourceFiles/history/history_widget.cpp | 21 +++++++++++-------- .../history_view_compose_controls.cpp | 5 ++++- .../SourceFiles/kotato/kotato_settings.cpp | 3 +++ .../kotato/kotato_settings_menu.cpp | 1 + 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Telegram/Resources/langs/rewrites/en.json b/Telegram/Resources/langs/rewrites/en.json index fd76c661c..f68b897f8 100644 --- a/Telegram/Resources/langs/rewrites/en.json +++ b/Telegram/Resources/langs/rewrites/en.json @@ -32,6 +32,7 @@ "ktg_settings_sticker_scale_both": "Apply to sticker width", "ktg_settings_sticker_scale_both_about": "When enabled, sticker maximum width will be changed along with sticker height.", "ktg_settings_emoji_outline": "Big emoji outline", + "ktg_settings_disable_up_edit": "Disable edit by Up key", "ktg_settings_always_show_scheduled": "Always show scheduled", "ktg_fonts_title": "Fonts", "ktg_settings_fonts": "Change application fonts", diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index d43872654..312e692e8 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -6237,15 +6237,18 @@ void HistoryWidget::keyPressEvent(QKeyEvent *e) { } else if (e->key() == Qt::Key_Down && !commonModifiers) { _scroll->keyPressEvent(e); } else if (e->key() == Qt::Key_Up && !commonModifiers) { - const auto item = _history - ? _history->lastEditableMessage() - : nullptr; - if (item - && _field->empty() - && !_editMsgId - && !_replyToId) { - editMessage(item); - return; + if (!::Kotato::JsonSettings::GetBool("disable_up_edit")) { + const auto item = _history + ? _history->lastEditableMessage() + : nullptr; + if (item + && item->allowsEdit(base::unixtime::now()) + && _field->empty() + && !_editMsgId + && !_replyToId) { + editMessage(item); + return; + } } _scroll->keyPressEvent(e); } else if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) { diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp index 4146e8eb8..755472bf8 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "history/view/controls/history_view_compose_controls.h" +#include "kotato/kotato_settings.h" #include "base/event_filter.h" #include "base/platform/base_platform_info.h" #include "base/qt_signal_producer.h" @@ -1548,7 +1549,9 @@ void ComposeControls::initKeyHandler() { _attachRequests.fire({}); return; } - if (key == Qt::Key_Up && !hasModifiers) { + if (key == Qt::Key_Up + && !hasModifiers + && !::Kotato::JsonSettings::GetBool("disable_up_edit")) { if (!isEditingMessage() && _field->empty()) { _editLastMessageRequests.fire(std::move(keyEvent)); return; diff --git a/Telegram/SourceFiles/kotato/kotato_settings.cpp b/Telegram/SourceFiles/kotato/kotato_settings.cpp index d47b1ec7f..3203deaaf 100644 --- a/Telegram/SourceFiles/kotato/kotato_settings.cpp +++ b/Telegram/SourceFiles/kotato/kotato_settings.cpp @@ -289,6 +289,9 @@ const std::map> DefinitionMap { .type = SettingType::IntSetting, .defaultValue = 0, .limitHandler = NetSpeedBoostConv(IntLimit(0, 3)), }}, + { "disable_up_edit", { + .type = SettingType::BoolSetting, + .defaultValue = false, }}, }; using OldOptionKey = QString; diff --git a/Telegram/SourceFiles/kotato/kotato_settings_menu.cpp b/Telegram/SourceFiles/kotato/kotato_settings_menu.cpp index a19344605..96c3a9bd6 100644 --- a/Telegram/SourceFiles/kotato/kotato_settings_menu.cpp +++ b/Telegram/SourceFiles/kotato/kotato_settings_menu.cpp @@ -107,6 +107,7 @@ void SetupKotatoChats( AddSkip(container); AddSubsectionTitle(container, rktr("ktg_settings_chats")); + SettingsMenuJsonSwitch(ktg_settings_disable_up_edit, disable_up_edit); SettingsMenuJsonSwitch(ktg_settings_always_show_scheduled, always_show_scheduled); AddButton(