From: Aleksander Ɓukasz Date: Wed, 7 Aug 2013 08:04:09 +0000 (+0200) Subject: Allow for creating footnote from selected text X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/739242f6208f3e58570194fb1000086bafd527ef?hp=39f08569a5e595a7622b8bb4ab27dbfcab502c62 Allow for creating footnote from selected text --- diff --git a/modules/documentCanvas/commands.js b/modules/documentCanvas/commands.js index bb86991..8152ccd 100644 --- a/modules/documentCanvas/commands.js +++ b/modules/documentCanvas/commands.js @@ -1,6 +1,6 @@ define([ - -], function() { +'modules/documentCanvas/canvas/documentElement' +], function(documentElement) { 'use strict'; @@ -113,11 +113,18 @@ commands.register('newNodeRequested', function(canvas, params) { }); commands.register('footnote', function(canvas, params) { - var position = canvas.getCursor().getPosition(); + var cursor = canvas.getCursor(), + position = cursor.getPosition(), + asideElement; + - var asideElement = position.element.divide({tag: 'aside', klass: 'footnote', offset: position.offset}); + if(cursor.isSelectingWithinElement()) { + asideElement = position.element.wrapWithNodeElement({tag: 'aside', klass: 'footnote', start: cursor.getSelectionStart().offset, end: cursor.getSelectionEnd().offset}); + } else { + asideElement = position.element.divide({tag: 'aside', klass: 'footnote', offset: position.offset}); + asideElement.append({text: ''}); + } - asideElement.append({text: ''}); asideElement.toggle(true); canvas.setCurrentElement(asideElement); });