This repository has been archived by the owner on Mar 3, 2023. It is now read-only.
Character Measurements (iframe) #7945
Closed
Closed
Changes from all commits
Commits
Show all changes
61 commits
Select commit
Hold shift + click to select a range
92e1388
:art: Extract `LineHtmlBuilder` out
as-cii f66fde5
Create a `LinesYardstick` to measure stuff
as-cii b396ef4
Use a `console.log` instead for realistic metrics
as-cii 70d5f9f
Measure multiple lines
as-cii c9d04ef
:racehorse: No Spans
as-cii 25e28e1
:racehorse: Measure lineOffset only once
as-cii eed3491
:art:
as-cii 87df7df
:racehorse: We don't need to compute a `lineOffset`
as-cii fd7ced5
Remove `style` from line in measuring context
as-cii 14b4764
Remove the DOM node before parsing HTML
as-cii 2f3125d
:fire:
as-cii abad3e2
Use the same HTML on the measuring context
as-cii e2ae88d
Merge branch 'master' into as-iframe-measurements
as-cii d7f05b0
:green_heart: Wait for `linesYardstick` to be fully initialized
as-cii b4596f7
:art: Start crafting `pixelPositionForScreenPosition`
as-cii e454b3f
Use real font information in `LinesYardstick`
as-cii 22663fc
:memo: Remember which lines to precompute
as-cii be48432
:green_heart: Adapt specs to the new tokens HTML
as-cii 1050bab
Use `forEach` so that we can accept both `Set` and `Array`
as-cii a0a13d3
:racehorse: Make HTML insertion incremental
as-cii 4b66b21
:bug: Fix `LinesYardstick`
as-cii 2e3eb25
Identify lines by id
as-cii b1900f4
Rebuild `lineNodesByScreenRow`
as-cii fb4df84
:art:
as-cii e9a86d4
Begin to improve generated lines HTML
as-cii 270fa1f
Split `updateContentDimensions`
as-cii e2ee49e
Guard against unconstructed line nodes
as-cii 13608a7
Batch cursor updates
as-cii b063d7b
Replace `TextEditorPresenter#pixelPositionForScreenPosition`
as-cii ec9ffbd
:bug: Round down while finding token
as-cii 5483cbc
Remove unnecessary level of nesting
as-cii e97cd3e
Add syntax theme to `LinesYardstick`
as-cii 23794de
:fire:
as-cii 28405e0
:racehorse: Introduce smaller measuring contexts
as-cii 3a16156
:art:
as-cii ea2dd19
Use `line.id` to perform changes in `LinesYardstick`
as-cii 71ad3eb
:bug: Store only new lines to avoid mismatches
as-cii 2257688
:racehorse: Use a subset of `atom-styles`
as-cii eb8a1c0
Build only those scopes that have an impact on char widths
as-cii b4209b0
Merge branch 'master' into as-iframe-measurements
as-cii 63ca3d5
:bug: Fix trailing whitespace end index calculation
as-cii 377771c
:bug: Guard against empty trailing whitespace
as-cii 44c34d8
Remove null bytes from generated HTML
as-cii c7b6d58
Correctly exclude scope tokens
as-cii b40fb11
Exclude extra spans for lines on the main document
as-cii 49eb45d
:art: Revert changes to specs
as-cii c729d78
Merge branch 'master' into as-iframe-measurements
as-cii b7e8155
Merge branch 'master' into as-iframe-measurements
as-cii 82910ec
Merge branch 'master' into as-iframe-measurements
as-cii 57637cc
Merge branch 'master' into as-iframe-measurements
as-cii 9ce3c07
Use TokenIterator and NodeIterator to measure stuff
as-cii 5b79955
Some :art:
as-cii 6d1b2e0
Refactor LinesYardstick to be ignorant about lines creation
as-cii 1427e37
Start working on `TextEditorPresenter` specs
as-cii 556f794
:racehorse: Remove double iteration of tokens
as-cii 45da0e7
Merge branch 'master' into as-iframe-measurements
as-cii 8764721
Reset fonts on yardstick initialization
as-cii 89cad9f
Merge branch 'master' into as-iframe-measurements
as-cii 7faca84
:racehorse: Build only needed rows
as-cii 78287dd
Merge branch 'master' into as-iframe-measurements
as-cii 4e96d4c
:green_heart: Fix `TextEditorPresenter` specs
as-cii File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
LinesYardstick = require '../src/lines-yardstick' | ||
{Point} = require 'text-buffer' | ||
|
||
describe "LinesYardstick", -> | ||
[linesYardstick, editor, styleNodesToRemove] = [] | ||
|
||
styleSheetWithSelectorAndFont = (selector, font) -> | ||
styleNode = document.createElement("style") | ||
styleNode.innerHTML = """ | ||
#{selector} { | ||
font: #{font}; | ||
} | ||
""" | ||
document.body.appendChild(styleNode) | ||
styleNodesToRemove ?= [] | ||
styleNodesToRemove.push(styleNode) | ||
styleNode | ||
|
||
cleanupStyleSheets = -> | ||
styleNode.remove() while styleNode = styleNodesToRemove?.pop() | ||
|
||
beforeEach -> | ||
waitsForPromise -> | ||
atom.packages.activatePackage('language-javascript') | ||
|
||
waitsForPromise -> | ||
atom.project.open('sample.js').then (o) -> editor = o | ||
|
||
runs -> | ||
linesYardstick = new LinesYardstick(editor) | ||
document.body.appendChild(linesYardstick.getDomNode()) | ||
|
||
waitsFor -> | ||
linesYardstick.canMeasure() | ||
|
||
afterEach -> | ||
linesYardstick.getDomNode().remove() | ||
cleanupStyleSheets() | ||
|
||
describe "::buildDomNodesForScreenRows(screenRows)", -> | ||
it "asks for a line HTML only once", -> | ||
requestedLinesByScreenRow = {} | ||
linesYardstick.setLineHtmlProvider (screenRow, line) -> | ||
requestedLinesByScreenRow[screenRow] ?= 0 | ||
requestedLinesByScreenRow[screenRow]++ | ||
|
||
"<div></div>" | ||
|
||
linesYardstick.buildDomNodesForScreenRows([0, 1, 2]) | ||
linesYardstick.buildDomNodesForScreenRows([1, 2, 3]) | ||
linesYardstick.buildDomNodesForScreenRows([3, 4, 5]) | ||
|
||
expect(Object.keys(requestedLinesByScreenRow).length).not.toBe(0) | ||
for screenRow, requestsCount of requestedLinesByScreenRow | ||
expect(requestsCount).toBe(1) | ||
|
||
describe "::leftPixelPositionForScreenPosition(point)", -> | ||
it "measure positions based on stylesheets and default font", -> | ||
editor.setText("hello\nworld\n") | ||
linesYardstick.setDefaultFont("monospace", "14px") | ||
linesYardstick.setLineHtmlProvider (screenRow, line) -> | ||
if screenRow is 0 | ||
"<div>he<span class='bigger'>l</span>lo</div>" | ||
else if screenRow is 1 | ||
"<div>world</div>" | ||
else | ||
throw new Error("This screen row shouldn't have been requested.") | ||
|
||
linesYardstick.buildDomNodesForScreenRows([0, 1]) | ||
|
||
conversionTable = [ | ||
[new Point(0, 0), {left: 0, top: editor.getLineHeightInPixels() * 0}] | ||
[new Point(0, 1), {left: 8, top: editor.getLineHeightInPixels() * 0}] | ||
[new Point(0, 3), {left: 24, top: editor.getLineHeightInPixels() * 0}] | ||
[new Point(1, 0), {left: 0, top: editor.getLineHeightInPixels() * 1}] | ||
[new Point(1, 1), {left: 8, top: editor.getLineHeightInPixels() * 1}] | ||
[new Point(1, 4), {left: 32, top: editor.getLineHeightInPixels() * 1}] | ||
] | ||
|
||
for [point, position] in conversionTable | ||
expect( | ||
linesYardstick.pixelPositionForScreenPosition(point) | ||
).toEqual(position) | ||
|
||
linesYardstick.resetStyleSheets([ | ||
styleSheetWithSelectorAndFont(".bigger", "16px monospace") | ||
]) | ||
|
||
conversionTable = [ | ||
[new Point(0, 0), {left: 0, top: 0 * editor.getLineHeightInPixels()}] | ||
[new Point(0, 1), {left: 8, top: 0 * editor.getLineHeightInPixels()}] | ||
[new Point(0, 3), {left: 26, top: 0 * editor.getLineHeightInPixels()}] | ||
[new Point(1, 0), {left: 0, top: 1 * editor.getLineHeightInPixels()}] | ||
[new Point(1, 1), {left: 8, top: 1 * editor.getLineHeightInPixels()}] | ||
[new Point(1, 4), {left: 32, top: 1 * editor.getLineHeightInPixels()}] | ||
] | ||
|
||
for [point, position] in conversionTable | ||
expect( | ||
linesYardstick.pixelPositionForScreenPosition(point) | ||
).toEqual(position) |
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
Oops, something went wrong.
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.
I like this comparison test for now, but will we be able to drop the old method before merging this and test the new method directly?