void ToggleCodeCommentWithBlockComments() { var blockStarts = TextEditorFactory.GetSyntaxProperties(textEditor.MimeType, "BlockCommentStart"); var blockEnds = TextEditorFactory.GetSyntaxProperties(textEditor.MimeType, "BlockCommentEnd"); if (blockStarts == null || blockEnds == null || blockStarts.Length == 0 || blockEnds.Length == 0) { return; } string blockStart = blockStarts[0]; string blockEnd = blockEnds[0]; using (var undo = textEditor.OpenUndoGroup()) { IDocumentLine startLine; IDocumentLine endLine; if (textEditor.IsSomethingSelected) { startLine = textEditor.GetLineByOffset(textEditor.SelectionRange.Offset); endLine = textEditor.GetLineByOffset(textEditor.SelectionRange.EndOffset); // If selection ends at begining of line... This is visible as previous line // is selected, hence we want to select previous line Bug 26287 if (endLine.Offset == textEditor.SelectionRange.EndOffset) { endLine = endLine.PreviousLine; } } else { startLine = endLine = textEditor.GetLine(textEditor.CaretLine); } string startLineText = textEditor.GetTextAt(startLine.Offset, startLine.Length); string endLineText = textEditor.GetTextAt(endLine.Offset, endLine.Length); if (startLineText.StartsWith(blockStart, StringComparison.Ordinal) && endLineText.EndsWith(blockEnd, StringComparison.Ordinal)) { textEditor.RemoveText(endLine.Offset + endLine.Length - blockEnd.Length, blockEnd.Length); textEditor.RemoveText(startLine.Offset, blockStart.Length); if (textEditor.IsSomethingSelected) { textEditor.SelectionAnchorOffset -= blockEnd.Length; } } else { textEditor.InsertText(endLine.Offset + endLine.Length, blockEnd); textEditor.InsertText(startLine.Offset, blockStart); if (textEditor.IsSomethingSelected) { textEditor.SelectionAnchorOffset += blockEnd.Length; } } } }
public CodeCompletionContext CreateCodeCompletionContext(int triggerOffset) { var line = editor.GetLineByOffset(triggerOffset); return(new CodeCompletionContext { TriggerOffset = triggerOffset, TriggerLine = line.LineNumber, TriggerLineOffset = line.Offset, TriggerXCoord = 0, TriggerYCoord = 0, TriggerTextHeight = 0, TriggerWordLength = 0 }); }
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); } }