예제 #1
0
 public static void UpdateCursorPosition(this EditText editText, ITextInput entry)
 {
     if (editText.SelectionStart != entry.CursorPosition)
     {
         UpdateCursorSelection(editText, entry);
     }
 }
예제 #2
0
        public Workspace(IConsole console)
        {
            _console = console;
            commandPalette = new CommandPalette(_console, 20, 1, 40);

            commandPalette.CommandRecieved += (object sender, CommandArgs commandArgs) =>
            {
                string command = commandArgs.Command;

                switch (command)
                {
                    case "new":
                        NewEditor();
                        lastEditor = Editors[0];
                        ActiveEditor = commandPalette;
                        return;
                    case "open":
                        //OpenEditor();
                    case "save":
                        //SaveEditor();
                    default:
                        return;
                }
            };
        }
예제 #3
0
        public static void UpdateMaxLength(this TextBox textBox, ITextInput textInput)
        {
            var maxLength = textInput.MaxLength;

            if (maxLength == 0)
            {
                textBox.IsReadOnly = true;
            }
            else
            {
                textBox.IsReadOnly = textInput.IsReadOnly;
            }

            if (maxLength == -1)
            {
                maxLength = int.MaxValue;
            }

            textBox.MaxLength = maxLength;

            var currentControlText = textBox.Text;

            if (currentControlText.Length > maxLength)
            {
                textBox.Text = currentControlText.Substring(0, maxLength);
            }
        }
        private Option<Token> TryIdentifySingleToken(ITextInput input)
        {
            StringBuilder recognizedInput = new StringBuilder();
            int state = 0;
            IEnumerator<char> lookahead = input.LookAhead.GetEnumerator();
            Option<string> longestTokenClass = Option<string>.None();
            int longestTokenLength = 0;

            while (lookahead.MoveNext() && this.Table.ContainsTransition(state, lookahead.Current))
            {

                recognizedInput.Append(lookahead.Current);
                state = this.Table.GetTransition(state, lookahead.Current);

                this
                    .Table
                    .TryGetReduction(state)
                    .ForEach(tokenClass =>
                        {
                            longestTokenClass = Option<string>.Some(tokenClass);
                            longestTokenLength = recognizedInput.Length;
                        });

            }

            recognizedInput.Length = longestTokenLength;

            return
                longestTokenClass
                    .Select(tokenClass => new Token(recognizedInput.ToString(), tokenClass))
                    .Select(token => Option<Token>.Some(token))
                    .DefaultIfEmpty(Option<Token>.None())
                    .Single();
        }
예제 #5
0
 public static void UpdateMaxLength(this Entry platformEntry, ITextInput entry)
 {
     if (entry.MaxLength > 0 && platformEntry.Text.Length > entry.MaxLength)
     {
         platformEntry.Text = platformEntry.Text.Substring(0, entry.MaxLength);
     }
 }
예제 #6
0
 public static void UpdateCursorPosition(this TextBox textBox, ITextInput entry)
 {
     if (textBox.SelectionStart != entry.CursorPosition)
     {
         textBox.SelectionStart = entry.CursorPosition;
     }
 }
예제 #7
0
 public static void UpdateSelectionLength(this TextBox textBox, ITextInput entry)
 {
     if (textBox.SelectionLength != entry.SelectionLength)
     {
         textBox.SelectionLength = entry.SelectionLength;
     }
 }
예제 #8
0
 public static void UpdateSelectionLength(this EditText editText, ITextInput entry)
 {
     if ((editText.SelectionEnd - editText.SelectionStart) != entry.SelectionLength)
     {
         UpdateCursorSelection(editText, entry);
     }
 }
        IEnumerable<Token> ILexicalAnalyzer.Analyze(ITextInput input)
        {
            Contract.Requires<ArgumentNullException>(input != null, "Text input must be non-null.");

            Contract.Ensures(Contract.Result<IEnumerable<Token>>() != null);
            Contract.Ensures(Contract.Result<IEnumerable<Token>>().All(token => token != null));

            return new Token[0];
        }
