fix(tui): preserve text selection on question prompt options (#24988)
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { createStore } from "solid-js/store"
|
import { createStore } from "solid-js/store"
|
||||||
import { createMemo, createSignal, For, Show } from "solid-js"
|
import { createMemo, createSignal, For, Show } from "solid-js"
|
||||||
|
import { useRenderer } from "@opentui/solid"
|
||||||
import type { TextareaRenderable } from "@opentui/core"
|
import type { TextareaRenderable } from "@opentui/core"
|
||||||
import { selectedForeground, tint, useTheme } from "../../context/theme"
|
import { selectedForeground, tint, useTheme } from "../../context/theme"
|
||||||
import type { QuestionAnswer, QuestionRequest } from "@opencode-ai/sdk/v2"
|
import type { QuestionAnswer, QuestionRequest } from "@opencode-ai/sdk/v2"
|
||||||
@@ -12,6 +13,7 @@ import { useBindings } from "../../keymap"
|
|||||||
export function QuestionPrompt(props: { request: QuestionRequest }) {
|
export function QuestionPrompt(props: { request: QuestionRequest }) {
|
||||||
const sdk = useSDK()
|
const sdk = useSDK()
|
||||||
const { theme } = useTheme()
|
const { theme } = useTheme()
|
||||||
|
const renderer = useRenderer()
|
||||||
const tuiConfig = useTuiConfig()
|
const tuiConfig = useTuiConfig()
|
||||||
|
|
||||||
const questions = createMemo(() => props.request.questions)
|
const questions = createMemo(() => props.request.questions)
|
||||||
@@ -302,7 +304,10 @@ export function QuestionPrompt(props: { request: QuestionRequest }) {
|
|||||||
}
|
}
|
||||||
onMouseOver={() => setTabHover(index())}
|
onMouseOver={() => setTabHover(index())}
|
||||||
onMouseOut={() => setTabHover(null)}
|
onMouseOut={() => setTabHover(null)}
|
||||||
onMouseUp={() => selectTab(index())}
|
onMouseUp={() => {
|
||||||
|
if (renderer.getSelection()?.getSelectedText()) return
|
||||||
|
selectTab(index())
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<text
|
<text
|
||||||
fg={
|
fg={
|
||||||
@@ -327,7 +332,10 @@ export function QuestionPrompt(props: { request: QuestionRequest }) {
|
|||||||
}
|
}
|
||||||
onMouseOver={() => setTabHover("confirm")}
|
onMouseOver={() => setTabHover("confirm")}
|
||||||
onMouseOut={() => setTabHover(null)}
|
onMouseOut={() => setTabHover(null)}
|
||||||
onMouseUp={() => selectTab(questions().length)}
|
onMouseUp={() => {
|
||||||
|
if (renderer.getSelection()?.getSelectedText()) return
|
||||||
|
selectTab(questions().length)
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<text fg={confirm() ? selectedForeground(theme, theme.accent) : theme.textMuted}>Confirm</text>
|
<text fg={confirm() ? selectedForeground(theme, theme.accent) : theme.textMuted}>Confirm</text>
|
||||||
</box>
|
</box>
|
||||||
@@ -351,7 +359,10 @@ export function QuestionPrompt(props: { request: QuestionRequest }) {
|
|||||||
<box
|
<box
|
||||||
onMouseOver={() => moveTo(i())}
|
onMouseOver={() => moveTo(i())}
|
||||||
onMouseDown={() => moveTo(i())}
|
onMouseDown={() => moveTo(i())}
|
||||||
onMouseUp={() => selectOption()}
|
onMouseUp={() => {
|
||||||
|
if (renderer.getSelection()?.getSelectedText()) return
|
||||||
|
selectOption()
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<box flexDirection="row">
|
<box flexDirection="row">
|
||||||
<box backgroundColor={active() ? theme.backgroundElement : undefined} paddingRight={1}>
|
<box backgroundColor={active() ? theme.backgroundElement : undefined} paddingRight={1}>
|
||||||
@@ -380,7 +391,10 @@ export function QuestionPrompt(props: { request: QuestionRequest }) {
|
|||||||
<box
|
<box
|
||||||
onMouseOver={() => moveTo(options().length)}
|
onMouseOver={() => moveTo(options().length)}
|
||||||
onMouseDown={() => moveTo(options().length)}
|
onMouseDown={() => moveTo(options().length)}
|
||||||
onMouseUp={() => selectOption()}
|
onMouseUp={() => {
|
||||||
|
if (renderer.getSelection()?.getSelectedText()) return
|
||||||
|
selectOption()
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<box flexDirection="row">
|
<box flexDirection="row">
|
||||||
<box backgroundColor={other() ? theme.backgroundElement : undefined} paddingRight={1}>
|
<box backgroundColor={other() ? theme.backgroundElement : undefined} paddingRight={1}>
|
||||||
|
|||||||
Reference in New Issue
Block a user