microsoft / microsoft/terminal

A lone zero-width character in the first column occupies 1 column

Open
#18,296 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area-Output Issue-Bug Needs-Tag-Fix Priority-3
Dominant language
C++
Stars
105k
Forks
9.6k
Avg merge
3d 17h
Merged PRs (30d)
29

Description

### Windows Terminal version

1.23.3411.0

### Windows build number

_No response_

### Other Software

_No response_

### Steps to reproduce

In PowerShell:
```pwsh
"`r`u{200B}foo"
```

### Expected Behavior

```
foo
```

### Actual Behavior

```
foo
```

> The reason it happens is because before inserting anything in our text buffer we check if it joins with the already existing character and then merge it together with the new input. For any other characters we clamp the width of each grapheme cluster to a value between 1 and 2. Since a zero-width character can't join with anything in the first column it will be measured as its own cluster which results in a width of 1.
> The reason we do this is primarily because of our architecture which assumes O(1) lookups in the text buffer. The only way to make that work is by assuming that each grapheme cluster has a width of 1-2. The secondary reason for that is because inserting the ZWSP there puts it in front of the first column, assigning it column -1, which is not something that should be possible. Put differently, if you're at column 1 and iterate to the previous grapheme cluster, you would end up at column 0 (the start of the line), but after the ZWSP. It's a problem I don't have a good solution for except "add a bunch of special conditions" which gave me the gut feeling of "the problem has not been fundamentally solved".

https://github.com/microsoft/terminal/issues/18267#issuecomment-2529077871

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the PowerShell example and inspect the text-buffer insertion and grapheme-cluster handling described in the report. Determine how a zero-width character in the first column is measured and positioned without violating the buffer's lookup assumptions. Done means the lone zero-width character no longer occupies a visible column while the surrounding text remains aligned.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.