-
-
Save jessegrosjean/6c592493ea21d7279324 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(function (require, exports, module) { | |
'use strict'; | |
var Extensions = require('ft/core/extensions').Extensions; | |
function test(editor, options, tagName) { | |
var collapseNodes = []; | |
function fun(node) { | |
var infos; | |
if (node.firstChild && node.firstChild.line().trim() == ":INFOS:") { | |
infos = node.firstChild; | |
} else { | |
infos = node.tree.createNode(":INFOS:"); | |
node.insertChildBefore(infos, node.firstChild) | |
} | |
var child = infos.tree.createNode("ADDED LINE"); | |
infos.insertChildBefore(child, infos.firstChild); | |
collapseNodes.push(node); | |
} | |
var tree = editor.tree(), | |
node; | |
if (options && options.node) { | |
node = options.node; | |
} else { | |
node = editor.selectedRange().startNode; | |
} | |
tree.beginUpdates(); | |
fun(node); | |
tree.endUpdates(); | |
collapseNodes.forEach(function (each) { | |
editor.collapseNode(each); | |
}); | |
} | |
Extensions.addCommand({ | |
name: 'test', | |
description: 'Test', | |
performCommand: function (editor, options) { | |
test(editor, options); | |
} | |
}); | |
Extensions.addInit(function (editor) { | |
editor.addKeyMap({ | |
'Cmd-Alt-D' : 'test' | |
}); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- blah | |
- item | |
- blah | |
Put your cursor on `item` then press Cmd-Alt-D | |
I used `editor.collapseNode(infos);` at line 36, which is not in the API :-/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment