コード例 #1
0
ファイル: TextInputExtensions.cs プロジェクト: Glepooek/maui
        internal static int GetCursorPosition(this IUITextInput platformView, int cursorOffset = 0)
        {
            var zeroPosition          = platformView.GetPosition(platformView.BeginningOfDocument, 0);
            var currentCursorPosition = platformView.SelectedTextRange?.Start ?? zeroPosition;
            var newCursorPosition     = cursorOffset + (int)platformView.GetOffsetFromPosition(platformView.BeginningOfDocument, currentCursorPosition);

            return(Math.Max(0, newCursorPosition));
        }
コード例 #2
0
        public static UITextRange GetTextRange(this IUITextInput textInput, int start, int end)
        {
            if (textInput?.BeginningOfDocument == null)
            {
                return(null);
            }

            var from = textInput.GetPosition(textInput.BeginningOfDocument, start);
            var to   = textInput.GetPosition(textInput.BeginningOfDocument, end);

            if (from == null || to == null)
            {
                return(null);
            }

            return(textInput.GetTextRange(from, to));
        }
コード例 #3
0
ファイル: TextInputExtensions.cs プロジェクト: Glepooek/maui
        internal static void SetTextRange(this IUITextInput platformView, int start, int selectedTextLength)
        {
            int end = start + selectedTextLength;

            // Let's be sure we have positive positions
            start = Math.Max(start, 0);
            end   = Math.Max(end, 0);

            // Switch start and end positions if necessary
            start = Math.Min(start, end);
            end   = Math.Max(start, end);

            var startPosition = platformView.GetPosition(platformView.BeginningOfDocument, start);
            var endPosition   = platformView.GetPosition(platformView.BeginningOfDocument, end);

            platformView.SelectedTextRange = platformView.GetTextRange(startPosition, endPosition);
        }