Set font-size css property using style tag

This commit is contained in:
Corey Johnson 2013-01-30 12:11:17 -08:00
parent 9ea29b2899
commit 29ccd271de
2 changed files with 27 additions and 9 deletions

View File

@ -551,13 +551,26 @@ describe "Editor", ->
expect(editor.verticalScrollbarContent.height()).toBe buffer.getLineCount() * editor.lineHeight
describe "font size", ->
it "sets the initial font size based on the value from config", ->
config.set("editor.fontSize", 20)
newEditor = editor.splitRight()
expect(editor.css('font-size')).toBe '20px'
expect(newEditor.css('font-size')).toBe '20px'
beforeEach ->
expect(editor.css('font-size')).not.toBe "20px"
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}"
describe "when the font size changes", ->
it "updates the font family on new and existing editors", ->
rootView.attachToDom()
rootView.height(200)
rootView.width(200)
config.set("editor.fontSize", 20)
newEditor = editor.splitRight()
expect($("head style.font-size").text()).toMatch "{font-size: 20px}"
expect(editor.css('font-size')).toBe '20px'
expect(newEditor.css('font-size')).toBe '20px'
describe "when the font size changes on the view", ->
it "updates the font sizes of editors and recalculates dimensions critical to cursor positioning", ->
rootView.attachToDom()
rootView.height(200)

View File

@ -683,9 +683,14 @@ class Editor extends View
@save() if @getPath()?
setFontSize: (@fontSize) ->
if fontSize?
@css('font-size', fontSize + 'px')
@redraw()
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}")
@redraw()
getFontSize: -> @fontSize