예제 #1
0
        internal static int GetStartOfLineOffset(TextEditorData data, DocumentLocation loc)
        {
            var line = data.Document.GetLine(loc.Line);

            loc = new DocumentLocation(loc.Line, line.Length + 1);

            // handle folding
            var         foldings = data.Document.GetFoldingsFromOffset(line.Offset);
            FoldSegment segment  = null;

            foreach (FoldSegment folding in foldings)
            {
                if (folding.IsFolded)
                {
                    if (segment != null && segment.Offset < folding.Offset)
                    {
                        continue;
                    }
                    segment = folding;
                }
            }
            if (segment != null)
            {
                loc = data.Document.OffsetToLocation(segment.StartLine.Offset);
            }
            line = data.GetLine(loc.Line);
            return(line.Offset);
        }
예제 #2
0
 public FoldSegment(FoldSegment foldSegment) : base(foldSegment.Offset, foldSegment.Length)
 {
     this.doc         = foldSegment.doc;
     this.isFolded    = foldSegment.IsFolded;
     this.Description = foldSegment.Description;
     this.FoldingType = foldSegment.FoldingType;
 }
        public static void Right(TextEditorData data)
        {
            if (Platform.IsMac && data.IsSomethingSelected && !data.Caret.PreserveSelection)
            {
                data.Caret.Offset = System.Math.Max(data.SelectionAnchor, data.Caret.Offset);
                data.ClearSelection();
                return;
            }

            DocumentLine line = data.Document.GetLine(data.Caret.Line);
            IEnumerable <FoldSegment> foldings = data.Document.GetStartFoldings(line);
            FoldSegment segment = null;

            foreach (FoldSegment folding in foldings)
            {
                if (folding.IsFolded && folding.Column == data.Caret.Column)
                {
                    segment = folding;
                    break;
                }
            }
            if (segment != null)
            {
                data.Caret.Offset = segment.EndOffset;
                return;
            }

            if (data.Caret.Column >= line.Length + 1)
            {
                int nextColumn;
                if (data.HasIndentationTracker && data.Options.IndentStyle == IndentStyle.Virtual && data.Caret.Column == DocumentLocation.MinColumn)
                {
                    nextColumn = data.GetVirtualIndentationColumn(data.Caret.Location);
                }
                else if (data.Caret.AllowCaretBehindLineEnd)
                {
                    nextColumn = data.Caret.Column + 1;
                }
                else
                {
                    nextColumn = line.Length + 1;
                }

                if (data.Caret.Column < nextColumn)
                {
                    data.Caret.Column = nextColumn;
                }
                else
                {
                    if (data.Caret.Line < data.LineCount)
                    {
                        data.Caret.Location = new DocumentLocation(data.Caret.Line + 1, DocumentLocation.MinColumn);
                    }
                }
            }
            else
            {
                data.Caret.Column++;
            }
        }
예제 #4
0
        internal static int GetEndOfLineOffset(TextEditorData data, DocumentLocation loc, bool includeDelimiter = true)
        {
            var line = data.Document.GetLine(loc.Line);

            loc = new DocumentLocation(loc.Line, line.Length + 1);

            // handle folding
            var         foldings = data.Document.GetStartFoldings(loc.Line);
            FoldSegment segment  = null;

            foreach (FoldSegment folding in foldings)
            {
                if (folding.IsFolded && folding.Contains(data.Document.LocationToOffset(loc)))
                {
                    segment = folding;
                    break;
                }
            }
            if (segment != null)
            {
                loc = data.Document.OffsetToLocation(segment.EndLine.Offset + segment.EndColumn - 1);
            }
            line = data.GetLine(loc.Line);
            return(includeDelimiter ? line.EndOffsetIncludingDelimiter : line.EndOffset);
        }
예제 #5
0
        public void Dispose()
        {
            margin  = null;
            editor  = null;
            segment = null;

            Accessible.PerformPress -= PerformPress;
            Accessible = null;
        }
        /// <summary>
        /// Opens the current fold
        /// </summary>
        public static void OpenFold(TextEditorData data)
        {
            FoldSegment currentFold = GetOutermostClosedFold(data);

            if (null != currentFold)
            {
                currentFold.IsFolded = false;
                Commit(data);
            }
        }
        /// <summary>
        /// Closes the current fold
        /// </summary>
        public static void CloseFold(TextEditorData data)
        {
            FoldSegment currentFold = GetInnermostOpenedFold(data);

            if (null != currentFold)
            {
                currentFold.IsFolded = true;
                Commit(data);
            }
        }
