-
Notifications
You must be signed in to change notification settings - Fork 4
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
fix(lines-wordwrap): support wordbreak and hyphens option on lines method #3
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
78ccfdd
fix(lines-long): support wordwrap option on lines method
arnaud-zg 3862a09
fix(lines): add documentation for wordwrap option
arnaud-zg 5dfa447
fix(word-wrap): move wordwrap before loop over text parts
arnaud-zg 53adbb8
fix(build): add compiled build for wordwrap feature
arnaud-zg 9f2116a
fix(wordwrap): add wordwrap and hyphens option
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,60 @@ test('Computes maxFontSize', t => { | |
t.is(val, '183px'); | ||
}); | ||
|
||
test('Computes lines with one very long word with break all option', t => { | ||
const el = document.querySelector('#height'); | ||
|
||
const text = 'Craspharetrapharetragravida.Vivamusconsequatlacusvelposuerecongue.Duisaloremvitaeexauctorscelerisquenoneuturpis.Utimperdietmagnasitametjustobibendumvehicula.'; | ||
const expected = [ | ||
'Craspharetraphar', | ||
'retragravida.Vivam', | ||
'musconsequatlac', | ||
'cusvelposuerecon', | ||
'ngue.Duisaloremv', | ||
'vitaeexauctorscel', | ||
'lerisquenoneutur', | ||
'rpis.Utimperdietma', | ||
'agnasitametjustob', | ||
'bibendumvehicul', | ||
'la.' | ||
]; | ||
|
||
const value = textMetrics(el).lines(text, {multiline: true, wordBreak: 'break-all'}); | ||
|
||
t.is(value.length, expected.length); | ||
|
||
for (let i = 0; i < value.length; i++) { | ||
t.is(value[i], expected[i]); | ||
} | ||
}); | ||
|
||
test('Computes lines with one very long word with hyphen option', t => { | ||
const el = document.querySelector('#height'); | ||
|
||
const text = 'Craspharetrapharetragravida.Vivamusconsequatlacusvelposuerecongue.Duisaloremvitaeexauctorscelerisquenoneuturpis.Utimperdietmagnasitametjustobibendumvehicula.'; | ||
const expected = [ | ||
'Craspharetraphar-', | ||
'retragravida.Vivam-', | ||
'musconsequatlac-', | ||
'cusvelposuerecon-', | ||
'ngue.Duisaloremv-', | ||
'vitaeexauctorscel-', | ||
'lerisquenoneutur-', | ||
'rpis.Utimperdietma-', | ||
'agnasitametjustob-', | ||
'bibendumvehicul-', | ||
'la.' | ||
]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hyphens 'auto' behaves different. If you want to add a hyphen at the end of each line you can do const value = textMetrics(el).lines(text.replace(/(.{1})/g,"$1­")) |
||
|
||
const value = textMetrics(el).lines(text, {multiline: true, hyphens: 'auto'}); | ||
|
||
t.is(value.length, expected.length); | ||
|
||
for (let i = 0; i < value.length; i++) { | ||
t.is(value[i], expected[i]); | ||
} | ||
}); | ||
|
||
test('Computes lines', t => { | ||
const el = document.querySelector('#height'); | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As i said, the break-all case is already handled here:
https://github.com/bezoerb/text-metrics/blob/master/src/index.js#L143
https://github.com/bezoerb/text-metrics/blob/master/src/utils.js#L426