carbon: Line-wrapping bug

Potentially related to #761

Expected Behavior

  • Code is not line-wrapped, OR
  • code is line-wrapped at 80 chars and preserves indentation, OR
  • control over line-wrapping (best behavior)

Actual Behavior

Line with <= 80 chars gets wrapped to newline, ignoring indentation

(Compare lines 5 and 6 in the output below to the input snippet)

Details

Output:

3cf10212-a156-4cde-9756-e245851c5b51

Input:

function html (tagName, attributes, ...childNodes) {
  const el = document.createElement(tagName);
  if (attributes) {
    for (const [prop, value] of Object.entries(attributes)) {
      if (prop === 'style' && (Array.isArray(value) || value instanceof Map)) {
        for (const declaration of value) {
          el.style.setProperty(...declaration);
        }
      }
      else {
        el.setAttribute(prop, value);
      }
    }
  }
  if (childNodes) {
    for (let node of childNodes) {
      if (typeof node === 'string') {
        node = document.createTextNode(node);
      }
      el.appendChild(node);
    }
  }
  return el;
}

Carbon config:

(Note: I removed the icon property)

{
  "paddingVertical": "0px",
  "paddingHorizontal": "0px",
  "marginVertical": "45px",
  "marginHorizontal": "45px",
  "backgroundImage": null,
  "backgroundImageSelection": null,
  "backgroundMode": "color",
  "backgroundColor": "rgba(171, 184, 195, 1)",
  "dropShadow": false,
  "dropShadowOffsetY": "20px",
  "dropShadowBlurRadius": "68px",
  "theme": "one-dark",
  "windowTheme": "sharp",
  "language": "javascript",
  "fontFamily": "Hack",
  "fontSize": "14px",
  "lineHeight": "133%",
  "windowControls": false,
  "widthAdjustment": false,
  "lineNumbers": true,
  "exportSize": "2x",
  "watermark": false,
  "squaredImage": false,
  "loading": false,
  "isVisible": true,
  "custom": true
}
Browser: Win 10, Chrome 75.0.3770.80

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

Noticing an incorrect linewrap of my own on Chrome 77.0.3865.90 (linux) with:

// Big Step Operational Semantics

impl Expression for Add {
    fn evaluate(&self, environment: &Environment) -> Expr {
        match (
            self.0.evaluate(environment).as_value(),
            self.1.evaluate(environment).as_value(),
        ) {
            (Some(Value::Number(a)), Some(Value::Number(b))) => Value::Number(a + b).into(),
            _ => panic!("Unexpected values"),
        }
    }
}

png rendered output

Seems like there should be a linebreak before the _ => panic!("Unexpected values"), instead of just following on as a continuation.

I have no idea at this time what the cause of the issue is. If I had to guess I would say that some kind of width calculation is very slightly off, so it renders incorrect results when certain combinations of fonts, font sizes and rendering engines are used.