예제 #10
0
        /* Updates both the IEntry.CursorPosition and IEntry.SelectionLength properties. */
        static void UpdateCursorSelection(EditText editText, ITextInput entry)
        {
            if (!entry.IsReadOnly)            // && editText.HasFocus)// || editText.RequestFocus()))//&& editText.RequestFocus())
            {
                int start = GetSelectionStart(editText, entry);
                int end   = GetSelectionEnd(editText, entry, start);

                editText.SetSelection(start, end);
            }
        }
예제 #11
0
        public static void UpdateSelectionLength(this TextBox textBox, ITextInput entry)
        {
            // It seems that the TextBox does not limit the SelectionLength to the Text.Length natively
            entry.SelectionLength = Math.Min(entry.SelectionLength, textBox.Text.Length - textBox.SelectionStart);

            if (textBox.SelectionLength != entry.SelectionLength)
            {
                textBox.SelectionLength = entry.SelectionLength;
            }
        }
예제 #12
0
        public static void UpdateCursorPosition(this TextBox textBox, ITextInput entry)
        {
            // It seems that the TextBox does not limit the CursorPosition to the Text.Length natively
            entry.CursorPosition = Math.Min(entry.CursorPosition, textBox.Text.Length);

            if (textBox.SelectionStart != entry.CursorPosition)
            {
                textBox.SelectionStart = entry.CursorPosition;
            }
        }
예제 #13
0
        static int GetSelectionEnd(Entry platformEntry, ITextInput entry, int start)
        {
            int end             = Math.Max(start, Math.Min(platformEntry.Text?.Length ?? 0, start + entry.SelectionLength));
            int selectionLength = end - start;

            if (selectionLength != entry.SelectionLength)
            {
                entry.SelectionLength = selectionLength;
            }
            return(end);
        }
예제 #14
0
        public static void UpdateText(this ITextInput textInput, string?text)
        {
            // Even though <null> is technically different to "", it has no
            // functional difference to apps. Thus, hide it.
            var mauiText     = textInput.Text ?? string.Empty;
            var platformText = text ?? string.Empty;

            if (mauiText != platformText)
            {
                textInput.Text = platformText;
            }
        }
예제 #15
0
        private ITextInput InitializeInput()
        {

            this.PromptUser();

            string text = this.ReadText();
            this.basicInput = new StringInput(text);

            this.GetBasicTextInput = () => this.basicInput;

            return this.basicInput;

        }
예제 #16
0
 public Interactor(
     ITextInput textInput,
     IWordCountAnalyzer wordCountAnalyzer,
     IWordCountAnalyzerOutput wordCountAnalyzerOutput,
     IIndexOutput indexOutput,
     IHelpOutput helpOutput)
 {
     TextInput               = textInput;
     WordCountAnalyzer       = wordCountAnalyzer;
     WordCountAnalyzerOutput = wordCountAnalyzerOutput;
     IndexOutput             = indexOutput;
     HelpOutput              = helpOutput;
 }
예제 #17
0
        internal static void SetInputType(this EditText editText, ITextInput textInput)
        {
            if (textInput.IsReadOnly)
            {
                editText.InputType = InputTypes.Null;
            }
            else
            {
                var keyboard = textInput.Keyboard;
                var nativeInputTypeToUpdate = keyboard.ToInputType();

                if (keyboard is not CustomKeyboard)
                {
                    // TODO: IsSpellCheckEnabled handling must be here.

                    if ((nativeInputTypeToUpdate & InputTypes.TextFlagNoSuggestions) != InputTypes.TextFlagNoSuggestions)
                    {
                        if (!textInput.IsTextPredictionEnabled)
                        {
                            nativeInputTypeToUpdate |= InputTypes.TextFlagNoSuggestions;
                        }
                    }
                }

                if (keyboard == Keyboard.Numeric)
                {
                    editText.KeyListener = LocalizedDigitsKeyListener.Create(editText.InputType);
                }

                if (textInput is IEntry entry && entry.IsPassword)
                {
                    if ((nativeInputTypeToUpdate & InputTypes.ClassText) == InputTypes.ClassText)
                    {
                        nativeInputTypeToUpdate |= InputTypes.TextVariationPassword;
                    }

                    if ((nativeInputTypeToUpdate & InputTypes.ClassNumber) == InputTypes.ClassNumber)
                    {
                        nativeInputTypeToUpdate |= InputTypes.NumberVariationPassword;
                    }
                }

                editText.InputType = nativeInputTypeToUpdate;
            }

            if (textInput is IEditor)
            {
                editText.InputType |= InputTypes.TextFlagMultiLine;
            }
        }
