Microsoft.R.Editor.TextViewExtensions.GetItemBeforeCaret C# (CSharp) Method

GetItemBeforeCaret() public static method

Extracts identifier or a keyword before caret. Typically used when inserting expansions (aka code snippets) at the caret location.
public static GetItemBeforeCaret ( this textView, Span &span, bool>.Func tokenTypeCheck = null ) : string
textView this
span Span
tokenTypeCheck bool>.Func
return string
        public static string GetItemBeforeCaret(this ITextView textView, out Span span, Func<RTokenType, bool> tokenTypeCheck = null) {
            if (!textView.Caret.InVirtualSpace) {
                SnapshotPoint position = textView.Caret.Position.BufferPosition;
                ITextSnapshotLine line = position.GetContainingLine();
                tokenTypeCheck = tokenTypeCheck ?? new Func<RTokenType, bool>((x) => x == RTokenType.Identifier);
                if (position.Position > line.Start) {
                    return GetItemAtPosition(line, position.Position - 1, tokenTypeCheck, out span);
                }
            }
            span = Span.FromBounds(0, 0);
            return string.Empty;
        }