mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Scope softWrap, softWrapAtPreferredLineLength, preferredLineLength
`editor.*` config settings
This commit is contained in:
@@ -3769,3 +3769,52 @@ describe "TextEditor", ->
|
||||
editor.setCursorBufferPosition [0, 7]
|
||||
editor.selectWordsContainingCursors()
|
||||
expect(editor.getSelectedBufferRange()).toEqual [[0, 4], [0, 13]]
|
||||
|
||||
describe 'scoped config settings', ->
|
||||
coffeeEditor = null
|
||||
beforeEach ->
|
||||
waitsForPromise ->
|
||||
atom.packages.activatePackage('language-coffee-script')
|
||||
waitsForPromise ->
|
||||
atom.project.open('coffee.coffee', autoIndent: false).then (o) -> coffeeEditor = o
|
||||
|
||||
afterEach: ->
|
||||
atom.packages.deactivatePackages()
|
||||
atom.packages.unloadPackages()
|
||||
|
||||
describe 'soft wrap config settings', ->
|
||||
beforeEach ->
|
||||
atom.config.set '.source.coffee', 'editor.softWrap', true
|
||||
atom.config.set '.source.coffee', 'editor.preferredLineLength', 17
|
||||
atom.config.set '.source.coffee', 'editor.softWrapAtPreferredLineLength', true
|
||||
|
||||
editor.setEditorWidthInChars(20)
|
||||
coffeeEditor.setEditorWidthInChars(20)
|
||||
|
||||
it 'isSoftWrapped() returns true for coffeescript', ->
|
||||
expect(editor.isSoftWrapped()).toBe false
|
||||
expect(coffeeEditor.isSoftWrapped()).toBe true
|
||||
|
||||
it 'correctly wraps coffeescript file', ->
|
||||
expect(editor.lineTextForScreenRow(2)).toEqual ' if (items.length <= 1) return items;'
|
||||
expect(coffeeEditor.lineTextForScreenRow(3)).toEqual ' return items '
|
||||
|
||||
it 'updates the wrapped lines when editor.preferredLineLength changes', ->
|
||||
atom.config.set '.source.coffee', 'editor.preferredLineLength', 20
|
||||
expect(coffeeEditor.lineTextForScreenRow(2)).toEqual ' return items if '
|
||||
|
||||
it 'updates the wrapped lines when editor.softWrapAtPreferredLineLength changes', ->
|
||||
atom.config.set '.source.coffee', 'editor.softWrapAtPreferredLineLength', false
|
||||
expect(coffeeEditor.lineTextForScreenRow(2)).toEqual ' return items if '
|
||||
|
||||
it 'updates the wrapped lines when editor.softWrap changes', ->
|
||||
atom.config.set '.source.coffee', 'editor.softWrap', false
|
||||
expect(coffeeEditor.lineTextForScreenRow(2)).toEqual ' return items if items.length <= 1'
|
||||
|
||||
atom.config.set '.source.coffee', 'editor.softWrap', true
|
||||
expect(coffeeEditor.lineTextForScreenRow(3)).toEqual ' return items '
|
||||
|
||||
it 'updates the wrapped lines when the grammar changes', ->
|
||||
editor.setGrammar(coffeeEditor.getGrammar())
|
||||
expect(editor.isSoftWrapped()).toBe true
|
||||
expect(editor.lineTextForScreenRow(0)).toEqual 'var quicksort = '
|
||||
|
||||
@@ -3,7 +3,7 @@ EmitterMixin = require('emissary').Emitter
|
||||
guid = require 'guid'
|
||||
Serializable = require 'serializable'
|
||||
{Model} = require 'theorist'
|
||||
{Emitter} = require 'event-kit'
|
||||
{CompositeDisposable, Emitter} = require 'event-kit'
|
||||
{Point, Range} = require 'text-buffer'
|
||||
TokenizedBuffer = require './tokenized-buffer'
|
||||
RowMap = require './row-map'
|
||||
@@ -45,7 +45,6 @@ class DisplayBuffer extends Model
|
||||
|
||||
@emitter = new Emitter
|
||||
|
||||
@softWrapped ?= atom.config.get('editor.softWrap') ? false
|
||||
@tokenizedBuffer ?= new TokenizedBuffer({tabLength, buffer, @invisibles})
|
||||
@buffer = @tokenizedBuffer.buffer
|
||||
@charWidthsByScope = {}
|
||||
@@ -56,16 +55,27 @@ class DisplayBuffer extends Model
|
||||
@updateAllScreenLines()
|
||||
@createFoldForMarker(marker) for marker in @buffer.findMarkers(@getFoldMarkerAttributes())
|
||||
@subscribe @tokenizedBuffer.onDidChange @handleTokenizedBufferChange
|
||||
@subscribe @tokenizedBuffer.onDidChangeGrammar @subscribeForSoftWrapConfigChanges
|
||||
@subscribe @buffer.onDidUpdateMarkers @handleBufferMarkersUpdated
|
||||
@subscribe @buffer.onDidCreateMarker @handleBufferMarkerCreated
|
||||
|
||||
@subscribe atom.config.onDidChange 'editor.preferredLineLength', =>
|
||||
@updateWrappedScreenLines() if @isSoftWrapped() and atom.config.get('editor.softWrapAtPreferredLineLength')
|
||||
@subscribeForSoftWrapConfigChanges()
|
||||
@updateAllScreenLines()
|
||||
|
||||
@subscribe atom.config.onDidChange 'editor.softWrapAtPreferredLineLength', =>
|
||||
subscribeForSoftWrapConfigChanges: =>
|
||||
@softWrapConfigSubscriptions?.dispose()
|
||||
@softWrapConfigSubscriptions = new CompositeDisposable
|
||||
|
||||
scopeDescriptor = @getCurrentScopeDescriptor()
|
||||
|
||||
@softWrapConfigSubscriptions.add atom.config.onDidChange scopeDescriptor, 'editor.softWrap', =>
|
||||
@updateWrappedScreenLines()
|
||||
|
||||
@softWrapConfigSubscriptions.add atom.config.onDidChange scopeDescriptor, 'editor.softWrapAtPreferredLineLength', =>
|
||||
@updateWrappedScreenLines() if @isSoftWrapped()
|
||||
|
||||
@updateAllScreenLines()
|
||||
@softWrapConfigSubscriptions.add atom.config.onDidChange scopeDescriptor, 'editor.preferredLineLength', =>
|
||||
@updateWrappedScreenLines() if @isSoftWrapped() and atom.config.get(scopeDescriptor, 'editor.softWrapAtPreferredLineLength')
|
||||
|
||||
serializeParams: ->
|
||||
id: @id
|
||||
@@ -412,11 +422,15 @@ class DisplayBuffer extends Model
|
||||
if softWrapped isnt @softWrapped
|
||||
@softWrapped = softWrapped
|
||||
@updateWrappedScreenLines()
|
||||
@emit 'soft-wrap-changed', @softWrapped
|
||||
@emitter.emit 'did-change-soft-wrapped', @softWrapped
|
||||
@softWrapped
|
||||
softWrapped = @isSoftWrapped()
|
||||
@emit 'soft-wrap-changed', softWrapped
|
||||
@emitter.emit 'did-change-soft-wrapped', softWrapped
|
||||
softWrapped
|
||||
else
|
||||
@isSoftWrapped()
|
||||
|
||||
isSoftWrapped: -> @softWrapped
|
||||
isSoftWrapped: ->
|
||||
@softWrapped ? atom.config.get(@getCurrentScopeDescriptor(), 'editor.softWrap') ? false
|
||||
|
||||
# Set the number of characters that fit horizontally in the editor.
|
||||
#
|
||||
@@ -438,8 +452,8 @@ class DisplayBuffer extends Model
|
||||
@editorWidthInChars
|
||||
|
||||
getSoftWrapColumn: ->
|
||||
if atom.config.get('editor.softWrapAtPreferredLineLength')
|
||||
Math.min(@getEditorWidthInChars(), atom.config.get('editor.preferredLineLength'))
|
||||
if atom.config.get(@getCurrentScopeDescriptor(), 'editor.softWrapAtPreferredLineLength')
|
||||
Math.min(@getEditorWidthInChars(), atom.config.get(@getCurrentScopeDescriptor(), 'editor.preferredLineLength'))
|
||||
else
|
||||
@getEditorWidthInChars()
|
||||
|
||||
@@ -1034,6 +1048,9 @@ class DisplayBuffer extends Model
|
||||
line = @tokenizedLineForScreenRow(row).text
|
||||
console.log row, @bufferRowForScreenRow(row), line, line.length
|
||||
|
||||
getCurrentScopeDescriptor: ->
|
||||
@tokenizedBuffer.grammarScopeDescriptor
|
||||
|
||||
handleTokenizedBufferChange: (tokenizedBufferChange) =>
|
||||
{start, end, delta, bufferChange} = tokenizedBufferChange
|
||||
@updateScreenLines(start, end + 1, delta, delayChangeEvent: bufferChange?)
|
||||
|
||||
Reference in New Issue
Block a user