Remove presenter as a dependency where possible

Although we have a couple of components which still access it, we
agreed it would have been just better to avoid relying on
`TextEditorPresenter` where possible and use it purposefully in other
places (e.g. `LinesComponent` which needs it to store text
measurements).

/cc: @jssln
This commit is contained in:
Antonio Scandurra
2015-06-13 14:18:36 +02:00
parent b6049857ed
commit e893b5105b
6 changed files with 33 additions and 31 deletions

View File

@@ -7,7 +7,7 @@ LineNumberGutterComponent = require './line-number-gutter-component'
module.exports =
class GutterContainerComponent
constructor: ({@onLineNumberGutterMouseDown, @editor, @presenter}) ->
constructor: ({@onLineNumberGutterMouseDown, @editor}) ->
# An array of objects of the form: {name: {String}, component: {Object}}
@gutterComponents = []
@gutterComponentsByGutterName = {}
@@ -34,7 +34,7 @@ class GutterContainerComponent
gutterComponent = @gutterComponentsByGutterName[gutter.name]
if not gutterComponent
if gutter.name is 'line-number'
gutterComponent = new LineNumberGutterComponent({onMouseDown: @onLineNumberGutterMouseDown, @presenter, @editor, gutter})
gutterComponent = new LineNumberGutterComponent({onMouseDown: @onLineNumberGutterMouseDown, @editor, gutter})
@lineNumberGutterComponent = gutterComponent
else
gutterComponent = new CustomGutterComponent({gutter})

View File

@@ -7,7 +7,7 @@ module.exports =
class LineNumberGutterComponent extends TiledComponent
dummyLineNumberNode: null
constructor: ({@onMouseDown, @editor, @presenter, @gutter}) ->
constructor: ({@onMouseDown, @editor, @gutter}) ->
@lineNumberNodesById = {}
@visible = true
@@ -77,11 +77,6 @@ class LineNumberGutterComponent extends TiledComponent
DummyLineNumberComponent.newState = @newState
@dummyLineNumberNode.innerHTML = DummyLineNumberComponent.buildLineNumberInnerHTML(0, false)
lineNumberNodeForScreenRow: (screenRow) ->
tile = @presenter.tileForRow(screenRow)
@componentsByTileId[tile]?.lineNumberNodeForScreenRow(screenRow)
onMouseDown: (event) =>
{target} = event
lineNumber = target.parentNode

View File

@@ -14,7 +14,7 @@ class LinesComponent extends TiledComponent
@domNode = document.createElement('div')
@domNode.classList.add('lines')
@cursorsComponent = new CursorsComponent(@presenter)
@cursorsComponent = new CursorsComponent
@domNode.appendChild(@cursorsComponent.getDomNode())
if @useShadowDOM
@@ -95,8 +95,3 @@ class LinesComponent extends TiledComponent
component.clearMeasurements()
@presenter.clearScopedCharacterWidths()
lineNodeForScreenRow: (screenRow) ->
tile = @presenter.tileForRow(screenRow)
@componentsByTileId[tile]?.lineNodeForScreenRow(screenRow)

View File

@@ -25,7 +25,7 @@ class LinesTileComponent
@domNode.style.position = "absolute"
@domNode.style.display = "block"
@highlightsComponent = new HighlightsComponent(@presenter)
@highlightsComponent = new HighlightsComponent
@domNode.appendChild(@highlightsComponent.getDomNode())
getDomNode: ->

View File

@@ -165,7 +165,7 @@ class TextEditorComponent
@overlayManager?.measureOverlays()
mountGutterContainerComponent: ->
@gutterContainerComponent = new GutterContainerComponent({@editor, @onLineNumberGutterMouseDown, @presenter})
@gutterContainerComponent = new GutterContainerComponent({@editor, @onLineNumberGutterMouseDown})
@domNode.insertBefore(@gutterContainerComponent.getDomNode(), @domNode.firstChild)
becameVisible: ->
@@ -724,9 +724,18 @@ class TextEditorComponent
consolidateSelections: (e) ->
e.abortKeyBinding() unless @editor.consolidateSelections()
lineNodeForScreenRow: (screenRow) -> @linesComponent.lineNodeForScreenRow(screenRow)
lineNodeForScreenRow: (screenRow) ->
tileRow = @presenter.tileForRow(screenRow)
tileComponent = @linesComponent.getComponentForTile(tileRow)
lineNumberNodeForScreenRow: (screenRow) -> @gutterContainerComponent.getLineNumberGutterComponent().lineNumberNodeForScreenRow(screenRow)
tileComponent?.lineNodeForScreenRow(screenRow)
lineNumberNodeForScreenRow: (screenRow) ->
tileRow = @presenter.tileForRow(screenRow)
gutterComponent = @gutterContainerComponent.getLineNumberGutterComponent()
tileComponent = gutterComponent.getComponentForTile(tileRow)
tileComponent?.lineNumberNodeForScreenRow(screenRow)
screenRowForNode: (node) ->
while node?

View File

@@ -17,32 +17,35 @@ class TiledComponent
@afterUpdateSync?(state)
removeTileNodes: ->
@removeTileNode(id) for id of @oldState.tiles
@removeTileNode(tileRow) for tileRow of @oldState.tiles
return
removeTileNode: (id) ->
node = @componentsByTileId[id].getDomNode()
removeTileNode: (tileRow) ->
node = @componentsByTileId[tileRow].getDomNode()
node.remove()
delete @componentsByTileId[id]
delete @oldState.tiles[id]
delete @componentsByTileId[tileRow]
delete @oldState.tiles[tileRow]
updateTileNodes: ->
@componentsByTileId ?= {}
for id of @oldState.tiles
unless @newState.tiles.hasOwnProperty(id)
@removeTileNode(id)
for tileRow of @oldState.tiles
unless @newState.tiles.hasOwnProperty(tileRow)
@removeTileNode(tileRow)
for id, tileState of @newState.tiles
if @oldState.tiles.hasOwnProperty(id)
component = @componentsByTileId[id]
for tileRow, tileState of @newState.tiles
if @oldState.tiles.hasOwnProperty(tileRow)
component = @componentsByTileId[tileRow]
else
component = @componentsByTileId[id] = @buildComponentForTile(id)
component = @componentsByTileId[tileRow] = @buildComponentForTile(tileRow)
@getTilesNode().appendChild(component.getDomNode())
@oldState.tiles[id] = cloneObject(tileState)
@oldState.tiles[tileRow] = cloneObject(tileState)
component.updateSync(@newState)
return
getComponentForTile: (tileRow) ->
@componentsByTileId[tileRow]