예제 #1
0
        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);
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #5
0
        public EntityValueArray(TextSlice slice, IValueConverter <TValue> converter)
        {
            _slice     = slice;
            _converter = converter;

            _values = new List <Value <TValue> >();
        }
예제 #6
0
        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);
        }
예제 #7
0
        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");
        }
예제 #9
0
        public bool TryConvert(TextSlice slice, out Value <string> convertedValue)
        {
            Debug.Assert(slice != null);

            convertedValue = new StringValue(slice.SourceText, slice.SourceSpan);

            return(true);
        }
예제 #10
0
        public void Map(TEntity entity, TextSlice slice)
        {
            var valueSlice = _valueSliceFactory(slice, _position);

            var value = _valueFactory(valueSlice);

            _writeProperty.Set(entity, value);
        }
예제 #11
0
        TextSlice Single(TextSlice slice, int position)
        {
            TextSlice result;

            slice.TryGetSlice(position, out result);

            return(result ?? Slice.Missing);
        }
예제 #12
0
 private static bool IsDotDot(TextSlice slice, string path)
 {
     if (slice.Length != 2)
     {
         return(false);
     }
     return(path[slice.Start] == '.' && path[slice.End] == '.');
 }
예제 #13
0
        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);
        }
예제 #14
0
        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);
        }
예제 #15
0
        int Do(int position)
        {
            var slice = _dos[position];

            var newPosition = (slice.Text == _textSlice.Text || _dos.Count < MaxDosCount) ? position : position - 1;

            TextSlice = slice;

            return(newPosition);
        }
예제 #16
0
        public TEntity GetEntity(TextSlice slice)
        {
            TEntity entity = _factory.Create();

            for (int i = 0; i < _properties.Length; i++)
            {
                _properties[i].Map(entity, slice);
            }

            return(entity);
        }
예제 #17
0
        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}");
        }
예제 #18
0
        public bool TryGetSlice(int index, out TextSlice slice)
        {
            if (index != 0)
            {
                slice = Slice.Missing;
                return(false);
            }

            slice = this;
            return(true);
        }
예제 #19
0
        public bool TryGetSlice(int index, out TextSlice slice)
        {
            if (index != 0)
            {
                slice = default;
                return(false);
            }

            slice = this;
            return(true);
        }
예제 #20
0
        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));
        }
예제 #21
0
        TEntity Convert(TextSlice slice)
        {
            var entity = _factory.Create();

            for (var i = 0; i < _properties.Length; i++)
            {
                _properties[i].Convert(entity, slice);
            }

            return(entity);
        }
예제 #22
0
        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}");
        }
예제 #23
0
        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);
        }
예제 #24
0
        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);
        }
예제 #25
0
        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);
        }
예제 #26
0
        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);
        }
예제 #27
0
        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);
        }
예제 #28
0
        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);
        }
예제 #29
0
        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);
                }
            }
        }
예제 #30
0
        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);
        }
예제 #31
0
		// 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);
					}
				}
예제 #32
0
		// 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();
					}
				}
예제 #33
0
			// 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);
						}
					}