Skip to content

[Epic] Text Buffer rewrite  #8000

Closed
Closed

Description

This is the issue tracking the great buffer rewrite of 202x.

Aims

Notes

Surrogate Pairs

Work will be required to teach WriteCharsLegacy to measure UTF-16 codepoints in aggregate, rather than individual code units.

I have done a small amount of work in WriteCharsLegacy. It is slow going.

Motivation

#8689 (IRM) requires us to be able to shift buffer contents rightward. I implemented it in a hacky way, but then realized that UnicodeStorage would need to be rekeyed.

Implementation

The buffer is currently stored as a vector (small_vector) of CharRowCell, each of which contains a DbcsAttribute and a wchar_t. Each cell takes 3 bytes (plus padding, if required.)

In the common case (all narrow text), this is terribly wasteful.

To better support codepoints requiring one or more code units representing a character, we are going to move to a single wchar string combined with a column count table. The column count table will be stored compressed by way of til::rle (#8741).

Simple case - all glyphs narrow
 CHAR    A    B    C    D
UNITS 0041 0042 0043 0044
 COLS    1    1    1    1

Simple case - all glyphs wide
 CHAR   カ   タ   カ   ナ
UNITS 30ab 30bf 30ab 30ca
 COLS    2    2    2    2

Surrogate pair case - glyphs narrow
 CHAR         🕴        🕴        🕴
UNITS d83d dd74 d83d dd74 d83d dd74
 COLS    1    0    1    0    1    0

Surrogate pair case - glyphs wide
 CHAR        🥶        🥶        🥶
UNITS d83e dd76 d83e dd76 d83e dd76
 COLS    2    0    2    0    2    0

Representative complicated case
 CHAR        🥶    A    B         🕴
UNITS d83e dd76 0041 0042 d83d dd74
 COLS    2    0    1    1    1    0

Representative complicated case (huge character)
[FUTURE WORK]
 CHAR ﷽
UNITS         fdfd
 COLS           12

Representative complicated case (Emoji with skin tone variation)
[FUTURE WORK]
 CHAR 👍🏼
UNITS d83d dc31 200d d83d dc64
 COLS    2    0    0    0    0

A column count of zero indicates a code unit that is a continuation of an existing glyph.

Since there is one column width for each code unit, it is trivial to match column offsets with character string indices by summation.

Work Log

Other issues that might just be fixed by this

Activity

  1. ghost added
    Needs-TriageIt's a new issue that the core contributor team needs to triage at the next triage meeting
    on Oct 22, 2020
  2. ghost added
    Needs-Tag-FixDoesn't match tag requirements
    on Oct 22, 2020
  3. added and removed
    Needs-TriageIt's a new issue that the core contributor team needs to triage at the next triage meeting
    on Oct 22, 2020
  4. changed the title [-]<camper>[/-] [+]Epic: Buffer rewrite of 2021[/+] on Jan 12, 2021
  5. changed the title [-]Epic: Buffer rewrite of 2021[/-] [+]Epic: Text Buffer rewrite of 2021[/+] on Jan 12, 2021
  6. changed the title [-]Epic: Text Buffer rewrite of 2021[/-] [+][Epic] Text Buffer rewrite of 2021[/+] on Jan 12, 2021
  7. DHowett commented on Jan 12, 2021

    @DHowett
    MemberAuthor

    Alright, I've claimed this issue for the text buffer updates.

  8. added
    Area-OutputRelated to output processing (inserting text into buffer, retrieving buffer text, etc.)
    Area-ServerDown in the muck of API call servicing, interprocess communication, eventing, etc.
    Product-ConhostFor issues in the Console codebase
    and removed on Jan 12, 2021
  9. ghost removed
    Needs-Tag-FixDoesn't match tag requirements
    on Jan 12, 2021
  10. 45 remaining items

  11. ofek commented on Mar 4, 2023

    @ofek
    Contributor

    IRM might be easier now, now that we don't need to re-key all that. We may want to revisit.

    Did we end up revisiting this?

  12. j4james commented on Mar 4, 2023

    @j4james
    Collaborator
  13. lhecker commented on May 2, 2023

    @lhecker
    Member

    The linked issue (#1472) is just a reference what that bullet point is for and not the task itself. Thinking about it some more, I realize that this issue (#8000) is actually kind of done already. I rewrote the buffer in #13626 and the other commits I've done since aren't really related to the "Text Buffer" anymore and they're more related to #1472, hmm... Eh, I guess it's not really that important.

  14. lhecker commented on Apr 23, 2024

    @lhecker
    Member

    With only a few places left that rely on the old grid-based buffer layout, all of which require some long term, but focused work, I'll be going ahead and close this more general issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-OutputRelated to output processing (inserting text into buffer, retrieving buffer text, etc.)Area-ServerDown in the muck of API call servicing, interprocess communication, eventing, etc.Issue-ScenarioNeeds-Tag-FixDoesn't match tag requirementsProduct-ConhostFor issues in the Console codebaseProduct-TerminalThe new Windows Terminal.

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions