From 6eaceefa6feb62b6727d98bc7b2dc4e0b4fbfa99 Mon Sep 17 00:00:00 2001 From: Jos van den Oever Date: Thu, 2 May 2013 18:33:22 +0200 Subject: [PATCH] Fix selection problem that occurs in cursor movement by clicking. Sometimes a selection would appear when the cursor was moved by clicking. This is fixed by explicitly collapsing the selection which effectively makes it invisible. In addition the onmouseup event is also registered to move the cursor. The onclick event does not suffice to catch all user actions intended to move the cursor. --- webodf/lib/gui/SessionController.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/webodf/lib/gui/SessionController.js b/webodf/lib/gui/SessionController.js index 36b6c10a..5548e6b2 100644 --- a/webodf/lib/gui/SessionController.js +++ b/webodf/lib/gui/SessionController.js @@ -84,6 +84,7 @@ gui.SessionController = (function () { * @param {!Event} e */ function dummyHandler(e) { + // runtime.log("ignore event " + e.type); cancelEvent(e); } @@ -102,6 +103,9 @@ gui.SessionController = (function () { // not belonging to a cursor, like e.g. the caret and the cursor // avatarflag are. node = selection.focusNode; + if (!node) { + return; + } while (node !== canvasElement) { if (node.namespaceURI === 'urn:webodf:names:cursor' && node.localName === 'cursor') { return; @@ -111,6 +115,7 @@ gui.SessionController = (function () { // create a move op with the distance to that position steps = odtDocument.getDistanceFromCursor(inputMemberId, selection.focusNode, selection.focusOffset); + selection.collapse(); if (steps !== 0) { op = new ops.OpMoveCursor(); @@ -320,6 +325,7 @@ gui.SessionController = (function () { listenEvent(canvasElement, "cut", dummyHandler); listenEvent(canvasElement, "paste", dummyHandler); listenEvent(canvasElement, "click", handleMouseClick); + listenEvent(canvasElement, "mouseup", handleMouseClick); }; /**