Fix exception when trying to fold non-foldable row

This commit is contained in:
Max Brunsfeld 2017-10-23 10:20:45 -07:00
parent 43ec5193ff
commit 8d532e7780
2 changed files with 22 additions and 2 deletions

View File

@ -173,6 +173,26 @@ describe('TextEditor', () => {
})
})
describe('.foldCurrentRow()', () => {
it('creates a fold at the location of the last cursor', async () => {
editor = await atom.workspace.open()
editor.setText('\nif (x) {\n y()\n}')
editor.setCursorBufferPosition([1, 0])
expect(editor.getScreenLineCount()).toBe(4)
editor.foldCurrentRow()
expect(editor.getScreenLineCount()).toBe(3)
})
it('does nothing when the current row cannot be folded', async () => {
editor = await atom.workspace.open()
editor.setText('var x;\nx++\nx++')
editor.setCursorBufferPosition([0, 0])
expect(editor.getScreenLineCount()).toBe(3)
editor.foldCurrentRow()
expect(editor.getScreenLineCount()).toBe(3)
})
})
describe('.foldAllAtIndentLevel(indentLevel)', () => {
it('folds blocks of text at the given indentation level', async () => {
editor = await atom.workspace.open('sample.js', {autoIndent: false})

View File

@ -3310,8 +3310,8 @@ class TextEditor extends Model
# level.
foldCurrentRow: ->
{row} = @getCursorBufferPosition()
range = @tokenizedBuffer.getFoldableRangeContainingPoint(Point(row, Infinity))
@displayLayer.foldBufferRange(range)
if range = @tokenizedBuffer.getFoldableRangeContainingPoint(Point(row, Infinity))
@displayLayer.foldBufferRange(range)
# Essential: Unfold the most recent cursor's row by one level.
unfoldCurrentRow: ->