From bbf1fc28ca8403d0a805ac4a35e5b23bb167c171 Mon Sep 17 00:00:00 2001 From: Lucas Werkmeister Date: Thu, 11 Feb 2021 19:44:03 +0100 Subject: [PATCH] lookingGlass: Let history trim input MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Checking whether the item is empty is now the history’s job, per the previous two commits. The history also trims the input for us. The effect of this is that we call _history.addItem(), and thereby move to the end of the history, even if the input is empty (or consists only of whitespace); clearing the input field and pressing Enter becomes a quick way to jump back to the end of the history. (The current history item is not overwritten if the input is empty.) Part-of: --- js/ui/lookingGlass.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/js/ui/lookingGlass.js b/js/ui/lookingGlass.js index 728983ea2..e59fa2930 100644 --- a/js/ui/lookingGlass.js +++ b/js/ui/lookingGlass.js @@ -1129,10 +1129,6 @@ class LookingGlass extends St.BoxLayout { // Ensure we don't get newlines in the command; the history file is // newline-separated. text = text.replace('\n', ' '); - // Strip leading and trailing whitespace - text = text.replace(/^\s+/g, '').replace(/\s+$/g, ''); - if (text == '') - return true; this._evaluate(text); return true; }); @@ -1240,7 +1236,9 @@ class LookingGlass extends St.BoxLayout { } _evaluate(command) { - this._history.addItem(command); + command = this._history.addItem(command); // trims command + if (!command) + return; let lines = command.split(';'); lines.push('return %s'.format(lines.pop()));