Example #1
0
        private void AddText()
        {
            var value = Text;

            if (string.IsNullOrWhiteSpace(value))
            {
                return;
            }

            var previous = _filtersHistory.TakeWhile(x => !string.Equals(x, value, StringComparison.OrdinalIgnoreCase)).Count();

            if (previous < _filtersHistory.Count)
            {
                _filtersHistory.Move(previous, 0);
            }
            else if (DateTime.Now - _lastChanged > TimeSpan.FromSeconds(4) || _filtersHistory.Count == 0)
            {
                if (_filtersHistory.Count > MaxSize)
                {
                    _filtersHistory.RemoveAt(_filtersHistory.Count - 1);
                }

                _filtersHistory.Insert(0, value);
            }
            else
            {
                _filtersHistory[0] = value;
            }

            _lastChanged = DateTime.Now;

            var saveKey = SaveKey;

            if (saveKey != null)
            {
                ValuesStorage.Set(saveKey, _filtersHistory);
            }
        }