add config option for line height

This renames the original lineHeight variable to rowHeight to avoid
collision
This commit is contained in:
Justin Palmer
2013-01-15 16:23:02 -08:00
committed by Corey Johnson
parent a83460452e
commit f138a29a87

View File

@@ -16,6 +16,7 @@ class Editor extends View
@configDefaults:
fontFamily: "Inconsolata, Monaco, Courier"
fontSize: 20
lineHeight: 1.5
showInvisibles: false
autosave: false
autoIndent: true
@@ -308,7 +309,7 @@ class Editor extends View
@scrollTop(newScrollTop, adjustVerticalScrollbar: true)
getPageRows: ->
Math.max(1, Math.ceil(@scrollView[0].clientHeight / @lineHeight))
Math.max(1, Math.ceil(@scrollView[0].clientHeight / @rowHeight))
setShowInvisibles: (showInvisibles) ->
return if showInvisibles == @showInvisibles
@@ -342,6 +343,7 @@ class Editor extends View
@observeConfig 'editor.invisibles', (invisibles) => @setInvisibles(invisibles)
@observeConfig 'editor.fontSize', (fontSize) => @setFontSize(fontSize)
@observeConfig 'editor.fontFamily', (fontFamily) => @setFontFamily(fontFamily)
@observeConfig 'editor.lineHeight', (lineHeight) => @setLineHeight(lineHeight)
handleEvents: ->
@on 'focus', =>
@@ -575,7 +577,7 @@ class Editor extends View
@scrollTop() + @scrollView.height()
scrollToBottom: ->
@scrollBottom(@screenLineCount() * @lineHeight)
@scrollBottom(@screenLineCount() * @rowHeight)
scrollToBufferPosition: (bufferPosition, options) ->
@scrollToPixelPosition(@pixelPositionForBufferPosition(bufferPosition), options)
@@ -597,12 +599,12 @@ class Editor extends View
unless scrollTop < pixelPosition.top < scrollBottom
@scrollTop(pixelPosition.top - (scrollViewHeight / 2))
else
linesInView = @scrollView.height() / @lineHeight
linesInView = @scrollView.height() / @rowHeight
maxScrollMargin = Math.floor((linesInView - 1) / 2)
scrollMargin = Math.min(@vScrollMargin, maxScrollMargin)
margin = scrollMargin * @lineHeight
margin = scrollMargin * @rowHeight
desiredTop = pixelPosition.top - margin
desiredBottom = pixelPosition.top + @lineHeight + margin
desiredBottom = pixelPosition.top + @rowHeight + margin
if desiredBottom > scrollBottom
@scrollTop(desiredBottom - scrollViewHeight)
else if desiredTop < scrollTop
@@ -696,6 +698,12 @@ class Editor extends View
getFontFamily: -> @fontFamily
setLineHeight: (@lineHeight) ->
if lineHeight?
@css('line-height', "#{lineHeight}em")
@redraw()
getLineHeight: -> @lineHeight
redraw: ->
return unless @attached
@@ -798,16 +806,16 @@ class Editor extends View
lineRect = fragment[0].getBoundingClientRect()
charRect = fragment.find('span')[0].getBoundingClientRect()
@lineHeight = lineRect.height
@rowHeight = lineRect.height
@charWidth = charRect.width
@charHeight = charRect.height
@height(@lineHeight) if @mini
@height(@rowHeight) if @mini
fragment.remove()
updateLayerDimensions: ->
@gutter.calculateWidth()
height = @lineHeight * @screenLineCount()
height = @rowHeight * @screenLineCount()
unless @layerHeight == height
@renderedLines.height(height)
@underlayer.css('min-height', height)
@@ -1015,19 +1023,19 @@ class Editor extends View
row++
updatePaddingOfRenderedLines: ->
paddingTop = @firstRenderedScreenRow * @lineHeight
paddingTop = @firstRenderedScreenRow * @rowHeight
@renderedLines.css('padding-top', paddingTop)
@gutter.lineNumbers.css('padding-top', paddingTop)
paddingBottom = (@getLastScreenRow() - @lastRenderedScreenRow) * @lineHeight
paddingBottom = (@getLastScreenRow() - @lastRenderedScreenRow) * @rowHeight
@renderedLines.css('padding-bottom', paddingBottom)
@gutter.lineNumbers.css('padding-bottom', paddingBottom)
getFirstVisibleScreenRow: ->
Math.floor(@scrollTop() / @lineHeight)
Math.floor(@scrollTop() / @rowHeight)
getLastVisibleScreenRow: ->
Math.max(0, Math.ceil((@scrollTop() + @scrollView.height()) / @lineHeight) - 1)
Math.max(0, Math.ceil((@scrollTop() + @scrollView.height()) / @rowHeight) - 1)
isScreenRowVisible: (row) ->
@getFirstVisibleScreenRow() <= row <= @getLastVisibleScreenRow()
@@ -1126,7 +1134,7 @@ class Editor extends View
pixelPositionForScreenPosition: (position) ->
position = Point.fromObject(position)
{ top: position.row * @lineHeight, left: position.column * @charWidth }
{ top: position.row * @rowHeight, left: position.column * @charWidth }
pixelOffsetForScreenPosition: (position) ->
{top, left} = @pixelPositionForScreenPosition(position)
@@ -1134,7 +1142,7 @@ class Editor extends View
{top: top + offset.top, left: left + offset.left}
screenPositionFromPixelPosition: ({top, left}) ->
screenPosition = new Point(Math.floor(top / @lineHeight), Math.floor(left / @charWidth))
screenPosition = new Point(Math.floor(top / @rowHeight), Math.floor(left / @charWidth))
screenPositionFromMouseEvent: (e) ->
{ pageX, pageY } = e