Set font size and family directly on editor element

Previously this was set via a style tag which ate up a lot of spec
time and seemed to be functionally equivalent to just setting the
style directly on the element instead of finding and adding/removing
style tags.
This commit is contained in:
Kevin Sawicki 2013-10-02 14:47:32 -07:00
parent 6a5151ccbb
commit e2fb2fdae5
2 changed files with 8 additions and 39 deletions

View File

@ -288,15 +288,13 @@ describe "Editor", ->
describe "font family", ->
beforeEach ->
expect(editor.css('font-family')).not.toBe 'Courier'
expect(editor.css('font-family')).toBe 'Courier'
it "when there is no config in fontFamily don't set it", ->
expect($("head style.font-family")).not.toExist()
atom.config.set('editor.fontFamily', null)
expect(editor.css('font-family')).toBe ''
describe "when the font family changes", ->
afterEach ->
editor.clearFontFamily()
it "updates the font family of editors and recalculates dimensions critical to cursor positioning", ->
editor.attachToDom(12)
lineHeightBefore = editor.lineHeight
@ -305,7 +303,6 @@ describe "Editor", ->
config.set("editor.fontFamily", "PCMyungjo")
expect(editor.css('font-family')).toBe 'PCMyungjo'
expect($("head style.editor-font-family").text()).toMatch "{font-family: PCMyungjo}"
expect(editor.charWidth).not.toBe charWidthBefore
expect(editor.getCursorView().position()).toEqual { top: 5 * editor.lineHeight, left: 6 * editor.charWidth }
@ -319,8 +316,7 @@ describe "Editor", ->
expect(editor.css('font-size')).not.toBe "10px"
it "sets the initial font size based on the value from config", ->
expect($("head style.font-size")).toExist()
expect($("head style.font-size").text()).toMatch "{font-size: #{config.get('editor.fontSize')}px}"
expect(editor.css('font-size')).toBe "#{config.get('editor.fontSize')}px"
describe "when the font size changes", ->
it "updates the font sizes of editors and recalculates dimensions critical to cursor positioning", ->
@ -406,9 +402,6 @@ describe "Editor", ->
beforeEach ->
editor.setFontFamily('sans-serif')
afterEach ->
editor.clearFontFamily()
it "positions the cursor to the clicked row and column", ->
{top, left} = editor.pixelOffsetForScreenPosition([3, 30])
editor.renderedLines.trigger mousedownEvent(pageX: left, pageY: top)
@ -917,9 +910,6 @@ describe "Editor", ->
beforeEach ->
editor.setFontFamily('sans-serif')
afterEach ->
editor.clearFontFamily()
it "correctly positions the cursor", ->
editor.setCursorBufferPosition([3, 30])
expect(editor.getCursorView().position()).toEqual {top: 3 * editor.lineHeight, left: 178}

View File

@ -960,14 +960,7 @@ class Editor extends View
#
# fontSize - A {Number} indicating the font size in pixels.
setFontSize: (fontSize) ->
headTag = $("head")
styleTag = headTag.find("style.font-size")
if styleTag.length == 0
styleTag = $$ -> @style class: 'font-size'
headTag.append styleTag
styleTag.text(".editor {font-size: #{fontSize}px}")
@css('font-size', "#{fontSize}px}")
if @isOnDom()
@redraw()
else
@ -982,18 +975,8 @@ class Editor extends View
# Sets the font family for the editor.
#
# fontFamily - A {String} identifying the CSS `font-family`,
setFontFamily: (fontFamily) ->
headTag = $("head")
styleTag = headTag.find("style.editor-font-family")
if fontFamily?
if styleTag.length == 0
styleTag = $$ -> @style class: 'editor-font-family'
headTag.append styleTag
styleTag.text(".editor {font-family: #{fontFamily}}")
else
styleTag.remove()
setFontFamily: (fontFamily='') ->
@css('font-family', fontFamily)
@redraw()
# Gets the font family for the editor.
@ -1001,11 +984,7 @@ class Editor extends View
# Returns a {String} identifying the CSS `font-family`,
getFontFamily: -> @css("font-family")
# Clears the CSS `font-family` property from the editor.
clearFontFamily: ->
$('head style.editor-font-family').remove()
# Clears the CSS `font-family` property from the editor.
# Redraw the editor
redraw: ->
return unless @hasParent()
return unless @attached