From f3b490134e511730d0d9f1c1ab78d57b4de11006 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Sun, 5 Nov 2023 22:10:24 +0100 Subject: Fixes text input widget undo propagation. If not handled, undo propagates to other random widgets, and if none takes it, it is resent as a redo to all widgets. --- src/Fl_Input.cxx | 10 ++++++++-- src/Fl_Text_Editor.cxx | 8 +++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Fl_Input.cxx b/src/Fl_Input.cxx index 88ea49cc3..4bd799e62 100644 --- a/src/Fl_Input.cxx +++ b/src/Fl_Input.cxx @@ -440,8 +440,14 @@ int Fl_Input::handle_key() { if (mods==FL_COMMAND) return kf_copy_cut(); // Ctrl-X, Mac:Meta-X (Standard/OSX-HIG) break; case 'z': - if (mods==FL_COMMAND && !shift) return kf_undo(); // Ctrl-Z, Mac:Meta-Z (Standard/OSX-HIG) - if (mods==FL_COMMAND && shift) return kf_redo(); // Shift-Ctrl-Z, Mac:Shift-Meta-Z (Standard/OSX-HIG) + if (mods==FL_COMMAND && !shift) { // Ctrl-Z, Mac:Meta-Z (Standard/OSX-HIG) + if (!kf_undo()) fl_beep(); + return 1; + } + if (mods==FL_COMMAND && shift) { // Shift-Ctrl-Z, Mac:Shift-Meta-Z (Standard/OSX-HIG) + if (!kf_redo()) fl_beep(); + return 1; + } break; // handle other combos elsewhere } diff --git a/src/Fl_Text_Editor.cxx b/src/Fl_Text_Editor.cxx index c548ef6be..29fb0d6e3 100644 --- a/src/Fl_Text_Editor.cxx +++ b/src/Fl_Text_Editor.cxx @@ -663,7 +663,13 @@ int Fl_Text_Editor::handle_key() { Key_Func f; f = bound_key_function(key, state, global_key_bindings); if (!f) f = bound_key_function(key, state, key_bindings); - if (f) return f(key, this); + if (f == kf_undo || f == kf_redo) { + // never propagate undo and redo up to another widget + if (!f(key, this)) fl_beep(); + return 1; + } else if (f){ + return f(key, this); + } if (default_key_function_ && !state) return default_key_function_(c, this); return 0; } -- cgit v1.2.3