mirror of
https://github.com/atom/atom.git
synced 2026-02-08 21:55:05 -05:00
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:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user