0
0
mirror of https://github.com/go-gitea/gitea.git synced 2026-05-12 00:22:59 +02:00

code cleaning

This commit is contained in:
Michał Krela 2026-03-31 17:23:59 +02:00
parent 402c244e2b
commit 55cb58ee87

View File

@ -56,16 +56,18 @@ export default defineComponent({
const currentIndex = focusableItems.indexOf(currentFocused.closest('[role="menuitem"]') as HTMLElement); const currentIndex = focusableItems.indexOf(currentFocused.closest('[role="menuitem"]') as HTMLElement);
switch (event.key) { switch (event.key) {
case 'ArrowDown': // select next element case 'ArrowDown': { // select next element
event.preventDefault(); event.preventDefault();
const nextIndex = currentIndex === -1 ? 0 : Math.min(currentIndex + 1, focusableItems.length - 1); const nextIndex = currentIndex === -1 ? 0 : Math.min(currentIndex + 1, focusableItems.length - 1);
this.focusElem(focusableItems[nextIndex], currentIndex >= 0 ? focusableItems[currentIndex] : null); this.focusElem(focusableItems[nextIndex], currentIndex >= 0 ? focusableItems[currentIndex] : null);
break; break;
case 'ArrowUp': // select previous element }
case 'ArrowUp': { // select previous element
event.preventDefault(); event.preventDefault();
const prevIndex = currentIndex === -1 ? focusableItems.length - 1 : Math.max(currentIndex - 1, 0); const prevIndex = currentIndex === -1 ? focusableItems.length - 1 : Math.max(currentIndex - 1, 0);
this.focusElem(focusableItems[prevIndex], currentIndex >= 0 ? focusableItems[currentIndex] : null); this.focusElem(focusableItems[prevIndex], currentIndex >= 0 ? focusableItems[currentIndex] : null);
break; break;
}
case 'Escape': // close menu case 'Escape': // close menu
event.preventDefault(); event.preventDefault();
if (currentIndex >= 0) { if (currentIndex >= 0) {
@ -105,7 +107,8 @@ export default defineComponent({
const extensionMap = new Map<string, {total: number, visible: number}>(); const extensionMap = new Map<string, {total: number, visible: number}>();
const fileBoxes = document.querySelectorAll('#diff-file-boxes .diff-file-box[data-new-filename]'); const fileBoxes = document.querySelectorAll('#diff-file-boxes .diff-file-box[data-new-filename]');
// Count extensions and track visibility // Count extensions, track visibility and hidden count in a single pass
let hiddenCount = 0;
fileBoxes.forEach((box) => { fileBoxes.forEach((box) => {
const filename = (box as HTMLElement).getAttribute('data-new-filename') || ''; const filename = (box as HTMLElement).getAttribute('data-new-filename') || '';
const ext = this.getExtension(filename); const ext = this.getExtension(filename);
@ -117,6 +120,8 @@ export default defineComponent({
stats.total += 1; stats.total += 1;
if (!isHidden) { if (!isHidden) {
stats.visible += 1; stats.visible += 1;
} else {
hiddenCount += 1;
} }
}); });
@ -130,13 +135,6 @@ export default defineComponent({
})) }))
.sort((a, b) => b.count - a.count); .sort((a, b) => b.count - a.count);
// Update filtering state based on current visibility
let hiddenCount = 0;
fileBoxes.forEach((box) => {
if ((box as HTMLElement).classList.contains('tw-hidden')) {
hiddenCount += 1;
}
});
this.isFiltering = hiddenCount > 0; this.isFiltering = hiddenCount > 0;
}, },
/** /**
@ -190,11 +188,9 @@ export default defineComponent({
} }
}); });
// Update filtering state // Update filtering state and close the menu
this.isFiltering = hiddenCount > 0; this.isFiltering = hiddenCount > 0;
this.toggleMenu();
// Close the menu after applying
this.menuVisible = false;
}, },
}, },
}); });
@ -203,7 +199,7 @@ export default defineComponent({
<div class="ui scrolling dropdown custom diff-file-extension-filter"> <div class="ui scrolling dropdown custom diff-file-extension-filter">
<button <button
ref="expandBtn" ref="expandBtn"
class="ui tiny basic button tw-relative" class="ui tiny basic button"
:class="{'diff-ext-filter-btn-active': isFiltering}" :class="{'diff-ext-filter-btn-active': isFiltering}"
@click="toggleMenu()" @click="toggleMenu()"
:data-tooltip-content="locale.filter_by_file_extension" :data-tooltip-content="locale.filter_by_file_extension"