mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-12 02:33:50 +02:00
Code cleaning, small issues fix
This commit is contained in:
parent
55cb58ee87
commit
4e79902e3a
@ -36,7 +36,6 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onBodyClick(event: MouseEvent) {
|
onBodyClick(event: MouseEvent) {
|
||||||
// close this menu on click outside of this element when the dropdown is currently visible opened
|
|
||||||
if (this.$el.contains(event.target)) return;
|
if (this.$el.contains(event.target)) return;
|
||||||
if (this.menuVisible) {
|
if (this.menuVisible) {
|
||||||
this.toggleMenu();
|
this.toggleMenu();
|
||||||
@ -47,7 +46,6 @@ export default defineComponent({
|
|||||||
const currentFocused = document.activeElement as HTMLElement;
|
const currentFocused = document.activeElement as HTMLElement;
|
||||||
if (!this.$el.contains(currentFocused)) return;
|
if (!this.$el.contains(currentFocused)) return;
|
||||||
|
|
||||||
// Get all focusable menu items (checkboxes and buttons)
|
|
||||||
const menu = this.$el.querySelector('.menu') as HTMLElement;
|
const menu = this.$el.querySelector('.menu') as HTMLElement;
|
||||||
const focusableItems = Array.from(menu.querySelectorAll('[role="menuitem"]')) as HTMLElement[];
|
const focusableItems = Array.from(menu.querySelectorAll('[role="menuitem"]')) as HTMLElement[];
|
||||||
|
|
||||||
@ -56,19 +54,19 @@ 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': {
|
||||||
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': {
|
||||||
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':
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if (currentIndex >= 0) {
|
if (currentIndex >= 0) {
|
||||||
focusableItems[currentIndex].tabIndex = -1;
|
focusableItems[currentIndex].tabIndex = -1;
|
||||||
@ -107,7 +105,6 @@ 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, track visibility and hidden count in a single pass
|
|
||||||
let hiddenCount = 0;
|
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') || '';
|
||||||
@ -125,8 +122,6 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Convert to array and sort by count descending
|
|
||||||
// checked = true if any files of this extension are visible
|
|
||||||
this.extensions = Array.from(extensionMap.entries())
|
this.extensions = Array.from(extensionMap.entries())
|
||||||
.map(([ext, stats]) => ({
|
.map(([ext, stats]) => ({
|
||||||
ext,
|
ext,
|
||||||
@ -140,12 +135,11 @@ export default defineComponent({
|
|||||||
/**
|
/**
|
||||||
* Open dropdown, rescan extensions
|
* Open dropdown, rescan extensions
|
||||||
*/
|
*/
|
||||||
toggleMenu() {
|
toggleMenu(refocus = true) {
|
||||||
this.menuVisible = !this.menuVisible;
|
this.menuVisible = !this.menuVisible;
|
||||||
if (this.menuVisible) {
|
if (this.menuVisible) {
|
||||||
this.scanExtensions();
|
this.scanExtensions();
|
||||||
} else {
|
} else if (refocus) {
|
||||||
// when closing menu, restore focus to the button
|
|
||||||
const button = this.$refs.expandBtn as HTMLElement;
|
const button = this.$refs.expandBtn as HTMLElement;
|
||||||
button.tabIndex = 0;
|
button.tabIndex = 0;
|
||||||
button.focus();
|
button.focus();
|
||||||
@ -188,9 +182,8 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Update filtering state and close the menu
|
|
||||||
this.isFiltering = hiddenCount > 0;
|
this.isFiltering = hiddenCount > 0;
|
||||||
this.toggleMenu();
|
this.toggleMenu(false);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -276,9 +269,8 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
.ui.dropdown.diff-file-extension-filter .diff-ext-filter-btn-active {
|
.ui.dropdown.diff-file-extension-filter .diff-ext-filter-btn-active {
|
||||||
color: var(--color-red-700);
|
outline: 1px solid currentColor;
|
||||||
border-color: var(--color-red-300);
|
outline-offset: -1px;
|
||||||
background: var(--color-red-50);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.ui.dropdown.diff-file-extension-filter .diff-ext-text-btn {
|
.ui.dropdown.diff-file-extension-filter .diff-ext-text-btn {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user