From afad9c4869a2eb658e79be4f52798eff5dca1476 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Sun, 13 Oct 2024 13:26:45 +0100 Subject: [PATCH 1/5] Combine confirm paste and confirm drop --- src/Widgets/TerminalWidget.vala | 41 +++++++++++++-------------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/src/Widgets/TerminalWidget.vala b/src/Widgets/TerminalWidget.vala index 2b1f15f073..9de20c4757 100644 --- a/src/Widgets/TerminalWidget.vala +++ b/src/Widgets/TerminalWidget.vala @@ -519,21 +519,19 @@ namespace Terminal { protected override void paste_clipboard () { clipboard.request_text ((clipboard, text) => { - if (text == null) { - return; - } - - if (!text.validate ()) { - warning ("Dropping invalid UTF-8 paste"); - return; - } + validated_feed (text); + }); + } + // Check pasted and dropped text before feeding to child; + private void validated_feed (string? text) { + if (text != null && text.validate ()) { unowned var toplevel = (MainWindow) get_toplevel (); - - if (!toplevel.unsafe_ignored && Application.settings.get_boolean ("unsafe-paste-alert")) { + if (!toplevel.unsafe_ignored && + Application.settings.get_boolean ("unsafe-paste-alert")) { string? warn_text = null; - text._strip (); + text._strip (); if ("\n" in text) { warn_text = _("The pasted text may contain multiple commands"); } else if ("sudo" in text || "doas" in text) { @@ -543,22 +541,19 @@ namespace Terminal { if (warn_text != null) { var dialog = new UnsafePasteDialog (toplevel, warn_text, text); dialog.response.connect ((res) => { + dialog.destroy (); if (res == Gtk.ResponseType.ACCEPT) { - remember_command_start_position (); - base.paste_clipboard (); + feed_child (text.data); } - - dialog.destroy (); }); dialog.present (); return; } - } - remember_command_start_position (); - base.paste_clipboard (); - }); + feed_child (text.data); + } + } } private void update_theme () { @@ -789,12 +784,8 @@ namespace Terminal { break; case DropTargets.STRING: case DropTargets.TEXT: - var data = selection_data.get_text (); - - if (data != null) { - this.feed_child (data.data); - } - + var text = selection_data.get_text (); + validated_feed (text); break; } } From 68b4740ec0ee665d6544494945c073868819c8d4 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Sun, 3 Nov 2024 16:55:21 +0000 Subject: [PATCH 2/5] Handle unsafe paste alert off/ignored --- src/Widgets/TerminalWidget.vala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Widgets/TerminalWidget.vala b/src/Widgets/TerminalWidget.vala index 9de20c4757..44980e2ada 100644 --- a/src/Widgets/TerminalWidget.vala +++ b/src/Widgets/TerminalWidget.vala @@ -526,12 +526,12 @@ namespace Terminal { // Check pasted and dropped text before feeding to child; private void validated_feed (string? text) { if (text != null && text.validate ()) { + text._strip (); unowned var toplevel = (MainWindow) get_toplevel (); if (!toplevel.unsafe_ignored && Application.settings.get_boolean ("unsafe-paste-alert")) { - string? warn_text = null; - text._strip (); + string? warn_text = null; if ("\n" in text) { warn_text = _("The pasted text may contain multiple commands"); } else if ("sudo" in text || "doas" in text) { @@ -550,7 +550,7 @@ namespace Terminal { dialog.present (); return; } - + } else { feed_child (text.data); } } From 0b25969d826404268dd7f6caa15d57592ff87eb9 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Sun, 3 Nov 2024 17:30:06 +0000 Subject: [PATCH 3/5] Revert inadvertent change to text stripping --- src/Widgets/TerminalWidget.vala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Widgets/TerminalWidget.vala b/src/Widgets/TerminalWidget.vala index 44980e2ada..27bedbd4c3 100644 --- a/src/Widgets/TerminalWidget.vala +++ b/src/Widgets/TerminalWidget.vala @@ -526,7 +526,7 @@ namespace Terminal { // Check pasted and dropped text before feeding to child; private void validated_feed (string? text) { if (text != null && text.validate ()) { - text._strip (); + var stripped_text = text.strip (); unowned var toplevel = (MainWindow) get_toplevel (); if (!toplevel.unsafe_ignored && Application.settings.get_boolean ("unsafe-paste-alert")) { @@ -539,7 +539,7 @@ namespace Terminal { } if (warn_text != null) { - var dialog = new UnsafePasteDialog (toplevel, warn_text, text); + var dialog = new UnsafePasteDialog (toplevel, warn_text, stripped_text); dialog.response.connect ((res) => { dialog.destroy (); if (res == Gtk.ResponseType.ACCEPT) { From 96c8c844f5191cbbdb62141370ead33deded9e1c Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Wed, 6 Nov 2024 16:37:25 +0000 Subject: [PATCH 4/5] Lose unnecessary single-use var --- src/Widgets/TerminalWidget.vala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Widgets/TerminalWidget.vala b/src/Widgets/TerminalWidget.vala index d6a0a8b082..0507f5e800 100644 --- a/src/Widgets/TerminalWidget.vala +++ b/src/Widgets/TerminalWidget.vala @@ -526,7 +526,6 @@ namespace Terminal { // Check pasted and dropped text before feeding to child; private void validated_feed (string? text) { if (text != null && text.validate ()) { - var stripped_text = text.strip (); unowned var toplevel = (MainWindow) get_toplevel (); if (!toplevel.unsafe_ignored && Application.settings.get_boolean ("unsafe-paste-alert")) { @@ -539,7 +538,7 @@ namespace Terminal { } if (warn_text != null) { - var dialog = new UnsafePasteDialog (toplevel, warn_text, stripped_text); + var dialog = new UnsafePasteDialog (toplevel, warn_text, text.strip ()); dialog.response.connect ((res) => { dialog.destroy (); if (res == Gtk.ResponseType.ACCEPT) { From 4bda9e99491db16369880973ceddfd5d3c0316b5 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Wed, 6 Nov 2024 16:38:15 +0000 Subject: [PATCH 5/5] Lose unnecessary return --- src/Widgets/TerminalWidget.vala | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Widgets/TerminalWidget.vala b/src/Widgets/TerminalWidget.vala index 0507f5e800..f26628c2dc 100644 --- a/src/Widgets/TerminalWidget.vala +++ b/src/Widgets/TerminalWidget.vala @@ -547,7 +547,6 @@ namespace Terminal { }); dialog.present (); - return; } } else { feed_child (text.data);