コード例 #1
0
        public void UnfoldAndScroll(int lineNumber)
        {
            if (lineNumber <= 0 || lineNumber > textEditor.Document.LineCount)
            {
                return;
            }

            var line = textEditor.Document.GetLineByNumber(lineNumber);

            // unfold
            var foldings = foldingManager.GetFoldingsContaining(line.Offset);

            if (foldings != null)
            {
                foreach (var folding in foldings)
                {
                    if (folding.IsFolded)
                    {
                        folding.IsFolded = false;
                    }
                }
            }
            // scroll to
            textEditor.ScrollTo(lineNumber, 0);
        }
コード例 #2
0
        public void FoldToggle(int offset)
        {
            if (_foldingManager.AllFoldings == null)
            {
                return;
            }

            var foldSection = _foldingManager.GetFoldingsContaining(offset);

            if (foldSection.Count > 0)
            {
                foldSection[^ 1].IsFolded = !foldSection[^ 1].IsFolded;
コード例 #3
0
        public override void Run()
        {
            ITextEditor    editor         = SD.GetActiveViewContentService <ITextEditor>();
            FoldingManager foldingManager = editor.GetService(typeof(FoldingManager)) as FoldingManager;

            if (foldingManager != null)
            {
                // look for folding on this line:
                FoldingSection folding = foldingManager.GetNextFolding(editor.Document.PositionToOffset(editor.Caret.Line, 1));
                if (folding == null || editor.Document.GetLineForOffset(folding.StartOffset).LineNumber != editor.Caret.Line)
                {
                    // no folding found on current line: find innermost folding containing the caret
                    folding = foldingManager.GetFoldingsContaining(editor.Caret.Offset).LastOrDefault();
                }
                if (folding != null)
                {
                    folding.IsFolded = !folding.IsFolded;
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Toggles the folding at the caret position.
        /// </summary>
        public void ToggleCurrentFolding()
        {
            if (FoldingManager == null)
            {
                return;
            }

            // Get next folding on the current line.
            var folding = FoldingManager.GetNextFolding(CaretOffset);

            if (folding == null || Document.GetLocation(folding.StartOffset).Line != Document.GetLocation(CaretOffset).Line)
            {
                // No folding after caret on the same line. --> Search for innermost folding that contains
                // the caret.
                folding = FoldingManager.GetFoldingsContaining(CaretOffset).LastOrDefault();
            }

            // Toggle folding if a folding was found.
            if (folding != null)
            {
                folding.IsFolded = !folding.IsFolded;
            }
        }
コード例 #5
0
        public void Execute(TextViewContext context)
        {
            var textView = context.TextView;

            if (null == textView)
            {
                return;
            }
            var            editor         = textView.textEditor;
            FoldingManager foldingManager = context.TextView.FoldingManager;

            if (null == foldingManager)
            {
                return;
            }
            // TODO: or use Caret if position is not given?
            var posBox = context.Position;

            if (null == posBox)
            {
                return;
            }
            TextViewPosition pos = posBox.Value;
            // look for folding on this line:
            FoldingSection folding = foldingManager.GetNextFolding(editor.Document.GetOffset(pos.Line, 1));

            if (folding == null || editor.Document.GetLineByOffset(folding.StartOffset).LineNumber != pos.Line)
            {
                // no folding found on current line: find innermost folding containing the mouse position
                folding = foldingManager.GetFoldingsContaining(editor.Document.GetOffset(pos.Line, pos.Column)).LastOrDefault();
            }
            if (folding != null)
            {
                folding.IsFolded = !folding.IsFolded;
            }
        }
コード例 #6
0
 internal string GetFoldingTitle()
 {
     return(mFoldingManager.GetFoldingsContaining(mTextEditor.CaretOffset)[0].Title);
 }