コード例 #1
0
ファイル: Extensions.cs プロジェクト: vvmk/VsVim
        public static Result <IVsTextLines> GetTextLines(this IVsWindowFrame vsWindowFrame)
        {
            try
            {
                var vsCodeWindow = vsWindowFrame.GetCodeWindow().Value;

                ErrorHandler.ThrowOnFailure(vsCodeWindow.GetBuffer(out IVsTextLines vsTextLines));
                if (vsTextLines == null)
                {
                    return(Result.Error);
                }

                return(Result.CreateSuccess(vsTextLines));
            }
            catch (Exception ex)
            {
                return(Result.CreateError(ex));
            }
        }
コード例 #2
0
        internal bool TryGetFocusedTextView(out ITextView textView)
        {
            var activeView = ViewManager.Instance.ActiveView;
            var result     = _vsAdapter.GetWindowFrames();

            if (result.IsError)
            {
                textView = null;
                return(false);
            }

            IVsWindowFrame activeWindowFrame = null;

            foreach (var vsWindowFrame in result.Value)
            {
                var frame = vsWindowFrame as WindowFrame;
                if (frame != null && frame.FrameView == activeView)
                {
                    activeWindowFrame = frame;
                    break;
                }
            }

            if (activeWindowFrame == null)
            {
                textView = null;
                return(false);
            }

            // TODO: Should try and pick the ITextView which is actually focussed as
            // there could be several in a split screen
            try
            {
                textView = activeWindowFrame.GetCodeWindow().Value.GetPrimaryTextView(_editorAdaptersFactoryService).Value;
                return(textView != null);
            }
            catch
            {
                textView = null;
                return(false);
            }
        }