Skip to content

Commit

Permalink
A nearly working fold-completed implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mlms13 committed Jun 26, 2015
1 parent 72f5f74 commit 4f20cbe
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions keymaps/tasks.cson
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
'cmd-enter': 'tasks:add'
'cmd-shift-enter': 'tasks:add-above'
'cmd-d': 'tasks:complete'
'cmd-shift-d': 'tasks:fold-completed'
'cmd-shift-a': 'tasks:archive'
'ctrl-c': 'tasks:cancel'

Expand Down
35 changes: 35 additions & 0 deletions lib/tasks.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ module.exports =
"tasks:update-timestamps": => @tasksUpdateTimestamp()
"tasks:cancel": => @cancelTask()
"tasks:convert-to-task": => @convertToTask()
"tasks:fold-completed": => @tasksFold()



Expand Down Expand Up @@ -284,6 +285,40 @@ module.exports =
tasks.setMarker editor, row, marker


###*
* Helper for triggering code folding
* for completed and cancelled tasks
###
tasksFold: ->
editor = atom.workspace.getActiveTextEditor()
return if not editor

editor.transact ->

completedTasks = []
archiveProject = null

# 1. Find the archives section, if it exists

editor.displayBuffer.tokenizedBuffer.tokenizedLines.every (i, ind)->
# if we already found the archive, no need
# to parse any more!
return false if archiveProject
hasDone = tasks.getToken i.tokens, tasks.doneSelector
hasCancelled = tasks.getToken i.tokens, tasks.cancelledSelector
hasArchive = tasks.getToken i.tokens, tasks.archiveSelector

el =
lineNumber: ind
line: i

archiveProject = el if hasArchive
completedTasks.push el if hasDone or hasCancelled
true

# 2. move cursor through each completed task and fold there
completedTasks.forEach (i)->
editor.foldBufferRow i.lineNumber

###*
* Helper for handling the archiving of
Expand Down

0 comments on commit 4f20cbe

Please sign in to comment.