public static void UpdateCursorPosition(this EditText editText, ITextInput entry) { if (editText.SelectionStart != entry.CursorPosition) { UpdateCursorSelection(editText, entry); } }
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; } }; }
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(); }
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); } }
public static void UpdateCursorPosition(this TextBox textBox, ITextInput entry) { if (textBox.SelectionStart != entry.CursorPosition) { textBox.SelectionStart = entry.CursorPosition; } }
public static void UpdateSelectionLength(this TextBox textBox, ITextInput entry) { if (textBox.SelectionLength != entry.SelectionLength) { textBox.SelectionLength = entry.SelectionLength; } }
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]; }
/* 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); } }
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; } }
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; } }
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); }
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; } }
private ITextInput InitializeInput() { this.PromptUser(); string text = this.ReadText(); this.basicInput = new StringInput(text); this.GetBasicTextInput = () => this.basicInput; return this.basicInput; }
public Interactor( ITextInput textInput, IWordCountAnalyzer wordCountAnalyzer, IWordCountAnalyzerOutput wordCountAnalyzerOutput, IIndexOutput indexOutput, IHelpOutput helpOutput) { TextInput = textInput; WordCountAnalyzer = wordCountAnalyzer; WordCountAnalyzerOutput = wordCountAnalyzerOutput; IndexOutput = indexOutput; HelpOutput = helpOutput; }
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; } }
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); }
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(); }
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); }
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; } }
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"); }
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); }
/// <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); }
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; } }
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); } }
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); } }
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); }
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; }
public static void UpdateReturnType(this TextBox textBox, ITextInput textInput) { textBox.UpdateInputScope(textInput); }
private void NewEditor() { Editors.Insert(0, new Editor(_console, string.Format("untitled {0}", ++numUntitled), 0, 0, 80, 24)); ActiveEditor = Editors[0]; ResizeEditors(); RedrawEditors(); }
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(); } }
public static void UpdateKeyboard(this TextBox textBox, ITextInput textInput) { textBox.UpdateInputScope(textInput); }
public static void UpdateIsTextPredictionEnabled(this TextBox textBox, ITextInput textInput) { textBox.UpdateInputScope(textInput); }
public static void UpdateIsReadOnly(this TextBox textBox, ITextInput textInput) { textBox.IsReadOnly = textInput.IsReadOnly; }
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; }