From 739242f6208f3e58570194fb1000086bafd527ef Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Wed, 7 Aug 2013 10:04:09 +0200 Subject: [PATCH] Allow for creating footnote from selected text --- modules/documentCanvas/commands.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) 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); }); -- 2.20.1