mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-02 06:39:32 +02:00
feat(shortcut): Add keyboard shortcuts for repository file and code search
Add GitHub-like keyboard shortcuts for repository navigation: - Press 'T' to focus the "Go to file" search input - Press 'S' to focus the "Search code" input - Press 'Escape' to blur focused search inputs Both search inputs display a keyboard hint (kbd element) showing the available shortcut. The hint hides when the input is focused or has a value. Includes unit tests and e2e tests for the new functionality.
This commit is contained in:
@@ -23,6 +23,7 @@ const allFiles = ref<string[]>([]);
|
||||
const selectedIndex = ref(0);
|
||||
const isLoadingFileList = ref(false);
|
||||
const hasLoadedFileList = ref(false);
|
||||
const isInputFocused = ref(false);
|
||||
|
||||
const showPopup = computed(() => searchQuery.value.length > 0);
|
||||
|
||||
@@ -45,8 +46,8 @@ const handleKeyDown = (e: KeyboardEvent) => {
|
||||
if (e.isComposing) return;
|
||||
|
||||
if (e.key === 'Escape') {
|
||||
e.preventDefault();
|
||||
clearSearch();
|
||||
nextTick(() => refElemInput.value.blur());
|
||||
return;
|
||||
}
|
||||
if (!searchQuery.value || filteredFiles.value.length === 0) return;
|
||||
@@ -145,12 +146,14 @@ watch([searchQuery, filteredFiles], async () => {
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<div class="ui small input">
|
||||
<div class="ui small input repo-file-search-input-wrapper">
|
||||
<input
|
||||
ref="searchInput" :placeholder="placeholder" autocomplete="off"
|
||||
role="combobox" aria-autocomplete="list" :aria-expanded="searchQuery ? 'true' : 'false'"
|
||||
@input="handleSearchInput" @keydown="handleKeyDown"
|
||||
@focus="isInputFocused = true" @blur="isInputFocused = false"
|
||||
>
|
||||
<kbd v-show="!searchQuery && !isInputFocused" class="repo-search-shortcut-hint">T</kbd>
|
||||
</div>
|
||||
|
||||
<Teleport to="body">
|
||||
@@ -183,6 +186,42 @@ watch([searchQuery, filteredFiles], async () => {
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.repo-file-search-input-wrapper {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.repo-file-search-input-wrapper input {
|
||||
padding-right: 32px !important;
|
||||
border-right: 1px solid var(--color-input-border) !important;
|
||||
border-top-right-radius: 0.28571429rem !important;
|
||||
border-bottom-right-radius: 0.28571429rem !important;
|
||||
}
|
||||
|
||||
.repo-file-search-input-wrapper input:focus {
|
||||
border-color: var(--color-primary) !important;
|
||||
}
|
||||
|
||||
.repo-search-shortcut-hint {
|
||||
position: absolute;
|
||||
right: 10px;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
display: inline-block;
|
||||
padding: 2px 5px;
|
||||
font-size: 11px;
|
||||
line-height: 12px;
|
||||
color: var(--color-text-light-2);
|
||||
background-color: var(--color-box-body);
|
||||
border: 1px solid var(--color-secondary);
|
||||
border-radius: 3px;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
/* Hide kbd when input is focused so it doesn't interfere with focus border */
|
||||
.repo-file-search-input-wrapper input:focus + .repo-search-shortcut-hint {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.file-search-popup {
|
||||
position: absolute;
|
||||
background: var(--color-box-body);
|
||||
|
||||
Reference in New Issue
Block a user