fix(library): unconditionally prevent browser context menu on folder tree nodes and fix absolute path matching
This commit is contained in:
@@ -1637,8 +1637,11 @@ function Catalogue() {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{rows.map((n) => {
|
{rows.map((n) => {
|
||||||
const rootKey = n.key.split('/')[0];
|
const folder =
|
||||||
const folder = folders.find((f) => (f.name || '').replace(/\\/g, '/') === rootKey || f.name === rootKey) ?? null;
|
folders.find((f) => {
|
||||||
|
const fNorm = (f.name || '').replace(/\\/g, '/');
|
||||||
|
return n.key === fNorm || n.key.startsWith(`${fNorm}/`) || n.key === f.name || n.key.startsWith(`${f.name}/`);
|
||||||
|
}) ?? folders[0] ?? null;
|
||||||
// The row that says a reading is under way is the folder the
|
// The row that says a reading is under way is the folder the
|
||||||
// reading stands in — not the folder it was pointed at, which
|
// reading stands in — not the folder it was pointed at, which
|
||||||
// would be the same row for the whole of an afternoon while
|
// would be the same row for the whole of an afternoon while
|
||||||
@@ -1697,21 +1700,19 @@ function Catalogue() {
|
|||||||
// right-clicks. Shift+F10 raises the same event, which is
|
// right-clicks. Shift+F10 raises the same event, which is
|
||||||
// the keyboard's way in.
|
// the keyboard's way in.
|
||||||
onContextMenu={(e) => {
|
onContextMenu={(e) => {
|
||||||
if (!folder) return;
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const box = e.currentTarget.getBoundingClientRect();
|
e.stopPropagation();
|
||||||
// The row's own path under the picked folder, '' for
|
const targetFolder = folder || folders[0];
|
||||||
// the picked folder itself — what a scan started from
|
if (!targetFolder) return;
|
||||||
// here would be kept to. Spelled the way the walk
|
const fNorm = (targetFolder.name || '').replace(/\\/g, '/');
|
||||||
// spells it, trailing slash and all.
|
const sub = n.key.length > fNorm.length ? n.key.slice(fNorm.length + 1) : '';
|
||||||
const under = n.key.slice(folder.name.length + 1);
|
|
||||||
setMenu({
|
setMenu({
|
||||||
folder,
|
folder: targetFolder,
|
||||||
root: n.depth === 0,
|
root: n.depth === 0,
|
||||||
rel: under ? `${under}/` : '',
|
rel: sub ? `${sub}/` : '',
|
||||||
node: n.key,
|
node: n.key,
|
||||||
x: Math.min(e.clientX || box.left, window.innerWidth - 150),
|
x: Math.min(e.clientX, window.innerWidth - 160),
|
||||||
y: Math.min(e.clientY || box.top, window.innerHeight - 150),
|
y: Math.min(e.clientY, window.innerHeight - 200),
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user