public OffsetToLocation ( int offset ) : Mono.TextEditor.DocumentLocation | ||
offset | int | |
Résultat | Mono.TextEditor.DocumentLocation |
public void CopyData(TextEditorData data) { Selection selection; isLineSelectionMode = !data.IsSomethingSelected; if (data.IsSomethingSelected) { selection = data.MainSelection; } else { var start = DeleteActions.GetStartOfLineOffset(data, data.Caret.Location); var end = DeleteActions.GetEndOfLineOffset(data, data.Caret.Location, false); selection = new Selection(data.OffsetToLocation(start), data.OffsetToLocation(end)); } CopyData(data, selection); if (Copy != null) { Copy(copiedDocument != null ? copiedDocument.Text : null); } }
static void RemoveCharBeforeCaret(TextEditorData data) { int offset = data.Caret.Offset; if (offset <= 0) { return; } var version = data.Version; data.Remove(offset - 1, 1); data.Caret.Location = data.OffsetToLocation(version.MoveOffsetTo(data.Version, offset)); }
internal void UpdateCaretPosition(DocumentChangeEventArgs e) { if (e.AnchorMovementType == AnchorMovementType.BeforeInsertion && caretOffset == e.Offset) { return; } var curVersion = TextEditorData.Version; if (offsetVersion == null) { offsetVersion = curVersion; return; } var newOffset = offsetVersion.MoveOffsetTo(curVersion, caretOffset); offsetVersion = curVersion; if (newOffset == caretOffset || !AutoUpdatePosition) { return; } DocumentLocation old = Location; var newLocation = TextEditorData.OffsetToLocation(newOffset); int newColumn = newLocation.Column; var curLine = TextEditorData.GetLine(newLocation.Line); if (TextEditorData.HasIndentationTracker && TextEditorData.Options.IndentStyle == IndentStyle.Virtual && curLine.Length == 0) { var indentColumn = TextEditorData.GetVirtualIndentationColumn(Location); if (column == indentColumn) { newColumn = indentColumn; } } if (AllowCaretBehindLineEnd) { if (curLine != null && column > curLine.Length) { newColumn = column; } } line = newLocation.Line; column = newColumn; SetDesiredColumn(); UpdateCaretOffset(); OnPositionChanged(new DocumentLocationEventArgs(old)); }
internal void UpdateCaretPosition(TextChangeEventArgs e) { //if (e.AnchorMovementType == AnchorMovementType.BeforeInsertion && caretOffset == e.Offset) { // offsetVersion = TextEditorData.Version; // return; //} var curVersion = TextEditorData.Version; var newOffset = e.GetNewOffset(caretOffset); if (!AutoUpdatePosition) { return; } DocumentLocation old = Location; var newLocation = TextEditorData.OffsetToLocation(newOffset); int newColumn = newLocation.Column; var curLine = TextEditorData.GetLine(newLocation.Line); if (TextEditorData.HasIndentationTracker && TextEditorData.Options.IndentStyle == IndentStyle.Virtual && curLine.Length == 0) { var indentColumn = TextEditorData.GetVirtualIndentationColumn(newLocation); if (column == indentColumn) { newColumn = indentColumn; } } if (AllowCaretBehindLineEnd) { if (curLine != null && column > curLine.Length) { newColumn = column; } } line = newLocation.Line; column = newColumn; SetDesiredColumn(); UpdateCaretOffset(); OnPositionChanged(new CaretLocationEventArgs(old, currentBuffer ?? TextEditorData.Document.TextBuffer.CurrentSnapshot, CaretChangeReason.BufferChange)); }
public void CopyData(TextEditorData data) { MonoDevelop.Ide.Editor.Selection selection; isLineSelectionMode = !data.IsSomethingSelected; if (data.IsSomethingSelected) { selection = data.MainSelection; } else { var start = DeleteActions.GetStartOfLineOffset(data, data.Caret.Location); var end = DeleteActions.GetEndOfLineOffset(data, data.Caret.Location, false); selection = new MonoDevelop.Ide.Editor.Selection(data.OffsetToLocation(start), data.OffsetToLocation(end)); } CopyData(data, selection); if (Copy != null) { Copy(GetCopiedPlainText()); } }
static void RemoveCharBeforeCaret(TextEditorData data) { int offset = data.Caret.Offset; if (offset <= 0) { return; } var version = data.Version; var o = data.Caret.Offset; if (((ushort)data.GetCharAt(offset - 1) & CaretMoveActions.LowSurrogateMarker) == CaretMoveActions.LowSurrogateMarker) { data.Remove(offset - 2, 2); } else { data.Remove(offset - 1, 1); } data.Caret.Location = data.OffsetToLocation(version.MoveOffsetTo(data.Version, offset)); }
public string GetExpression(Mono.TextEditor.TextEditorData data, int offset) { if (offset < 0) { return(""); } var doc = IdeApp.Workbench.ActiveDocument; if (doc == null) { return(""); } var loc = RefactoringService.GetCorrectResolveLocation(doc, data.OffsetToLocation(offset)); var unit = doc.ParsedDocument.GetAst <SyntaxTree> (); var parsedFile = doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile; var node = unit.GetNodeAt <Expression> (loc.Line, loc.Column); if (unit == null || parsedFile == null || node == null) { return(""); } return(data.GetTextBetween(node.StartLocation, node.EndLocation)); }
public void CopyData (TextEditorData data) { Selection selection; isLineSelectionMode = !data.IsSomethingSelected; if (data.IsSomethingSelected) { selection = data.MainSelection; } else { var start = DeleteActions.GetStartOfLineOffset (data, data.Caret.Location); var end = DeleteActions.GetEndOfLineOffset (data, data.Caret.Location, false); selection = new Selection (data.OffsetToLocation (start), data.OffsetToLocation (end)); } CopyData (data, selection); if (Copy != null) Copy (copiedDocument != null ? copiedDocument.Text : null); }
public static void SelectAll (TextEditorData data) { data.Caret.PreserveSelection = true; data.MainSelection = new Selection (new DocumentLocation (DocumentLocation.MinLine, DocumentLocation.MinColumn), data.OffsetToLocation (data.Length)); data.Caret.PreserveSelection = false; }
public static List<InsertionPoint> GetInsertionPoints (TextEditorData data, ParsedDocument parsedDocument, IType type) { if (data == null) throw new ArgumentNullException ("data"); if (parsedDocument == null) throw new ArgumentNullException ("parsedDocument"); if (type == null) throw new ArgumentNullException ("type"); List<InsertionPoint> result = new List<InsertionPoint> (); int offset = data.LocationToOffset (type.BodyRegion.Start.Line, type.BodyRegion.Start.Column); if (offset < 0) return result; while (offset < data.Length && data.GetCharAt (offset) != '{') { offset++; } var realStartLocation = data.OffsetToLocation (offset); result.Add (GetInsertionPosition (data.Document, realStartLocation.Line, realStartLocation.Column)); result[0].LineBefore = NewLineInsertion.None; foreach (IMember member in type.Members) { DomLocation domLocation = member.BodyRegion.End; if (domLocation.Line <= 0) { LineSegment lineSegment = data.GetLine (member.Location.Line); if (lineSegment == null) continue; domLocation = new DomLocation (member.Location.Line, lineSegment.EditableLength + 1); } result.Add (GetInsertionPosition (data.Document, domLocation.Line, domLocation.Column)); } result[result.Count - 1].LineAfter = NewLineInsertion.None; CheckStartPoint (data.Document, result[0], result.Count == 1); if (result.Count > 1) { result.RemoveAt (result.Count - 1); NewLineInsertion insertLine; var lineBefore = data.GetLine (type.BodyRegion.End.Line - 1); if (lineBefore != null && lineBefore.EditableLength == lineBefore.GetIndentation (data.Document).Length) { insertLine = NewLineInsertion.None; } else { insertLine = NewLineInsertion.Eol; } // search for line start var line = data.GetLine (type.BodyRegion.End.Line); int col = type.BodyRegion.End.Column - 1; while (col > 1 && char.IsWhiteSpace (data.GetCharAt (line.Offset + col - 2))) col--; result.Add (new InsertionPoint (new DocumentLocation (type.BodyRegion.End.Line, col), insertLine, NewLineInsertion.Eol)); CheckEndPoint (data.Document, result[result.Count - 1], result.Count == 1); } foreach (var region in parsedDocument.UserRegions.Where (r => type.BodyRegion.Contains (r.Region))) { result.Add (new InsertionPoint (new DocumentLocation (region.Region.Start.Line + 1, 1), NewLineInsertion.Eol, NewLineInsertion.Eol)); result.Add (new InsertionPoint (new DocumentLocation (region.Region.End.Line, 1), NewLineInsertion.Eol, NewLineInsertion.Eol)); result.Add (new InsertionPoint (new DocumentLocation (region.Region.End.Line + 1, 1), NewLineInsertion.Eol, NewLineInsertion.Eol)); } result.Sort ((left, right) => left.Location.CompareTo (right.Location)); return result; }
public string GetIndentationString(int offset) { return(GetIndentationString(offset, data.OffsetToLocation(offset))); }
public static void SelectAll(TextEditorData data) { data.Caret.PreserveSelection = true; data.Caret.AutoScrollToCaret = false; data.Caret.Offset = data.Length; data.Caret.AutoScrollToCaret = true; data.MainSelection = new MonoDevelop.Ide.Editor.Selection(new DocumentLocation(DocumentLocation.MinLine, DocumentLocation.MinColumn), data.OffsetToLocation(data.Length)); data.Caret.PreserveSelection = false; }
public static void SelectAll(TextEditorData data) { data.Caret.PreserveSelection = true; data.MainSelection = new Selection(new DocumentLocation(DocumentLocation.MinLine, DocumentLocation.MinColumn), data.OffsetToLocation(data.Length)); data.Caret.PreserveSelection = false; }
public static List<InsertionPoint> GetInsertionPoints (TextEditorData data, ParsedDocument parsedDocument, IUnresolvedTypeDefinition type) { if (data == null) throw new ArgumentNullException ("data"); if (parsedDocument == null) throw new ArgumentNullException ("parsedDocument"); if (type == null) throw new ArgumentNullException ("type"); // update type from parsed document, since this is always newer. //type = parsedDocument.GetInnermostTypeDefinition (type.GetLocation ()) ?? type; List<InsertionPoint> result = new List<InsertionPoint> (); int offset = data.LocationToOffset (type.Region.Begin); if (offset < 0 || type.BodyRegion.IsEmpty) return result; while (offset < data.Length && data.GetCharAt (offset) != '{') { offset++; } var realStartLocation = data.OffsetToLocation (offset); result.Add (GetInsertionPosition (data.Document, realStartLocation.Line, realStartLocation.Column)); result [0].LineBefore = NewLineInsertion.None; foreach (var member in type.Members) { TextLocation domLocation = member.BodyRegion.End; if (domLocation.Line <= 0) { DocumentLine lineSegment = data.GetLine (member.Region.BeginLine); if (lineSegment == null) continue; domLocation = new TextLocation (member.Region.BeginLine, lineSegment.Length + 1); } result.Add (GetInsertionPosition (data.Document, domLocation.Line, domLocation.Column)); } foreach (var nestedType in type.NestedTypes) { TextLocation domLocation = nestedType.BodyRegion.End; if (domLocation.Line <= 0) { DocumentLine lineSegment = data.GetLine (nestedType.Region.BeginLine); if (lineSegment == null) continue; domLocation = new TextLocation (nestedType.Region.BeginLine, lineSegment.Length + 1); } result.Add (GetInsertionPosition (data.Document, domLocation.Line, domLocation.Column)); } result [result.Count - 1].LineAfter = NewLineInsertion.None; CheckStartPoint (data.Document, result [0], result.Count == 1); if (result.Count > 1) { result.RemoveAt (result.Count - 1); NewLineInsertion insertLine; var lineBefore = data.GetLine (type.BodyRegion.EndLine - 1); if (lineBefore != null && lineBefore.Length == lineBefore.GetIndentation (data.Document).Length) { insertLine = NewLineInsertion.None; } else { insertLine = NewLineInsertion.Eol; } // search for line start int col = type.BodyRegion.EndColumn - 1; var line = data.GetLine (type.BodyRegion.EndLine); if (line != null) { while (col > 1 && char.IsWhiteSpace (data.GetCharAt (line.Offset + col - 2))) col--; } result.Add (new InsertionPoint (new DocumentLocation (type.BodyRegion.EndLine, col), insertLine, NewLineInsertion.Eol)); CheckEndPoint (data.Document, result [result.Count - 1], result.Count == 1); } foreach (var region in parsedDocument.UserRegions.Where (r => type.BodyRegion.IsInside (r.Region.Begin))) { result.Add (new InsertionPoint (new DocumentLocation (region.Region.BeginLine + 1, 1), NewLineInsertion.Eol, NewLineInsertion.Eol)); result.Add (new InsertionPoint (new DocumentLocation (region.Region.EndLine, 1), NewLineInsertion.Eol, NewLineInsertion.Eol)); result.Add (new InsertionPoint (new DocumentLocation (region.Region.EndLine + 1, 1), NewLineInsertion.Eol, NewLineInsertion.Eol)); } result.Sort ((left, right) => left.Location.CompareTo (right.Location)); return result; }
static void RemoveCharBeforeCaret (TextEditorData data) { int offset = data.Caret.Offset; if (offset <= 0) return; var version = data.Version; data.Remove (offset - 1, 1); data.Caret.Location = data.OffsetToLocation (version.MoveOffsetTo (data.Version, offset)); }
private InsertionPoint GetInsertionPoint(MonoDevelop.Ide.Gui.Document document, IType type) { data = document.Editor; if (data == null) { throw new System.ArgumentNullException ("data"); } var parsedDocument = document.ParsedDocument; if (parsedDocument == null) { throw new System.ArgumentNullException ("parsedDocument"); } if (type == null) { throw new System.ArgumentNullException ("type"); } type = (parsedDocument.CompilationUnit.GetTypeAt (type.Location) ?? type); DomRegion domRegion = type.BodyRegion; var start = type.BodyRegion.Start.Line; indent = data.GetLine(start).GetIndentation(data.Document); DomLocation domLocation = domRegion.End; int num = data.LocationToOffset (domLocation.Line, 1); while (num < data.Length && data.GetCharAt(num) != '}') { num++; } num++; DocumentLocation documentLocation = data.OffsetToLocation (num); LineSegment lineAfterClassEnd = data.GetLine (domLocation.Line + 1); NewLineInsertion lineAfter; if (lineAfterClassEnd != null && lineAfterClassEnd.EditableLength == lineAfterClassEnd.GetIndentation (data.Document).Length) lineAfter = NewLineInsertion.BlankLine; else lineAfter = NewLineInsertion.None; return new InsertionPoint (documentLocation, NewLineInsertion.None, lineAfter); }
public string ResolveExpression (TextEditorData ed, Document doc, int offset, out int startOffset) { startOffset = offset; var editorData = DResolverWrapper.CreateEditorData(doc); if (editorData == null) return null; editorData.CaretOffset = offset; var edLoc = ed.OffsetToLocation(offset); editorData.CaretLocation = new CodeLocation(edLoc.Column,edLoc.Line); var o = DResolver.GetScopedCodeObject(editorData); if (o != null) { startOffset = ed.LocationToOffset (o.Location.Line, o.Location.Column); if (o is INode) return (o as INode).Name; return o.ToString (); } return null; }