Skip to content

style: update ai panel #631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion src/components/ai/AIAssistantPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ watch(dialogVisible, (val) => {
})

const input = ref(``)
const inputHistory = ref<string[]>([])
const historyIndex = ref<number | null>(null)

const configVisible = ref(false)
const loading = ref(false)
const copiedIndex = ref<number | null>(null)
Expand Down Expand Up @@ -62,6 +65,31 @@ function handleKeydown(e: KeyboardEvent) {
e.preventDefault()
sendMessage()
}
else if (e.key === `ArrowUp`) {
e.preventDefault()
if (inputHistory.value.length === 0)
return
if (historyIndex.value === null) {
historyIndex.value = inputHistory.value.length - 1
}
else if (historyIndex.value > 0) {
historyIndex.value--
}
input.value = inputHistory.value[historyIndex.value] || ``
}
else if (e.key === `ArrowDown`) {
e.preventDefault()
if (historyIndex.value === null)
return
if (historyIndex.value < inputHistory.value.length - 1) {
historyIndex.value++
input.value = inputHistory.value[historyIndex.value] || ``
}
else {
historyIndex.value = null
input.value = ``
}
}
}

async function scrollToBottom() {
Expand Down Expand Up @@ -96,6 +124,9 @@ async function sendMessage() {
if (!input.value.trim() || loading.value)
return

inputHistory.value.push(input.value.trim())
historyIndex.value = null

loading.value = true
const userInput = input.value.trim()
messages.value.push({ role: `user`, content: userInput })
Expand Down Expand Up @@ -256,7 +287,7 @@ async function sendMessage() {
v-model="input"
placeholder="说些什么……(按 Enter 发送,Shift+Enter 换行)"
rows="2"
class="custom-scroll w-full resize-none overflow-y-auto border-none focus-visible:ring-0"
class="custom-scroll w-full resize-none overflow-y-auto border-none focus:border-none focus-visible:outline-none focus-visible:ring-0 focus:ring-0 focus-visible:ring-offset-0"
@keydown="handleKeydown"
/>
<Button
Expand Down