예제 #18
0
        static int GetSelectionEnd(EditText editText, ITextInput entry, int start)
        {
            int end             = start;
            int selectionLength = entry.SelectionLength;

            end = System.Math.Max(start, System.Math.Min(editText.Length(), start + selectionLength));
            int newSelectionLength = System.Math.Max(0, end - start);

            // Updating this property results in UpdateSelectionLength being called again messing things up
            if (newSelectionLength != selectionLength)
            {
                entry.SelectionLength = newSelectionLength;
            }
            return(end);
        }
예제 #19
0
        internal static void UpdateInputScope(this MauiTextBox textBox, ITextInput textInput)
        {
            if (textInput.Keyboard is CustomKeyboard custom)
            {
                textBox.IsTextPredictionEnabled = (custom.Flags & KeyboardFlags.Suggestions) != 0;
                textBox.IsSpellCheckEnabled     = (custom.Flags & KeyboardFlags.Spellcheck) != 0;
            }
            else
            {
                textBox.IsTextPredictionEnabled = textInput.IsTextPredictionEnabled;

                // TODO: Update IsSpellCheckEnabled
            }

            textBox.InputScope = textInput.Keyboard.ToInputScope();
        }
예제 #20
0
        static int GetSelectionStart(Entry platformEntry, ITextInput entry)
        {
            int start          = platformEntry.Text?.Length ?? 0;
            int cursorPosition = entry.CursorPosition;

            if (!string.IsNullOrEmpty(platformEntry.Text))
            {
                start = Math.Min(start, cursorPosition);
            }

            if (start != cursorPosition)
            {
                entry.CursorPosition = start;
            }

            return(start);
        }
예제 #21
0
        public static void UpdateSelectionLength(this Entry platformEntry, ITextInput entry)
        {
            if (platformEntry.IsUpdatingCursorPosition)
            {
                return;
            }

            int start = GetSelectionStart(platformEntry, entry);
            int end   = GetSelectionEnd(platformEntry, entry, start);

            if (start < end)
            {
                platformEntry.SetSelectionRegion(start, end);
            }
            else
            {
                platformEntry.CursorPosition = entry.CursorPosition;
            }
        }
예제 #22
0
        public IEnumerable<Token> Analyze(ITextInput input)
        {
            while (input.CharactersRemaining > 0)
            {

                Option<Token> possibleToken = TryIdentifySingleToken(input);

                if (!possibleToken.Any())
                    yield break;

                Token token = possibleToken.Single();

                input.Advance(token.Representation.Length);
                yield return token;

            }

            yield return new Token(string.Empty, "end-of-input");
        }
예제 #23
0
        static int GetSelectionStart(EditText editText, ITextInput entry)
        {
            int start          = editText.Length();
            int cursorPosition = entry.CursorPosition;

            if (editText.Text != null)
            {
                // Capping cursorPosition to the end of the text if needed
                start = System.Math.Min(editText.Text.Length, cursorPosition);
            }

            if (start != cursorPosition)
            {
                // Update the interface if start was capped
                entry.CursorPosition = start;
            }

            return(start);
        }
