From 5dfd3438d1f6924ab8d9b3e4e007ec573fba03fb Mon Sep 17 00:00:00 2001 From: Aditya Bhatt Date: Wed, 4 Dec 2013 15:28:53 +0100 Subject: [PATCH] * Add moveCursor flag to OpSplitParagraph. * Adapt places where OpSplitParagraph is initialized to also add the moveCursor flag. * Let SplitParagraph vs SplitParagraph execute normally at the same position. --- webodf/lib/gui/PlainTextPasteboard.js | 3 ++- webodf/lib/gui/TextManipulator.js | 3 ++- webodf/lib/ops/OpSplitParagraph.js | 22 ++++++++++++++++++---- webodf/lib/ops/OperationTransformMatrix.js | 2 -- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/webodf/lib/gui/PlainTextPasteboard.js b/webodf/lib/gui/PlainTextPasteboard.js index 3ebd1de8..15364f1e 100644 --- a/webodf/lib/gui/PlainTextPasteboard.js +++ b/webodf/lib/gui/PlainTextPasteboard.js @@ -66,7 +66,8 @@ gui.PlainTextPasteboard = function PlainTextPasteboard(odtDocument, inputMemberI paragraphs.forEach(function(text) { operations.push(createOp(new ops.OpSplitParagraph(), { memberid: inputMemberId, - position: cursorPosition + position: cursorPosition, + moveCursor: true })); cursorPosition += 1; // Splitting a paragraph introduces 1 walkable position, bumping the cursor forward operations.push(createOp(new ops.OpInsertText(), { diff --git a/webodf/lib/gui/TextManipulator.js b/webodf/lib/gui/TextManipulator.js index 45572162..d68ee24d 100644 --- a/webodf/lib/gui/TextManipulator.js +++ b/webodf/lib/gui/TextManipulator.js @@ -96,7 +96,8 @@ gui.TextManipulator = function TextManipulator(session, inputMemberId, directSty op = new ops.OpSplitParagraph(); op.init({ memberid: inputMemberId, - position: selection.position + position: selection.position, + moveCursor: true }); operations.push(op); diff --git a/webodf/lib/ops/OpSplitParagraph.js b/webodf/lib/ops/OpSplitParagraph.js index 4e3ca1c8..8f181424 100644 --- a/webodf/lib/ops/OpSplitParagraph.js +++ b/webodf/lib/ops/OpSplitParagraph.js @@ -40,18 +40,25 @@ /*global ops, odf*/ /** + * This operation splits the paragraph at the given + * position. If the `moveCursor` flag is specified + * and is set as true, the cursor is moved to the + * beginning of the next paragraph. Otherwise, it + * remains in it's original position. * @constructor * @implements ops.Operation */ ops.OpSplitParagraph = function OpSplitParagraph() { "use strict"; - var memberid, timestamp, position, odfUtils; + var memberid, timestamp, position, moveCursor, + odfUtils; this.init = function (data) { memberid = data.memberid; timestamp = data.timestamp; position = data.position; + moveCursor = data.moveCursor === 'true' || data.moveCursor === true; odfUtils = new odf.OdfUtils(); }; @@ -59,10 +66,11 @@ ops.OpSplitParagraph = function OpSplitParagraph() { this.execute = function (odtDocument) { var domPosition, paragraphNode, targetNode, - node, splitNode, splitChildNode, keptChildNode; + node, splitNode, splitChildNode, keptChildNode, + cursor = odtDocument.getCursor(memberid); odtDocument.upgradeWhitespacesAtPosition(position); - domPosition = odtDocument.getTextNodeAtStep(position, memberid); + domPosition = odtDocument.getTextNodeAtStep(position); if (!domPosition) { return false; } @@ -147,6 +155,11 @@ ops.OpSplitParagraph = function OpSplitParagraph() { } odtDocument.emit(ops.OdtDocument.signalStepsInserted, {position: position, length: 1}); + if (cursor && moveCursor) { + odtDocument.moveCursor(memberid, position + 1, 0); + odtDocument.emit(ops.OdtDocument.signalCursorMoved, cursor); + } + odtDocument.fixCursorPositions(); odtDocument.getOdfCanvas().refreshSize(); // mark both paragraphs as edited @@ -170,7 +183,8 @@ ops.OpSplitParagraph = function OpSplitParagraph() { optype: "SplitParagraph", memberid: memberid, timestamp: timestamp, - position: position + position: position, + moveCursor: moveCursor }; }; }; diff --git a/webodf/lib/ops/OperationTransformMatrix.js b/webodf/lib/ops/OperationTransformMatrix.js index 3a906444..5b38c04b 100644 --- a/webodf/lib/ops/OperationTransformMatrix.js +++ b/webodf/lib/ops/OperationTransformMatrix.js @@ -717,8 +717,6 @@ ops.OperationTransformMatrix = function OperationTransformMatrix() { } else { splitParagraphSpecA.position += 1; } - // TODO: cursors get out of sync, so for now have OT fail - return null; } return {