From db69ee562784d9a469fe34a7a04393e18033534d Mon Sep 17 00:00:00 2001 From: Corey Johnson & Nathan Sobo Date: Fri, 15 Jun 2012 16:44:15 -0700 Subject: [PATCH] Calculate gutter dimensions when editor's dimensions are calculated --- spec/app/editor-spec.coffee | 9 +++++++++ src/app/editor.coffee | 4 +++- src/app/gutter.coffee | 11 ++++++++--- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index 8623c178703..c629626c72c 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -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 diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 663852e1b3d..c2f0463e25d 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -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() @@ -627,6 +627,8 @@ class Editor extends View @height(@lineHeight) if @mini fragment.remove() + @gutter.calculateDimensions() + prepareForScrolling: -> @adjustHeightOfRenderedLines() @adjustWidthOfRenderedLines() diff --git a/src/app/gutter.coffee b/src/app/gutter.coffee index 2d3ddd88a07..5e51b28b34c 100644 --- a/src/app/gutter.coffee +++ b/src/app/gutter.coffee @@ -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)