예제 #8
0
        void ActivateFold(FoldSegment segment)
        {
            segment.IsCollapsed = !segment.IsCollapsed;
            editor.Document.InformFoldChanged(new FoldSegmentEventArgs(segment));

            editor.SetAdjustments();
            editor.Caret.MoveCaretBeforeFoldings();

            // Collapsing the fold causes highlighting to disappear
            HighlightFold(segment);
        }
예제 #9
0
        /// <summary>
        /// Closes the current fold
        /// </summary>
        public static void CloseFold(TextEditorData data)
        {
            FoldSegment currentFold = GetInnermostOpenedFold(data);

            if (null != currentFold)
            {
                currentFold.IsCollapsed = true;
                data.Document.InformFoldChanged(new FoldSegmentEventArgs(currentFold));
                Commit(data);
            }
        }
예제 #10
0
        public FoldingAccessible(FoldSegment segment, FoldMarkerMargin margin, MonoTextEditor editor)
        {
            Accessible = AccessibilityElementProxy.ButtonElementProxy();
            Accessible.PerformPress += PerformPress;
            Accessible.GtkParent     = margin.Accessible.GtkParent;

            this.segment = segment;
            this.margin  = margin;
            this.editor  = editor;

            UpdateAccessibility();
        }
예제 #11
0
 internal protected override void MouseLeft()
 {
     base.MouseLeft();
     hoverSegment = null;
     if (lineHover != null)
     {
         lineHover = null;
         editor.RedrawMargin(this);
     }
     StopTimer();
     RemoveBackgroundRenderer();
 }
예제 #12
0
        FoldSegment GetSelectedSegment(int lineNumber)
        {
            FoldSegment selectedSegment = null;

            foreach (var segment in editor.Document.GetFoldingContaining(lineNumber))
            {
                if (selectedSegment == null || selectedSegment.Contains(segment.Offset))
                {
                    selectedSegment = segment;
                }
            }
            return(selectedSegment);
        }
        /// <summary>
        /// If the caret is on a closed fold, opens it and all its children;
        /// else closes the current fold and all its parents.
        /// </summary>
        public static void ToggleFoldRecursive(TextEditorData data)
        {
            FoldSegment currentFold = GetOutermostClosedFold(data);

            if (null == currentFold)
            {
                CloseFoldRecursive(data);
            }
            else
            {
                OpenFoldRecursive(data);
            }
        }
예제 #14
0
        public static void Right(TextEditorData data)
        {
            if (Platform.IsMac && data.IsSomethingSelected && !data.Caret.PreserveSelection)
            {
                data.Caret.Offset = System.Math.Max(data.SelectionAnchor, data.Caret.Offset);
                data.ClearSelection();
                return;
            }

            LineSegment line = data.Document.GetLine(data.Caret.Line);
            IEnumerable <FoldSegment> foldings = data.Document.GetStartFoldings(line);
            FoldSegment segment = null;

            foreach (FoldSegment folding in foldings)
            {
                if (folding.IsFolded && folding.Column == data.Caret.Column)
                {
                    segment = folding;
                    break;
                }
            }
            if (segment != null)
            {
                data.Caret.Location = data.Document.OffsetToLocation(segment.EndLine.Offset + segment.EndColumn);
                return;
            }
            if (data.Caret.Column < line.EditableLength + 1 || data.Caret.AllowCaretBehindLineEnd)
            {
                if (data.Caret.Column >= line.EditableLength + 1)
                {
                    int nextColumn = data.GetNextVirtualColumn(data.Caret.Line, data.Caret.Column);
                    if (data.Caret.Column != nextColumn)
                    {
                        data.Caret.Column = nextColumn;
                    }
                    else
                    {
                        data.Caret.Location = new DocumentLocation(data.Caret.Line + 1, DocumentLocation.MinColumn);
                        data.Caret.CheckCaretPosition();
                    }
                }
                else
                {
                    data.Caret.Column++;
                }
            }
            else if (data.Caret.Line + 1 <= data.Document.LineCount)
            {
                data.Caret.Location = new DocumentLocation(data.Caret.Line + 1, DocumentLocation.MinColumn);
            }
        }
        internal static void InternalCaretMoveHome(TextEditorData data, bool firstNonWhitespace, bool hop)
        {
            if (!data.Caret.PreserveSelection)
            {
                data.ClearSelection();
            }

            DocumentLine line = data.Document.GetLine(data.Caret.Line);
            int          newColumn;

            if (firstNonWhitespace)
            {
                int homeMark = GetHomeMark(data.Document, line);
                if (hop)
                {
                    newColumn = data.Caret.Column == homeMark ? DocumentLocation.MinColumn : homeMark;
                }
                else
                {
                    newColumn = homeMark;
                }
            }
            else
            {
                newColumn = DocumentLocation.MinColumn;
            }
            var newLocation = new DocumentLocation(data.Caret.Line, newColumn);
            // handle folding
            IEnumerable <FoldSegment> foldings = data.Document.GetEndFoldings(line);
            FoldSegment segment = null;

            foreach (FoldSegment folding in foldings)
            {
                if (folding.IsFolded && folding.Contains(data.Document.LocationToOffset(newLocation)))
                {
                    segment = folding;
                    break;
                }
            }
            if (segment != null)
            {
                newLocation = data.Document.OffsetToLocation(segment.StartLine.Offset);
            }


            if (newLocation != data.Caret.Location)
            {
                data.Caret.Location = newLocation;
            }
        }
