+
+ return _.extend(state, {
+ allowed: true,
+ description: createParams.wrapDescription,
+ execute: function(callback, params) {
+ params.fragment.document.transaction(function() {
+ var parent = params.fragment.startNode.parent(),
+ doc = params.fragment.document,
+ wrapper, lastTextNode;
+
+ wrapper = parent.wrapText({
+ _with: {tagName: 'span', attrs: {'class': createParams.klass}},
+ offsetStart: params.fragment.startOffset,
+ offsetEnd: params.fragment.endOffset,
+ textNodeIdx: [params.fragment.startNode.getIndex(), params.fragment.endNode.getIndex()]
+ });
+
+ lastTextNode = wrapper.getLastTextNode();
+ if(lastTextNode) {
+ return doc.createFragment(doc.CaretFragment, {node: lastTextNode, offset: lastTextNode.getText().length});
+ }
+ }, {
+ metadata: {
+ description: createParams.wrapDescription
+ },
+ success: callback
+ });
+ }
+ });
+ }
+ return _.extend(state, {allowed: false});