예제 #1
0
        /// <summary>
        /// Returns the ITextView which should have keyboard focus.  This method is used during macro
        /// running and hence must account for view changes which occur during a macro run.  Say by the
        /// macro containing the 'gt' command.  Unfortunately these don't fully process through Visual
        /// Studio until the next UI thread pump so we instead have to go straight to the view controller
        /// </summary>
        public override FSharpOption <ITextView> GetFocusedTextView()
        {
            var activeView = ViewManager.Instance.ActiveView;

            // Now find the ITextBuffer which has the matching View instance
            foreach (var textBuffer in _textManager.TextBuffers)
            {
                var result = _adapter.GetContainingWindowFrame(textBuffer);
                if (result.IsError)
                {
                    continue;
                }

                var frame = result.Value as WindowFrame;
                if (frame != null && frame.FrameView == activeView)
                {
                    // TODO: Should try and pick the ITextView which is actually focussed as
                    // there could be several in a split screen
                    var textView = _textManager.GetTextViews(textBuffer).FirstOrDefault();
                    if (textView != null)
                    {
                        return(FSharpOption.Create(textView));
                    }
                }
            }

            return(FSharpOption <ITextView> .None);
        }