From b8b989a94c36f712d842bbd2ccca1d283fceb2c8 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 14 Feb 2013 09:11:13 -0800 Subject: [PATCH] Use editor.preferredLineLength as default column This config value will be used when no custom column exists for the current path. --- docs/configuring.md | 3 ++- src/packages/wrap-guide/lib/wrap-guide-view.coffee | 9 +++++---- src/packages/wrap-guide/spec/wrap-guide-spec.coffee | 6 +++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/docs/configuring.md b/docs/configuring.md index 86aeed322..24c7aeda4 100644 --- a/docs/configuring.md +++ b/docs/configuring.md @@ -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 diff --git a/src/packages/wrap-guide/lib/wrap-guide-view.coffee b/src/packages/wrap-guide/lib/wrap-guide-view.coffee index 8704cdf7a..491e19705 100644 --- a/src/packages/wrap-guide/lib/wrap-guide-view.coffee +++ b/src/packages/wrap-guide/lib/wrap-guide-view.coffee @@ -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) diff --git a/src/packages/wrap-guide/spec/wrap-guide-spec.coffee b/src/packages/wrap-guide/spec/wrap-guide-spec.coffee index 31fee3f2e..e4df6f356 100644 --- a/src/packages/wrap-guide/spec/wrap-guide-spec.coffee +++ b/src/packages/wrap-guide/spec/wrap-guide-spec.coffee @@ -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)