1 define(function(require) {
7 var _ = require('libs/underscore');
13 fragment: {type: 'context', name: 'fragment'}
17 label: gettext('Create a gap'),
18 execute: function(callback, params) {
19 var doc = params.fragment.document;
21 doc.transaction(function() {
22 var wrapper = params.fragment.startNode.parent().wrapText({
23 _with: {tagName: 'aside', attrs: {'class': 'gap'}},
24 offsetStart: params.fragment.startOffset,
25 offsetEnd: params.fragment.endOffset,
26 textNodeIdx: [params.fragment.startNode.getIndex(), params.fragment.endNode.getIndex()]
28 last = _.last(wrapper.contents());
30 return doc.createFragment(doc.CaretFragment, {node: last, offset: last.getText().length});
33 description: gettext('Create a gap')
39 getState: function(params) {
41 allowed: params.fragment &&
42 params.fragment.isValid() &&
43 params.fragment instanceof params.fragment.TextRangeFragment &&
44 params.fragment.hasSiblingBoundries() &&
45 params.fragment.startNode.isInside('exercise.gap') &&
46 !params.fragment.startNode.isInside({tagName: 'aside', klass: 'gap'}),
48 description: gettext('Turn selection into a gap')
56 fragment: {type: 'context', name: 'fragment'}
60 label: gettext('Remove a gap'),
61 execute: function(callback, params) {
62 var doc = params.fragment.document;
64 doc.transaction(function() {
65 var ret = params.fragment.node.getParent('gap').unwrapContent();
67 return doc.createFragment(doc.CaretFragment, {node:ret.element2, offset: ret.element2.getText().length});
70 description: gettext('Remove a gap')
76 getState: function(params) {
78 allowed: params.fragment &&
79 params.fragment.isValid() &&
80 params.fragment instanceof params.fragment.NodeFragment &&
81 params.fragment.node.isInside('exercise.gap') &&
82 params.fragment.node.isInside('gap'),
84 description: gettext('Remove a gap')
90 return [createGap, removeGap];