Skip to content

Commit e2655f3

Browse files
committed
move plain click check to utils
1 parent 0c8c45f commit e2655f3

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

web_src/js/components/ViewFileTreeItem.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script lang="ts" setup>
22
import {SvgIcon} from '../svg.ts';
3+
import {isPlainClick} from '../utils/dom.ts';
34
import {ref} from 'vue';
45
56
type Item = {
@@ -42,15 +43,15 @@ const doLoadChildren = async (e?: MouseEvent) => {
4243
4344
const doLoadDirContent = (e: MouseEvent) => {
4445
// only load the directory content without a window refresh if the user didn't press any special key
45-
if (e.button !== 0 || e.ctrlKey || e.metaKey || e.altKey || e.shiftKey) return;
46+
if (!isPlainClick(e)) return;
4647
e.preventDefault();
4748
4849
doLoadChildren();
4950
props.navigateViewContent(props.item.fullPath);
5051
};
5152
5253
const doLoadFileContent = (e: MouseEvent) => {
53-
if (e.button !== 0 || e.ctrlKey || e.metaKey || e.altKey || e.shiftKey) return;
54+
if (!isPlainClick(e)) return;
5455
e.preventDefault();
5556
5657
props.navigateViewContent(props.item.fullPath);

web_src/js/utils/dom.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,3 +369,8 @@ export function addDelegatedEventListener<T extends HTMLElement, E extends Event
369369
listener(elem as T, e as E);
370370
}, options);
371371
}
372+
373+
// Check if a click is done without any special mouse or key inputs that would trigger special browser behavior.
374+
export function isPlainClick(e: MouseEvent) {
375+
return e.button === 0 && !e.ctrlKey && !e.metaKey && !e.altKey && !e.shiftKey;
376+
}

0 commit comments

Comments
 (0)