/// <summary> /// Changes the value of a text. /// </summary> /// <param name="nodeIndex">Index of the state with the string to change.</param> /// <param name="propertyName">Name of the property 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 ChangeTextAndCaretPosition(IFocusIndex nodeIndex, string propertyName, 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) => RedoChangeText(operation); System.Action <IWriteableOperation> HandlerUndo = (IWriteableOperation operation) => UndoChangeText(operation); IFocusNodeState State = (IFocusNodeState)StateTable[NodeIndex]; FocusChangeTextOperation Operation = CreateChangeTextOperation(State.Node, propertyName, Text, oldCaretPosition, newCaretPosition, changeCaretBeforeText, HandlerRedo, HandlerUndo, isNested: false); Operation.Redo(); SetLastOperation(Operation); CheckInvariant(); }
private protected virtual bool IsSameChangeTextOperationFocus(FocusChangeTextOperation 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); string PropertyName = operation.PropertyName; Node FocusedNode = null; IFocusFrame FocusedFrame = null; Focus.GetLocationInSourceCode(out FocusedNode, out FocusedFrame); return(FocusedNode == Node && FocusedFrame is IFocusTextValueFrame AsTextValueFrame && AsTextValueFrame.PropertyName == PropertyName); }