Skip to content

Commit

Permalink
Fix selecting items by clicking in Firefox
Browse files Browse the repository at this point in the history
Closes #92

This applies to the file explorer, and not the desktop,
due to the app using iframes.

This was broken when introducing nested iframes to the file explorer in:
0c7a9e7d3c38c09a953c404

`instanceof` is inconsistent between Chrome and Firefox when an element
is created in one document and then appended to a different document:
https://jsfiddle.net/1j01/m8t19oyv/
https://bugzilla.mozilla.org/show_bug.cgi?id=1470017

In Firefox (version 127.0), the element is considered an instance of
the `Element` class of the document that it's appended to.

In Chrome (version 126.0.6478.127), the element is considered
an instance of the original scope's `Element`.
  • Loading branch information
1j01 committed Jun 30, 2024
1 parent 7357f92 commit e052b79
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/FolderView.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,11 @@ function FolderView(folder_path, { asDesktop = false, onStatus, openFolder, open
var selection_anchor_item_el;

function select_item(item_or_item_el, event, delay_scroll) {
const item_el_to_select = item_or_item_el instanceof Element ? item_or_item_el : item_or_item_el.element;
// Note: can't use `item_or_item_el instanceof Element` because iframes have their own `Element` constructors
// and `instanceof` is actually inconsistent between browsers when an element is created in one document and
// appended to another. See https://github.com/1j01/98/issues/92
// Also see https://bugzilla.mozilla.org/show_bug.cgi?id=1470017
const item_el_to_select = "nodeType" in item_or_item_el ? item_or_item_el : item_or_item_el.element;
const extend_selection = event.shiftKey;
if (selection_anchor_item_el && !self.items.some(item => item.element === selection_anchor_item_el)) {
selection_anchor_item_el = null; // item was removed somehow
Expand Down

0 comments on commit e052b79

Please sign in to comment.