X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/e6993e4bfe0e5fd38ccf554da489b5af3625c2fb..232e5bd6f1b93f27e227a291b7913867e7d76be7:/src/editor/plugins/core/switch.js diff --git a/src/editor/plugins/core/switch.js b/src/editor/plugins/core/switch.js index 2730761..9b34721 100644 --- a/src/editor/plugins/core/switch.js +++ b/src/editor/plugins/core/switch.js @@ -32,7 +32,8 @@ var createSwitchAction = function(createParams) { var node = f instanceof f.CaretFragment ? f.node.parent() : f.getCommonParent(), alreadyInTarget = node.isInside(createParams.to), - toSwitch = node; + toSwitch = node, + textNodePath = (f.node || f.startNode).getPath(); if(!toSwitch.is(createParams.from)) { toSwitch = toSwitch.getParent(createParams.from); @@ -43,7 +44,7 @@ var createSwitchAction = function(createParams) { allowed: !!toSwitch, toggled: alreadyInTarget, description: description, - execute: alreadyInTarget ? function() {} : function() { + execute: alreadyInTarget ? function() {} : function(callback) { f.document.transaction(function() { if(createParams.to.tagName) { toSwitch = toSwitch.setTag(createParams.to.tagName); @@ -51,10 +52,12 @@ var createSwitchAction = function(createParams) { if(!_.isUndefined(createParams.to.klass)) { toSwitch.setClass(createParams.to.klass); } + return f.document.createFragment(f.CaretFragment, {node: f.document.getNodeByPath(textNodePath), offset: f.offset}); }, { metadata: { description: description - } + }, + success: callback }); } }); @@ -62,12 +65,25 @@ var createSwitchAction = function(createParams) { }; }; +var headerAction = createSwitchAction({name: 'switchToHeader', from: {tagName: 'div', klass: 'p'}, to: {tagName: 'header', klass: '', name: gettext('header')}}), + paragraphAction = createSwitchAction({name: 'switchToParagraph', from: {tagName: 'header'}, to: {tagName: 'div', klass: 'p', name: gettext('paragraf')}}); return { - actions: [ - createSwitchAction({name: 'switchToHeader', from: {tagName: 'div', klass: 'p'}, to: {tagName: 'header', klass: '', name: gettext('header')}}), - createSwitchAction({name: 'switchToParagraph', from: {tagName: 'header'}, to: {tagName: 'div', klass: 'p', name: gettext('paragraf')}}) - ] + actions: [headerAction, paragraphAction], + canvasActionHandler: { + handles: [headerAction, paragraphAction], + // handle: function(canvas, action, ret) { + // var params = {}, + // f; + // if(ret && ret.node2) { + // f = ret.oldFragment; + // if(f && f instanceof f.CaretFragment) { + // params.caretTo = f.offset; + // } + // canvas.setCurrentElement(ret.node2, params); + // } + // } + } }; }); \ No newline at end of file