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.
This commit is contained in:
Jos van den Oever
2013-05-02 18:33:22 +02:00
parent 9ae5bb99ed
commit 6eaceefa6f
+6
View File
@@ -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);
};
/**