aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/Buttons.hx46
-rw-r--r--src/client/InputWithHistory.hx54
-rw-r--r--src/client/Main.hx9
3 files changed, 70 insertions, 39 deletions
diff --git a/src/client/Buttons.hx b/src/client/Buttons.hx
index 2d32d99..8a1264e 100644
--- a/src/client/Buttons.hx
+++ b/src/client/Buttons.hx
@@ -12,8 +12,6 @@ import js.html.Event;
class Buttons {
- static final personalHistory:Array<String> = [];
- static var personalHistoryId = -1;
static var split:Split;
static var settings:ClientSettings;
@@ -312,40 +310,16 @@ class Buttons {
}
}
- final chatLine:InputElement = cast ge("#chatline");
- chatLine.onkeydown = function(e:KeyboardEvent) {
- switch (e.keyCode) {
- case 13: // Enter
- if (chatLine.value.length == 0) return;
- main.send({
- type: Message,
- message: {
- clientName: "",
- text: chatLine.value
- }
- });
- personalHistory.push(chatLine.value);
- if (personalHistory.length > 50) personalHistory.shift();
- personalHistoryId = -1;
- chatLine.value = "";
- case 38: // Up
- personalHistoryId--;
- if (personalHistoryId == -2) {
- personalHistoryId = personalHistory.length - 1;
- if (personalHistoryId == -1) return;
- } else if (personalHistoryId == -1) personalHistoryId++;
- chatLine.value = personalHistory[personalHistoryId];
- case 40: // Down
- if (personalHistoryId == -1) return;
- personalHistoryId++;
- if (personalHistoryId > personalHistory.length - 1) {
- personalHistoryId = -1;
- chatLine.value = "";
- return;
- }
- chatLine.value = personalHistory[personalHistoryId];
- }
- }
+ new InputWithHistory(cast ge("#chatline"), 50, value -> {
+ main.send({
+ type: Message,
+ message: {
+ clientName: "",
+ text: value
+ }
+ });
+ return true;
+ });
}
}
diff --git a/src/client/InputWithHistory.hx b/src/client/InputWithHistory.hx
new file mode 100644
index 0000000..9c5b615
--- /dev/null
+++ b/src/client/InputWithHistory.hx
@@ -0,0 +1,54 @@
+package client;
+
+import js.html.KeyboardEvent;
+import js.html.InputElement;
+
+class InputWithHistory {
+
+ final element:InputElement;
+ final maxItems:Int;
+ final history:Array<String>;
+ final onEnter:(value:String)->Bool;
+ var historyId = -1;
+
+ public function new(
+ element:InputElement, ?history:Array<String>, maxItems:Int,
+ onEnter:(value:String)->Bool
+ ) {
+ this.element = element;
+ if (history != null) this.history = history;
+ else this.history = [];
+ this.maxItems = maxItems;
+ this.onEnter = onEnter;
+ element.onkeydown = onKeyDown;
+ }
+
+ 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);
+ if (history.length > maxItems) history.shift();
+ historyId = -1;
+ element.value = "";
+ case 38: // Up
+ historyId--;
+ if (historyId == -2) {
+ historyId = history.length - 1;
+ if (historyId == -1) return;
+ } else if (historyId == -1) historyId++;
+ element.value = history[historyId];
+ case 40: // Down
+ if (historyId == -1) return;
+ historyId++;
+ if (historyId > history.length - 1) {
+ historyId = -1;
+ element.value = "";
+ return;
+ }
+ element.value = history[historyId];
+ }
+ }
+
+}
diff --git a/src/client/Main.hx b/src/client/Main.hx
index e5cd58b..5e114ca 100644
--- a/src/client/Main.hx
+++ b/src/client/Main.hx
@@ -136,9 +136,10 @@ class Main {
ge("#queue_next").onclick = e -> addVideoUrl(false);
ge("#queue_end").onclick = e -> addVideoUrl(true);
- ge("#mediaurl").onkeydown = (e:KeyboardEvent) -> {
- if (e.keyCode == 13) addVideoUrl(true);
- }
+ new InputWithHistory(cast ge("#mediaurl"), settings.latestLinks, 10, value -> {
+ addVideoUrl(true);
+ return true;
+ });
ge("#ce_queue_next").onclick = e -> addIframe(false);
ge("#ce_queue_end").onclick = e -> addIframe(true);
@@ -189,6 +190,8 @@ class Main {
final url = mediaUrl.value;
if (url.length == 0) return;
mediaUrl.value = "";
+ settings.latestLinks.push(url);
+ Settings.write(settings);
final url = ~/,(https?)/g.replace(url, "|$1");
final links = url.split("|");
handleUrlMasks(links);
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage