/// <summary> /// Changes the value of a comment. /// </summary> /// <param name="nodeIndex">Index of the state with the comment to change.</param> /// <param name="text">The new text.</param> /// <param name="oldCaretPosition">The old caret position.</param> /// <param name="newCaretPosition">The new caret position.</param> /// <param name="changeCaretBeforeText">True if the caret should be changed before the text, to preserve the caret invariant.</param> public virtual void ChangeCommentAndCaretPosition(IFocusIndex nodeIndex, string text, int oldCaretPosition, int newCaretPosition, bool changeCaretBeforeText) { Contract.RequireNotNull(nodeIndex, out IFocusIndex NodeIndex); Contract.RequireNotNull(text, out string Text); Debug.Assert(StateTable.ContainsKey(NodeIndex)); System.Action <IWriteableOperation> HandlerRedo = (IWriteableOperation operation) => RedoChangeComment(operation); System.Action <IWriteableOperation> HandlerUndo = (IWriteableOperation operation) => UndoChangeComment(operation); IFocusNodeState State = (IFocusNodeState)StateTable[NodeIndex]; FocusChangeCommentOperation Operation = CreateChangeCommentOperation(State.Node, Text, oldCaretPosition, newCaretPosition, changeCaretBeforeText, HandlerRedo, HandlerUndo, isNested: false); Operation.Redo(); SetLastOperation(Operation); CheckInvariant(); }
private protected virtual bool IsSameChangeCommentOperationFocus(FocusChangeCommentOperation operation) { Node Node = null; if (operation.State.ParentIndex is IFocusNodeIndex AsNodeIndex) { Node = AsNodeIndex.Node; } else if (operation.State is IFocusOptionalNodeState AsOptionalNodeState && AsOptionalNodeState.ParentInner.IsAssigned) { Node = AsOptionalNodeState.Node; } Debug.Assert(Node != null); Node FocusedNode = null; IFocusFrame FocusedFrame = null; Focus.GetLocationInSourceCode(out FocusedNode, out FocusedFrame); return(FocusedNode == Node && FocusedFrame is IFocusCommentFrame); }