Skip to content

Commit

Permalink
Calculate gutter dimensions when editor's dimensions are calculated
Browse files Browse the repository at this point in the history
  • Loading branch information
probablycorey-and-nathan committed Jun 16, 2012
1 parent d9500e6 commit db69ee5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
9 changes: 9 additions & 0 deletions spec/app/editor-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,15 @@ describe "Editor", ->
rootView.setFontSize(22)
expect(editor.css('font-size')).toBe '30px'

it "updates the gutter width and font size", ->
rootView.attachToDom()
originalFontSize = rootView.getFontSize()
originalGutterWidth = editor.gutter.width()

rootView.setFontSize(originalFontSize * 4)
expect(editor.gutter.css('font-size')).toBe "#{originalFontSize * 4}px"
expect(editor.gutter.width()).toBe(originalGutterWidth * 4)

it "updates lines if there are unrendered lines", ->
editor.attachToDom(heightInLines: 5)
originalLineCount = editor.renderedLines.find(".line").length
Expand Down
4 changes: 3 additions & 1 deletion src/app/editor.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ class Editor extends View
rootView.on "font-size-change.editor#{@id}", => @setFontSize(rootView.getFontSize())

setFontSize: (fontSize) ->
if fontSize
if fontSize?
@css('font-size', fontSize + 'px')
@calculateDimensions()
@updateCursorViews()
Expand Down Expand Up @@ -627,6 +627,8 @@ class Editor extends View
@height(@lineHeight) if @mini
fragment.remove()

@gutter.calculateDimensions()

prepareForScrolling: ->
@adjustHeightOfRenderedLines()
@adjustWidthOfRenderedLines()
Expand Down
11 changes: 8 additions & 3 deletions src/app/gutter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@ class Gutter extends View
@div class: 'gutter', =>
@div outlet: 'lineNumbers', class: 'wtf'

renderLineNumbers: (startScreenRow, endScreenRow) ->
editor: ->
editor = @parentView

renderLineNumbers: (startScreenRow, endScreenRow) ->
lastScreenRow = -1
rows = editor.bufferRowsForScreenRows(startScreenRow, endScreenRow)
rows = @editor().bufferRowsForScreenRows(startScreenRow, endScreenRow)

@lineNumbers[0].innerHTML = $$$ ->
for row in rows
@div {class: 'line-number'}, if row == lastScreenRow then '' else row + 1
lastScreenRow = row

@lineNumbers.width(editor.buffer.getLastRow().toString().length * editor.charWidth)
@calculateDimensions()

calculateDimensions: ->
@lineNumbers.width(@editor().buffer.getLastRow().toString().length * @editor().charWidth)

0 comments on commit db69ee5

Please sign in to comment.