Clicking a fold placeholder removes the associated fold

There are some problems with nested folds that still need to be ironed
out.
This commit is contained in:
Nathan Sobo
2012-02-28 19:46:41 -07:00
parent da53eeb80d
commit 17e78f41ae
3 changed files with 31 additions and 4 deletions

View File

@@ -92,6 +92,10 @@ class Editor extends View
@hiddenInput.focus()
false
@on 'mousedown', '.fold-placeholder', (e) =>
@lineFolder.destroyFoldById($(e.currentTarget).attr('foldId'))
false
@on 'mousedown', (e) =>
clickCount = e.originalEvent.detail
@@ -130,7 +134,7 @@ class Editor extends View
if tokens.length
for token in tokens
if token.type is 'fold-placeholder'
@span ' ', class: 'fold-placeholder', style: "width: #{3 * charWidth}px; height: #{charHeight * .85 }px;", =>
@span ' ', class: 'fold-placeholder', style: "width: #{3 * charWidth}px; height: #{charHeight * .85 }px;", 'foldId': token.fold.id, =>
@div class: "ellipsis", => @raw "…"
else
@span { class: token.type.replace('.', ' ') }, token.value

View File

@@ -7,11 +7,14 @@ EventEmitter = require 'event-emitter'
module.exports =
class LineFolder
activeFolds: null
foldsById: null
lineMap: null
lastHighlighterChangeEvent: null
constructor: (@highlighter) ->
@activeFolds = {}
@foldsById = {}
@buildLineMap()
@highlighter.buffer.on 'change', (e) => @handleBufferChange(e)
@highlighter.on 'change', (e) => @lastHighlighterChangeEvent = e
@@ -57,13 +60,18 @@ class LineFolder
@trigger 'change', oldRange: oldScreenRange, newRange: newScreenRange
@trigger 'unfold', fold.getRange()
destroyFoldById: (foldId) ->
@foldsById[foldId]?.destroy()
registerFold: (bufferRow, fold) ->
@activeFolds[bufferRow] ?= []
@activeFolds[bufferRow].push(fold)
@foldsById[fold.id] = fold
unregisterFold: (bufferRow, fold) ->
folds = @activeFolds[bufferRow]
folds.splice(folds.indexOf(fold), 1)
delete @foldsById[fold.id]
handleBufferChange: (e) ->
for row, folds of @activeFolds
@@ -102,7 +110,7 @@ class LineFolder
screenLine
buildFoldPlaceholder: (fold) ->
new ScreenLineFragment([{value: '...', type: 'fold-placeholder'}], '...', [0, 3], fold.getRange().toDelta(), isAtomic: true)
new ScreenLineFragment([{value: '...', type: 'fold-placeholder', fold}], '...', [0, 3], fold.getRange().toDelta(), isAtomic: true)
foldsForBufferRow: (bufferRow) ->
@activeFolds[bufferRow] or []
@@ -150,7 +158,10 @@ class LineFolder
_.extend LineFolder.prototype, EventEmitter
class Fold
@idCounter: 1
constructor: (@lineFolder, {@start, @end}) ->
@id = @constructor.idCounter++
destroy: ->
@lineFolder.destroyFold(this)