예제 #16
0
        void HighlightFold(FoldSegment segment)
        {
            var line = segment.GetStartLine(editor.Document);
            var list = new List <FoldSegment>(editor.Document.GetFoldingContaining(line));

            list.Sort((x, y) => x.Offset.CompareTo(y.Offset));

            editor.TextViewMargin.DisposeLayoutDict();
            editor.TextViewMargin.BackgroundRenderer = new FoldingScreenbackgroundRenderer(editor, list);
            editor.ScrollTo(line.LineNumber, 0);

            if (accessibles != null)
            {
                AtkCocoaExtensions.SetCurrentFocus(accessibles[segment].Accessible);
            }
        }
        /// <summary>
        /// Opens the current fold and all its children
        /// </summary>
        public static void OpenFoldRecursive(TextEditorData data)
        {
            FoldSegment currentFold = GetOutermostClosedFold(data);

            if (null != currentFold)
            {
                foreach (FoldSegment fold in data.Document.FoldSegments)
                {
                    if (fold.Offset >= currentFold.Offset &&
                        fold.Offset <= currentFold.EndOffset)
                    {
                        fold.IsFolded = false;
                    }
                }
                Commit(data);
            }
        }
        internal protected override void MouseHover(MarginMouseEventArgs args)
        {
            base.MouseHover(args);

            DocumentLine lineSegment = null;

            if (args.LineSegment != null)
            {
                lineSegment = args.LineSegment;
                if (lineHover != lineSegment)
                {
                    lineHover = lineSegment;
                    editor.RedrawMargin(this);
                }
            }
            lineHover = lineSegment;

            hoverSegment = GetSelectedSegment(args.LineNumber);
            bool found = hoverSegment != null;

            StopTimer();
            if (found)
            {
                var list = new List <FoldSegment>(editor.Document.GetFoldingContaining(lineSegment));
                list.Sort((x, y) => x.Offset.CompareTo(y.Offset));
                foldings = list;
                if (editor.TextViewMargin.BackgroundRenderer == null)
                {
                    if (timerId == null)
                    {
                        timerId          = new Timer(150);
                        timerId.Elapsed += SetBackgroundRenderer;
                    }
                    timerId.Start();
                }
                else
                {
                    SetBackgroundRenderer(null, null);
                }
            }
            else
            {
                RemoveBackgroundRenderer();
            }
        }
예제 #19
0
        /// <summary>
        /// Opens the current fold and all its children
        /// </summary>
        public static void OpenFoldRecursive(TextEditorData data)
        {
            FoldSegment currentFold = GetOutermostClosedFold(data);

            if (null != currentFold)
            {
                foreach (FoldSegment fold in data.Document.FoldSegments)
                {
                    if (fold.Offset >= currentFold.Offset &&
                        fold.Offset <= currentFold.EndOffset)
                    {
                        fold.IsCollapsed = false;
                        data.Document.InformFoldChanged(new FoldSegmentEventArgs(currentFold));
                    }
                }
                Commit(data);
            }
        }
예제 #20
0
        public static void Left(TextEditorData data)
        {
            if (Platform.IsMac && data.IsSomethingSelected && !data.Caret.PreserveSelection)
            {
                data.Caret.Offset = System.Math.Min(data.SelectionAnchor, data.Caret.Offset);
                data.ClearSelection();
                return;
            }

            LineSegment line = data.Document.GetLine(data.Caret.Line);
            IEnumerable <FoldSegment> foldings = data.Document.GetEndFoldings(line);
            FoldSegment segment = null;

            foreach (FoldSegment folding in foldings)
            {
                if (folding.IsFolded && folding.EndColumn + 1 == data.Caret.Column)
                {
                    segment = folding;
                    break;
                }
            }
            if (segment != null)
            {
                data.Caret.Location = data.Document.OffsetToLocation(segment.StartLine.Offset + segment.Column - 1);
                return;
            }

            if (data.Caret.Column > DocumentLocation.MinColumn)
            {
                if (data.Caret.Column > line.EditableLength + 1)
                {
                    data.Caret.Column = line.EditableLength + 1;
                }
                else
                {
                    data.Caret.Column--;
                }
            }
            else if (data.Caret.Line > DocumentLocation.MinLine)
            {
                LineSegment prevLine = data.Document.GetLine(data.Caret.Line - 1);
                data.Caret.Location = new DocumentLocation(data.Caret.Line - 1, prevLine.EditableLength + 1);
            }
        }
