public void FindEditPositionFrom()
        {
            var maskedTextProvider = new MaskedTextProvider(TestSimpleDigitMask);

            Assert.Equal(0, maskedTextProvider.FindEditPositionFrom(0, true));
            Assert.Equal(5, maskedTextProvider.FindEditPositionFrom(5, false));
        }
        int AdvanceToNextEditPosition(int position)
        {
            var newPos = Provider.FindEditPositionFrom(position, true);

            if (newPos >= 0)
            {
                position = newPos;
            }
            return(position);
        }
Beispiel #3
0
        // Finds the next non-mask character.
        private int SkipToEditableCharacter(int startPos)
        {
            int newPos = maskProvider.FindEditPositionFrom(startPos, true);

            if (newPos == -1)
            {
                // Already at the end of the string.
                return(startPos);
            }
            else
            {
                return(newPos);
            }
        }
Beispiel #4
0
        private static bool CanReplace(MaskedTextProvider provider, string text, int startPosition, int selectionLength, bool rejectInputOnFirstFailure, out int tentativeCaretIndex)
        {
            var endPosition = startPosition + selectionLength - 1;

            tentativeCaretIndex = -1;

            var success = false;

            foreach (var character in text)
            {
                if (!provider.VerifyEscapeChar(character, startPosition))
                {
                    var editPositionFrom = provider.FindEditPositionFrom(startPosition, true);
                    if (editPositionFrom == MaskedTextProvider.InvalidIndex)
                    {
                        break;
                    }
                    startPosition = editPositionFrom;
                }

                var length    = endPosition >= startPosition ? 1 : 0;
                var overwrite = length > 0;

                if (PlaceChar(provider, character, startPosition, length, overwrite, out tentativeCaretIndex))
                {
                    // Only one successfully inserted character is enough to declare the replace operation successful.
                    success       = true;
                    startPosition = tentativeCaretIndex + 1;
                }
                else if (rejectInputOnFirstFailure)
                {
                    return(false);
                }
            }

            if ((selectionLength > 0) && (startPosition <= endPosition))
            {
                // Erase the remaining of the assigned edit character.
                int notUsed;
                MaskedTextResultHint notUsedHint;
                if (!provider.RemoveAt(startPosition, endPosition, out notUsed, out notUsedHint))
                {
                    success = false;
                }
            }

            return(success);
        }
Beispiel #5
0
        protected override void OnKeyPress(KeyPressEventArgs e)
        {
            if (is_empty_mask)
            {
                base.OnKeyPress(e);
                return;
            }

            int testPosition, editPosition;
            MaskedTextResultHint resultHint;
            bool result;

            if (e.KeyChar == '\b')
            {
                if (SelectionLength == 0)
                {
                    result = provider.RemoveAt(SelectionStart - 1, SelectionStart - 1, out testPosition, out resultHint);
                }
                else
                {
                    result = provider.RemoveAt(SelectionStart, SelectionStart + SelectionLength - 1, out testPosition, out resultHint);
                }

                editPosition = testPosition;
            }
            else if (IsOverwriteMode || SelectionLength > 0)                 // Replace
            {
                int start = provider.FindEditPositionFrom(SelectionStart, true);
                int end   = SelectionLength > 0 ? SelectionStart + SelectionLength - 1 : start;
                result = provider.Replace(e.KeyChar, start, end, out testPosition, out resultHint);

                editPosition = testPosition + 1;
            }
            else
            {
                // Move chars to the right
                result       = provider.InsertAt(e.KeyChar, SelectionStart, out testPosition, out resultHint);
                editPosition = testPosition + 1;
            }

            PostprocessKeyboardInput(result, editPosition, testPosition, resultHint);

            e.Handled = true;
        }
Beispiel #6
0
 ///<inheritdoc/>
 public int Cursor(int pos)
 {
     if (pos < 0)
     {
         return(CursorStart());
     }
     else if (pos > provider.Length)
     {
         return(CursorEnd());
     }
     else
     {
         var p = provider.FindEditPositionFrom(pos, false);
         if (p == -1)
         {
             p = provider.FindEditPositionFrom(pos, true);
         }
         return(p);
     }
 }
        private int GetNextCharacterPosition(int startPosition, bool goForward)
        {
            var position = _provider.FindEditPositionFrom(startPosition, goForward);

            return(position == -1 ? startPosition : position);
        }
Beispiel #8
0
        private int FindCharacterPosition(int startPosition, bool direction = true)
        {
            var position = _maskedTextProvider.FindEditPositionFrom(startPosition, direction);

            return(position == -1 ? startPosition : position);
        }