GetWordFromPosition() публичный Метод

Gets a word from the specified position
public GetWordFromPosition ( int position ) : string
position int
Результат string
Пример #1
0
        /// <summary> Tested ? Working ? </summary>
        /// <param name="sender"> </param>
        /// <param name="e"> </param>
        private void selectedScintilla_CharAdded(object sender, CharAddedEventArgs e)
        {
            // Find the word start
            var currentPos   = selectedScintilla.CurrentPosition;
            var wordStartPos = selectedScintilla.WordStartPosition(currentPos, true);

            //string AutoCompleteList = "Gen_SQLite Gen_TreeView Gen_Grid List<int> List<TreeNode>";  // list of words to offer autocomplete options

            //string AutoCompleteString = String.Join(" ", AutoCompleteList.ToArray());

            selectedScintilla.AutoCAutoHide = false;  // hide popup after text is ruled out

            string trimmedWordList = "";
            // Display the autocompletion list
            var lenEntered = currentPos - wordStartPos;

            if (lenEntered > 0)
            {
                selectedScintilla.AutoCIgnoreCase     = true;
                selectedScintilla.AutoCChooseSingle   = false;
                selectedScintilla.AutoCMaxHeight      = 10;
                selectedScintilla.AutoCDropRestOfWord = true;

                string SoFarText = selectedScintilla.GetWordFromPosition(wordStartPos);  // word typed so far
                //ahk.MsgBox(Text);

                //string[] words = AutoCompleteList.Split(' ');
                string[] words = autoCompleteList.ToArray();

                foreach (string word in words)
                {
                    string TextInList = ahk.FirstCharacters(word, lenEntered); // returns first X characters in string
                    if (TextInList.ToUpper() == SoFarText.ToUpper())
                    {
                        trimmedWordList = trimmedWordList + " " + word;
                    }
                    //if (TextInList.ToUpper().Contains(SoFarText.ToUpper())) { trimmedWordList = trimmedWordList + " " + word; }
                }
                selectedScintilla.AutoCShow(lenEntered, trimmedWordList.Trim());

                //if (lenEntered > 3) { scintilla1.AutoCComplete(); }  // autocomplete past X characters

                selectedScintilla.AutoCCompleted += new EventHandler <AutoCSelectionEventArgs>(selectedScintilla_AutoCompleteAccepted);
                hit = false;

                //scintilla1.AutoCShow(lenEntered, AutoCompleteList);
                //     regex pattern matching and highlighting - untested
                //foreach (Match m in Patterns.Keyword0.Matches(Encoding.ASCII.GetString(e.RawText)))
                //   e.GetRange(m.Index, m.Index + m.Length).SetStyle(1);
            }
        }
Пример #2
0
        private IEnumerable <AutocompleteMenuNS.AutocompleteItem> BuildList()
        {
            var startPosition = _tb.WordStartPosition(_tb.CurrentPosition, false);

            var currentWord = _tb.GetWordFromPosition(startPosition);

            if (currentWord.Contains("."))
            {
                foreach (var word in _keywords.Where(k => k.Word.StartsWith(currentWord)))// || k.Word.StartsWith("any.")))
                {
                    yield return(new AutocompleteMenuNS.MethodAutocompleteItem(word.Word.Split('.')[1]));
                }

                if (_words.Contains(currentWord.Trim('.')))
                {
                    foreach (var word in _keywords.Where(k => k.Word.StartsWith("any.")))
                    {
                        yield return(new AutocompleteMenuNS.MethodAutocompleteItem(word.Word.Split('.')[1]));
                    }
                }
            }
            else
            {
                foreach (var word in _keywords.Where(k => k.Word.StartsWith(currentWord) && !k.Word.Contains(".")))
                {
                    yield return(new AutocompleteMenuNS.AutocompleteItem(word.Word));
                }

                foreach (var word in _words.Where(w => w.StartsWith(currentWord)))
                {
                    yield return(new AutocompleteMenuNS.AutocompleteItem(word));
                }
            }
        }
Пример #3
0
        static void editor_CharAdded(object sender, CharAddedEventArgs e)
        {
            ScintillaNET.Scintilla editor = sender as ScintillaNET.Scintilla;
            int    pos  = editor.NativeInterface.GetCurrentPos();
            string word = editor.GetWordFromPosition(pos);

            if (e.Ch == '.')
            {
                word = editor.GetWordFromPosition(pos - 1);

                //
                // This is a quick and dirty way to populate an autocomplete list.  For a more through implementation you would want to
                // support caching of this information.  This will eliminate the reflection hit each time.
                //
                Type foundType = (from a in AppDomain.CurrentDomain.GetAssemblies()
                                  from type in GetTypes(a)
                                  where type != null && type.Name.ToLower() == word.ToLower()
                                  select type).FirstOrDefault();

                if (foundType != null)
                {
                    List <string> acList = (from m in foundType.GetMembers()
                                            where !m.Name.Contains("ctor")
                                            orderby m.Name ascending
                                            select m.Name).ToList();

                    if (acList.Count > 0)
                    {
                        Timer t = new Timer();
                        t.Interval = 10;
                        t.Tag      = editor;
                        t.Tick    += new EventHandler((obj, ev) =>
                        {
                            editor.AutoComplete.Show(acList);

                            t.Stop();
                            t.Enabled = false;
                            t.Dispose();
                        });
                        t.Start();
                    }
                }
            }
        }
Пример #4
0
        public Editor(ScintillaNET.Scintilla editor, AutocompleteMenuNS.AutocompleteMenu autocomplete)
        {
            _codeArea = editor;

            _codeArea.CharAdded += (sender, e) =>
            {
                var currentPos = _codeArea.CurrentPosition;
                InsertMatchedChars(e);

                _autocompleteItems.RefreshWords();
                if (e.Char == 32)
                {
                    var lastWord = _codeArea.GetWordFromPosition(currentPos - 1);
                    _autocompleteItems.AddWord(lastWord);
                }
                if (e.Char == 13)
                {
                    var lastWord = _codeArea.GetWordFromPosition(currentPos - 3);
                    _autocompleteItems.AddWord(lastWord);
                }
            };

            _autocompleteMenu = autocomplete;
        }