mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-11 04:48:44 +03:00
Only show wrap guide when enough space
Previously the wrap guide would cause the editor to scroll if the editor was narrower than the wrap guide column without taking into account whether any lines actually reach the guide. Now the wrap guide only displays when either the wrap guide column is less than the minimum width of the editor layer or if the wrap guide column is less than the entire width of the editor.
This commit is contained in:
parent
ab407a297a
commit
a9b9c09a86
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user