Skip to content

Commit 5ac6459

Browse files
committed
fix bug with lastIndexOf matching first character
1 parent 7db2d71 commit 5ac6459

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

cli/src/components/multiline-input.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,11 @@ export const MultilineInput = forwardRef<
652652
if (afterNewline === -1) {
653653
afterNewline = value.length
654654
}
655-
let prevNewlineExclusive = value.lastIndexOf('\n', cursorPosition - 1)
655+
// For some reason, there is a special case for lastIndexOf for negative indices if the match is a prefix
656+
let prevNewlineExclusive =
657+
cursorPosition === 0
658+
? -1
659+
: value.lastIndexOf('\n', cursorPosition - 1)
656660
const col = (cursorPosition - prevNewlineExclusive) % cols
657661
onChange({
658662
text: value,

0 commit comments

Comments
 (0)