From 7e606cdd9f97f55689ed10923e7b83810c88d360 Mon Sep 17 00:00:00 2001
From: ed
Date: Wed, 30 Jun 2021 01:44:25 +0200
Subject: [PATCH] make search rate-control less visually confusing
---
README.md | 2 --
copyparty/web/browser.css | 2 +-
copyparty/web/browser.js | 30 +++++++++++++++++++++++++++---
copyparty/web/up2k.js | 4 +---
copyparty/web/util.js | 3 +++
5 files changed, 32 insertions(+), 9 deletions(-)
diff --git a/README.md b/README.md
index 76d5b017..408e5fc6 100644
--- a/README.md
+++ b/README.md
@@ -614,8 +614,6 @@ in the `scripts` folder:
roughly sorted by priority
-* ctrl-click overrides onclick (tree, ...)
-* indicate dropped queries in search ui
* readme.md as epilogue
* reduce up2k roundtrips
* start from a chunk index and just go
diff --git a/copyparty/web/browser.css b/copyparty/web/browser.css
index 702b9b58..3032deb9 100644
--- a/copyparty/web/browser.css
+++ b/copyparty/web/browser.css
@@ -607,7 +607,7 @@ input.eq_gain {
#srch_q {
white-space: pre;
color: #f80;
- height: 1em;
+ min-height: 1em;
margin: .2em 0 -1em 1.6em;
}
#tq_raw {
diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js
index c973503d..98f0039a 100644
--- a/copyparty/web/browser.js
+++ b/copyparty/web/browser.js
@@ -1879,6 +1879,7 @@ document.onkeydown = function (e) {
}
var search_timeout,
+ defer_timeout,
search_in_progress = 0;
function ev_search_input() {
@@ -1893,9 +1894,29 @@ document.onkeydown = function (e) {
if (id != "q_raw")
encode_query();
- clearTimeout(search_timeout);
- if (Date.now() - search_in_progress > 30 * 1000)
+ set_vq();
+
+ clearTimeout(defer_timeout);
+ defer_timeout = setTimeout(try_search, 2000);
+ try_search();
+ }
+
+ function try_search() {
+ if (Date.now() - search_in_progress > 30 * 1000) {
+ clearTimeout(defer_timeout);
+ clearTimeout(search_timeout);
search_timeout = setTimeout(do_search, 200);
+ }
+ }
+
+ function set_vq() {
+ if (search_in_progress)
+ return;
+
+ var q = ebi('q_raw').value,
+ vq = ebi('files').getAttribute('q_raw');
+
+ srch_msg(false, (q == vq) ? '' : 'search results below are from a previous query:\n ' + (vq ? vq : '(*)'));
}
function encode_query() {
@@ -1965,7 +1986,8 @@ document.onkeydown = function (e) {
xhr.setRequestHeader('Content-Type', 'text/plain');
xhr.onreadystatechange = xhr_search_results;
xhr.ts = Date.now();
- xhr.send(JSON.stringify({ "q": ebi('q_raw').value }));
+ xhr.q_raw = ebi('q_raw').value;
+ xhr.send(JSON.stringify({ "q": xhr.q_raw }));
}
function xhr_search_results() {
@@ -2036,6 +2058,8 @@ document.onkeydown = function (e) {
ofiles.innerHTML = html.join('\n');
ofiles.setAttribute("ts", this.ts);
+ ofiles.setAttribute("q_raw", this.q_raw);
+ set_vq();
mukey.render();
reload_browser();
filecols.set_style(['File Name']);
diff --git a/copyparty/web/up2k.js b/copyparty/web/up2k.js
index 8a511ab5..7676caa2 100644
--- a/copyparty/web/up2k.js
+++ b/copyparty/web/up2k.js
@@ -1,7 +1,5 @@
"use strict";
-window.onerror = vis_exh;
-
function goto_up2k() {
if (up2k === false)
@@ -32,7 +30,7 @@ catch (ex) {
}
catch (ex) { }
}
-window['treectl'].onscroll(); // uhh
+treectl.onscroll();
function up2k_flagbus() {
diff --git a/copyparty/web/util.js b/copyparty/web/util.js
index 92eb14a5..e4563fc0 100644
--- a/copyparty/web/util.js
+++ b/copyparty/web/util.js
@@ -32,6 +32,9 @@ function esc(txt) {
});
}
function vis_exh(msg, url, lineNo, columnNo, error) {
+ if (!window.onerror)
+ return;
+
window.onerror = undefined;
window['vis_exh'] = null;
var html = ['you hit a bug!
please screenshot this error and send me a copy arigathanks gozaimuch (ed/irc.rizon.net or ed#2644)
',