From 7336e8313c1c6122ea2e7df0bb8af142eb474fb6 Mon Sep 17 00:00:00 2001 From: Corey Johnson & Nathan Sobo Date: Fri, 16 Mar 2012 14:35:07 -0700 Subject: [PATCH] Folds can be created on the penultimate screen line of a wrapped buffer line --- spec/atom/renderer-spec.coffee | 26 +++++++++++++++++++++++++- src/atom/renderer.coffee | 14 +++++++------- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/spec/atom/renderer-spec.coffee b/spec/atom/renderer-spec.coffee index 8c8904e8f..74e354a74 100644 --- a/spec/atom/renderer-spec.coffee +++ b/spec/atom/renderer-spec.coffee @@ -42,7 +42,7 @@ describe "Renderer", -> expect(renderer.lineForRow(3).text).toBe ' var pivot = items.shift(), current, left = [], ' expect(renderer.lineForRow(4).text).toBe 'right = [];' - describe "when a fold is created on the second screen line of a wrapped buffer line", -> + describe "when a fold is created on the last screen line of a wrapped buffer line", -> it "inserts the placeholder in the correct location and fires a change event", -> fold = renderer.createFold([[3, 52], [3, 56]]) expect(renderer.lineForRow(3).text).toBe ' var pivot = items.shift(), current, left = [], ' @@ -62,6 +62,30 @@ describe "Renderer", -> expect(event.oldRange).toEqual([[3, 0], [4, 10]]) expect(event.newRange).toEqual([[3, 0], [4, 11]]) + describe "when a fold is created on the penultimate screen line of a wrapped buffer line", -> + beforeEach -> + renderer.setMaxLineLength(36) + changeHandler.reset() + + it "inserts the placeholder in the correct location and fires a change event", -> + fold = renderer.createFold([[6, 29], [6, 33]]) + expect(renderer.lineForRow(8).text).toBe " current < pivot ? " + expect(renderer.lineForRow(9).text).toBe "left....(current) : " + expect(renderer.lineForRow(10).text).toBe "right.push(current);" + + expect(changeHandler).toHaveBeenCalled() + [[event]]= changeHandler.argsForCall + expect(event.oldRange).toEqual([[8, 0], [10, 20]]) + expect(event.newRange).toEqual([[8, 0], [10, 20]]) + + changeHandler.reset() + fold.destroy() + + expect(changeHandler).toHaveBeenCalled() + [[event]]= changeHandler.argsForCall + expect(event.oldRange).toEqual([[8, 0], [10, 20]]) + expect(event.newRange).toEqual([[8, 0], [10, 20]]) + describe "when there is a fold placeholder straddling the max length boundary", -> it "wraps the line before the fold placeholder", -> renderer.createFold([[3, 49], [6, 1]]) diff --git a/src/atom/renderer.coffee b/src/atom/renderer.coffee index 8f09e15c7..770643807 100644 --- a/src/atom/renderer.coffee +++ b/src/atom/renderer.coffee @@ -135,7 +135,7 @@ class Renderer @buildLinesForBufferRows(bufferRow, bufferRow) buildLinesForBufferRows: (startRow, endRow) -> - buildLinesForBufferRows = (startRow, endRow, startColumn, currentScreenLineLength=0) => + recursiveBuildLinesForBufferRows = (startRow, endRow, startColumn, currentScreenLineLength=0) => return [] if startRow > endRow and not startColumn? startColumn ?= 0 @@ -145,23 +145,23 @@ class Renderer for fold in @foldsForBufferRow(startRow) if fold.start.column >= startColumn - if fold.start.column > wrapColumn - foldPlaceholderLength - wrapColumn = Math.min(wrapColumn, fold.start.column) + if (fold.start.column - startColumn) > wrapColumn - foldPlaceholderLength + wrapColumn = Math.min(wrapColumn, fold.start.column - startColumn) break prefix = line.splitAt(fold.start.column - startColumn)[0] placeholder = @buildFoldPlaceholder(fold) currentScreenLineLength = currentScreenLineLength + (prefix?.text.length ? 0) + foldPlaceholderLength - suffix = buildLinesForBufferRows(fold.end.row, endRow, fold.end.column, currentScreenLineLength) + suffix = recursiveBuildLinesForBufferRows(fold.end.row, endRow, fold.end.column, currentScreenLineLength) return _.compact _.flatten [prefix, placeholder, suffix] if wrapColumn? line = line.splitAt(wrapColumn)[0] line.screenDelta = new Point(1, 0) - [line].concat buildLinesForBufferRows(startRow, endRow, startColumn + wrapColumn) + [line].concat recursiveBuildLinesForBufferRows(startRow, endRow, startColumn + wrapColumn) else - [line].concat buildLinesForBufferRows(startRow + 1, endRow) + [line].concat recursiveBuildLinesForBufferRows(startRow + 1, endRow) - buildLinesForBufferRows(@foldStartRowForBufferRow(startRow), endRow) + recursiveBuildLinesForBufferRows(@foldStartRowForBufferRow(startRow), endRow) foldStartRowForBufferRow: (bufferRow) -> @bufferRowForScreenRow(@screenRowForBufferRow(bufferRow))