예제 #24
0
        /// <summary>
        /// Lazy loads a text input mapped to a dto
        /// </summary>
        /// <param name="src">source entity</param>
        /// <returns></returns>
        public static ITextInputDto MapTextInputToDto(ITextInput src)
        {
            if (src == null)
            {
                return(null);
            }
            Lazy <TextInputDto> textInput = new Lazy <TextInputDto>(() => new TextInputDto
            {
                DisplayName       = src.DisplayName,
                Id                = src.Id,
                MultiLine         = src.MultiLine,
                HelpToolTip       = src.HelpToolTip,
                AvailableOnRemove = src.AvailableOnRemove,
                AvailableOnChange = src.AvailableOnChange,
                AvailableOnAdd    = src.AvailableOnAdd
            });

            return(textInput.Value);
        }
예제 #25
0
        public static void UpdateText(this TextBox nativeControl, ITextInput textInput)
        {
            var newText = textInput.Text;

            if (nativeControl is MauiPasswordTextBox passwordTextBox && passwordTextBox.Password == newText)
            {
                return;
            }
            if (nativeControl.Text == newText)
            {
                return;
            }

            nativeControl.Text = newText ?? string.Empty;

            if (!string.IsNullOrEmpty(nativeControl.Text))
            {
                nativeControl.SelectionStart = nativeControl.Text.Length;
            }
        }
예제 #26
0
        public static void UpdateText(this TextBox platformControl, ITextInput textInput)
        {
            var newText = textInput.Text;

            if (platformControl is MauiPasswordTextBox passwordTextBox && passwordTextBox.Password == newText)
            {
                return;
            }
            if (platformControl.Text == newText)
            {
                return;
            }

            platformControl.Text = newText ?? string.Empty;

            if (!string.IsNullOrEmpty(platformControl.Text))
            {
                platformControl.Select(platformControl.Text.Length, 0);
            }
        }
예제 #27
0
        public static void UpdateText(this ITextInput textInput, Android.Text.TextChangedEventArgs e)
        {
            if (e.BeforeCount == 0 && e.AfterCount == 0)
            {
                return;
            }

            if (e.Text is Java.Lang.ICharSequence cs)
            {
                textInput.UpdateText(cs.ToString());
            }
            else if (e.Text != null)
            {
                textInput.UpdateText(String.Concat(e.Text));
            }
            else
            {
                textInput.UpdateText((string?)null);
            }
        }
        public void OnInputTextChanged(ITextInput txt, string newText)
        {
            IDataSetSource dss = _owner.DataSetStore;

            if (dss != null)
            {
                string colName  = null;
                string propName = txt.GetTextPropertyName();
                if (txt.DataBindings != null)
                {
                    foreach (Binding bd in txt.DataBindings)
                    {
                        if (string.CompareOrdinal(bd.PropertyName, propName) == 0)
                        {
                            colName = bd.BindingMemberInfo.BindingMember;
                            break;
                        }
                    }
                }
                dss.SetFieldValueEx(this.DataRowIndex, colName, newText);
            }
        }
예제 #29
0
        public static bool TextWithinMaxLength(this ITextInput textInput, string?text, Foundation.NSRange range, string replacementString)
        {
            var currLength = text?.Length ?? 0;

            // fix a crash on undo
            if (range.Length + range.Location > currLength)
            {
                return(false);
            }

            if (textInput.MaxLength < 0)
            {
                return(true);
            }

            var addLength = replacementString?.Length ?? 0;
            var remLength = range.Length;

            var newLength = currLength + addLength - remLength;

            return(newLength <= textInput.MaxLength);
        }
예제 #30
0
        internal static void UpdateInputScope(this TextBox textBox, ITextInput textInput)
        {
            if (textInput.Keyboard is CustomKeyboard custom)
            {
                textBox.IsTextPredictionEnabled = (custom.Flags & KeyboardFlags.Suggestions) != 0;
                textBox.IsSpellCheckEnabled     = (custom.Flags & KeyboardFlags.Spellcheck) != 0;
            }
            else
            {
                textBox.IsTextPredictionEnabled = textInput.IsTextPredictionEnabled;
                textBox.IsSpellCheckEnabled     = textInput.IsTextPredictionEnabled;
            }

            var inputScope = new UI.Xaml.Input.InputScope();

            if (textInput is IEntry entry && entry.ReturnType == ReturnType.Search)
            {
                inputScope.Names.Add(new UI.Xaml.Input.InputScopeName(UI.Xaml.Input.InputScopeNameValue.Search));
            }

            inputScope.Names.Add(textInput.Keyboard.ToInputScopeName());

            textBox.InputScope = inputScope;
        }