예제 #21
0
        public static void LineEnd(TextEditorData data)
        {
            if (!data.Caret.PreserveSelection)
            {
                data.ClearSelection();
            }
            DocumentLocation newLocation = data.Caret.Location;
            LineSegment      line        = data.Document.GetLine(data.Caret.Line);

            newLocation.Column = line.EditableLength + 1;

            // handle folding
            IEnumerable <FoldSegment> foldings = data.Document.GetStartFoldings(line);
            FoldSegment segment = null;

            foreach (FoldSegment folding in foldings)
            {
                if (folding.IsFolded && folding.Contains(data.Document.LocationToOffset(newLocation)))
                {
                    segment = folding;
                    break;
                }
            }
            if (segment != null)
            {
                newLocation = data.Document.OffsetToLocation(segment.EndLine.Offset + segment.EndColumn);
            }
            if (newLocation != data.Caret.Location)
            {
                data.Caret.Location = newLocation;
            }

            if (data.Caret.AllowCaretBehindLineEnd)
            {
                int nextColumn = data.GetNextVirtualColumn(data.Caret.Line, data.Caret.Column);
                if (nextColumn != data.Caret.Column)
                {
                    data.Caret.Column = nextColumn;
                }
            }
        }
예제 #22
0
        public static void LineEnd(TextEditorData data)
        {
            using (var undo = data.OpenUndoGroup()) {
                if (!data.Caret.PreserveSelection)
                {
                    data.ClearSelection();
                }
                var line        = data.Document.GetLine(data.Caret.Line);
                var newLocation = new DocumentLocation(data.Caret.Line, line.Length + 1);

                // handle folding
                IEnumerable <FoldSegment> foldings = data.Document.GetStartFoldings(line);
                FoldSegment segment = null;
                foreach (FoldSegment folding in foldings)
                {
                    if (folding.IsFolded && folding.Contains(data.Document.LocationToOffset(newLocation)))
                    {
                        segment = folding;
                        break;
                    }
                }
                if (segment != null)
                {
                    newLocation = data.Document.OffsetToLocation(segment.EndLine.Offset + segment.EndColumn - 1);
                }
                if (newLocation != data.Caret.Location)
                {
                    data.Caret.Location = newLocation;
                }

                if (data.HasIndentationTracker && data.Options.IndentStyle == IndentStyle.Virtual)
                {
                    int virtualIndentColumn = data.GetVirtualIndentationColumn(data.Caret.Location);
                    if (virtualIndentColumn > data.Caret.Column)
                    {
                        data.Caret.Column = virtualIndentColumn;
                    }
                }
            }
        }
