Skip to content

Conhost color selection doesn't work correctly with wrapping and DBCS #8572

Closed

Description

Environment

Windows build number: Version 10.0.18363.1198
Windows Terminal version (if applicable):

Steps to reproduce

  1. Open a cmd shell in conhost.
  2. Open the Properties dialog and make sure Enable line wrapping selection is turned on.
  3. Select a range of text wrapped across multiple lines.
  4. Press Ctrl+4 to highlight the selected text in green.
  5. Output some text from double byte character set.
  6. Select a range of those characters starting and ending halfway through a double width character.
  7. Again press Ctrl+4 to highlight the selected text in green.

Expected behavior

When the selection wraps across multiple lines, the green highlighting should also wrap in exactly the same way. When selecting halfway through a double width character, the selection always covers the full width, so I'd expect the green highlighting to work in the same way.

image

Actual behavior

The wrapped selection changes to a block selection when painting the green background. And only half of the start and end characters in the DBCS range are painted green (I should note that this renders differently in the current openconsole build, but is still doesn't match the initial selection).

image

The reason for this behaviour is that the color selection code just uses a simple rect spanning the start and end points of the selection, where typically a selection operation should be using the Selection::GetSelectionRects method to obtain the affected range (which automatically handles the line wrapping option, and makes sure double width characters are fully covered).

The code I'm referring to is here:

ColorSelection(_srSelectionRect, selectionAttr);

And my recommendation would be to change the line above to use the GetSelectionRects method like this:

const auto selectionRects = GetSelectionRects();
for (const auto& selectionRect : selectionRects)
{
    ColorSelection(selectionRect, selectionAttr);
}

I suppose it's possible the current behaviour is deliberate, but I think it's more likely it was just an oversight when conhost was updated to support wrapped selections.

Activity

  1. ghost added
    Needs-Triage
    on Dec 13, 2020
  2. ghost added
    Needs-Tag-Fix
    on Dec 13, 2020
  3. DHowett commented on Dec 13, 2020

    @DHowett
    Member

    Definitely an oversight, probably owing to Color Select being a hidden feature 😄

    Legend has it, someone who uses CDB a lot inside the Windows organization added it as well as the “strip leading zeroes on copy” option long before Michael took over the project in ca. 2015.

    I think it’s cool; my only beef with it (apart from this bug. Excellent find on your part!) is that it actually manipulates the buffer.

    We have some plans to build on the TextBuffer pattern range support + a new interface to pass to the renderer (ICustomTextEffect?) to make this kind of stuff render-only. Eventually, eventually.

  4. ghost added
    In-PR
    on Dec 13, 2020
  5. ghost closed this as completedin #8577on Dec 14, 2020
  6. ghost removed
    In-PR
    on Dec 14, 2020
  7. ghost added a commit that references this issue on Dec 14, 2020
  8. ghost added
    Resolution-Fix-Committed
    on Dec 14, 2020
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

    Needs-Tag-FixNeeds-TriageResolution-Fix-Committed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions