Skip to content
Open
9 changes: 1 addition & 8 deletions lib/Toc.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ class Toc
updateOnSave: 1 # updateOnSave
orderedList: 0 # orderedList

at = @
@editor.getBuffer().onWillSave () ->
if at.options.updateOnSave is 1
if at._hasToc()
at._deleteToc()
at.editor.setTextInBufferRange [[at.open,0], [at.open,0]], at._createToc()


# ----------------------------------------------------------------------------
# main methods (highest logic level)
Expand All @@ -45,7 +38,7 @@ class Toc


autosave: ->
if @_hasToc()
if @_hasToc() && @.options.updateOnSave is 1
@_deleteToc()
@editor.setTextInBufferRange [[@open,0], [@open,0]], @_createToc()

Expand Down
36 changes: 25 additions & 11 deletions lib/markdown-toc.coffee
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
Toc = require './Toc'

module.exports =
atom.workspace.observeTextEditors (editor) ->
if atom.config.get('markdown-toc.automatically-update')
@toc = new Toc(editor)
@toc.autosave()

editor.onDidSave () ->
if atom.config.get('markdown-toc.automatically-update')
@toc = new Toc(editor)
@toc.autosave()

module.exports =
config:
'automatically-update':
title: 'Automatically update TOC',
type: 'boolean'
default: false
activate: (state) ->
atom.commands.add 'atom-workspace', 'markdown-toc:create': =>
@toc = new Toc(atom.workspace.getActivePaneItem())
@toc.create()
@toc = new Toc(atom.workspace.getActivePaneItem())
@toc.create()
atom.commands.add 'atom-workspace', 'markdown-toc:update': =>
@toc = new Toc(atom.workspace.getActivePaneItem())
@toc.update()
@toc = new Toc(atom.workspace.getActivePaneItem())
@toc.update()
atom.commands.add 'atom-workspace', 'markdown-toc:delete': =>
@toc = new Toc(atom.workspace.getActivePaneItem());
@toc.delete()
@toc = new Toc(atom.workspace.getActivePaneItem());
@toc.delete()
atom.commands.add 'atom-workspace', 'markdown-toc:toggle': =>
@toc = new Toc(atom.workspace.getActivePaneItem())
@toc.toggle()
@toc = new Toc(atom.workspace.getActivePaneItem())
@toc.toggle()

# deactivate: ->
# @toc.destroy()
# deactivate: ->
# @toc.destroy()
8 changes: 0 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@
"main": "./lib/markdown-toc",
"version": "0.4.1",
"description": "Generate TOC (table of contents) of headlines from parsed markdown file",
"activationCommands": {
"atom-workspace": [
"markdown-toc:toggle",
"markdown-toc:create",
"markdown-toc:update",
"markdown-toc:delete"
]
},
"repository": {
"type": "git",
"url": "https://github.com/nok/markdown-toc"
Expand Down