mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-21 16:08:24 +03:00
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:
parent
6a5151ccbb
commit
e2fb2fdae5
@ -288,15 +288,13 @@ describe "Editor", ->
|
|||||||
|
|
||||||
describe "font family", ->
|
describe "font family", ->
|
||||||
beforeEach ->
|
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", ->
|
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", ->
|
describe "when the font family changes", ->
|
||||||
afterEach ->
|
|
||||||
editor.clearFontFamily()
|
|
||||||
|
|
||||||
it "updates the font family of editors and recalculates dimensions critical to cursor positioning", ->
|
it "updates the font family of editors and recalculates dimensions critical to cursor positioning", ->
|
||||||
editor.attachToDom(12)
|
editor.attachToDom(12)
|
||||||
lineHeightBefore = editor.lineHeight
|
lineHeightBefore = editor.lineHeight
|
||||||
@ -305,7 +303,6 @@ describe "Editor", ->
|
|||||||
|
|
||||||
config.set("editor.fontFamily", "PCMyungjo")
|
config.set("editor.fontFamily", "PCMyungjo")
|
||||||
expect(editor.css('font-family')).toBe '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.charWidth).not.toBe charWidthBefore
|
||||||
expect(editor.getCursorView().position()).toEqual { top: 5 * editor.lineHeight, left: 6 * editor.charWidth }
|
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"
|
expect(editor.css('font-size')).not.toBe "10px"
|
||||||
|
|
||||||
it "sets the initial font size based on the value from config", ->
|
it "sets the initial font size based on the value from config", ->
|
||||||
expect($("head style.font-size")).toExist()
|
expect(editor.css('font-size')).toBe "#{config.get('editor.fontSize')}px"
|
||||||
expect($("head style.font-size").text()).toMatch "{font-size: #{config.get('editor.fontSize')}px}"
|
|
||||||
|
|
||||||
describe "when the font size changes", ->
|
describe "when the font size changes", ->
|
||||||
it "updates the font sizes of editors and recalculates dimensions critical to cursor positioning", ->
|
it "updates the font sizes of editors and recalculates dimensions critical to cursor positioning", ->
|
||||||
@ -406,9 +402,6 @@ describe "Editor", ->
|
|||||||
beforeEach ->
|
beforeEach ->
|
||||||
editor.setFontFamily('sans-serif')
|
editor.setFontFamily('sans-serif')
|
||||||
|
|
||||||
afterEach ->
|
|
||||||
editor.clearFontFamily()
|
|
||||||
|
|
||||||
it "positions the cursor to the clicked row and column", ->
|
it "positions the cursor to the clicked row and column", ->
|
||||||
{top, left} = editor.pixelOffsetForScreenPosition([3, 30])
|
{top, left} = editor.pixelOffsetForScreenPosition([3, 30])
|
||||||
editor.renderedLines.trigger mousedownEvent(pageX: left, pageY: top)
|
editor.renderedLines.trigger mousedownEvent(pageX: left, pageY: top)
|
||||||
@ -917,9 +910,6 @@ describe "Editor", ->
|
|||||||
beforeEach ->
|
beforeEach ->
|
||||||
editor.setFontFamily('sans-serif')
|
editor.setFontFamily('sans-serif')
|
||||||
|
|
||||||
afterEach ->
|
|
||||||
editor.clearFontFamily()
|
|
||||||
|
|
||||||
it "correctly positions the cursor", ->
|
it "correctly positions the cursor", ->
|
||||||
editor.setCursorBufferPosition([3, 30])
|
editor.setCursorBufferPosition([3, 30])
|
||||||
expect(editor.getCursorView().position()).toEqual {top: 3 * editor.lineHeight, left: 178}
|
expect(editor.getCursorView().position()).toEqual {top: 3 * editor.lineHeight, left: 178}
|
||||||
|
@ -960,14 +960,7 @@ class Editor extends View
|
|||||||
#
|
#
|
||||||
# fontSize - A {Number} indicating the font size in pixels.
|
# fontSize - A {Number} indicating the font size in pixels.
|
||||||
setFontSize: (fontSize) ->
|
setFontSize: (fontSize) ->
|
||||||
headTag = $("head")
|
@css('font-size', "#{fontSize}px}")
|
||||||
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}")
|
|
||||||
|
|
||||||
if @isOnDom()
|
if @isOnDom()
|
||||||
@redraw()
|
@redraw()
|
||||||
else
|
else
|
||||||
@ -982,18 +975,8 @@ class Editor extends View
|
|||||||
# Sets the font family for the editor.
|
# Sets the font family for the editor.
|
||||||
#
|
#
|
||||||
# fontFamily - A {String} identifying the CSS `font-family`,
|
# fontFamily - A {String} identifying the CSS `font-family`,
|
||||||
setFontFamily: (fontFamily) ->
|
setFontFamily: (fontFamily='') ->
|
||||||
headTag = $("head")
|
@css('font-family', fontFamily)
|
||||||
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()
|
|
||||||
|
|
||||||
@redraw()
|
@redraw()
|
||||||
|
|
||||||
# Gets the font family for the editor.
|
# Gets the font family for the editor.
|
||||||
@ -1001,11 +984,7 @@ class Editor extends View
|
|||||||
# Returns a {String} identifying the CSS `font-family`,
|
# Returns a {String} identifying the CSS `font-family`,
|
||||||
getFontFamily: -> @css("font-family")
|
getFontFamily: -> @css("font-family")
|
||||||
|
|
||||||
# Clears the CSS `font-family` property from the editor.
|
# Redraw the editor
|
||||||
clearFontFamily: ->
|
|
||||||
$('head style.editor-font-family').remove()
|
|
||||||
|
|
||||||
# Clears the CSS `font-family` property from the editor.
|
|
||||||
redraw: ->
|
redraw: ->
|
||||||
return unless @hasParent()
|
return unless @hasParent()
|
||||||
return unless @attached
|
return unless @attached
|
||||||
|
Loading…
Reference in New Issue
Block a user