diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 4e9e97cb0..446a82b1b 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -759,6 +759,7 @@ class Editor extends View @underlayer.css('min-width', minWidth) @overlayer.css('min-width', minWidth) @layerMinWidth = minWidth + @trigger 'editor:min-width-changed' clearRenderedLines: -> @renderedLines.empty() diff --git a/src/packages/wrap-guide/spec/wrap-guide-spec.coffee b/src/packages/wrap-guide/spec/wrap-guide-spec.coffee index 82129d6dd..1bc562624 100644 --- a/src/packages/wrap-guide/spec/wrap-guide-spec.coffee +++ b/src/packages/wrap-guide/spec/wrap-guide-spec.coffee @@ -10,6 +10,7 @@ describe "WrapGuide", -> rootView.attachToDom() editor = rootView.getActiveEditor() wrapGuide = rootView.find('.wrap-guide').view() + editor.width(editor.charWidth * wrapGuide.defaultColumn * 2) afterEach -> rootView.deactivate() @@ -27,6 +28,7 @@ describe "WrapGuide", -> width = editor.charWidth * wrapGuide.defaultColumn expect(width).toBeGreaterThan(0) expect(wrapGuide.position().left).toBe(width) + expect(wrapGuide).toBeVisible() describe "when the font size changes", -> it "updates the wrap guide position", -> @@ -34,6 +36,7 @@ describe "WrapGuide", -> expect(initial).toBeGreaterThan(0) rootView.trigger('window:increase-font-size') expect(wrapGuide.position().left).toBeGreaterThan(initial) + expect(wrapGuide).toBeVisible() describe "overriding getGuideColumn", -> it "invokes the callback with the editor path", -> @@ -41,7 +44,7 @@ describe "WrapGuide", -> wrapGuide.getGuideColumn = (path) -> editorPath = path 80 - wrapGuide.updateGuide(editor) + wrapGuide.updateGuide() expect(editorPath).toBe(require.resolve('fixtures/sample.js')) it "invokes the callback with a default value", -> @@ -51,7 +54,7 @@ describe "WrapGuide", -> column = defaultColumn defaultColumn - wrapGuide.updateGuide(editor) + wrapGuide.updateGuide() expect(column).toBeGreaterThan(0) # this is disabled because we no longer support passing config to an extension @@ -68,5 +71,11 @@ describe "WrapGuide", -> it "hides the guide when the column is less than 1", -> wrapGuide.getGuideColumn = (path) -> -1 - wrapGuide.updateGuide(editor) + wrapGuide.updateGuide() + expect(wrapGuide).toBeHidden() + + describe "when no lines exceed the guide column and the editor width is smaller than the guide column position", -> + it "hides the guide", -> + editor.width(10) + wrapGuide.updateGuide() expect(wrapGuide).toBeHidden() diff --git a/src/packages/wrap-guide/src/wrap-guide.coffee b/src/packages/wrap-guide/src/wrap-guide.coffee index 752443e95..8442cc736 100644 --- a/src/packages/wrap-guide/src/wrap-guide.coffee +++ b/src/packages/wrap-guide/src/wrap-guide.coffee @@ -1,4 +1,5 @@ {View} = require 'space-pen' +$ = require 'jquery' module.exports = class WrapGuide extends View @@ -28,13 +29,18 @@ class WrapGuide extends View else @getGuideColumn = (path, defaultColumn) -> defaultColumn - @observeConfig 'editor.fontSize', => @updateGuide(@editor) - @subscribe @editor, 'editor-path-change', => @updateGuide(@editor) - @subscribe @editor, 'before-remove', => @rootView.off('.wrap-guide') + @observeConfig 'editor.fontSize', => @updateGuide() + @subscribe @editor, 'editor-path-change', => @updateGuide() + @subscribe @editor, 'editor:min-width-changed', => @updateGuide() + @subscribe $(window), 'resize', => @updateGuide() - updateGuide: (editor) -> - column = @getGuideColumn(editor.getPath(), @defaultColumn) + updateGuide: -> + column = @getGuideColumn(@editor.getPath(), @defaultColumn) if column > 0 - @css('left', "#{editor.charWidth * column}px").show() + columnWidth = @editor.charWidth * column + if columnWidth < @editor.layerMinWidth or columnWidth < @editor.width() + @css('left', "#{columnWidth}px").show() + else + @hide() else @hide()