From c0d7aa9e4a8f2e3026b97992756a8e3d32d62c37 Mon Sep 17 00:00:00 2001 From: ed Date: Sat, 6 Nov 2021 22:02:43 +0100 Subject: [PATCH] add file selection from text viewer --- copyparty/web/baguettebox.js | 4 ++-- copyparty/web/browser.css | 9 +++++++++ copyparty/web/browser.js | 39 ++++++++++++++++++++++++++++++++---- 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/copyparty/web/baguettebox.js b/copyparty/web/baguettebox.js index 0a8b8c2a..defdbbcf 100644 --- a/copyparty/web/baguettebox.js +++ b/copyparty/web/baguettebox.js @@ -331,7 +331,7 @@ window.baguetteBox = (function () { function tglsel() { var thumb = currentGallery[currentIndex].imageElement, - name = vsplit(thumb.href)[1], + name = vsplit(thumb.href)[1].split('?')[0], files = msel.getall(); for (var a = 0; a < files.length; a++) @@ -345,7 +345,7 @@ window.baguetteBox = (function () { function selbg() { var img = vidimg(), thumb = currentGallery[currentIndex].imageElement, - name = vsplit(thumb.href)[1], + name = vsplit(thumb.href)[1].split('?')[0], files = msel.getsel(), sel = false; diff --git a/copyparty/web/browser.css b/copyparty/web/browser.css index 508a005d..ff70e51a 100644 --- a/copyparty/web/browser.css +++ b/copyparty/web/browser.css @@ -748,6 +748,11 @@ input.eq_gain { #tree li:last-child { border-bottom: none; } +#tree ul a.sel { + background: #111; + box-shadow: -.8em 0 0 #c37 inset; + color: #fff; +} #tree ul a.hl { color: #400; background: #fc4; @@ -1053,6 +1058,10 @@ html.light #doc .line-highlight { #tree #docul a { display: block; } +#seldoc.sel { + color: #fff; + background: #925; +} #pvol, #barbuf, #barpos, diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index 3302ae09..4957322e 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -2489,11 +2489,34 @@ var showfile = (function () { r.updtree = function () { var fn = QS('#path span:last-child'), - lis = QSA('#docul li a'); + lis = QSA('#docul li a'), + sels = msel.getsel(), + actsel = false; fn = fn ? fn.textContent : ''; - for (var a = 0, aa = lis.length; a < aa; a++) - clmod(lis[a], 'hl', lis[a].textContent == fn); + for (var a = 0, aa = lis.length; a < aa; a++) { + var lin = lis[a].textContent, + sel = false; + + for (var b = 0; b < sels.length; b++) + if (vsplit(sels[b].vp)[1] == lin) + sel = true; + + clmod(lis[a], 'hl', lin == fn); + clmod(lis[a], 'sel', sel); + if (lin == fn && sel) + actsel = true; + } + clmod(ebi('seldoc'), 'sel', actsel); + }; + + r.tglsel = function () { + var fn = ebi('docname').textContent; + for (var a = 0; a < r.files.length; a++) + if (r.files[a].name == fn) + clmod(ebi(r.files[a].id).closest('tr'), 'sel', 't'); + + msel.selui(); }; var bdoc = ebi('bdoc'); @@ -2504,6 +2527,7 @@ var showfile = (function () { '💾 download\n' + '⬆ prev\n' + '⬇ next\n' + + 'sel\n' + '' ); ebi('xdoc').onclick = function () { @@ -2512,6 +2536,7 @@ var showfile = (function () { ebi('dldoc').setAttribute('download', ''); ebi('prevdoc').onclick = function () { tree_neigh(-1); }; ebi('nextdoc').onclick = function () { tree_neigh(1); }; + ebi('seldoc').onclick = r.tglsel; return r; })(); @@ -2867,7 +2892,7 @@ function tree_neigh(n) { } var act = -1; for (var a = 0, aa = links.length; a < aa; a++) { - if (links[a].getAttribute('class') == 'hl') { + if (clgot(links[a], 'hl')) { act = a; break; } @@ -3039,6 +3064,11 @@ document.onkeydown = function (e) { if (k == 'KeyD') return QSA('#ghead a[z]')[1].click(); } + + if (showfile.active()) { + if (k == 'KeyS') + showfile.tglsel(); + } }; @@ -4455,6 +4485,7 @@ var msel = (function () { clmod(ebi('wtoggle'), 'sel', r.getsel().length); thegrid.loadsel(); fileman.render(); + showfile.updtree(); } r.seltgl = function (e) { ev(e);