mirror of
https://github.com/atom/atom.git
synced 2026-02-10 22:55:09 -05:00
Install Renderer in Editor instead of LineWrapper & LineFolder
This commit is contained in:
@@ -2,9 +2,7 @@
|
||||
Buffer = require 'buffer'
|
||||
Cursor = require 'cursor'
|
||||
Gutter = require 'gutter'
|
||||
Highlighter = require 'highlighter'
|
||||
LineFolder = require 'line-folder'
|
||||
LineWrapper = require 'line-wrapper'
|
||||
Renderer = require 'renderer'
|
||||
Point = require 'point'
|
||||
Range = require 'range'
|
||||
Selection = require 'selection'
|
||||
@@ -32,7 +30,7 @@ class Editor extends View
|
||||
selection: null
|
||||
buffer: null
|
||||
highlighter: null
|
||||
lineWrapper: null
|
||||
renderer: null
|
||||
undoManager: null
|
||||
|
||||
initialize: () ->
|
||||
@@ -150,21 +148,19 @@ class Editor extends View
|
||||
@lines.append @buildLineElement(screenLine)
|
||||
|
||||
getScreenLines: ->
|
||||
@lineWrapper.getLines()
|
||||
@renderer.getLines()
|
||||
|
||||
linesForScreenRows: (start, end) ->
|
||||
@lineWrapper.linesForScreenRows(start, end)
|
||||
linesForRows: (start, end) ->
|
||||
@renderer.linesForRows(start, end)
|
||||
|
||||
screenLineCount: ->
|
||||
@lineWrapper.lineCount()
|
||||
@renderer.lineCount()
|
||||
|
||||
lastScreenRow: ->
|
||||
lastRow: ->
|
||||
@screenLineCount() - 1
|
||||
|
||||
setBuffer: (@buffer) ->
|
||||
@highlighter = new Highlighter(@buffer)
|
||||
@lineFolder = new LineFolder(@highlighter)
|
||||
@lineWrapper = new LineWrapper(Infinity, @lineFolder)
|
||||
@renderer = new Renderer(@buffer)
|
||||
@undoManager = new UndoManager(@buffer)
|
||||
@renderLines()
|
||||
@gutter.renderLineNumbers(@getScreenLines())
|
||||
@@ -174,12 +170,12 @@ class Editor extends View
|
||||
@buffer.on 'change', (e) =>
|
||||
@cursor.bufferChanged(e)
|
||||
|
||||
@lineWrapper.on 'change', (e) =>
|
||||
@renderer.on 'change', (e) =>
|
||||
@gutter.renderLineNumbers(@getScreenLines())
|
||||
|
||||
@cursor.refreshScreenPosition()
|
||||
{ oldRange, newRange } = e
|
||||
screenLines = @linesForScreenRows(newRange.start.row, newRange.end.row)
|
||||
screenLines = @linesForRows(newRange.start.row, newRange.end.row)
|
||||
if newRange.end.row > oldRange.end.row
|
||||
# update, then insert elements
|
||||
for row in [newRange.start.row..newRange.end.row]
|
||||
@@ -223,7 +219,10 @@ class Editor extends View
|
||||
else
|
||||
Infinity
|
||||
|
||||
@lineWrapper.setMaxLength(maxLength) if maxLength
|
||||
@renderer.setMaxLineLength(maxLength) if maxLength
|
||||
|
||||
createFold: (range) ->
|
||||
@renderer.createFold(range)
|
||||
|
||||
setSoftWrap: (@softWrap) ->
|
||||
@setMaxLineLength()
|
||||
@@ -234,7 +233,7 @@ class Editor extends View
|
||||
$(window).off 'resize', @_setMaxLineLength
|
||||
|
||||
clipScreenPosition: (screenPosition, options={}) ->
|
||||
@lineWrapper.clipScreenPosition(screenPosition, options)
|
||||
@renderer.clipScreenPosition(screenPosition, options)
|
||||
|
||||
pixelPositionForScreenPosition: ({row, column}) ->
|
||||
{ top: row * @lineHeight, left: @linesPositionLeft() + column * @charWidth }
|
||||
@@ -246,16 +245,16 @@ class Editor extends View
|
||||
screenPosition = new Point(Math.floor(top / @lineHeight), Math.floor(left / @charWidth))
|
||||
|
||||
screenPositionForBufferPosition: (position) ->
|
||||
@lineWrapper.screenPositionForBufferPosition(position)
|
||||
@renderer.screenPositionForBufferPosition(position)
|
||||
|
||||
bufferPositionForScreenPosition: (position) ->
|
||||
@lineWrapper.bufferPositionForScreenPosition(position)
|
||||
@renderer.bufferPositionForScreenPosition(position)
|
||||
|
||||
screenRangeForBufferRange: (range) ->
|
||||
@lineWrapper.screenRangeForBufferRange(range)
|
||||
@renderer.screenRangeForBufferRange(range)
|
||||
|
||||
bufferRangeForScreenRange: (range) ->
|
||||
@lineWrapper.bufferRangeForScreenRange(range)
|
||||
@renderer.bufferRangeForScreenRange(range)
|
||||
|
||||
screenPositionFromMouseEvent: (e) ->
|
||||
{ pageX, pageY } = e
|
||||
@@ -322,6 +321,6 @@ class Editor extends View
|
||||
@undoManager.redo()
|
||||
|
||||
destroyFold: (foldId) ->
|
||||
fold = @lineFolder.foldsById[foldId]
|
||||
fold = @renderer.foldsById[foldId]
|
||||
fold.destroy()
|
||||
@setCursorBufferPosition(fold.start)
|
||||
|
||||
@@ -31,7 +31,10 @@ class Renderer
|
||||
@lineMap.insertAtInputRow 0, @buildLinesForBufferRows(0, @buffer.lastRow())
|
||||
|
||||
setMaxLineLength: (@maxLineLength) ->
|
||||
oldRange = @rangeForAllLines()
|
||||
@buildLineMap()
|
||||
newRange = @rangeForAllLines()
|
||||
@trigger 'change', { oldRange, newRange }
|
||||
|
||||
lineForRow: (row) ->
|
||||
@lineMap.lineForOutputRow(row)
|
||||
@@ -39,6 +42,9 @@ class Renderer
|
||||
linesForRows: (startRow, endRow) ->
|
||||
@lineMap.linesForOutputRows(startRow, endRow)
|
||||
|
||||
getLines: ->
|
||||
@lineMap.linesForOutputRows(0, @lineMap.lastOutputRow())
|
||||
|
||||
createFold: (bufferRange) ->
|
||||
bufferRange = Range.fromObject(bufferRange)
|
||||
return if bufferRange.isEmpty()
|
||||
@@ -81,6 +87,15 @@ class Renderer
|
||||
screenRangeForBufferRange: (bufferRange) ->
|
||||
@lineMap.outputRangeForInputRange(bufferRange)
|
||||
|
||||
bufferRangeForScreenRange: (screenRange) ->
|
||||
@lineMap.inputRangeForOutputRange(screenRange)
|
||||
|
||||
lineCount: ->
|
||||
@lineMap.outputLineCount()
|
||||
|
||||
lastRow: ->
|
||||
@lineCount() - 1
|
||||
|
||||
logLines: ->
|
||||
@lineMap.logLines()
|
||||
|
||||
@@ -193,4 +208,7 @@ class Renderer
|
||||
{ start, end } = bufferRange
|
||||
new Range([start.row, 0], [end.row, @lineMap.lineForInputRow(end.row).text.length])
|
||||
|
||||
rangeForAllLines: ->
|
||||
new Range([0, 0], @clipScreenPosition([Infinity, Infinity]))
|
||||
|
||||
_.extend Renderer.prototype, EventEmitter
|
||||
|
||||
@@ -168,5 +168,5 @@ class Selection extends View
|
||||
|
||||
fold: ->
|
||||
range = @getBufferRange()
|
||||
@editor.lineFolder.createFold(range)
|
||||
@editor.createFold(range)
|
||||
@cursor.setBufferPosition(range.end)
|
||||
|
||||
Reference in New Issue
Block a user