예제 #23
0
        public static DocumentLocation GetLineEndLocation(TextEditorData data, int lineNumber)
        {
            DocumentLine line = data.Document.GetLine(lineNumber);

            DocumentLocation result = new DocumentLocation(lineNumber, line.Length + 1);

            FoldSegment segment = null;

            foreach (FoldSegment folding in data.Document.GetStartFoldings(line))
            {
                if (folding.IsFolded && folding.Contains(data.Document.LocationToOffset(result)))
                {
                    segment = folding;
                    break;
                }
            }
            if (segment != null)
            {
                result = data.Document.OffsetToLocation(segment.EndLine.Offset + segment.EndColumn - 1);
            }
            return(result);
        }
        /// <summary>
        /// Gets the outermost closed fold pertaining to the current caret position
        /// </summary>
        static FoldSegment GetOutermostClosedFold(TextEditorData data)
        {
            FoldSegment currentFold = null;
            int         endOffset = -1, startOffset = int.MaxValue;
            IEnumerable <FoldSegment> folds = data.Document.GetFoldingContaining(data.Caret.Line);
            int lineNumber = data.LogicalToVisualLocation(data.Caret.Location).Line;

            if (null != folds)
            {
                foreach (FoldSegment fold in folds)
                {
                    if (fold.IsFolded && data.LogicalToVisualLine(data.OffsetToLineNumber(fold.Offset)) == lineNumber &&
                        fold.Offset <= startOffset && fold.EndOffset >= endOffset)
                    {
                        currentFold = fold;
                        startOffset = fold.Offset;
                        endOffset   = fold.EndOffset;
                    }
                }
            }

            return(currentFold);
        }
        /// <summary>
        /// Gets the innermost opened fold containing the current caret position
        /// </summary>
        static FoldSegment GetInnermostOpenedFold(TextEditorData data)
        {
            FoldSegment currentFold         = null;
            int         endOffset           = int.MaxValue,
                        startOffset         = -1;
            IEnumerable <FoldSegment> folds = data.Document.GetFoldingContaining(data.Caret.Line);

            if (null != folds)
            {
                foreach (FoldSegment fold in folds)
                {
                    if (!fold.IsFolded &&
                        fold.Offset >= startOffset && fold.EndOffset <= endOffset)
                    {
                        currentFold = fold;
                        startOffset = fold.Offset;
                        endOffset   = fold.EndOffset;
                    }
                }
            }

            return(currentFold);
        }
        public void Draw(Cairo.Context cr, Cairo.Rectangle area, DocumentLine lineSegment, double x, double y, double lineHeight)
        {
            int foundSegment = -1;

            if (lineSegment != null)
            {
                for (int i = 0; i < foldSegments.Count; i++)
                {
                    FoldSegment segment = foldSegments [i];
                    if (segment.StartLine.Offset <= lineSegment.Offset && lineSegment.EndOffsetIncludingDelimiter <= segment.EndLine.EndOffsetIncludingDelimiter)
                    {
                        foundSegment = i;
                        roles [i]    = Roles.Between;
                        if (segment.StartLine.Offset == lineSegment.Offset)
                        {
                            roles [i] |= Roles.Start;
                            if (segment.IsFolded)
                            {
                                roles [i] |= Roles.End;
                            }
                        }
                        if (segment.EndLine.Offset == lineSegment.Offset)
                        {
                            roles [i] |= Roles.End;
                        }
                    }
                }
            }
            TextViewMargin textViewMargin = editor.TextViewMargin;
            ISyntaxMode    mode           = Document.SyntaxMode != null && editor.Options.EnableSyntaxHighlighting ? Document.SyntaxMode : new SyntaxMode(Document);

            //	Gdk.Rectangle lineArea = new Gdk.Rectangle (textViewMargin.XOffset, y, editor.Allocation.Width - textViewMargin.XOffset, editor.LineHeight);
            //	Gdk.GC gc = new Gdk.GC (drawable);
            TextViewMargin.LayoutWrapper lineLayout = null;
            double brightness = HslColor.Brightness(editor.ColorStyle.Default.BackgroundColor);

            int colorCount = foldSegments.Count + 2;

            for (int segment = -1; segment <= foundSegment; segment++)
            {
                HslColor hslColor      = new HslColor(editor.ColorStyle.Default.BackgroundColor);
                int      colorPosition = segment + 1;
                if (segment == foldSegments.Count - 1)
                {
                    colorPosition += 2;
                }
                if (brightness < 0.5)
                {
                    hslColor.L = hslColor.L * 0.81 + hslColor.L * 0.25 * (colorCount - colorPosition) / colorCount;
                }
                else
                {
                    hslColor.L = hslColor.L * 0.86 + hslColor.L * 0.1 * colorPosition / colorCount;
                }

                Roles  role           = Roles.Between;
                double xPos           = textViewMargin.XOffset;
                double rectangleWidth = editor.Allocation.Width - xPos;
                if (segment >= 0)
                {
                    DocumentLine segmentStartLine = foldSegments [segment].StartLine;
                    lineLayout = textViewMargin.CreateLinePartLayout(mode, segmentStartLine, segmentStartLine.Offset, segmentStartLine.Length, -1, -1);
                    Pango.Rectangle rectangle = lineLayout.Layout.IndexToPos(GetFirstNonWsIdx(lineLayout.Layout.Text));
                    xPos = System.Math.Max(textViewMargin.XOffset, (textViewMargin.XOffset + rectangle.X / Pango.Scale.PangoScale - editor.HAdjustment.Value));

                    DocumentLine segmentEndLine = foldSegments [segment].EndLine;
                    lineLayout = textViewMargin.CreateLinePartLayout(mode, segmentEndLine, segmentEndLine.Offset, segmentEndLine.Length, -1, -1);
                    rectangle  = lineLayout.Layout.IndexToPos(GetFirstNonWsIdx(lineLayout.Layout.Text));
                    xPos       = System.Math.Min(xPos, System.Math.Max(textViewMargin.XOffset, (textViewMargin.XOffset + rectangle.X / Pango.Scale.PangoScale - editor.HAdjustment.Value)));

                    int width = editor.Allocation.Width;
                    if (editor.HAdjustment.Upper > width)
                    {
                        width = (int)(textViewMargin.XOffset + editor.HAdjustment.Upper - editor.HAdjustment.Value);
                    }
                    rectangleWidth = (int)(width - xPos - 6 * (segment + 1));
                    role           = roles [segment];
                }
                DrawRoundRectangle(cr, (role & Roles.Start) == Roles.Start, (role & Roles.End) == Roles.End, xPos, y, editor.LineHeight / 2, rectangleWidth, lineHeight);
                cr.Color = ColorScheme.ToCairoColor(hslColor);
                cr.Fill();

                /*		if (segment == foldSegments.Count - 1) {
                 *  cr.Color = new Cairo.Color (0.5, 0.5, 0.5, 1);
                 *  cr.Stroke ();
                 * }*/
                if (lineLayout != null && lineLayout.IsUncached)
                {
                    lineLayout.Dispose();
                    lineLayout = null;
                }
            }
            //		gc.Dispose ();
        }
		internal protected override void MouseLeft ()
		{
			base.MouseLeft ();
			hoverSegment = null;
			if (lineHover != null) {
				lineHover = null;
				editor.RedrawMargin (this);
			}
			StopTimer ();
			RemoveBackgroundRenderer ();
		}
