From 44db540528684a0477b1d2ec421f46f4db8bc175 Mon Sep 17 00:00:00 2001 From: Corey Johnson & Nathan Sobo Date: Thu, 30 Aug 2012 17:12:40 -0600 Subject: [PATCH] All specs pass --- spec/app/editor-spec.coffee | 6 +++--- spec/app/root-view-spec.coffee | 21 +++++++++++---------- spec/extensions/command-panel-spec.coffee | 2 +- spec/spec-helper.coffee | 2 +- src/app/editor.coffee | 9 ++++++--- src/stdlib/jquery-extensions.coffee | 6 ++++++ static/editor.css | 3 +-- 7 files changed, 29 insertions(+), 20 deletions(-) diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index 4568d8e75..ffc27e0ed 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -975,7 +975,7 @@ describe "Editor", -> describe "when all lines in the buffer are visible on screen", -> beforeEach -> editor.attachToDom() - expect(editor.height()).toBe buffer.getLineCount() * editor.lineHeight + expect(editor.trueHeight()).toBeCloseTo buffer.getLineCount() * editor.lineHeight it "creates a line element for each line in the buffer with the html-escaped text of the line", -> expect(editor.renderedLines.find('.line').length).toEqual(buffer.getLineCount()) @@ -1031,8 +1031,8 @@ describe "Editor", -> editor.getSelection().setBufferRange(new Range([6, 30], [6, 55])) [region1, region2] = editor.getSelectionView().regions - expect(region1.offset().top).toBe(editor.renderedLines.find('.line:eq(7)').offset().top) - expect(region2.offset().top).toBe(editor.renderedLines.find('.line:eq(8)').offset().top) + expect(region1.offset().top).toBeCloseTo(editor.renderedLines.find('.line:eq(7)').offset().top) + expect(region2.offset().top).toBeCloseTo(editor.renderedLines.find('.line:eq(8)').offset().top) it "handles changes to wrapped lines correctly", -> buffer.insert([6, 28], '1234567') diff --git a/spec/app/root-view-spec.coffee b/spec/app/root-view-spec.coffee index 194a78eea..aa9a881ae 100644 --- a/spec/app/root-view-spec.coffee +++ b/spec/app/root-view-spec.coffee @@ -289,38 +289,39 @@ describe "RootView", -> expect(row1.children().length).toBe 2 column1 = row1.children(':eq(0)').view() pane1 = row1.children(':eq(1)').view() - expect(column1.outerWidth()).toBe Math.floor(2/3 * rootView.panes.width()) + expect(column1.outerWidth()).toBe Math.round(2/3 * rootView.panes.width()) expect(column1.outerHeight()).toBe rootView.height() - expect(pane1.outerWidth()).toBe Math.floor(1/3 * rootView.panes.width()) + expect(pane1.outerWidth()).toBe Math.round(1/3 * rootView.panes.width()) expect(pane1.outerHeight()).toBe rootView.height() - expect(pane1.position().left).toBe column1.outerWidth() + expect(Math.round(pane1.position().left)).toBe column1.outerWidth() expect(column1.children().length).toBe 2 row2 = column1.children(':eq(0)').view() pane2 = column1.children(':eq(1)').view() expect(row2.outerWidth()).toBe column1.outerWidth() - expect(row2.height()).toBe Math.floor(2/3 * rootView.panes.height()) + expect(row2.height()).toBe 2/3 * rootView.panes.height() expect(pane2.outerWidth()).toBe column1.outerWidth() - expect(pane2.outerHeight()).toBe Math.floor(1/3 * rootView.panes.height()) + expect(pane2.outerHeight()).toBe 1/3 * rootView.panes.height() expect(pane2.position().top).toBe row2.height() expect(row2.children().length).toBe 2 column3 = row2.children(':eq(0)').view() pane3 = row2.children(':eq(1)').view() - expect(column3.outerWidth()).toBe Math.floor(1/3 * rootView.panes.width()) + expect(column3.outerWidth()).toBe Math.round(1/3 * rootView.panes.width()) expect(column3.outerHeight()).toBe row2.outerHeight() - expect(pane3.outerWidth()).toBe Math.floor(1/3 * rootView.panes.width()) + # the built in rounding seems to be rounding x.5 down, but we need to go up. this sucks. + expect(Math.round(pane3.trueWidth())).toBe Math.round(1/3 * rootView.panes.width()) expect(pane3.height()).toBe row2.outerHeight() - expect(pane3.position().left).toBe column3.width() + expect(Math.round(pane3.position().left)).toBe column3.width() expect(column3.children().length).toBe 2 pane4 = column3.children(':eq(0)').view() pane5 = column3.children(':eq(1)').view() expect(pane4.outerWidth()).toBe column3.width() - expect(pane4.outerHeight()).toBe Math.floor(1/3 * rootView.panes.height()) + expect(pane4.outerHeight()).toBe 1/3 * rootView.panes.height() expect(pane5.outerWidth()).toBe column3.width() expect(pane5.position().top).toBe pane4.outerHeight() - expect(pane5.outerHeight()).toBe Math.floor(1/3 * rootView.panes.height()) + expect(pane5.outerHeight()).toBe 1/3 * rootView.panes.height() pane5.remove() diff --git a/spec/extensions/command-panel-spec.coffee b/spec/extensions/command-panel-spec.coffee index 76c10e262..7acbbc62e 100644 --- a/spec/extensions/command-panel-spec.coffee +++ b/spec/extensions/command-panel-spec.coffee @@ -330,7 +330,7 @@ describe "CommandPanel", -> expect(previewList.find('li:last')).toHaveClass 'selected' expect(previewList.getSelectedOperation()).toBe _.last(previewList.getOperations()) - expect(previewList.scrollBottom()).toBe previewList.prop('scrollHeight') + expect(previewList.scrollBottom()).toBeCloseTo previewList.prop('scrollHeight'), -1 _.times previewList.getOperations().length, -> previewList.trigger 'move-up' diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index a78cef439..047f4bd86 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -11,7 +11,7 @@ TextMateBundle = require 'text-mate-bundle' TextMateTheme = require 'text-mate-theme' fs = require 'fs' require 'window' -atom.showDevTools() +# atom.showDevTools() requireStylesheet "jasmine.css" TextMateBundle.loadAll() diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 4176df1b0..43811f957 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -655,9 +655,12 @@ class Editor extends View calculateDimensions: -> fragment = $('') @renderedLines.append(fragment) - @charWidth = fragment.width() - @charHeight = fragment.find('span').height() - @lineHeight = fragment.outerHeight() + + lineRect = fragment[0].getBoundingClientRect() + charRect = fragment.find('span')[0].getBoundingClientRect() + @lineHeight = lineRect.height + @charWidth = charRect.width + @charHeight = charRect.height @height(@lineHeight) if @mini fragment.remove() diff --git a/src/stdlib/jquery-extensions.coffee b/src/stdlib/jquery-extensions.coffee index f8becf602..adf11ea32 100644 --- a/src/stdlib/jquery-extensions.coffee +++ b/src/stdlib/jquery-extensions.coffee @@ -30,3 +30,9 @@ $.fn.flashError = -> @addClass 'error' removeErrorClass = => @removeClass 'error' window.setTimeout(removeErrorClass, 200) + +$.fn.trueHeight = -> + this[0].getBoundingClientRect().height + +$.fn.trueWidth = -> + this[0].getBoundingClientRect().width diff --git a/static/editor.css b/static/editor.css index 32b777f8c..c1267f136 100644 --- a/static/editor.css +++ b/static/editor.css @@ -76,7 +76,6 @@ white-space: pre; margin: 0; padding: 0; - padding-bottom: .05em; } .editor .line > span { @@ -121,4 +120,4 @@ .editor .fold.selected { background-color: #244; -} \ No newline at end of file +}