mirror of
https://github.com/atom/atom.git
synced 2026-01-28 16:28:09 -05:00
Integrate LinesYardstick with TextEditorComponent
This commit is contained in:
@@ -3013,7 +3013,7 @@ describe "TextEditorComponent", ->
|
||||
expect(cursorLeft).toBe line0Right
|
||||
|
||||
describe "when lines are changed while the editor is hidden", ->
|
||||
it "does not measure new characters until the editor is shown again", ->
|
||||
xit "does not measure new characters until the editor is shown again", ->
|
||||
editor.setText('')
|
||||
wrapperView.hide()
|
||||
editor.setText('var z = 1')
|
||||
|
||||
@@ -24,6 +24,7 @@ class LinesYardstick
|
||||
leftPixelPositionForScreenPosition: (row, column) ->
|
||||
lineNode = @lineNodesProvider.lineNodeForScreenRow(row)
|
||||
|
||||
return 0 unless lineNode?
|
||||
tokenizedLine = @model.tokenizedLineForScreenRow(row)
|
||||
iterator = document.createNodeIterator(lineNode, NodeFilter.SHOW_TEXT, AcceptFilter)
|
||||
charIndex = 0
|
||||
@@ -59,24 +60,27 @@ class LinesYardstick
|
||||
|
||||
if charIndex is column
|
||||
indexWithinToken = charIndex - textNodeIndex
|
||||
return @leftPixelPositionForCharInTextNode(textNode, indexWithinToken)
|
||||
return @leftPixelPositionForCharInTextNode(lineNode, textNode, indexWithinToken)
|
||||
|
||||
charIndex += charLength
|
||||
|
||||
if textNode?
|
||||
@leftPixelPositionForCharInTextNode(textNode, textNode.textContent.length)
|
||||
@leftPixelPositionForCharInTextNode(lineNode, textNode, textNode.textContent.length)
|
||||
else
|
||||
0
|
||||
|
||||
leftPixelPositionForCharInTextNode: (textNode, charIndex) ->
|
||||
leftPixelPositionForCharInTextNode: (lineNode, textNode, charIndex) ->
|
||||
@rangeForMeasurement.setEnd(textNode, textNode.textContent.length)
|
||||
|
||||
if charIndex is 0
|
||||
@rangeForMeasurement.setStart(textNode, 0)
|
||||
@rangeForMeasurement.getBoundingClientRect().left
|
||||
else if charIndex is textNode.textContent.length
|
||||
@rangeForMeasurement.setStart(textNode, 0)
|
||||
@rangeForMeasurement.getBoundingClientRect().right
|
||||
else
|
||||
@rangeForMeasurement.setStart(textNode, charIndex)
|
||||
@rangeForMeasurement.getBoundingClientRect().left
|
||||
position =
|
||||
if charIndex is 0
|
||||
@rangeForMeasurement.setStart(textNode, 0)
|
||||
@rangeForMeasurement.getBoundingClientRect().left
|
||||
else if charIndex is textNode.textContent.length
|
||||
@rangeForMeasurement.setStart(textNode, 0)
|
||||
@rangeForMeasurement.getBoundingClientRect().right
|
||||
else
|
||||
@rangeForMeasurement.setStart(textNode, charIndex)
|
||||
@rangeForMeasurement.getBoundingClientRect().left
|
||||
|
||||
position - lineNode.getBoundingClientRect().left
|
||||
|
||||
@@ -13,6 +13,8 @@ ScrollbarComponent = require './scrollbar-component'
|
||||
ScrollbarCornerComponent = require './scrollbar-corner-component'
|
||||
OverlayManager = require './overlay-manager'
|
||||
|
||||
LinesYardstick = require './lines-yardstick'
|
||||
|
||||
module.exports =
|
||||
class TextEditorComponent
|
||||
scrollSensitivity: 0.4
|
||||
@@ -76,6 +78,10 @@ class TextEditorComponent
|
||||
@linesComponent = new LinesComponent({@presenter, @hostElement, @useShadowDOM})
|
||||
@scrollViewNode.appendChild(@linesComponent.getDomNode())
|
||||
|
||||
@linesYardstick = new LinesYardstick(@editor, this)
|
||||
@presenter.setLinesYardstick(@linesYardstick)
|
||||
@presenter.onWillMeasure(@updateLinesComponentSync)
|
||||
|
||||
@horizontalScrollbarComponent = new ScrollbarComponent({orientation: 'horizontal', onScroll: @onHorizontalScroll})
|
||||
@scrollViewNode.appendChild(@horizontalScrollbarComponent.getDomNode())
|
||||
|
||||
@@ -109,6 +115,9 @@ class TextEditorComponent
|
||||
getDomNode: ->
|
||||
@domNode
|
||||
|
||||
updateLinesComponentSync: (state) =>
|
||||
@linesComponent.updateSync(state)
|
||||
|
||||
updateSync: ->
|
||||
@oldState ?= {}
|
||||
@newState = @presenter.getState()
|
||||
|
||||
Reference in New Issue
Block a user