diff options
| author | RblSb <msrblsb@gmail.com> | 2020-05-23 22:06:31 +0300 |
|---|---|---|
| committer | RblSb <msrblsb@gmail.com> | 2020-05-23 22:06:31 +0300 |
| commit | 45080aa1f6d80f2ef64983904acbe1645c312d25 (patch) | |
| tree | 42eb53343e49a564b12951bf6ce7e42992492a36 /src/client/InputWithHistory.hx | |
| parent | a45d0bef0dccb5472bec095d8e00af8647173a56 (diff) | |
Improve history inputs
Diffstat (limited to 'src/client/InputWithHistory.hx')
| -rw-r--r-- | src/client/InputWithHistory.hx | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/client/InputWithHistory.hx b/src/client/InputWithHistory.hx index 9c5b615..ecba43a 100644 --- a/src/client/InputWithHistory.hx +++ b/src/client/InputWithHistory.hx @@ -23,12 +23,18 @@ class InputWithHistory { element.onkeydown = onKeyDown; } + public static function pushIfNotLast(arr:Array<String>, item:String):Void { + final len = arr.length; + if (len == 0 || arr[len - 1] != item) arr.push(item); + } + function onKeyDown(e:KeyboardEvent) { switch (e.keyCode) { case 13: // Enter - if (element.value.length == 0) return; - final isAdd = onEnter(element.value); - if (isAdd) history.push(element.value); + final value = element.value; + if (value.length == 0) return; + final isAdd = onEnter(value); + if (isAdd) pushIfNotLast(history, value); if (history.length > maxItems) history.shift(); historyId = -1; element.value = ""; |
