Skip to content
Open
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
41 changes: 35 additions & 6 deletions dashboard/src/components/chat/CommandSuggestion.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
</template>

<script setup lang="ts">
import { computed, reactive } from "vue";
import { computed, reactive, ref, watch } from "vue";
import { useModuleI18n } from "@/i18n/composables";

export interface SuggestionCommand {
Expand Down Expand Up @@ -88,6 +88,8 @@ const tooltip = reactive({
y: 0,
});

const hoveredKey = ref<string | null>(null);

const tooltipStyle = computed(() => ({
position: "fixed" as const,
left: `${tooltip.x + 12}px`,
Expand All @@ -113,6 +115,30 @@ const panelStyle = computed(() => {
};
});

watch(
() => props.visible,
(val) => {
if (!val) {
tooltip.visible = false;
}
},
);
Comment thread
elecvoid243 marked this conversation as resolved.

watch(
() => props.commands,
(cmds) => {
if (hoveredKey.value) {
const stillExists = cmds.some(
(c) => `${c.handler_full_name}:${c.effective_command}` === hoveredKey.value,
);
if (!stillExists) {
tooltip.visible = false;
hoveredKey.value = null;
}
}
},
);

function handleSelect(index: number) {
const cmd = props.commands[index];
if (cmd) {
Expand All @@ -122,11 +148,13 @@ function handleSelect(index: number) {

function handleMouseEnter(index: number) {
emit("updateSelectedIndex", index);
// 显示 tooltip
const cmd = props.commands[index];
if (cmd?.description) {
tooltip.text = cmd.description;
tooltip.visible = true;
if (cmd) {
hoveredKey.value = `${cmd.handler_full_name}:${cmd.effective_command}`;
if (cmd.description) {
tooltip.text = cmd.description;
tooltip.visible = true;
}
}
}

Expand All @@ -137,6 +165,7 @@ function handleMouseMove(e: MouseEvent) {

function handleMouseLeave() {
tooltip.visible = false;
hoveredKey.value = null;
}
</script>

Expand Down Expand Up @@ -224,7 +253,7 @@ function handleMouseLeave() {
}

.is-dark .command-description {
color: #999;
color: #e0e0e0;
}

.command-suggestion-hint {
Expand Down
Loading