void SetTextHint(TextSlice slice) { _predictionSlice = slice; if (slice.Text.Length == 0) { _ambiguousKeys.Clear(); } var hints = _ambiguousKeys.Count > 0 ? _ambiguousKeys : null; _queuedPrediction = _predictor.CreatePrediction(slice.Text, slice.Start, slice.Length, _isAutoSpaceNeeded, hints); if (AppSettings.Instance.Prediction.PredictCharacters) { var characterSuggestions = _queuedPrediction.GetSuggestions(SuggestionType.Character); _environment.GazeProvider?.SetCharacterSuggestions(characterSuggestions); } foreach (var item in SuggestionItems) { item.IsEnabled = false; } foreach (var item in PhraseItems) { item.IsEnabled = false; } if (!_suggesterRunning) { _suggesterRunning = true; ThreadPool.QueueUserWorkItem(SuggesterThread); } }
Value <TValue> GetValue() { Value <TValue> value; TextSlice slice; if (_position.HasValue) { if (_slice.TryGetSlice(_position.Value, out slice)) { Value <TValue> getValue; value = _converter.TryConvert(slice, out getValue) ? getValue : new InvalidValue <TValue>(slice); } else { slice = Slice.Missing; value = Value.Missing <TValue>(); } } else { slice = _slice; Value <TValue> getValue; value = _converter.TryConvert(slice, out getValue) ? getValue : new InvalidValue <TValue>(slice); } _valueSlice = slice ?? Slice.Missing; _value = value ?? Value.Missing <TValue>(); _valueComputed = true; return(_value); }
public bool TryConvert(TextSlice slice, out Value <TEntity> convertedValue) { var entity = Convert(slice); convertedValue = new ConvertedValue <TEntity>(slice.SourceText, slice.SourceSpan, entity); return(true); }
/// <summary> /// Interpret keystrokes. /// </summary> /// <param name="keys">SendKeys coded keystrokes.</param> public TextSlice Interpret(string keys) { switch (keys.ToUpperInvariant()) { // Undo. case "^Z": if (0 < _doPosition) { _doPosition = Do(_doPosition - 1); } break; // Redo. case "^Y": case "^Y{END}": if (_doPosition < _redoLimit) { _doPosition = Do(_doPosition + 1); } break; default: var slice = KeystrokeInterpreter.Interpret(_clipboardProvider, TextSlice, keys); if (slice != TextSlice) { TextSlice = slice; _redoLimit = _dos.Count; } break; } return(TextSlice); }
public EntityValueArray(TextSlice slice, IValueConverter <TValue> converter) { _slice = slice; _converter = converter; _values = new List <Value <TValue> >(); }
public bool TryConvert(TextSlice slice, out Value <TValue> convertedValue) { Debug.Assert(slice != null); convertedValue = new ConvertedValue <TValue>(slice.SourceText, slice.SourceSpan, _valueProvider(slice)); return(true); }
public ConvertedValue(TextSlice slice, TValue value, bool hasValue = true) { Value = value; HasValue = hasValue; Slice = slice; }
static void Check(TextBoxEditor editor, string keys, TextSlice expected) { var clipboardProvider = new TestClipboardProvider(); editor.Interpret(keys); Assert.AreEqual(expected, editor.TextSlice, "Expected result of keystroke"); }
public bool TryConvert(TextSlice slice, out Value <string> convertedValue) { Debug.Assert(slice != null); convertedValue = new StringValue(slice.SourceText, slice.SourceSpan); return(true); }
public void Map(TEntity entity, TextSlice slice) { var valueSlice = _valueSliceFactory(slice, _position); var value = _valueFactory(valueSlice); _writeProperty.Set(entity, value); }
TextSlice Single(TextSlice slice, int position) { TextSlice result; slice.TryGetSlice(position, out result); return(result ?? Slice.Missing); }
private static bool IsDotDot(TextSlice slice, string path) { if (slice.Length != 2) { return(false); } return(path[slice.Start] == '.' && path[slice.End] == '.'); }
public bool TryConvert(TextSlice slice, out Value <string> convertedValue) { Debug.Assert(slice != null); string text = slice.Text.ToString(); convertedValue = new ConvertedValue <string>(slice, text); return(true); }
public bool TryConvert(TextSlice slice, out Value <FT> convertedValue) { Debug.Assert(slice != null); string text = slice.Text.ToString(); convertedValue = new ConvertedValue <FT>(slice.SourceText, slice.SourceSpan, text, text?.Length > 0); return(true); }
int Do(int position) { var slice = _dos[position]; var newPosition = (slice.Text == _textSlice.Text || _dos.Count < MaxDosCount) ? position : position - 1; TextSlice = slice; return(newPosition); }
public TEntity GetEntity(TextSlice slice) { TEntity entity = _factory.Create(); for (int i = 0; i < _properties.Length; i++) { _properties[i].Map(entity, slice); } return(entity); }
public T GetEntity <T>(TextSlice slice) where T : Entity { if (typeof(T).IsAssignableFrom(typeof(TEntity))) { object entity = GetEntity(slice); return((T)entity); } throw new ArgumentException($"The type argument {TypeCache<T>.ShortName} is not assignable from the entity type ({TypeCache<TEntity>.ShortName}"); }
public bool TryGetSlice(int index, out TextSlice slice) { if (index != 0) { slice = Slice.Missing; return(false); } slice = this; return(true); }
public bool TryGetSlice(int index, out TextSlice slice) { if (index != 0) { slice = default; return(false); } slice = this; return(true); }
Value <TValue> Factory(TextSlice slice) { if (SliceProvider != null) { var valueSlice = SliceProvider(slice, Position); return(new ConvertValue <TValue>(valueSlice, _valueConverter)); } return(new ConvertValue <TValue>(slice, Position, _valueConverter)); }
TEntity Convert(TextSlice slice) { var entity = _factory.Create(); for (var i = 0; i < _properties.Length; i++) { _properties[i].Convert(entity, slice); } return(entity); }
public T Convert <T>(TextSlice slice) where T : Entity { var entity = Convert(slice); if (entity is T result) { return(result); } throw new ArgumentException($"The type argument {TypeCache<T>.ShortName} is not assignable from the entity type ({TypeCache<TEntity>.ShortName}"); }
public bool TryConvert(TextSlice slice, out Value <TEntity> convertedValue) { TEntity entity = _factory.Create(); for (int i = 0; i < _properties.Length; i++) { _properties[i].Map(entity, slice); } convertedValue = new ConvertedValue <TEntity>(slice, entity); return(true); }
public bool TryConvert(TextSlice slice, out Value <Guid> convertedValue) { Debug.Assert(slice != null); if (Guid.TryParse(slice.Text.ToString(), out var value)) { convertedValue = new ConvertedValue <Guid>(slice.SourceText, slice.SourceSpan, value); return(true); } convertedValue = null; return(false); }
public bool TryConvert(TextSlice slice, out Value <DateTimeOffset> convertedValue) { Debug.Assert(slice != null); if (DateTimeOffset.TryParse(slice.Text.ToString(), CultureInfo.InvariantCulture, Styles, out var value)) { convertedValue = new ConvertedValue <DateTimeOffset>(slice.SourceText, slice.SourceSpan, value); return(true); } convertedValue = Value.Empty <DateTimeOffset>(); return(false); }
public bool TryConvert(TextSlice slice, out Value <int> convertedValue) { Debug.Assert(slice != null); if (int.TryParse(slice.Text.ToString(), _styles, CultureInfo.InvariantCulture, out var value)) { convertedValue = new ConvertedValue <int>(slice.SourceText, slice.SourceSpan, value); return(true); } convertedValue = null; return(false); }
static TextSlice List(TextSlice slice, int position) { if (slice.TryGetSlice(position, out var result)) { if (result is ListTextSlice list && list.TryGetListSlice(out result)) { return(result); } throw new MacheteParserException($"The slice is not a list: {TypeCache<TEntity>.ShortName}.ValueList<{TypeCache<TValue>.ShortName}>"); } return(Slice.Missing); }
public bool TryConvert(TextSlice slice, out Value <decimal> convertedValue) { Debug.Assert(slice != null); decimal value; if (decimal.TryParse(slice.Text.ToString(), _styles, CultureInfo.InvariantCulture, out value)) { convertedValue = new ConvertedValue <decimal>(slice, value); return(true); } convertedValue = null; return(false); }
static bool IsComponentEmpty(TextSlice slice) { for (int i = 0;; i++) { if (!slice.TryGetSlice(i, out var nextSlice)) { return(true); } if (nextSlice.TryGetSlice(0, out _)) { return(false); } } }
public bool TryConvert(TextSlice slice, out Value <DateTimeOffset> convertedValue) { Debug.Assert(slice != null); DateTimeOffset value; if (DateTimeOffset.TryParseExact(slice.Text.ToString(), _patterns, CultureInfo.InvariantCulture, Styles, out value)) { convertedValue = new ConstantValue <DateTimeOffset>(value); return(true); } convertedValue = Value.Empty <DateTimeOffset>(); return(false); }
// Get a text slice with the given length, from the given position. public void GetSlice(int pos, int length, TextSlice slice) { // get the character count int charCount = CharCount; // enforce position bounds limits if(pos < 0 || pos >= charCount) { throw new ArgumentOutOfRangeException("pos"); } // enforce length bounds limits if(length <= 0 || (pos + length) >= charCount) { throw new ArgumentOutOfRangeException("length"); } // set the slice length slice.length = length; // set the slice character array and start position if((pos + length) <= gapStart) { // set the slice character array slice.chars = (char[])array; // set the slice start position slice.start = pos; } else if(pos >= gapStart) { // set the slice character array slice.chars = (char[])array; // set the slice start position slice.start = (pos + (gapEnd - gapStart)); } else { // create the slice character array slice.chars = new char[length]; // set the slice start position slice.start = 0; // get the number of characters to copy before the gap int before = (gapStart - pos); // get the number of characters to copy after the gap int after = (length - before); // copy the before gap characters to the slice array Array.Copy(array, pos, slice.chars, 0, before); // copy the after gap characters to the slice array Array.Copy(array, gapEnd, slice.chars, before, after); } }
// Get a string with the given length, from the given position. public String this[int pos, int length] { get { // create a text slice TextSlice slice = new TextSlice(); // get the slice data for the given range GetSlice(pos, length, slice); // create a new string from the slice return slice.ToString(); } }
// Update after an insertion. public static unsafe void InsertionUpdate (TextTree tree, TextBuffer buffer, int offset, int length) { // NOTE: this is here to keep the method calls down to // a minimum... technically, this belongs in the // tree, but it's more efficient to do this here, // where we can access the line/node fields // directly // declare the start offset of the insertion line int lineStart; // find the insertion line TextLine line = tree.FindLineByCharOffset (offset, out lineStart); // get the parent of the insertion line TextNode parent = line.Parent; // get the end offset of the insertion line int lineEnd = line.end.Offset; // create a text slice TextSlice slice = new TextSlice(); // get the inserted data into the slice buffer.GetSlice(offset, length, slice); // get the current line start position int currStart = lineStart; // get the current line end position int currEnd = (offset + 1); // set the default new line list TextLine first = null; // set the default previous new line TextLine prev = null; // find and create new lines, quickly fixed(char* start = &slice.chars[slice.start]) { char* curr = start; // get the insertion end position char* end = (curr + slice.length); // find and create new lines while(curr != end) { if(*curr == '\n') { if(currStart == lineStart) { // shorten the insertion line line.end.Move(currEnd); } else { // create a new line TextLine newline = new TextLine (buffer.MarkPosition(currStart, true), buffer.MarkPosition(currEnd, true)); // update list links if(first == null) { // set the current line as the first first = newline; } else { // set the current line's prev newline.prev = prev; // set the previous line's next prev.next = newline; } // set the previous line to the current prev = newline; } // update the current line start position currStart = currEnd; } // increment the current input pointer ++curr; // increment the current line end position ++currEnd; } } // insert new lines and rebalance parent, if needed if(first != null) { // add any remaining characters to new line if(currEnd < lineEnd) { // create a new line TextLine newline = new TextLine (buffer.MarkPosition(currStart, true), buffer.MarkPosition(currEnd, true)); // set the current line's prev reference newline.prev = prev; // set the previous line's next reference prev.next = newline; } // insert the new lines parent.InsertChildren(line, first); // rebalance, starting at the new lines' parent parent.Rebalance(tree); } }