Skip to content

Commit ca6a6da

Browse files
authored
fix: render normal cursor with contrast (#99)
fix: render vim normal cursor with contrast Co-authored-by: leohenon <[email protected]>
1 parent c3feabe commit ca6a6da

1 file changed

Lines changed: 23 additions & 17 deletions

File tree

  • packages/opencode/src/cli/cmd/tui/component/prompt

packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,9 @@ export function Prompt(props: PromptProps) {
415415
return
416416
}
417417
const visual = vimState.isVisual()
418+
const block = !props.disabled && vimEnabled() && store.mode === "normal" && vimState.mode() === "normal"
418419
input.cursorColor = theme.text
419-
input.showCursor = !visual
420+
input.showCursor = !(visual || block)
420421
input.selectionBg = visual ? theme.secondary : undefined
421422
input.selectionFg = visual ? selectedForeground(theme, theme.secondary) : undefined
422423
})
@@ -1943,23 +1944,28 @@ export function Prompt(props: PromptProps) {
19431944
const render = input.render.bind(input)
19441945
input.render = (buffer, deltaTime) => {
19451946
render(buffer, deltaTime)
1946-
if (!vimState.isVisual()) return
1947-
const rows = emptyRows(
1948-
input.plainText,
1949-
input.editorView.getSelection(),
1950-
input.lineInfo,
1951-
input.scrollY,
1952-
input.height,
1953-
)
1954-
if (rows.length) {
1955-
const bg = input.selectionBg ?? input.textColor
1956-
const fg =
1957-
input.selectionFg ??
1958-
(input.backgroundColor.a > 0 ? input.backgroundColor : RGBA.fromInts(0, 0, 0))
1959-
rows.forEach((row) => {
1960-
buffer.setCell(input.x, input.y + row, " ", fg, bg)
1961-
})
1947+
const visual = vimState.isVisual()
1948+
if (visual) {
1949+
const rows = emptyRows(
1950+
input.plainText,
1951+
input.editorView.getSelection(),
1952+
input.lineInfo,
1953+
input.scrollY,
1954+
input.height,
1955+
)
1956+
if (rows.length) {
1957+
const bg = input.selectionBg ?? input.textColor
1958+
const fg =
1959+
input.selectionFg ??
1960+
(input.backgroundColor.a > 0 ? input.backgroundColor : RGBA.fromInts(0, 0, 0))
1961+
rows.forEach((row) => {
1962+
buffer.setCell(input.x, input.y + row, " ", fg, bg)
1963+
})
1964+
}
19621965
}
1966+
const block = !props.disabled && vimEnabled() && store.mode === "normal" && vimState.mode() === "normal"
1967+
if (!(visual || block)) return
1968+
if (!input.focused) return
19631969
if (input.visualCursor.visualRow < 0 || input.visualCursor.visualRow >= input.height) return
19641970
if (input.visualCursor.visualCol < 0 || input.visualCursor.visualCol >= input.width) return
19651971
// recolor the cursor cell in place; setCell would clobber the underlying glyph

0 commit comments

Comments
 (0)