From 304bd1e77a5442f614aacd2b35f330777118b2cd Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Mon, 19 Oct 2026 15:32:53 -0700 Subject: merge with upstream https://github.com/RblSb/SyncTube --- src/client/InputWithHistory.hx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/client/InputWithHistory.hx') diff --git a/src/client/InputWithHistory.hx b/src/client/InputWithHistory.hx index e41ec16..c82267f 100644 --- a/src/client/InputWithHistory.hx +++ b/src/client/InputWithHistory.hx @@ -1,5 +1,6 @@ package client; +import js.html.Event; import js.html.InputElement; import js.html.KeyboardEvent; @@ -8,19 +9,22 @@ class InputWithHistory { final maxItems:Int; final history:Array; final onEnter:(value:String) -> Bool; + final onInterceptKeyDown:Null<(e:KeyboardEvent) -> Bool>; var historyId = -1; public function new( element:InputElement, ?history:Array, maxItems:Int, - onEnter:(value:String) -> Bool + onEnter:(value:String) -> Bool, + ?onInterceptKeyDown:(e:KeyboardEvent) -> Bool ) { this.element = element; if (history != null) this.history = history; else this.history = []; this.maxItems = maxItems; this.onEnter = onEnter; + this.onInterceptKeyDown = onInterceptKeyDown; element.onkeydown = onKeyDown; } @@ -30,6 +34,7 @@ class InputWithHistory { } function onKeyDown(e:KeyboardEvent) { + if (onInterceptKeyDown != null && onInterceptKeyDown(e)) return; final key:KeyCode = cast e.keyCode; switch (key) { case Return: @@ -59,11 +64,13 @@ class InputWithHistory { element.value = history[historyId]; } onInput(); + case Escape: + e.preventDefault(); default: } } function onInput():Void { - if (element.oninput != null) element.oninput(); + element.dispatchEvent(new Event("input")); } } -- cgit v1.2.3