예제 #28
0
		FoldSegment AddMarker (List<FoldSegment> foldSegments, string text, DomRegion region, FoldingType type)
		{
			Document document = textEditorData.Document;
			if (document == null || region.Start.Line <= 0 || region.End.Line <= 0 || region.Start.Line > document.LineCount || region.End.Line > document.LineCount)
				return null;
			int startOffset = document.LocationToOffset (region.Start.Line, region.Start.Column);
			// end doesn't include the char at that position.
			int endOffset   = document.LocationToOffset (region.End.Line, region.End.Column) - 1;
			FoldSegment result = new FoldSegment (document, text, startOffset, endOffset - startOffset, type);
			
			foldSegments.Add (result);
			return result;
		}
예제 #29
0
		void RemoveFolding (FoldSegment folding)
		{
			Gtk.Application.Invoke (delegate {
				folding.isAttached = false;
				if (folding.isFolded)
					foldedSegments.Remove (folding);
				foldSegmentTree.Remove (folding);
			});
		}
예제 #30
0
		void RemoveFolding (FoldSegment folding)
		{
			folding.isAttached = false;
			if (folding.isFolded)
				foldedSegments.Remove (folding);
			foldSegmentTree.Remove (folding);
		}
예제 #31
0
		public int GetLineCount (FoldSegment segment)
		{
			return segment.EndLine.LineNumber - segment.StartLine.LineNumber;
		}
		public FoldSegment (FoldSegment foldSegment) : base (foldSegment.Offset, foldSegment.Length)
		{
			this.doc = foldSegment.doc;
			this.isFolded = foldSegment.IsFolded;
			this.Description = foldSegment.Description;
			this.FoldingType = foldSegment.FoldingType;
		}
예제 #33
0
        public static void Right(TextEditorData data)
        {
            using (var undo = data.OpenUndoGroup()) {
                if (Platform.IsMac && data.IsSomethingSelected && !data.Caret.PreserveSelection)
                {
                    data.Caret.Offset = System.Math.Max(data.SelectionAnchor, data.Caret.Offset);
                    data.ClearSelection();
                    return;
                }
                DocumentLine line = data.Document.GetLine(data.Caret.Line);
                IEnumerable <FoldSegment> foldings = data.Document.GetStartFoldings(line);
                FoldSegment segment = null;
                foreach (FoldSegment folding in foldings)
                {
                    if (folding.IsCollapsed && folding.Offset == data.Caret.Offset)
                    {
                        segment = folding;
                        break;
                    }
                }
                if (segment != null)
                {
                    data.Caret.Offset = segment.EndOffset;
                    return;
                }

                if (data.Caret.Column >= line.Length + 1)
                {
                    int nextColumn;
                    if (data.HasIndentationTracker && data.Options.IndentStyle == IndentStyle.Virtual && data.Caret.Column == DocumentLocation.MinColumn)
                    {
                        nextColumn = data.GetVirtualIndentationColumn(data.Caret.Location);
                    }
                    else if (data.Caret.AllowCaretBehindLineEnd)
                    {
                        nextColumn = data.Caret.Column + 1;
                    }
                    else
                    {
                        nextColumn = line.Length + 1;
                    }

                    if (data.Caret.Column < nextColumn)
                    {
                        data.Caret.Column = nextColumn;
                    }
                    else
                    {
                        if (data.Caret.Line < data.LineCount)
                        {
                            data.Caret.Location = new DocumentLocation(data.Caret.Line + 1, DocumentLocation.MinColumn);
                        }
                    }
                }
                else
                {
                    data.Caret.Column++;
                    var layout = data.Parent?.TextViewMargin?.GetLayout(line);
                    if (layout != null && data.Caret.Column < line.Length)
                    {
                        uint curIndex = 0, byteIndex = 0;
                        int  utf8ByteIndex = (int)layout.TranslateToUTF8Index((uint)data.Caret.Column - 1, ref curIndex, ref byteIndex);
                        layout.Layout.GetCursorPos(utf8ByteIndex, out var strong_pos, out var weak_pos);
                        if (strong_pos.X != weak_pos.X)
                        {
                            data.Caret.Column++;
                        }
                    }
                }
                var curOffset = data.Caret.Offset;
                if (curOffset > 0 && curOffset < data.Length && IsLowSurrogateMarkerSet(data.GetCharAt(curOffset)))
                {
                    data.Caret.Offset++;
                }
            }
        }
