Add config.editor.fontSize

This commit is contained in:
Nathan Sobo
2012-12-12 15:23:36 -08:00
parent 8088e4d90c
commit 3c2b84a46d
6 changed files with 64 additions and 57 deletions

View File

@@ -502,10 +502,10 @@ describe "Editor", ->
editor.getBuffer().saveAs("/tmp/atom-new.txt")
expect(eventHandler).toHaveBeenCalled()
describe "font size", ->
it "sets the initial font size based on the value assigned to the root view", ->
rootView.setFontSize(20)
rootView.simulateDomAttachment()
fdescribe "font size", ->
it "sets the initial font size based on the value from config", ->
config.editor.fontSize = 20
config.update()
newEditor = editor.splitRight()
expect(editor.css('font-size')).toBe '20px'
expect(newEditor.css('font-size')).toBe '20px'
@@ -515,12 +515,15 @@ describe "Editor", ->
rootView.attachToDom()
rootView.height(200)
rootView.width(200)
rootView.setFontSize(10)
config.editor.fontSize = 10
config.update()
lineHeightBefore = editor.lineHeight
charWidthBefore = editor.charWidth
editor.setCursorScreenPosition [5, 6]
rootView.setFontSize(30)
config.editor.fontSize = 30
config.update()
expect(editor.css('font-size')).toBe '30px'
expect(editor.lineHeight).toBeGreaterThan lineHeightBefore
expect(editor.charWidth).toBeGreaterThan charWidthBefore
@@ -528,17 +531,14 @@ describe "Editor", ->
expect(editor.renderedLines.outerHeight()).toBe buffer.getLineCount() * editor.lineHeight
expect(editor.verticalScrollbarContent.height()).toBe buffer.getLineCount() * editor.lineHeight
# ensure we clean up font size subscription
editor.trigger('core:close')
rootView.setFontSize(22)
expect(editor.css('font-size')).toBe '30px'
it "updates the position and size of selection regions", ->
rootView.attachToDom()
rootView.setFontSize(10)
config.editor.fontSize = 10
config.update()
editor.setSelectedBufferRange([[5, 2], [5, 7]])
rootView.setFontSize(30)
config.editor.fontSize = 30
config.update()
selectionRegion = editor.find('.region')
expect(selectionRegion.position().top).toBe 5 * editor.lineHeight
expect(selectionRegion.position().left).toBe 2 * editor.charWidth
@@ -547,10 +547,11 @@ describe "Editor", ->
it "updates the gutter width and font size", ->
rootView.attachToDom()
originalFontSize = rootView.getFontSize()
originalFontSize = editor.getFontSize()
originalGutterWidth = editor.gutter.width()
rootView.setFontSize(originalFontSize * 4)
config.editor.fontSize = originalFontSize * 4
config.update()
expect(editor.gutter.css('font-size')).toBe "#{originalFontSize * 4}px"
expect(editor.gutter.width()).toBe(originalGutterWidth * 4)
@@ -558,7 +559,9 @@ describe "Editor", ->
editor.attachToDom(heightInLines: 5)
originalLineCount = editor.renderedLines.find(".line").length
expect(originalLineCount).toBeGreaterThan 0
editor.setFontSize(10)
config.editor.fontSize = 10
config.update()
expect(editor.renderedLines.find(".line").length).toBeGreaterThan originalLineCount
describe "mouse events", ->

View File

@@ -540,29 +540,27 @@ describe "RootView", ->
expect(rootView.getTitle()).toBe rootView.project.getPath()
describe "font size adjustment", ->
editor = null
beforeEach ->
editor = rootView.getActiveEditor()
it "increases/decreases font size when increase/decrease-font-size events are triggered", ->
fontSizeBefore = rootView.getFontSize()
editor = rootView.getActiveEditor()
fontSizeBefore = editor.getFontSize()
rootView.trigger 'window:increase-font-size'
expect(rootView.getFontSize()).toBe fontSizeBefore + 1
expect(editor.getFontSize()).toBe fontSizeBefore + 1
rootView.trigger 'window:increase-font-size'
expect(rootView.getFontSize()).toBe fontSizeBefore + 2
expect(editor.getFontSize()).toBe fontSizeBefore + 2
rootView.trigger 'window:decrease-font-size'
expect(rootView.getFontSize()).toBe fontSizeBefore + 1
expect(editor.getFontSize()).toBe fontSizeBefore + 1
rootView.trigger 'window:decrease-font-size'
expect(rootView.getFontSize()).toBe fontSizeBefore
expect(editor.getFontSize()).toBe fontSizeBefore
it "does not allow the font size to be less than 1", ->
rootView.setFontSize(1)
expect(rootView.getFontSize()).toBe 1
rootView.setFontSize(0)
expect(rootView.getFontSize()).toBe 1
it "is serialized and set when deserialized", ->
rootView.setFontSize(100)
rootView.remove()
newRootView = RootView.deserialize(rootView.serialize())
expect(newRootView.getFontSize()).toBe(100)
config.editor.fontSize = 1
config.update()
rootView.trigger 'window:decrease-font-size'
expect(editor.getFontSize()).toBe 1
describe ".open(path, options)", ->
describe "when there is no active editor", ->

