Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

newline character not respected if text-max-width is set to zero #8575

Closed
samanpwbb opened this issue Jul 29, 2019 · 2 comments · Fixed by #8706
Closed

newline character not respected if text-max-width is set to zero #8575

samanpwbb opened this issue Jul 29, 2019 · 2 comments · Fixed by #8706

Comments

@samanpwbb
Copy link
Contributor

samanpwbb commented Jul 29, 2019

mapbox-gl-js version: 1.1.0

browser: not browser specific

Steps to Trigger Behavior

  1. Use a newline character \n in a text field value
  2. Set text-max-width to zero

Link to Demonstration

https://jsbin.com/zawiyegehe/1/edit?html,output

Expected Behavior

Text wraps to second line after newline character:
Screen Shot 2019-07-29 at 1 23 05 PM

Actual Behavior

Text does not wrap:
Screen Shot 2019-07-29 at 1 23 08 PM

@mourner
Copy link
Member

mourner commented Jul 30, 2019

Good catch! Looks like we skip determining line breaks entirely if max-width is not set (regressed in #3725):

if (!maxWidth)
return [];

@ryanhamley
Copy link
Contributor

ryanhamley commented Aug 20, 2019

@malwoodsantoro and I have been working on this bug together and I wanted to capture what we've discovered so far.

The proximate culprit is the check noted above

if (!maxWidth)
    return [];

Removing this check however runs into a related issue caused by this bit of code.

sizes.textMaxSize = unevaluatedLayoutValues['text-size'].possiblyEvaluate(new EvaluationParameters(18));
const lineHeight = layout.get('text-line-height') * ONE_EM;

If symbol-placement is set to line or line-center, text-max-width is set to zero. This makes sense since text that follows a line shouldn't have breaks, but removing the if (!maxWidth) check causes the line to break on every whitespace character - exactly the opposite of what we want. This is confirmed by numerous failing line rendering tests if the if statement is removed.

A perhaps more correct way to write the if statement would be something like this:

// disable line breaking entirely on text-along-a-line
// point placed symbols will always be shaped
if (symbolPlacement !== 'point') {
    return [];
}

The only problem with this is that shaping.js does not have access to the layout instance or the symbol-placement property so we'll have to pass that in. Mal and I will work on submitting a PR in our meeting next week; I confirmed with Studio that this timeline is acceptable as this is not a high priority issue for them.

cc @asheemmamoowala

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

Successfully merging a pull request may close this issue.

4 participants