예제 #31
0
 public static void UpdateReturnType(this TextBox textBox, ITextInput textInput)
 {
     textBox.UpdateInputScope(textInput);
 }
예제 #32
0
 private void NewEditor()
 {
     Editors.Insert(0, new Editor(_console, string.Format("untitled {0}", ++numUntitled), 0, 0, 80, 24));
     ActiveEditor = Editors[0];
     ResizeEditors();
     RedrawEditors();
 }
예제 #33
0
        public void Run()
        {
            if (Editors.Count == 0)
            {
                _console.Clear();
                _console.CursorTop = 2;
                _console.CursorLeft = 4;
                _console.Write("* No editors! Press Ctrl+N to create or Ctrl+O to open!");
            }
            else
            {
                RedrawEditors();
            }

            while (true)
            {
                var keyInfo = _console.ReadKey(true);
                if (keyInfo.Modifiers.HasFlag(ConsoleModifiers.Control))
                {
                    switch (keyInfo.Key)
                    {
                        case ConsoleKey.X:
                            //if (commandPalette.Focused) break;
                            lastEditor = (Editor) ActiveEditor;
                            commandPalette.Show();
                            ActiveEditor = commandPalette;
                            break;
                        case ConsoleKey.N:
                            NewEditor();
                            break;
                        case ConsoleKey.O:
                            OpenEditor();
                            break;
                        case ConsoleKey.LeftArrow:
                            {
                                var idx = Editors.FindIndex(x => x == ActiveEditor);
                                ActiveEditor = Editors[idx == 0 ? Editors.Count - 1 : idx - 1];
                                ActiveEditor.ActivateCursor();
                                continue;
                            }
                        case ConsoleKey.RightArrow:
                            {
                                var idx = Editors.FindIndex(x => x == ActiveEditor);
                                ActiveEditor = Editors[(idx + 1) % Editors.Count];
                                ActiveEditor.ActivateCursor();
                                continue;
                            }
                    }
                }

                if (Editors.Count == 0 && !commandPalette.Focused)
                {
                    continue;
                }
                

                bool redraw = false;

                switch (keyInfo.Key)
                {
                    case ConsoleKey.UpArrow:
                        if (keyInfo.Modifiers.HasFlag(ConsoleModifiers.Control))
                            redraw = ActiveEditor.HandleInput(EditorInput.ControlUpArrow);
                        else
                            redraw = ActiveEditor.HandleInput(EditorInput.UpArrow);
                        break;
                    case ConsoleKey.DownArrow:
                        if (keyInfo.Modifiers.HasFlag(ConsoleModifiers.Control))
                            redraw = ActiveEditor.HandleInput(EditorInput.ControlDownArrow);
                        else
                            redraw = ActiveEditor.HandleInput(EditorInput.DownArrow);
                        break;
                    case ConsoleKey.LeftArrow:
                        redraw = ActiveEditor.HandleInput(EditorInput.LeftArrow);
                        break;
                    case ConsoleKey.RightArrow:
                        redraw = ActiveEditor.HandleInput(EditorInput.RightArrow);
                        break;
                    case ConsoleKey.Enter:    
                        // I dont f*****g care, sue me
                        // This is why we need to f*****g refactor
                        redraw = ActiveEditor.HandleInput(EditorInput.Enter);
                        if (ActiveEditor is CommandPalette && lastEditor != null)
                        {
                            ActiveEditor = lastEditor;
                            RedrawEditors();
                        }
                        else if(Editors.Count == 0)
                        {
                            lastEditor = null;
                            ActiveEditor = null;
                            _console.ResetColor();
                            _console.Clear();
                            _console.CursorTop = 2;
                            _console.CursorLeft = 4;
                            _console.Write("* No editors! Press Ctrl+N to create or Ctrl+O to open!");
                            continue;
                        }
                        break;
                    case ConsoleKey.Backspace:
                        redraw = ActiveEditor.HandleInput(EditorInput.Backspace);
                        break;
                    case ConsoleKey.Tab:
                        if (keyInfo.Modifiers.HasFlag(ConsoleModifiers.Shift))
                            redraw = ActiveEditor.HandleInput(EditorInput.ShiftTab);
                        else
                            redraw = ActiveEditor.HandleInput(EditorInput.Tab);
                        break;
                    case ConsoleKey.Home:
                        if (keyInfo.Modifiers.HasFlag(ConsoleModifiers.Control))
                            redraw = ActiveEditor.HandleInput(EditorInput.ControlHome);
                        else
                            redraw = ActiveEditor.HandleInput(EditorInput.Home);
                        break;
                    case ConsoleKey.End:
                        if (keyInfo.Modifiers.HasFlag(ConsoleModifiers.Control))
                            redraw = ActiveEditor.HandleInput(EditorInput.ControlEnd);
                        else
                            redraw = ActiveEditor.HandleInput(EditorInput.End);
                        break;
                    case ConsoleKey.PageDown:
                        if (keyInfo.Modifiers.HasFlag(ConsoleModifiers.Control))
                            redraw = ActiveEditor.HandleInput(EditorInput.ControlPageDown);
                        else
                            redraw = ActiveEditor.HandleInput(EditorInput.PageDown);
                        break;
                    case ConsoleKey.PageUp:
                        if (keyInfo.Modifiers.HasFlag(ConsoleModifiers.Control))
                            redraw = ActiveEditor.HandleInput(EditorInput.ControlPageUp);
                        else
                            redraw = ActiveEditor.HandleInput(EditorInput.PageUp);
                        break;
                    case ConsoleKey.Delete:
                        redraw = ActiveEditor.HandleInput(EditorInput.Delete);
                        break;
                }

                if (!Char.IsControl(keyInfo.KeyChar))
                {
                    redraw = ActiveEditor.HandleInput(keyInfo.KeyChar.ToString());
                }

                if (redraw)
                {
                    ActiveEditor.AdjustWindow();
                    ActiveEditor.Render();
                }
                else if (ActiveEditor.AdjustWindow())
                {
                    ActiveEditor.Render();
                }

                ActiveEditor.ActivateCursor();
            }
        }
