From 9da83a0cb059fa87e0e443b8518f258241fb0eb6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Thu, 27 Mar 2014 14:41:54 +0100 Subject: [PATCH 1/1] editor: Handle invalid element passed to Canvas.setCurrentElement --- src/editor/modules/documentCanvas/canvas/canvas.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/editor/modules/documentCanvas/canvas/canvas.js b/src/editor/modules/documentCanvas/canvas/canvas.js index 663b8a6..6bc5c41 100644 --- a/src/editor/modules/documentCanvas/canvas/canvas.js +++ b/src/editor/modules/documentCanvas/canvas/canvas.js @@ -2,15 +2,17 @@ define([ 'libs/jquery', 'libs/underscore', 'libs/backbone', +'fnpjs/logging/logging', 'modules/documentCanvas/canvas/documentElement', 'modules/documentCanvas/canvas/keyboard', 'modules/documentCanvas/canvas/utils', 'modules/documentCanvas/canvas/wlxmlListener' -], function($, _, Backbone, documentElement, keyboard, utils, wlxmlListener) { +], function($, _, Backbone, logging, documentElement, keyboard, utils, wlxmlListener) { 'use strict'; /* global document:false, window:false, Node:false */ +var logger = logging.getLogger('canvas'); var TextHandler = function(canvas) {this.canvas = canvas; this.buffer = null;}; $.extend(TextHandler.prototype, { @@ -228,13 +230,20 @@ $.extend(Canvas.prototype, { return this.getDocumentElement(this.wrapper.find('.current-text-element')[0]); }, - + contains: function(element) { + return element.dom().parents().index(this.wrapper) !== -1; + }, setCurrentElement: function(element, params) { if(!(element instanceof documentElement.DocumentElement)) { element = utils.findCanvasElement(element); } + if(!element || !this.contains(element)) { + logger.warning('Cannot set current element: element doesn\'t exist on canvas'); + return; + } + params = _.extend({caretTo: 'end'}, params); var findFirstDirectTextChild = function(e, nodeToLand) { var byBrowser = this.getCursor().getPosition().element; -- 2.20.1