예제 #34
0
 public FoldSegmentEventArgs(FoldSegment foldSegment)
 {
     this.FoldSegment = foldSegment;
 }
		internal protected override void MouseHover (MarginMouseEventArgs args)
		{
			base.MouseHover (args);
			
			DocumentLine lineSegment = null;
			if (args.LineSegment != null) {
				lineSegment = args.LineSegment;
				if (lineHover != lineSegment) {
					lineHover = lineSegment;
					editor.RedrawMargin (this);
				}
			} 
			lineHover = lineSegment;

			hoverSegment = GetSelectedSegment (args.LineNumber);
			bool found = hoverSegment != null;

			StopTimer ();
			if (found) {
				var list = new List<FoldSegment>(editor.Document.GetFoldingContaining (lineSegment));
				list.Sort ((x, y) => x.Offset.CompareTo (y.Offset));
				foldings = list;
				if (editor.TextViewMargin.BackgroundRenderer == null) {
					timerId = GLib.Timeout.Add (150, SetBackgroundRenderer);
				} else {
					SetBackgroundRenderer ();
				}
			} else {
				RemoveBackgroundRenderer ();
			}
		}
예제 #36
0
 public FoldSegment(FoldSegment foldSegment) : base(foldSegment.Offset, foldSegment.Length)
 {
     this.isFolded      = foldSegment.IsCollapsed;
     this.CollapsedText = foldSegment.CollapsedText;
     this.FoldingType   = foldSegment.FoldingType;
 }
예제 #37
0
        public int CompareTo(object obj)
        {
            FoldSegment segment = (FoldSegment)obj;

            return(this.Offset != segment.Offset ? this.Offset.CompareTo(segment.Offset) : 0);
        }