View File

@@ -22,6 +22,8 @@ beforeEach ->
# don't load user configuration
spyOn(config, 'load')
config.loadDefaults()
# make editor display updates synchronous
spyOn(Editor.prototype, 'requestDisplayUpdate').andCallFake -> @updateDisplay()
spyOn(RootView.prototype, 'updateWindowTitle').andCallFake ->

View File

@@ -9,19 +9,22 @@ class Config
@configJsonPath = fs.join(@configDirPath, "config.json")
@userInitScriptPath = fs.join(@configDirPath, "atom.coffee")
@core = {}
@editor = {}
load: ->
if fs.exists(@configJsonPath)
userConfig = JSON.parse(fs.read(@configJsonPath))
_.extend(this, userConfig)
@assignDefaults()
@requireUserInitScript()
assignDefaults: ->
@core ?= {}
_.defaults(@core, require('root-view').configDefaults)
@editor ?= {}
_.defaults(@editor, require('editor').configDefaults)
update: ->
@trigger 'update'
requireUserInitScript: ->
try
require @userInitScriptPath if fs.exists(@userInitScriptPath)

View File

@@ -15,6 +15,10 @@ module.exports =
class Editor extends View
@idCounter: 1
@configDefaults:
fontSize: 20
showInvisibles: false
@content: (params) ->
@div class: @classes(params), tabindex: -1, =>
@subview 'gutter', new Gutter
@@ -302,8 +306,9 @@ class Editor extends View
backwardsScanInRange: (args...) -> @getBuffer().backwardsScanInRange(args...)
configure: ->
@setShowInvisibles(config.editor.showInvisibles ? false)
@setShowInvisibles(config.editor.showInvisibles)
@setInvisibles(config.editor.invisibles)
@setFontSize(config.editor.fontSize)
handleEvents: ->
config.on "update.editor#{@id}", => @configure()
@@ -394,7 +399,6 @@ class Editor extends View
afterAttach: (onDom) ->
return if @attached or not onDom
@attached = true
@subscribeToFontSize()
@calculateDimensions()
@hiddenInput.width(@charWidth)
@setSoftWrapColumn() if @activeEditSession.getSoftWrap()
@@ -612,19 +616,17 @@ class Editor extends View
autosave: ->
@save() if @getPath()?
subscribeToFontSize: ->
return unless rootView = @rootView()
@setFontSize(rootView.getFontSize())
rootView.on "font-size-change.editor#{@id}", => @setFontSize(rootView.getFontSize())
setFontSize: (fontSize) ->
setFontSize: (@fontSize) ->
if fontSize?
@css('font-size', fontSize + 'px')
return unless @attached
@calculateDimensions()
@updatePaddingOfRenderedLines()
@updateLayerDimensions()
@requestDisplayUpdate()
getFontSize: -> @fontSize
newSplitEditor: ->
new Editor { editSession: @activeEditSession.copy() }

View File

@@ -15,21 +15,21 @@ TextMateTheme = require 'text-mate-theme'
module.exports =
class RootView extends View
@configDefaults: {}
@content: ->
@div id: 'root-view', tabindex: -1, =>
@div id: 'horizontal', outlet: 'horizontal', =>
@div id: 'vertical', outlet: 'vertical', =>
@div id: 'panes', outlet: 'panes'
@deserialize: ({ projectPath, panesViewState, extensionStates, fontSize }) ->
@deserialize: ({ projectPath, panesViewState, extensionStates }) ->
rootView = new RootView(projectPath, extensionStates: extensionStates, suppressOpen: true)
rootView.setRootPane(rootView.deserializeView(panesViewState)) if panesViewState
rootView.setFontSize(fontSize) if fontSize > 0
rootView
extensions: null
extensionStates: null
fontSize: 20
title: null
initialize: (pathToOpen, { @extensionStates, suppressOpen } = {}) ->
@@ -53,7 +53,6 @@ class RootView extends View
projectPath: @project?.getPath()
panesViewState: @panes.children().view()?.serialize()
extensionStates: @serializeExtensions()
fontSize: @getFontSize()
handleEvents: ->
@on 'toggle-dev-tools', => atom.toggleDevTools()
@@ -77,8 +76,15 @@ class RootView extends View
else
@setTitle("untitled")
@command 'window:increase-font-size', => @setFontSize(@getFontSize() + 1)
@command 'window:decrease-font-size', => @setFontSize(@getFontSize() - 1)
@command 'window:increase-font-size', =>
config.editor.fontSize += 1
config.update()
@command 'window:decrease-font-size', =>
if config.editor.fontSize > 1
config.editor.fontSize -= 1
config.update()
@command 'window:focus-next-pane', => @focusNextPane()
@command 'window:save-all', => @saveAll()
@command 'window:toggle-invisibles', =>
@@ -242,12 +248,5 @@ class RootView extends View
@project.destroy()
super
setFontSize: (newFontSize) ->
newFontSize = Math.max(1, newFontSize)
[oldFontSize, @fontSize] = [@fontSize, newFontSize]
@trigger 'font-size-change' if oldFontSize != newFontSize
getFontSize: -> @fontSize
saveAll: ->
editor.save() for editor in @getEditors()