Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect cursor position when text area contains multi-byte strings #133

Closed
macocci7 opened this issue Apr 14, 2024 · 2 comments · Fixed by #137
Closed

Incorrect cursor position when text area contains multi-byte strings #133

macocci7 opened this issue Apr 14, 2024 · 2 comments · Fixed by #137
Assignees
Labels

Comments

@macocci7
Copy link
Contributor

macocci7 commented Apr 14, 2024

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:

  1. The last line will not be displayed.
  2. Press [Home], press [End], then the last line will not be displayed.
  3. Press [Home], press [↓], then the cursor will move to right of 'd'.
  4. Press [↓] after step 3 above, then the cursor will move to right of 'l'.
  5. Press [↓] after step 4 above, then the cursor will move to right of '0'.
  6. Press [↓] after step 5 above, then the cursor will move to right of '8'.
@jessarcher
Copy link
Member

@joetannenbaum are you able to take a look at this one please?

@jessarcher jessarcher self-assigned this Apr 15, 2024
@jessarcher jessarcher added the bug label Apr 15, 2024
@joetannenbaum
Copy link
Contributor

Will do 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants