work out dsel bugs

also probably introduce new bugs
also work out merge conflicts
also cleanup things
also tabs instead of spaces
This commit is contained in:
icxes 2026-01-16 11:53:02 +02:00
parent 5d7cf80ff0
commit c4210e7281
No known key found for this signature in database

View file

@ -9760,26 +9760,34 @@ function reload_browser() {
(function() { (function() {
var is_selma = false; var is_selma = false;
var is_drag = false; var dragging = false;
var prevent_click = false;
var fwrapper = null;
var startx, starty; var startx, starty;
var selbox = null; var selbox = null;
var ttimer = null; var ttimer = null;
var lpdelay = 400; var lpdelay = 250;
var mvthresh = 10; var mvthresh = 10;
function unbox() { function unbox() {
qsr('.selbox'); qsr('.selbox');
if (fwrapper) {
ebi("gfiles").style.userSelect = 'auto';
fwrapper = null;
}
selbox = null; selbox = null;
is_drag = false; dragging = false;
is_selma = false; is_selma = false;
ttimer = null;
} }
function getpp(e) { function getpp(e) {
if (e.touches && e.touches.length > 0) { var touch = (e.touches && e.touches[0]) || e;
return { x: e.touches[0].clientX, y: e.touches[0].clientY }; return { x: touch.clientX, y: touch.clientY };
}
return { x: e.clientX, y: e.clientY };
} }
function sel_toggle(el) { function sel_toggle(el) {
@ -9794,57 +9802,79 @@ function reload_browser() {
} }
} }
function bob(rect1, rect2) { function bob(b1, b2) {
return !(rect1.right < rect2.left || rect1.left > rect2.right || return !(b1.right < b2.left || b1.left > b2.right ||
rect1.bottom < rect2.top || rect1.top > rect2.bottom); b1.bottom < b2.top || b1.top > b2.bottom);
}
function sel_excl(e, exclist) {
for (var id of exclist) {
if ((e.target && e.target.closest(id))) {
return true
}
}
return false
} }
function sel_start(e) { function sel_start(e) {
if (e.button !== 0 && e.type !== 'touchstart') return;
if (!thegrid.en || !treectl.dsel) return; if (!thegrid.en || !treectl.dsel) return;
if (sel_excl(e, ['#widget','#ops','.opview','.doc'])) return;
var pos = getpp(e); var pos = getpp(e);
startx = pos.x; startx = pos.x;
starty = pos.y; starty = pos.y;
is_selma = true;
ttimer = null;
prevent_click = false;
if (e.type === 'mousedown') { fwrapper = e.target.closest('#wrap');
if (e.button !== 0) { if (fwrapper) ebi('gfiles').style.userSelect = 'none';
unbox();
return; if (e.type === 'touchstart') {
} if (ttimer) clearTimeout(ttimer);
is_selma = true;
start_drag(pos);
}
else if (e.type === 'touchstart') {
ttimer = setTimeout(function() { ttimer = setTimeout(function() {
is_selma = true; ttimer = null;
start_drag(pos); start_drag(pos);
}, lpdelay); }, lpdelay);
} }
} }
function start_drag(pos) { function start_drag(pos) {
is_drag = true; if (dragging) return;
dragging = true;
selbox = document.createElement('div'); selbox = document.createElement('div');
selbox.className = 'selbox'; selbox.className = 'selbox';
document.body.appendChild(selbox); document.body.appendChild(selbox);
document.body.style.userSelect = 'none';
} }
function sel_move(e) { function sel_move(e) {
if (!treectl.dsel) return; if (!is_selma) return;
var pos = getpp(e); var pos = getpp(e);
if (ttimer && !is_drag) { if (e.type === 'touchmove') {
if (ttimer !== null) {
var dist = Math.sqrt(Math.pow(pos.x - startx, 2) + Math.pow(pos.y - starty, 2)); var dist = Math.sqrt(Math.pow(pos.x - startx, 2) + Math.pow(pos.y - starty, 2));
if (dist > mvthresh) { if (dist > mvthresh) {
clearTimeout(ttimer); clearTimeout(ttimer);
ttimer = null; ttimer = null;
is_selma = false;
}
return;
}
if (e.cancelable) e.preventDefault();
}
if (!dragging && !has_txtsel()) {
var dist = Math.sqrt(Math.pow(pos.x - startx, 2) + Math.pow(pos.y - starty, 2));
if (dist > mvthresh) {
if (!fwrapper) return;
start_drag(pos);
} }
} }
if (!is_drag || !selbox) return; if (!dragging || !selbox) return;
ev(e); ev(e);
var width = Math.abs(pos.x - startx); var width = Math.abs(pos.x - startx);
@ -9865,21 +9895,35 @@ function reload_browser() {
clearTimeout(ttimer); clearTimeout(ttimer);
ttimer = null; ttimer = null;
if (!is_drag) return; if (dragging) {
prevent_click = true;
if (selbox) { if (selbox) {
var sbrect = selbox.getBoundingClientRect(); var sbrect = selbox.getBoundingClientRect();
var faf = QSA('#ggrid a'); var faf = QSA('#ggrid a');
for (var a = 0, aa = faf.length; a < aa; a++) for (var a = 0, aa = faf.length; a < aa; a++)
if (bob(sbrect, faf[a].getBoundingClientRect())) if (bob(sbrect, faf[a].getBoundingClientRect()))
sel_toggle(faf[a]); sel_toggle(faf[a]);
msel.selui(); msel.selui();
} }
ev(e);
}
unbox(); unbox();
document.body.style.userSelect = 'auto'; setTimeout(function() {
prevent_click = false;
}, 50);
}
function has_txtsel() {
var txtsel = window.getSelection();
return txtsel && txtsel.toString().length > 0;
}
function clickblock(e) {
if (prevent_click) {
e.stopImmediatePropagation();
e.preventDefault();
}
} }
function dsel_init() { function dsel_init() {
@ -9887,12 +9931,14 @@ function reload_browser() {
window.addEventListener('mousemove', sel_move); window.addEventListener('mousemove', sel_move);
window.addEventListener('mouseup', sel_end); window.addEventListener('mouseup', sel_end);
window.addEventListener('click', clickblock, true);
window.addEventListener('touchstart', sel_start, { passive: true }); window.addEventListener('touchstart', sel_start, { passive: true });
window.addEventListener('touchmove', sel_move, { passive: false }); window.addEventListener('touchmove', sel_move, { passive: false });
window.addEventListener('touchend', sel_end, { passive: true }); window.addEventListener('touchend', sel_end, { passive: true });
window.addEventListener('dragstart', function(e) { window.addEventListener('dragstart', function(e) {
if (treectl.dsel && (is_selma || is_drag)) { if (treectl.dsel && (is_selma || dragging)) {
e.preventDefault(); e.preventDefault();
} }
}); });