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.IsCollapsed) { if (segment != null && segment.Offset < folding.Offset) { continue; } segment = folding; } } if (segment != null) { loc = data.Document.OffsetToLocation(segment.GetStartLine(data.Document).Offset); } line = data.GetLine(loc.Line); return(line.Offset); }
internal static void InternalCaretMoveHome(TextEditorData data, bool firstNonWhitespace, bool hop) { using (var undo = data.OpenUndoGroup()) { 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.IsCollapsed && folding.Contains(data.Document.LocationToOffset(newLocation))) { segment = folding; break; } } if (segment != null) { newLocation = data.Document.OffsetToLocation(segment.GetStartLine(data.Document).Offset); } if (newLocation != data.Caret.Location) { data.Caret.Location = newLocation; } } }
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); } }
void UpdateAccessibility() { var startLine = segment.GetStartLine(editor.Document).LineNumber; var endLine = segment.GetEndLine(editor.Document).LineNumber; Accessible.Label = GettextCatalog.GetString("Fold Region: Line {0} to line {1} - {2}", startLine, endLine, segment.isFolded ? GettextCatalog.GetString("Folded") : GettextCatalog.GetString("Expanded")); if (segment.isFolded) { Accessible.Help = GettextCatalog.GetString("Activate to expand the region"); } else { Accessible.Help = GettextCatalog.GetString("Activate to fold the region"); } startY = editor.LineToY(startLine); double endY; if (segment.isFolded) { endY = startY; } else { endY = editor.LineToY(endLine); } var rect = new Gdk.Rectangle(0, (int)startY, (int)margin.Width, (int)(endY - startY)); Accessible.FrameInGtkParent = rect; var halfParentHeight = margin.RectInParent.Height / 2; var dEndY = endY - halfParentHeight; var cocoaEndY = halfParentHeight - dEndY; var dStartY = startY - halfParentHeight; var cocoaStartY = halfParentHeight - dStartY; var minY = Math.Min(cocoaStartY, cocoaEndY); var maxY = Math.Max(cocoaStartY, cocoaEndY); Accessible.FrameInParent = new Gdk.Rectangle(0, (int)(minY - editor.LineHeight), (int)margin.Width, (int)((maxY - minY) + editor.LineHeight)); }