[PR #10449] fix(tui): resolve textarea flickering when pasting long text in question prompt #13446

Open
opened 2026-02-16 18:18:18 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/10449

State: open
Merged: No


Problem

When pasting long text into the "Type your own answer" textarea in the question tool UI, the text would continuously flicker between showing the start of the text and the end of the text. Clicking with the cursor would temporarily stop the flickering. This bug to me occurred by the use of text-to-speech software like Superwhisper which paste the whole speech as text into the text area.

Fixes: #10450 and (likely) #9885

Bug Demo

https://github.com/user-attachments/assets/198b86dc-48a7-4d98-8b14-e85bcfea04fe

Root Cause

The default scrollMargin (0.2 = 20% of viewport) was causing a scroll position conflict. On each render frame, the textarea was trying to keep the cursor visible with a margin, which caused the viewport to alternate between:

  1. Scrolling to show the start of text (default position)
  2. Scrolling to show the cursor at the end (scroll margin behavior)

Solution

  • Set scrollMargin={0} to disable the automatic scroll-to-cursor margin behavior
  • Extract CustomAnswerTextarea component with proper lifecycle management via onMount
  • Add custom onPaste handler that prevents default paste behavior and manually handles text insertion with explicit viewport positioning
  • Disable cursor blinking to reduce unnecessary render cycles
  • Use gotoBufferEnd() for consistent cursor positioning at end of content

Fix Demo

https://github.com/user-attachments/assets/91d3b712-3908-42ae-a131-11adf811334c

Testing

  1. Run bun dev in packages/opencode
  2. Trigger a question with custom answer option
  3. Select "Type your own answer"
  4. Paste a long sentence.
  5. Verify text displays stably without flickering

Changes

  • packages/opencode/src/cli/cmd/tui/routes/session/question.tsx
    • Extracted CustomAnswerTextarea component
    • Added scrollMargin={0} prop
    • Added custom onPaste handler with viewport management
    • Added cursorStyle={{ style: "block", blinking: false }}
    • Changed from gotoLineEnd() to gotoBufferEnd()
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/10449 **State:** open **Merged:** No --- ## Problem When pasting long text into the "Type your own answer" textarea in the question tool UI, the text would continuously flicker between showing the start of the text and the end of the text. Clicking with the cursor would temporarily stop the flickering. This bug to me occurred by the use of text-to-speech software like Superwhisper which paste the whole speech as text into the text area. Fixes: #10450 and (likely) #9885 ### Bug Demo https://github.com/user-attachments/assets/198b86dc-48a7-4d98-8b14-e85bcfea04fe ## Root Cause The default `scrollMargin` (0.2 = 20% of viewport) was causing a scroll position conflict. On each render frame, the textarea was trying to keep the cursor visible with a margin, which caused the viewport to alternate between: 1. Scrolling to show the start of text (default position) 2. Scrolling to show the cursor at the end (scroll margin behavior) ## Solution - Set `scrollMargin={0}` to disable the automatic scroll-to-cursor margin behavior - Extract `CustomAnswerTextarea` component with proper lifecycle management via `onMount` - Add custom `onPaste` handler that prevents default paste behavior and manually handles text insertion with explicit viewport positioning - Disable cursor blinking to reduce unnecessary render cycles - Use `gotoBufferEnd()` for consistent cursor positioning at end of content ### Fix Demo https://github.com/user-attachments/assets/91d3b712-3908-42ae-a131-11adf811334c ## Testing 1. Run `bun dev` in `packages/opencode` 2. Trigger a question with custom answer option 3. Select "Type your own answer" 4. Paste a long sentence. 5. Verify text displays stably without flickering ## Changes - `packages/opencode/src/cli/cmd/tui/routes/session/question.tsx` - Extracted `CustomAnswerTextarea` component - Added `scrollMargin={0}` prop - Added custom `onPaste` handler with viewport management - Added `cursorStyle={{ style: "block", blinking: false }}` - Changed from `gotoLineEnd()` to `gotoBufferEnd()`
yindo added the pull-request label 2026-02-16 18:18:18 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13446