Skip to content

Commit

Permalink
feat: enable sending selected prompts by enter key only after arrow k…
Browse files Browse the repository at this point in the history
…ey navigation

Signed-off-by: DingChil <xu.dingchao@gmail.com>
  • Loading branch information
DingChil committed Nov 8, 2023
1 parent dd145d5 commit 08ec5c5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/components/PromptMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ const handleEditPrompt = index => {
margin: 0;
padding: 8px 0;
color: var(--webpilot-theme-main-text-color, #292929) !important;
font-weight: 400;
font-size: 14px !important;
line-height: 22px;
text-align: left;
Expand Down
9 changes: 6 additions & 3 deletions src/csui/Index/ThePopupBox/ThePopupBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ const showMenu = ref(false)
const showLogo = ref(true)
const inputCommand = ref('')
const chooseIndex = ref(-1)
const lastArrowKey = ref('')
const selectedPrompt = reactive({
index: -1,
prompt: {
Expand Down Expand Up @@ -132,16 +133,18 @@ useMagicKeys({
if (e.type !== 'keyup') return
if (e.key === 'ArrowUp') {
const newIndex = oldIndex - 1 < 0 ? length : oldIndex - 1
chooseIndex.value = newIndex
inputCommand.value = oldIndex - 1 < 0 ? '' : currentPromptsList.value[newIndex].command
chooseIndex.value = newIndex
lastArrowKey.value = e.key
}
if (e.key === 'ArrowDown') {
const newIndex = oldIndex + 1 > length ? 0 : oldIndex + 1
chooseIndex.value = newIndex
inputCommand.value = oldIndex + 1 === length ? '' : currentPromptsList.value[newIndex].command
chooseIndex.value = newIndex
lastArrowKey.value = e.key
}
if (e.key === 'Enter') {
if (oldIndex === -1) popUpAskAi()
if (!lastArrowKey.value || oldIndex === -1) popUpAskAi()
else if (oldIndex === length) handleCreatePrompt()
else handleChangePrompt({index: oldIndex, prompt: currentPromptsList.value[oldIndex]})
e.preventDefault()
Expand Down

0 comments on commit 08ec5c5

Please sign in to comment.