예제 #38
0
파일: TextEdit.cs 프로젝트: moscrif/ide
        private void ParseFoldingRegion(MatchCollection mc, ref List<FoldSegment> list, int start)
        {
            int needStart =1;
            int findEnd =0;

            if(mc == null || mc.Count<1) return;

            if(start >= mc.Count) return;

            Match startMatch = mc[start];
            if(startMatch.Value.Contains("@endregion")){
                start++;
                ParseFoldingRegion(mc, ref list, start);
                return;
            }
            for(int i=start+1; i<mc.Count;i++){
                if(!mc[i].Value.Contains("@endregion")){
                    needStart++;
                } else {
                    findEnd++;

                    if(needStart == findEnd){

                        int startIndex =startMatch.Index;
                        int endIndex =mc[i].Index- startIndex + mc[i].Value.Length;

                        Regex regex = new Regex(@"//\s*?@region", RegexOptions.Compiled);
                        string text = regex.Replace(startMatch.Value, "");

                        text = text.Trim();
                        if(String.IsNullOrEmpty(text)) text ="....";

                        FoldSegment fs = new FoldSegment(text,startIndex,endIndex,FoldingType.Region);
                        list.Add(fs);
                        break;
                    }
                }

            }
            start++;
            ParseFoldingRegion(mc, ref list, start);
        }
        public static TextEditorData Create(string content, ITextEditorOptions options = null)
        {
            var data = new TextEditorData ();
            data.Options.DefaultEolMarker = eolMarker;
            data.Options.IndentStyle = IndentStyle.Smart;
            if (options != null)
                data.Options = options;
            var sb = new StringBuilder ();
            int caretIndex = -1, selectionStart = -1, selectionEnd = -1;
            var foldSegments = new List<FoldSegment> ();
            var foldStack = new Stack<FoldSegment> ();

            for (int i = 0; i < content.Length; i++) {
                var ch = content [i];
                switch (ch) {
                    case '$':
                    caretIndex = sb.Length;
                    break;
                    case '<':
                    if (i + 1 < content.Length) {
                        if (content [i + 1] == '-') {
                            selectionStart = sb.Length;
                            i++;
                            break;
                        }
                    }
                    goto default;
                    case '-':
                    if (i + 1 < content.Length) {
                        var next = content [i + 1];
                        if (next == '>') {
                            selectionEnd = sb.Length;
                            i++;
                            break;
                        }
                        if (next == '[') {
                            var segment = new FoldSegment (data.Document, "...", sb.Length, 0, FoldingType.None);
                            segment.IsFolded = false;
                            foldStack.Push (segment);
                            i++;
                            break;
                        }
                    }
                    goto default;
                    case '+':
                    if (i + 1 < content.Length) {
                        var next = content [i + 1];
                        if (next == '[') {
                            var segment = new FoldSegment (data.Document, "...", sb.Length, 0, FoldingType.None);
                            segment.IsFolded = true;
                            foldStack.Push (segment);
                            i++;
                            break;
                        }
                    }
                    goto default;
                    case ']':
                    if (foldStack.Count > 0) {
                        FoldSegment segment = foldStack.Pop ();
                        segment.Length = sb.Length - segment.Offset;
                        foldSegments.Add (segment);
                        break;
                    }
                    goto default;
                    default:
                    sb.Append (ch);
                    break;
                }
            }

            data.Text = sb.ToString ();

            if (caretIndex >= 0)
                data.Caret.Offset = caretIndex;
            if (selectionStart >= 0) {
                if (caretIndex == selectionStart) {
                    data.SetSelection (selectionEnd, selectionStart);
                } else {
                    data.SetSelection (selectionStart, selectionEnd);
                    if (caretIndex < 0)
                        data.Caret.Offset = selectionEnd;
                }
            }
            if (foldSegments.Count > 0)
                data.Document.UpdateFoldSegments (foldSegments);
            return data;
        }
예제 #40
0
		public int GetLineCount (FoldSegment segment)
		{
			return OffsetToLineNumber(segment.EndLine.Offset) - OffsetToLineNumber(segment.StartLine.Offset);
		}
예제 #41
0
		void RemoveFolding (FoldSegment folding)
		{
			if (folding.isFolded)
				foldedSegments.Remove (folding);
			foldedSegments.Remove (folding);
		}
		public FoldSegmentEventArgs (FoldSegment foldSegment)
		{
			this.FoldSegment = foldSegment;
		}
예제 #43
0
		FoldSegment AddMarker (List<FoldSegment> foldSegments, string text, DomRegion region, FoldingType type)
		{
			Document document = textEditorData.Document;
			if (document == null || region.BeginLine <= 0 || region.EndLine <= 0 || region.BeginLine > document.LineCount || region.EndLine > document.LineCount)
				return null;
			
			int startOffset = document.LocationToOffset (region.BeginLine, region.BeginColumn);
			int endOffset   = document.LocationToOffset (region.EndLine, region.EndColumn );
			
			FoldSegment result = new FoldSegment (document, text, startOffset, endOffset - startOffset, type);
			
			foldSegments.Add (result);
			return result;
		}
예제 #44
0
파일: TextEdit.cs 프로젝트: moscrif/ide
        private void ParseFolding(MatchCollection mc, ref List<FoldSegment> list, int start, string startExpresion,string endExpresion)
        {
            int needStart =1;
            int findEnd =0;

            if(mc == null || mc.Count<1) return;

            if(start >= mc.Count) return;

            Match startMatch = mc[start];

            if(startMatch.Value.Contains(endExpresion)){//"}"
                start++;
                ParseFolding(mc, ref list, start,startExpresion,endExpresion);
                return;
            }

            for(int i=start+1; i<mc.Count;i++){
                if(mc[i].Value.Contains(startExpresion)){//"}"
                    needStart++;
                } else if (mc[i].Value.Contains(endExpresion)){
                    findEnd++;

                    if(needStart == findEnd){

                        int startIndex =startMatch.Index;
                        int endIndex =mc[i].Index- startIndex + mc[i].Value.Length;

                        FoldSegment fs = new FoldSegment("....",startIndex,endIndex,FoldingType.Region);
                        list.Add(fs);
                        break;
                    }
                }

            }
            start++;
            ParseFolding(mc, ref list, start,startExpresion,endExpresion);
        }