mirror of
https://github.com/webodf/WebODF.git
synced 2026-12-01 16:56:05 +01:00
Make text editing respect review mode constraints.
This commit is contained in:
@@ -89,7 +89,7 @@ gui.SessionControllerOptions = function () {
|
||||
args.directTextStylingEnabled, args.directParagraphStylingEnabled),
|
||||
createCursorStyleOp = /**@type {function (!number, !number, !boolean):ops.Operation}*/ (directFormattingController.createCursorStyleOp),
|
||||
createParagraphStyleOps = /**@type {function (!number):!Array.<!ops.Operation>}*/ (directFormattingController.createParagraphStyleOps),
|
||||
textController = new gui.TextController(session, inputMemberId, createCursorStyleOp, createParagraphStyleOps),
|
||||
textController = new gui.TextController(session, sessionConstraints, sessionContextCache, inputMemberId, createCursorStyleOp, createParagraphStyleOps),
|
||||
imageController = new gui.ImageController(session, sessionConstraints, sessionContextCache, inputMemberId, objectNameGenerator),
|
||||
imageSelector = new gui.ImageSelector(odtDocument.getOdfCanvas()),
|
||||
shadowCursorIterator = gui.SelectionMover.createPositionIterator(odtDocument.getRootNode()),
|
||||
@@ -1112,6 +1112,7 @@ gui.SessionControllerOptions = function () {
|
||||
hyperlinkClickHandler.destroy,
|
||||
hyperlinkController.destroy,
|
||||
metadataController.destroy,
|
||||
textController.destroy,
|
||||
destroy
|
||||
];
|
||||
|
||||
|
||||
@@ -26,12 +26,22 @@
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {core.Destroyable}
|
||||
* @param {!ops.Session} session
|
||||
* @param {!gui.SessionConstraints} sessionConstraints
|
||||
* @param {!gui.SessionContextCache} sessionContextCache
|
||||
* @param {!string} inputMemberId
|
||||
* @param {function(!number, !number, !boolean):ops.Operation} directStyleOp
|
||||
* @param {function(!number):!Array.<!ops.Operation>} paragraphStyleOps
|
||||
*/
|
||||
gui.TextController = function TextController(session, inputMemberId, directStyleOp, paragraphStyleOps) {
|
||||
gui.TextController = function TextController(
|
||||
session,
|
||||
sessionConstraints,
|
||||
sessionContextCache,
|
||||
inputMemberId,
|
||||
directStyleOp,
|
||||
paragraphStyleOps
|
||||
) {
|
||||
"use strict";
|
||||
|
||||
var odtDocument = session.getOdtDocument(),
|
||||
@@ -45,7 +55,37 @@ gui.TextController = function TextController(session, inputMemberId, directStyle
|
||||
* @const
|
||||
* @type {!boolean}
|
||||
*/
|
||||
FORWARD = true;
|
||||
FORWARD = true,
|
||||
isEnabled = false;
|
||||
|
||||
/**
|
||||
* @return {undefined}
|
||||
*/
|
||||
function updateEnabledState() {
|
||||
if (sessionConstraints.getState("edit.reviewMode") === true) {
|
||||
isEnabled = /**@type{!boolean}*/(sessionContextCache.isLocalCursorWithinOwnAnnotation());
|
||||
} else {
|
||||
isEnabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!ops.OdtCursor} cursor
|
||||
* @return {undefined}
|
||||
*/
|
||||
function onCursorEvent(cursor) {
|
||||
if (cursor.getMemberId() === inputMemberId) {
|
||||
updateEnabledState();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {!boolean}
|
||||
*/
|
||||
this.isEnabled = function () {
|
||||
return isEnabled;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Creates operations to remove the provided selection and update the destination
|
||||
@@ -115,6 +155,10 @@ gui.TextController = function TextController(session, inputMemberId, directStyle
|
||||
* @return {!boolean}
|
||||
*/
|
||||
this.enqueueParagraphSplittingOps = function() {
|
||||
if (!isEnabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var range = odtDocument.getCursor(inputMemberId).getSelectedRange(),
|
||||
selection = toForwardSelection(odtDocument.getCursorSelection(inputMemberId)),
|
||||
op, operations = [], styleOps;
|
||||
@@ -180,6 +224,10 @@ gui.TextController = function TextController(session, inputMemberId, directStyle
|
||||
* @return {!boolean}
|
||||
*/
|
||||
function removeTextInDirection(isForward) {
|
||||
if (!isEnabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var cursorNode,
|
||||
// Take a clone of the range as it will be modified if the selection length is 0
|
||||
range = /**@type{!Range}*/(odtDocument.getCursor(inputMemberId).getSelectedRange().cloneRange()),
|
||||
@@ -239,6 +287,10 @@ gui.TextController = function TextController(session, inputMemberId, directStyle
|
||||
* @return {!boolean}
|
||||
*/
|
||||
this.removeCurrentSelection = function () {
|
||||
if (!isEnabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var range = odtDocument.getCursor(inputMemberId).getSelectedRange(),
|
||||
selection = toForwardSelection(odtDocument.getCursorSelection(inputMemberId));
|
||||
if (selection.length !== 0) {
|
||||
@@ -253,6 +305,10 @@ gui.TextController = function TextController(session, inputMemberId, directStyle
|
||||
* @return {undefined}
|
||||
*/
|
||||
function insertText(text) {
|
||||
if (!isEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
var range = odtDocument.getCursor(inputMemberId).getSelectedRange(),
|
||||
selection = toForwardSelection(odtDocument.getCursorSelection(inputMemberId)),
|
||||
op, stylingOp, operations = [], useCachedStyle = false;
|
||||
@@ -279,4 +335,21 @@ gui.TextController = function TextController(session, inputMemberId, directStyle
|
||||
session.enqueue(operations);
|
||||
}
|
||||
this.insertText = insertText;
|
||||
|
||||
/**
|
||||
* @param {!function(!Error=)} callback, passing an error object in case of error
|
||||
* @return {undefined}
|
||||
*/
|
||||
this.destroy = function (callback) {
|
||||
odtDocument.unsubscribe(ops.Document.signalCursorMoved, onCursorEvent);
|
||||
sessionConstraints.unsubscribe("edit.reviewMode", updateEnabledState);
|
||||
callback();
|
||||
};
|
||||
|
||||
function init() {
|
||||
odtDocument.subscribe(ops.Document.signalCursorMoved, onCursorEvent);
|
||||
sessionConstraints.subscribe("edit.reviewMode", updateEnabledState);
|
||||
updateEnabledState();
|
||||
}
|
||||
init();
|
||||
};
|
||||
|
||||
@@ -189,7 +189,8 @@
|
||||
"odf.OdfNodeFilter"
|
||||
],
|
||||
"gui.TextController": [
|
||||
"ops.Session"
|
||||
"gui.SessionConstraints",
|
||||
"gui.SessionContextCache"
|
||||
],
|
||||
"gui.TrivialUndoManager": [
|
||||
"core.DomUtils",
|
||||
|
||||
@@ -120,7 +120,9 @@ gui.TextControllerTests = function TextControllerTests(runner) {
|
||||
|
||||
t.odtDocument = new ops.OdtDocument(new MockOdfCanvas(node));
|
||||
t.session = new MockSession(t.odtDocument);
|
||||
t.textController = new gui.TextController(t.session, inputMemberId, directStyleOp, paragraphStyleOps);
|
||||
t.sessionConstraints = new gui.SessionConstraints();
|
||||
t.sessionContextCache = new gui.SessionContextCache(t.session, inputMemberId);
|
||||
t.textController = new gui.TextController(t.session, t.sessionConstraints, t.sessionContextCache, inputMemberId, directStyleOp, paragraphStyleOps);
|
||||
t.cursor = new ops.OdtCursor(inputMemberId, t.odtDocument);
|
||||
t.odtDocument.addCursor(t.cursor);
|
||||
|
||||
|
||||
@@ -62,6 +62,8 @@
|
||||
"gui.TextControllerTests": [
|
||||
"core.UnitTester",
|
||||
"core.Utils",
|
||||
"gui.SessionConstraints",
|
||||
"gui.SessionContextCache",
|
||||
"gui.TextController",
|
||||
"odf.Namespaces",
|
||||
"odf.OdfCanvas",
|
||||
|
||||
Reference in New Issue
Block a user