private TextSpan GetCommentTextSpanAtCurrentCaret() { VSTextView textView = new VSTextView(VSTextView.ActiveTextView); if (textView != null) { int line, col; textView.GetCursorPositon(out line, out col); int topIndex = line; int bottomIndex = line; string topLineText = textView.GetOneLineText(topIndex); while (!string.IsNullOrEmpty(topLineText) && topLineText.Trim().StartsWith("///")) { topIndex--; topLineText = textView.GetOneLineText(topIndex); } string bottomLineText = textView.GetOneLineText(bottomIndex); while (!string.IsNullOrEmpty(topLineText) && bottomLineText.Trim().StartsWith("///")) { bottomIndex++; bottomLineText = textView.GetOneLineText(bottomIndex); } return new TextSpan() { iStartLine = topIndex, iEndLine = bottomIndex }; } return new TextSpan() { iStartLine = -1, iEndLine = -1 }; }
private static void InsertBlackLineBefore() { int line, col; VSTextView textView = new VSTextView(VSTextView.ActiveTextView); textView.GetCursorPositon(out line, out col); textView.InsertText("\r\n", line, 0); textView.MoveCursorTo(line, textView.GetStartTextIndexOfCurrLine()); }
private static void InsertPair(string pair) { if (BaseUCSetting.SettingModel.AutoBraceModel.OpenAutoBrace) { int currentLineIndex, currentColIndex; VSTextView textview = new VSTextView(VSTextView.ActiveTextView); textview.GetCursorPositon(out currentLineIndex, out currentColIndex); textview.InsertText(pair, currentLineIndex, currentColIndex); textview.MoveCursorTo(currentLineIndex, currentColIndex); } }
protected override void OnExecute(Microsoft.VisualStudio.Shell.OleMenuCommand command) { int curLineIndex, curColumnIndex; VSTextView textView = new VSTextView(VSTextView.ActiveTextView); if (textView == null) { MessageBox.Show("textView is null"); return; } textView.GetCursorPositon(out curLineIndex, out curColumnIndex); //帮助:http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/c62a70eb-d84c-4410-890d-b41a86b2b55f/ ILangService langService; LangService_GetInstance(out langService); if (langService == null) { MessageBox.Show("langService is null"); return; } IDECompilerHost compilerHost = new IDECompilerHost(); IProject prj; Project currentPro = VSDocument.ActiveDocument.ProjectItem.ContainingProject; LangService_GetDteProject(langService, currentPro, out prj); if (prj == null) { MessageBox.Show("prj is null"); return; } FileName fileName = new Microsoft.RestrictedUsage.CSharp.Core.FileName(VSDocument.ActiveDocument.FullName); CSRPOSDATA data = new CSRPOSDATA() { LineIndex = curLineIndex, ColumnIndex = curColumnIndex }; CSharpMember m = Utilities.GetMemberAtLocation(compilerHost, prj, fileName.Value, data); if (m != null && m.ReturnType != null) { string returnName = m.ReturnType.GetFormattedName(InteropTypeFormatFlags.TypeFormatFlags_BestNameGUI); returnName = FilterReturnName(returnName); if (string.IsNullOrEmpty(returnName)) { return; } int insertCol = GetInsertPosition(textView, curLineIndex, curColumnIndex); textView.InsertText(returnName + " v =", curLineIndex, insertCol); textView.SelectText(curLineIndex, insertCol + returnName.Length + 1, curLineIndex, insertCol + returnName.Length + 2); } }
private static void SelectCurrentLine() { VSTextView text = new VSTextView(VSTextView.ActiveTextView); if (text != null) { int line = 0; int col = 0; text.GetCursorPositon(out line, out col); text.SelectText(line, 0, line, text.GetOneLineText(line).Length); } }
private void ShowSuggest() { if (VSTextView.ActiveTextView == null) return; VSTextView textView = new VSTextView(VSTextView.ActiveTextView); //检测到前面的类型名字 //如果类型后面隔了一个空格这进行提示,否则不提示 int cursorLine; int cursorCol; textView.GetCursorPositon(out cursorLine, out cursorCol); string before = textView.GetText(cursorLine, cursorCol - 1, cursorLine, cursorCol); }