本文整理汇总了C#中TextEditor.LocationToOffset方法的典型用法代码示例。如果您正苦于以下问题:C# TextEditor.LocationToOffset方法的具体用法?C# TextEditor.LocationToOffset怎么用?C# TextEditor.LocationToOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TextEditor
的用法示例。
在下文中一共展示了TextEditor.LocationToOffset方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FormatStatmentAt
public static void FormatStatmentAt (TextEditor editor, DocumentContext context, MonoDevelop.Ide.Editor.DocumentLocation location, OptionSet optionSet = null)
{
var offset = editor.LocationToOffset (location);
var policyParent = context.Project != null ? context.Project.Policies : PolicyService.DefaultPolicies;
var mimeTypeChain = DesktopService.GetMimeTypeInheritanceChain (CSharpFormatter.MimeType);
Format (policyParent, mimeTypeChain, editor, context, offset, offset, false, true, optionSet: optionSet);
}
示例2: Insert
public int Insert (TextEditor editor, DocumentContext ctx, string text)
{
int offset = editor.LocationToOffset (Location);
using (var undo = editor.OpenUndoGroup ()) {
var line = editor.GetLineByOffset (offset);
int insertionOffset = line.Offset + Location.Column - 1;
offset = insertionOffset;
InsertNewLine (editor, LineBefore, ref offset);
int result = offset - insertionOffset;
editor.InsertText (offset, text);
offset += text.Length;
InsertNewLine (editor, LineAfter, ref offset);
CodeFormatterService.Format (editor, ctx, TextSegment.FromBounds (insertionOffset - 1, offset));
return result;
}
}
示例3: SortSelectedLines
public static void SortSelectedLines (TextEditor textEditor)
{
var selectionRegion = textEditor.SelectionRegion;
var start = selectionRegion.Begin;
var end = selectionRegion.End;
var caret = textEditor.CaretLocation;
int startLine = start.Line;
int endLine = end.Line;
if (startLine == endLine)
return;
int length = 0;
var lines = new string[endLine - startLine + 1];
for (int i = startLine; i <= endLine; i++) {
//get lines *with* line endings
var lineText = textEditor.GetLineText (i, true);
lines [i - startLine] = lineText;
length += lineText.Length;
}
var linesUnsorted = new string[lines.Length];
Array.Sort (lines, StringComparer.Ordinal);
bool changed = false;
for (int i = 0; i <= lines.Length; i++) {
//can't simply use reference comparison as Array.Sort is not stable
if (string.Equals (lines [i], linesUnsorted [i], StringComparison.Ordinal)) {
continue;
}
changed = true;
break;
}
if (!changed)
return;
var sb = new StringBuilder ();
for (int i = 0; i < lines.Length; i++) {
sb.Append (lines [i]);
}
var startOffset = textEditor.LocationToOffset (startLine, 1);
textEditor.ReplaceText (startOffset, length, sb.ToString ());
textEditor.CaretLocation = LimitColumn (textEditor, caret);
textEditor.SetSelection (LimitColumn (textEditor, start), LimitColumn (textEditor, end));
}
示例4: AssemblyBrowserWidget
public AssemblyBrowserWidget ()
{
this.Build ();
loader = new CecilLoader (true);
loader.IncludeInternalMembers = true;
TreeView = new AssemblyBrowserTreeView (new NodeBuilder[] {
new ErrorNodeBuilder (),
new ProjectNodeBuilder (this),
new AssemblyNodeBuilder (this),
new ModuleReferenceNodeBuilder (),
new AssemblyReferenceNodeBuilder (this),
new AssemblyReferenceFolderNodeBuilder (this),
new AssemblyResourceFolderNodeBuilder (),
new ResourceNodeBuilder (),
new NamespaceBuilder (this),
new DomTypeNodeBuilder (this),
new DomMethodNodeBuilder (this),
new DomFieldNodeBuilder (this),
new DomEventNodeBuilder (this),
new DomPropertyNodeBuilder (this),
new BaseTypeFolderNodeBuilder (this),
new BaseTypeNodeBuilder (this)
}, new TreePadOption [0]);
TreeView.Tree.Selection.Mode = Gtk.SelectionMode.Single;
TreeView.Tree.CursorChanged += HandleCursorChanged;
TreeView.ShadowType = ShadowType.None;
TreeView.BorderWidth = 1;
TreeView.ShowBorderLine = true;
TreeView.Zoom = 1.0;
treeViewPlaceholder.Add (TreeView);
treeViewPlaceholder.ShowAll ();
// this.descriptionLabel.ModifyFont (Pango.FontDescription.FromString ("Sans 9"));
// this.documentationLabel.ModifyFont (Pango.FontDescription.FromString ("Sans 12"));
// this.documentationLabel.ModifyBg (Gtk.StateType.Normal, new Gdk.Color (255, 255, 225));
// this.documentationLabel.Wrap = true;
var options = new MonoDevelop.Ide.Gui.CommonTextEditorOptions () {
ShowFoldMargin = false,
ShowIconMargin = false,
ShowInvalidLines = false,
ShowLineNumberMargin = false,
ShowSpaces = false,
ShowTabs = false,
HighlightCaretLine = true,
};
inspectEditor = new TextEditor (new TextDocument (), options);
inspectEditor.ButtonPressEvent += HandleInspectEditorButtonPressEvent;
this.inspectEditor.Document.ReadOnly = true;
// this.inspectEditor.Document.SyntaxMode = new Mono.TextEditor.Highlighting.MarkupSyntaxMode ();
this.inspectEditor.TextViewMargin.GetLink = delegate(Mono.TextEditor.MarginMouseEventArgs arg) {
var loc = inspectEditor.PointToLocation (arg.X, arg.Y);
int offset = inspectEditor.LocationToOffset (loc);
var referencedSegment = ReferencedSegments != null ? ReferencedSegments.FirstOrDefault (seg => seg.Segment.Contains (offset)) : null;
if (referencedSegment == null)
return null;
if (referencedSegment.Reference is TypeDefinition)
return new XmlDocIdGenerator ().GetXmlDocPath ((TypeDefinition)referencedSegment.Reference);
if (referencedSegment.Reference is MethodDefinition)
return new XmlDocIdGenerator ().GetXmlDocPath ((MethodDefinition)referencedSegment.Reference);
if (referencedSegment.Reference is PropertyDefinition)
return new XmlDocIdGenerator ().GetXmlDocPath ((PropertyDefinition)referencedSegment.Reference);
if (referencedSegment.Reference is FieldDefinition)
return new XmlDocIdGenerator ().GetXmlDocPath ((FieldDefinition)referencedSegment.Reference);
if (referencedSegment.Reference is EventDefinition)
return new XmlDocIdGenerator ().GetXmlDocPath ((EventDefinition)referencedSegment.Reference);
if (referencedSegment.Reference is FieldDefinition)
return new XmlDocIdGenerator ().GetXmlDocPath ((FieldDefinition)referencedSegment.Reference);
if (referencedSegment.Reference is TypeReference) {
return new XmlDocIdGenerator ().GetXmlDocPath ((TypeReference)referencedSegment.Reference);
}
return referencedSegment.Reference.ToString ();
};
this.inspectEditor.LinkRequest += InspectEditorhandleLinkRequest;
var scrolledWindow = new SmartScrolledWindow ();
scrolledWindow.Show ();
textEditorContainer = new TextEditorContainer (inspectEditor);
scrolledWindow.Child = textEditorContainer;
notebookInspection.Add (scrolledWindow);
var notebookChild = ((Notebook.NotebookChild)(notebookInspection [scrolledWindow]));
notebookChild.Position = 1;
// this.inspectLabel.ModifyBg (Gtk.StateType.Normal, new Gdk.Color (255, 255, 250));
// this.vpaned1.ExposeEvent += VPaneExpose;
this.hpaned1.ExposeEvent += HPaneExpose;
/* this.notebook1.SwitchPage += delegate {
// Hack for the switch page select all bug.
// this.inspectLabel.Selectable = false;
};*/
languageCombobox.AppendText (GettextCatalog.GetString ("Summary"));
languageCombobox.AppendText (GettextCatalog.GetString ("IL"));
//.........这里部分代码省略.........
示例5: UpdateFoldings
internal static async Task UpdateFoldings (TextEditor Editor, ParsedDocument parsedDocument, DocumentLocation caretLocation, bool firstTime = false, CancellationToken token = default (CancellationToken))
{
if (parsedDocument == null || !Editor.Options.ShowFoldMargin)
return;
// don't update parsed documents that contain errors - the foldings from there may be invalid.
if (parsedDocument.HasErrors)
return;
try {
var foldSegments = new List<IFoldSegment> ();
foreach (FoldingRegion region in await parsedDocument.GetFoldingsAsync (token)) {
if (token.IsCancellationRequested)
return;
var type = FoldingType.Unknown;
bool setFolded = false;
bool folded = false;
//decide whether the regions should be folded by default
switch (region.Type) {
case FoldType.Member:
type = FoldingType.TypeMember;
break;
case FoldType.Type:
type = FoldingType.TypeDefinition;
break;
case FoldType.UserRegion:
type = FoldingType.Region;
setFolded = DefaultSourceEditorOptions.Instance.DefaultRegionsFolding;
folded = true;
break;
case FoldType.Comment:
type = FoldingType.Comment;
setFolded = DefaultSourceEditorOptions.Instance.DefaultCommentFolding;
folded = true;
break;
case FoldType.CommentInsideMember:
type = FoldingType.Comment;
setFolded = DefaultSourceEditorOptions.Instance.DefaultCommentFolding;
folded = false;
break;
case FoldType.Undefined:
setFolded = true;
folded = region.IsFoldedByDefault;
break;
}
var start = Editor.LocationToOffset (region.Region.Begin);
var end = Editor.LocationToOffset (region.Region.End);
var marker = Editor.CreateFoldSegment (start, end - start);
foldSegments.Add (marker);
marker.CollapsedText = region.Name;
marker.FoldingType = type;
//and, if necessary, set its fold state
if (marker != null && setFolded && firstTime) {
// only fold on document open, later added folds are NOT folded by default.
marker.IsCollapsed = folded;
continue;
}
if (marker != null && region.Region.Contains (caretLocation.Line, caretLocation.Column))
marker.IsCollapsed = false;
}
if (firstTime) {
Editor.SetFoldings (foldSegments);
} else {
Application.Invoke (delegate {
if (!token.IsCancellationRequested)
Editor.SetFoldings (foldSegments);
});
}
} catch (Exception ex) {
LoggingService.LogError ("Unhandled exception in ParseInformationUpdaterWorkerThread", ex);
}
}
示例6: CreateErrorMarker
public static IErrorMarker CreateErrorMarker (TextEditor editor, Error info)
{
int offset = editor.LocationToOffset (info.Region.BeginLine, info.Region.BeginColumn);
int endOffset = editor.LocationToOffset (info.Region.EndLine, info.Region.EndColumn);
if (endOffset <= offset) {
endOffset = offset + 1;
while (endOffset < editor.Length && IsIdentifierPart (editor.GetCharAt (endOffset))) {
endOffset++;
}
if (endOffset == offset + 1) {
if (endOffset - 1 < editor.Length) {
var c = editor.GetCharAt (endOffset - 1);
while ((c == '\n' || c == '\r') && endOffset < editor.Length) {
c = editor.GetCharAt (endOffset);
endOffset++;
}
} else {
endOffset = editor.Length;
}
}
}
return editor.TextMarkerFactory.CreateErrorMarker (editor, info, offset, endOffset - offset);
}
示例7: CreateErrorMarker
public static IErrorMarker CreateErrorMarker (TextEditor editor, Error info)
{
int offset = editor.LocationToOffset (info.Region.BeginLine, info.Region.BeginColumn);
int endOffset = editor.LocationToOffset (info.Region.EndLine, info.Region.EndColumn);
if (endOffset < offset) {
endOffset = offset + 1;
while (endOffset < editor.Length && IsIdentifierPart (editor.GetCharAt (endOffset)))
endOffset++;
}
return editor.TextMarkerFactory.CreateErrorMarker (editor, info, offset, endOffset - offset);
}
示例8: AddRegisterDirective
public void AddRegisterDirective (WebFormsPageInfo.RegisterDirective directive, TextEditor editor, bool preserveCaretPosition)
{
if (doc == null)
return;
var node = GetRegisterInsertionPointNode ();
if (node == null)
return;
doc.Info.RegisteredTags.Add (directive);
var line = Math.Max (node.Region.EndLine, node.Region.BeginLine);
var pos = editor.LocationToOffset (line, editor.GetLine (line - 1).Length);
if (pos < 0)
return;
using (var undo = editor.OpenUndoGroup ()) {
var oldCaret = editor.CaretOffset;
var text = editor.FormatString (pos, editor.EolMarker + directive);
var inserted = text.Length;
editor.InsertText (pos, text);
if (preserveCaretPosition) {
editor.CaretOffset = (pos < oldCaret)? oldCaret + inserted : oldCaret;
}
}
}