예제 #34
0
 public static void UpdateKeyboard(this TextBox textBox, ITextInput textInput)
 {
     textBox.UpdateInputScope(textInput);
 }
예제 #35
0
 public static void UpdateIsTextPredictionEnabled(this TextBox textBox, ITextInput textInput)
 {
     textBox.UpdateInputScope(textInput);
 }
예제 #36
0
 public static void UpdateIsReadOnly(this TextBox textBox, ITextInput textInput)
 {
     textBox.IsReadOnly = textInput.IsReadOnly;
 }
예제 #37
0
 public static void MapSelectionLength(IEditorHandler handler, ITextInput editor)
 {
     handler.PlatformView?.UpdateSelectionLength(editor);
 }
        private Option<Token> TryIdentifySingleToken(ITextInput input)
        {

            DottedItemSet currentItemSet = this.InitialSet;

            IEnumerator<char> lookahead = input.LookAhead.GetEnumerator();

            PrintInitialItemSet(currentItemSet);

            Option<Token> outputToken = Option<Token>.None();

            while (currentItemSet.Any() && lookahead.MoveNext())
            {

                currentItemSet = currentItemSet.GetFollowingSet(lookahead.Current);

                currentItemSet
                    .TryReduce()
                    .ForEach(token => outputToken = Option<Token>.Some(token));

                PrintInputAndItemSet(lookahead.Current, currentItemSet, outputToken);

            }

            PrintReducedToken(outputToken);

            this.EndOfRecognitionStep();

            return outputToken;

        }