return new Selection(this);
},
+ select: function(fragment) {
+ if(fragment instanceof this.wlxmlDocument.RangeFragment) {
+ this.setCurrentElement(fragment.endNode, {caretTo: fragment.endOffset});
+ } else if(fragment instanceof this.wlxmlDocument.NodeFragment) {
+ var params = {
+ caretTo: fragment instanceof this.wlxmlDocument.CaretFragment ? fragment.offset : 'start'
+ };
+ this.setCurrentElement(fragment.node, params);
+ } else {
+ logger.debug('Fragment not supported');
+ }
+ },
+
setCurrentElement: function(element, params) {
if(!element) {
logger.debug('Invalid element passed to setCurrentElement: ' + element);
onAfterActionExecuted: function(action, ret) {
if(ret && ret.isValid()) {
logger.debug('The action returned a valid fragment');
- if(ret instanceof canvas.wlxmlDocument.RangeFragment) {
- canvas.setCurrentElement(ret.endNode, {caretTo: ret.endOffset});
- } else if(ret instanceof canvas.wlxmlDocument.NodeFragment) {
- var params = {
- caretTo: ret instanceof canvas.wlxmlDocument.CaretFragment ? ret.offset : 'start'
- };
- canvas.setCurrentElement(ret.node, params);
- } else {
- logger.debug('Fragment not supported');
- }
- return;
+ return canvas.select(ret);
}
+
logger.debug('No valid fragment returned from the action');
(actionHandlers[action.getPluginName()] || []).forEach(function(handler) {
return newFragment;
}, {
metadata: {
- description: createParams.unwrapDescription
+ description: createParams.unwrapDescription,
+ fragment: params.fragment
},
success: callback
});
}
}, {
metadata: {
- description: createParams.wrapDescription
+ description: createParams.wrapDescription,
+ fragment: params.fragment
},
success: callback
});
return doc.createFragment(doc.CaretFragment, {node: span.contents()[0], offset:0});
}, {
metadata: {
- description: action.getState().description
+ description: action.getState().description,
+ fragment: params.fragment
},
success: callback
});
return params.fragment;
}, {
metadata: {
- description: action.getState().description
+ description: action.getState().description,
+ fragment: params.fragment
},
success: callback
});
changeLink: function(e) {
var el = this,
+ doc = this.wlxmlNode.document,
dialog = Dialog.create({
title: gettext('Edit link'),
executeButtonText: gettext('Apply'),
event.success();
}, {
metadata: {
- description: gettext('Edit link')
+ description: gettext('Edit link'),
+ fragment: doc.createFragment(doc.CaretFragment, {node: el.wlxmlNode.contents()[0], offset:0})
}
});
});
},
deleteLink: function() {
- var el = this;
+ var el = this,
+ doc = this.wlxmlNode.document;
+
el.wlxmlNode.document.transaction(function() {
el.wlxmlNode.unwrapContent();
}, {
metadata: {
- description: gettext('Remove link')
+ description: gettext('Remove link'),
+ fragment: doc.createFragment(doc.CaretFragment, {node: el.wlxmlNode.contents()[0], offset:0})
}
});
},
return doc.createFragment(doc.CaretFragment, {node: text, offset:0});
}, {
metadata: {
- description: action.getState().description
+ description: action.getState().description,
+ fragment: params.fragment
},
success: callback
});
return toret;
}, {
metadata: {
- description: action.getState().description
+ description: action.getState().description,
+ fragment: params.fragment
},
success: callback
});
}
}, {
metadata: {
- description: action.getState().description
+ description: action.getState().description,
+ fragment: params.fragment
},
success: callback
});
return f.document.createFragment(f.CaretFragment, {node: f.document.getNodeByPath(textNodePath), offset: f.offset});
}, {
metadata: {
- description: description
+ description: description,
+ fragment: params.fragment
},
success: callback
});