mirror of
https://github.com/atom/atom.git
synced 2026-01-15 01:48:15 -05:00
Use editor.preferredLineLength as default column
This config value will be used when no custom column exists for the current path.
This commit is contained in:
@@ -40,7 +40,8 @@ its own namespace.
|
||||
- stripTrailingWhitespace
|
||||
- singleTrailingNewline: Whether to reduce multiple newlines to one at the end of files
|
||||
- wrapGuide
|
||||
- columns: Soon to be replaced by editor.preferredLineLength
|
||||
- columns: Array of hashes with a `pattern` and `column` key to match the
|
||||
the path of the current editor to a column position.
|
||||
|
||||
## Reading Config Settings
|
||||
|
||||
|
||||
@@ -11,23 +11,24 @@ class WrapGuideView extends View
|
||||
@content: ->
|
||||
@div class: 'wrap-guide'
|
||||
|
||||
defaultColumn: 80
|
||||
|
||||
initialize: (@editor) ->
|
||||
@observeConfig 'editor.fontSize', => @updateGuide()
|
||||
@subscribe @editor, 'editor:path-changed', => @updateGuide()
|
||||
@subscribe @editor, 'editor:min-width-changed', => @updateGuide()
|
||||
@subscribe $(window), 'resize', => @updateGuide()
|
||||
|
||||
getDefaultColumn: ->
|
||||
config.get('editor.preferredLineLength') ? 80
|
||||
|
||||
getGuideColumn: (path) ->
|
||||
customColumns = config.get('wrapGuide.columns')
|
||||
return @defaultColumn unless _.isArray(customColumns)
|
||||
return @getDefaultColumn() unless _.isArray(customColumns)
|
||||
for customColumn in customColumns
|
||||
continue unless _.isObject(customColumn)
|
||||
pattern = customColumn['pattern']
|
||||
continue unless pattern
|
||||
return parseInt(customColumn['column']) if new RegExp(pattern).test(path)
|
||||
@defaultColumn
|
||||
@getDefaultColumn()
|
||||
|
||||
updateGuide: ->
|
||||
column = @getGuideColumn(@editor.getPath(), @defaultColumn)
|
||||
|
||||
@@ -9,7 +9,7 @@ describe "WrapGuide", ->
|
||||
rootView.attachToDom()
|
||||
editor = rootView.getActiveEditor()
|
||||
wrapGuide = rootView.find('.wrap-guide').view()
|
||||
editor.width(editor.charWidth * wrapGuide.defaultColumn * 2)
|
||||
editor.width(editor.charWidth * wrapGuide.getDefaultColumn() * 2)
|
||||
|
||||
afterEach ->
|
||||
rootView.deactivate()
|
||||
@@ -24,7 +24,7 @@ describe "WrapGuide", ->
|
||||
|
||||
describe "@updateGuide", ->
|
||||
it "positions the guide at the configured column", ->
|
||||
width = editor.charWidth * wrapGuide.defaultColumn
|
||||
width = editor.charWidth * wrapGuide.getDefaultColumn()
|
||||
expect(width).toBeGreaterThan(0)
|
||||
expect(wrapGuide.position().left).toBe(width)
|
||||
expect(wrapGuide).toBeVisible()
|
||||
@@ -48,7 +48,7 @@ describe "WrapGuide", ->
|
||||
it "uses the default column when no custom column matches the path", ->
|
||||
config.set('wrapGuide.columns', [{pattern: '\.jsp$', column: '100'}])
|
||||
wrapGuide.updateGuide()
|
||||
width = editor.charWidth * wrapGuide.defaultColumn
|
||||
width = editor.charWidth * wrapGuide.getDefaultColumn()
|
||||
expect(width).toBeGreaterThan(0)
|
||||
expect(wrapGuide.position().left).toBe(width)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user