From 7506fe7eae2dedb4e2dc8ca387bec006eb43fc2b Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Sat, 29 Sep 2012 11:51:32 -0700 Subject: [PATCH] Provide default column to getGuideColumn callback --- spec/extensions/wrap-guide-spec.coffee | 12 +++++++++++- src/extensions/wrap-guide/wrap-guide.coffee | 5 +++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/spec/extensions/wrap-guide-spec.coffee b/spec/extensions/wrap-guide-spec.coffee index 28d2c1649..0aef8f95e 100644 --- a/spec/extensions/wrap-guide-spec.coffee +++ b/spec/extensions/wrap-guide-spec.coffee @@ -24,7 +24,7 @@ describe "WrapGuide", -> describe "@updateGuide", -> it "positions the guide at the configured column", -> - width = editor.charWidth * wrapGuide.getGuideColumn() + width = editor.charWidth * wrapGuide.defaultColumn expect(width).toBeGreaterThan(0) expect(wrapGuide.position().left).toBe(width) @@ -44,6 +44,16 @@ describe "WrapGuide", -> wrapGuide.updateGuide(editor) expect(editorPath).toBe(require.resolve('fixtures/sample.js')) + it "invokes the callback with a default value", -> + column = null + wrapGuide.getGuideColumn = (path, defaultColumn) -> + editorPath = path + column = defaultColumn + defaultColumn + + wrapGuide.updateGuide(editor) + expect(column).toBeGreaterThan(0) + it "uses the function from the config data", -> rootView.find('.wrap-guide').remove() config = diff --git a/src/extensions/wrap-guide/wrap-guide.coffee b/src/extensions/wrap-guide/wrap-guide.coffee index c21b99efa..1a585e3f8 100644 --- a/src/extensions/wrap-guide/wrap-guide.coffee +++ b/src/extensions/wrap-guide/wrap-guide.coffee @@ -20,19 +20,20 @@ class WrapGuide extends View @div class: 'wrap-guide' getGuideColumn: null + defaultColumn: 80 initialize: (@rootView, @editor, config = {}) => if typeof config.getGuideColumn is 'function' @getGuideColumn = config.getGuideColumn else - @getGuideColumn = -> 80 + @getGuideColumn = (path, defaultColumn) -> defaultColumn @updateGuide(@editor) @editor.on 'editor-path-change', => @updateGuide(@editor) @rootView.on 'font-size-change', => @updateGuide(@editor) updateGuide: (editor) -> - column = @getGuideColumn(editor.getPath()) + column = @getGuideColumn(editor.getPath(), @defaultColumn) if column > 0 @css('left', "#{editor.charWidth * column}px").show() else