Incorrect cursor position when text area contains multi-byte strings
macocci7 opened this issue · 2 comments
macocci7 commented
Laravel Prompts Version
0.1.18
Laravel Version
11.3.0
PHP Version
8.2.13
Operating System & Version
Ubuntu 22.04 via WSL2
Terminal Application
VS Code's integrated terminal
Description
Issue
If there is a multibyte string in the previous line, the cursor moves downwards to the wrong position.
The same goes for moving up.
Findings
$this->cursorPosition
in Laravel\Prompts\TextareaPrompt
includes multibyte widths counted as 2 by mb_strwidth()
, and I think it's necessary for determining cursor position in multiline text.
It seems the bug is caused by $this->cursorPosition
passed in:
return $this->addCursor($this->wrappedValue(), $this->cursorPosition + $this->cursorOffset(), -1);
I'm posting here because I couldn't find a good solution.
Steps To Reproduce
textarea(
label: 'Tell me a story.',
default: "ab\ncdef\nghijklmnnopqrs\ntuvwxyz\n0123456789\n+-*/",
);
run this code and:
- The last line will not be displayed.
- Press [Home], press [End], then the last line will not be displayed.
- Press [Home], press [↓], then the cursor will move to right of 'd'.
- Press [↓] after step 3 above, then the cursor will move to right of 'l'.
- Press [↓] after step 4 above, then the cursor will move to right of '0'.
- Press [↓] after step 5 above, then the cursor will move to right of '8'.
jessarcher commented
@joetannenbaum are you able to take a look at this one please?
joetannenbaum commented
Will do 👍