mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-08 03:01:47 +00:00
fix(tui): trim whitespace-only selection chrome
- clamp selection highlight to real row content so blank drag margins do not render or copy - keep successful copy actions quiet while preserving usage and failure feedback
This commit is contained in:
parent
a68793b6c4
commit
876bb60044
4 changed files with 98 additions and 9 deletions
57
ui-tui/packages/hermes-ink/src/ink/selection.test.ts
Normal file
57
ui-tui/packages/hermes-ink/src/ink/selection.test.ts
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { cellAt, CellWidth, CharPool, createScreen, HyperlinkPool, setCellAt, StylePool } from './screen.js'
|
||||
import {
|
||||
applySelectionOverlay,
|
||||
createSelectionState,
|
||||
getSelectedText,
|
||||
startSelection,
|
||||
updateSelection
|
||||
} from './selection.js'
|
||||
|
||||
const screenWithText = () => {
|
||||
const styles = new StylePool()
|
||||
const screen = createScreen(10, 3, styles, new CharPool(), new HyperlinkPool())
|
||||
|
||||
setCellAt(screen, 2, 1, { char: 'h', hyperlink: undefined, styleId: screen.emptyStyleId, width: CellWidth.Narrow })
|
||||
setCellAt(screen, 3, 1, { char: 'i', hyperlink: undefined, styleId: screen.emptyStyleId, width: CellWidth.Narrow })
|
||||
|
||||
return { screen, styles }
|
||||
}
|
||||
|
||||
describe('selection whitespace handling', () => {
|
||||
it('does not copy whitespace-only selections', () => {
|
||||
const { screen } = screenWithText()
|
||||
const selection = createSelectionState()
|
||||
|
||||
startSelection(selection, 0, 0)
|
||||
updateSelection(selection, 9, 0)
|
||||
|
||||
expect(getSelectedText(selection, screen)).toBe('')
|
||||
})
|
||||
|
||||
it('trims outer drag padding while preserving selected content', () => {
|
||||
const { screen } = screenWithText()
|
||||
const selection = createSelectionState()
|
||||
|
||||
startSelection(selection, 0, 1)
|
||||
updateSelection(selection, 9, 1)
|
||||
|
||||
expect(getSelectedText(selection, screen)).toBe('hi')
|
||||
})
|
||||
|
||||
it('does not paint selection background on leading/trailing empty cells or empty rows', () => {
|
||||
const { screen, styles } = screenWithText()
|
||||
const selection = createSelectionState()
|
||||
|
||||
startSelection(selection, 0, 0)
|
||||
updateSelection(selection, 9, 2)
|
||||
applySelectionOverlay(screen, selection, styles)
|
||||
|
||||
expect(cellAt(screen, 0, 0)?.styleId).toBe(screen.emptyStyleId)
|
||||
expect(cellAt(screen, 0, 1)?.styleId).toBe(screen.emptyStyleId)
|
||||
expect(cellAt(screen, 2, 1)?.styleId).not.toBe(screen.emptyStyleId)
|
||||
expect(cellAt(screen, 4, 1)?.styleId).toBe(screen.emptyStyleId)
|
||||
expect(cellAt(screen, 0, 2)?.styleId).toBe(screen.emptyStyleId)
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue