private void _update() { // Open code completion after the user has pressed dot: if (_completionWindow == null || !_completionWindow.IsVisible) { if (_li.Parent != null) { ((CompletionWindow)_li.Parent).Content = null; } _completionWindow = new CompletionWindow(_textEditor.TextArea, _li); _completionWindow.Changed += new EventHandler(_completionWindow_Changed); _completionWindow.Closed += delegate { if (_completionWindow != null) { _completionWindow.Content = null; } _completionWindow = null; }; } RangeObservableCollectionX <ICompletionData> data = (RangeObservableCollectionX <ICompletionData>)_li.CompletionData; data.Clear(); if (_skills == null) { _skills = new List <string>(); _skill_db = SdeEditor.Instance.ProjectDatabase.GetMetaTable <int>(ServerDbs.Skills); _skill_db.FastItems.ForEach(p => _skills.Add(p.GetStringValue(ServerSkillAttributes.Name.Index))); } string word = AvalonLoader.GetWholeWord(_textEditor.TextArea.Document, _textEditor); List <string> words = ScriptEditorList.Words.Where(p => p.IndexOf(word, StringComparison.OrdinalIgnoreCase) != -1).OrderBy(p => p).ToList(); List <string> constants = ScriptEditorList.Constants.Where(p => p.IndexOf(word, StringComparison.OrdinalIgnoreCase) != -1).OrderBy(p => p).ToList(); List <string> skills = _skills.Where(p => p.IndexOf(word, StringComparison.OrdinalIgnoreCase) != -1).OrderBy(p => p).ToList(); if (words.Count == 0 && constants.Count == 0 && skills.Count == 0) { _completionWindow.Close(); return; } IEnumerable <ICompletionData> results = words.Select(p => (ICompletionData) new MyCompletionData(p, _textEditor, DataType.Function)). Concat(constants.Select(p => (ICompletionData) new MyCompletionData(p, _textEditor, DataType.Constant))). Concat(skills.Select(p => (ICompletionData) new MyCompletionData(p, _textEditor, DataType.Skill))); data.AddRange(results); _completionWindow.CompletionList.ListBox.ItemsSource = data; _completionWindow.Show(); _completionWindow.CompletionList.SelectedItem = _completionWindow.CompletionList.CompletionData.FirstOrDefault(p => String.Compare(p.Text, word, StringComparison.OrdinalIgnoreCase) >= 0); TokeiLibrary.WPF.Extensions.ScrollToCenterOfView(_completionWindow.CompletionList.ListBox, _completionWindow.CompletionList.SelectedItem); }
private void _textArea_TextEntering(object sender, TextCompositionEventArgs e) { if (e.Text.Length > 0 && _completionWindow != null) { if (!char.IsLetterOrDigit(e.Text[0]) && e.Text[0] != '_') { if (e.Text[0] != '\t') { // The match must be exact string word = AvalonLoader.GetWholeWord(_textEditor.TextArea.Document, _textEditor); if (_li.SelectedItem == null || !_li.SelectedItem.ToString().StartsWith(word ?? "", StringComparison.OrdinalIgnoreCase)) { _completionWindow.Close(); return; } } _completionWindow.CompletionList.RequestInsertion(e); } } //if (e.Text.Length > 0 && _completionWindow == null) { // if (e.Text[0] == '}') { // int curLine = _textEditor.TextArea.Caret.Line; // var text = _getText(curLine); // int tabCount = _findIndex(curLine, '}'); // // if (tabCount > 0) { // if (tabCount == block.OuterIndent.Length + 1) { // // remove one! // doc.Text = block.OuterIndent + line.Substring(tabCount); // } // } // } //} }