From be4e8bb34e0f82341939ee97b4a8e18b1c69134d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Kr=C3=BCger?= Date: Mon, 19 Mar 2012 18:43:43 +0100 Subject: [PATCH] Added function to get the word segment at caret position. --- .../Completion/CSharpCompletionEngine.cs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs b/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs index 4b284445e3..c28ff0d3f4 100644 --- a/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs +++ b/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs @@ -73,6 +73,34 @@ namespace ICSharpCode.NRefactory.CSharp.Completion this.IndentString = "\t"; } + public bool TryGetCompletionWord (int offset, out int startPos, out int wordLength) + { + startPos = wordLength = 0; + int pos = offset - 1; + while (pos >= 0) { + char c = document.GetCharAt (pos); + if (!char.IsLetterOrDigit (c) && c != '_') + break; + pos--; + } + if (pos == -1) + return false; + + pos++; + startPos = pos; + + while (pos < document.TextLength) { + char c = document.GetCharAt (pos); + if (!char.IsLetterOrDigit (c) && c != '_') + break; + pos++; + } + wordLength = pos - startPos; + return true; + } + + + public IEnumerable GetCompletionData(int offset, bool controlSpace) { this.AutoCompleteEmptyMatch = true;