microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.36k stars 28.92k forks source link

Word wrapping around prefix symbols #205182

Closed locsite closed 4 months ago

locsite commented 8 months ago

Does this issue occur when all extensions are disabled?: Yes

Steps to Reproduce:

  1. Use the following editor settings.
    "editor.rulers": [80],
    "editor.wordWrapColumn": 80,
    "editor.wordWrap": "bounded",
    "editor.wrappingIndent": "indent"
  2. Open a new file and select the go language.
  3. Enter the following text:
    var x1234567890 int
    var a1234567890123456789012345678901234567890123456789012345678901234567890 = +x1234567890
    var b1234567890123456789012345678901234567890123456789012345678901234567890 = ^x1234567890
    var c1234567890123456789012345678901234567890123456789012345678901234567890 = &x1234567890
  4. The wrapped text appears as:
    var x1234567890 int
    var a1234567890123456789012345678901234567890123456789012345678901234567890 = 
    +x1234567890
    var b1234567890123456789012345678901234567890123456789012345678901234567890 = 
    ^x1234567890
    var c1234567890123456789012345678901234567890123456789012345678901234567890 = &
    x1234567890
  5. It should appear as (the only difference is the position of the & prefix between the last two lines that should wrap as a prefix attached to the prefixed word as in the previous lines for the + and ^ symbols):
    var x1234567890 int
    var a1234567890123456789012345678901234567890123456789012345678901234567890 = 
    +x1234567890
    var b1234567890123456789012345678901234567890123456789012345678901234567890 = 
    ^x1234567890
    var c1234567890123456789012345678901234567890123456789012345678901234567890 = 
    &x1234567890
  6. Any word-wrapping algorithm will fail somewhere because different languages have different needs. Having per-language settings for the allowed breaks around punctuation characters is an acceptable long-term solution.
alexdima commented 4 months ago

The reason of this behavior is the presence of & in this list: https://github.com/microsoft/vscode/blob/d8abddce40aee62b166cbdc279e5c60fd9ec4fbf/src/vs/editor/common/config/editorOptions.ts#L6181-L6185

It would be possible to configure this per language using:

"[go]": { "editor.wordWrapBreakAfterCharacters": " \t})]?|/.,;¢°′″‰℃、。。、¢,.:;?!%・・ゝゞヽヾーァィゥェォッャュョヮヵヶぁぃぅぇぉっゃゅょゎゕゖㇰㇱㇲㇳㇴㇵㇶㇷㇸㇹㇺㇻㇼㇽㇾㇿ々〻ァィゥェォャュョッー”〉》」』】〕)]}」"

The setting will appear as unknown in the UI but it should work. We found it too technical to expose.

Also, you can try configuring editor.wrappingStrategy: "advanced" which delegates wrapping point computation to the browser.