Skip to content

Instantly share code, notes, and snippets.

@jessegrosjean
Forked from dohzya/main.js
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jessegrosjean/6c592493ea21d7279324 to your computer and use it in GitHub Desktop.
Save jessegrosjean/6c592493ea21d7279324 to your computer and use it in GitHub Desktop.
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'
});
});
});
- 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