コード例 #1
0
 /// <summary>
 /// Extracts identifier sequence at the caret location.
 /// Fetches parts of 'abc$def' rather than tne entire expression.
 /// If there is selection, returns complete selected item as is.
 /// </summary>
 public static string GetIdentifierUnderCaret(this IEditorView view, out ITextRange span)
 {
     if (!view.Caret.InVirtualSpace)
     {
         if (view.Selection.Mode == SelectionMode.Stream)
         {
             var position      = view.Caret.Position;
             int caretPosition = -1;
             span = view.Selection.SelectedRange;
             if (span.Length > 0)
             {
                 return(view.EditorBuffer.CurrentSnapshot.GetText(span));
             }
             var line = position.GetContainingLine();
             caretPosition = caretPosition >= 0 ? caretPosition : position.Position;
             var item = GetItemAtPosition(line, caretPosition, x => x == RTokenType.Identifier, out span);
             if (string.IsNullOrEmpty(item))
             {
                 item = view.GetItemBeforeCaret(out span, x => x == RTokenType.Identifier);
             }
             return(item);
         }
     }
     span = TextRange.EmptyRange;
     return(string.Empty);
 }