* 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.
This commit is contained in:
Aditya Bhatt
2013-12-06 12:37:34 +01:00
parent 0cc5f25574
commit 5dfd3438d1
4 changed files with 22 additions and 8 deletions
+2 -1
View File
@@ -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(), {
+2 -1
View File
@@ -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);
+18 -4
View File
@@ -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
};
};
};
@@ -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 {