From 3c9dc9f1396002f73cc1520b9517d93603066901 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 17 Jun 2006 12:07:26 +0000 Subject: [PATCH] Fixed forum-8579: "Goto Matching Brace" doesn't work if "Highlighting matching braces" is deactivated git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1495 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/Src/Actions/MiscActions.cs | 7 ++- .../Project/Src/Gui/TextArea.cs | 57 +++++++++---------- .../NRefactoryCodeGenerator.cs | 5 +- 3 files changed, 35 insertions(+), 34 deletions(-) diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Actions/MiscActions.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Actions/MiscActions.cs index 722e2cba64..4539bb4d25 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Actions/MiscActions.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Actions/MiscActions.cs @@ -905,9 +905,10 @@ namespace ICSharpCode.TextEditor.Actions { public override void Execute(TextArea textArea) { - if (textArea.TextView.Highlight != null) { - Point p1 = new Point(textArea.TextView.Highlight.CloseBrace.X + 1, textArea.TextView.Highlight.CloseBrace.Y); - Point p2 = new Point(textArea.TextView.Highlight.OpenBrace.X + 1, textArea.TextView.Highlight.OpenBrace.Y); + Highlight highlight = textArea.FindMatchingBracketHighlight(); + if (highlight != null) { + Point p1 = new Point(highlight.CloseBrace.X + 1, highlight.CloseBrace.Y); + Point p2 = new Point(highlight.OpenBrace.X + 1, highlight.OpenBrace.Y); if (p1 == textArea.Caret.Position) { if (textArea.Document.TextEditorProperties.BracketMatchingStyle == BracketMatchingStyle.After) { textArea.Caret.Position = p2; diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextArea.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextArea.cs index 9c0f97f8a8..ec28525d6e 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextArea.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextArea.cs @@ -229,42 +229,39 @@ namespace ICSharpCode.TextEditor textView.Highlight = null; return; } - bool changed = false; - if (caret.Offset == 0) { - if (textView.Highlight != null) { - int line = textView.Highlight.OpenBrace.Y; - int line2 = textView.Highlight.CloseBrace.Y; - textView.Highlight = null; - UpdateLine(line); - UpdateLine(line2); - } - return; + int oldLine1 = -1, oldLine2 = -1; + if (textView.Highlight != null && textView.Highlight.OpenBrace.Y >=0 && textView.Highlight.OpenBrace.Y < Document.TotalNumberOfLines) { + oldLine1 = textView.Highlight.OpenBrace.Y; + } + if (textView.Highlight != null && textView.Highlight.CloseBrace.Y >=0 && textView.Highlight.CloseBrace.Y < Document.TotalNumberOfLines) { + oldLine2 = textView.Highlight.CloseBrace.Y; } + textView.Highlight = FindMatchingBracketHighlight(); + if (oldLine1 >= 0) + UpdateLine(oldLine1); + if (oldLine2 >= 0 && oldLine2 != oldLine1) + UpdateLine(oldLine2); + if (textView.Highlight != null) { + int newLine1 = textView.Highlight.OpenBrace.Y; + int newLine2 = textView.Highlight.CloseBrace.Y; + if (newLine1 != oldLine1 && newLine1 != oldLine2) + UpdateLine(newLine1); + if (newLine2 != oldLine1 && newLine2 != oldLine2 && newLine2 != newLine1) + UpdateLine(newLine2); + } + } + + public Highlight FindMatchingBracketHighlight() + { + if (Caret.Offset == 0) + return null; foreach (BracketHighlightingSheme bracketsheme in bracketshemes) { -// if (bracketsheme.IsInside(textareapainter.Document, textareapainter.Document.Caret.Offset)) { Highlight highlight = bracketsheme.GetHighlight(Document, Caret.Offset - 1); - if (textView.Highlight != null && textView.Highlight.OpenBrace.Y >=0 && textView.Highlight.OpenBrace.Y < Document.TotalNumberOfLines) { - UpdateLine(textView.Highlight.OpenBrace.Y); - } - if (textView.Highlight != null && textView.Highlight.CloseBrace.Y >=0 && textView.Highlight.CloseBrace.Y < Document.TotalNumberOfLines) { - UpdateLine(textView.Highlight.CloseBrace.Y); - } - textView.Highlight = highlight; if (highlight != null) { - changed = true; - break; - } -// } - } - if (changed || textView.Highlight != null) { - int line = textView.Highlight.OpenBrace.Y; - int line2 = textView.Highlight.CloseBrace.Y; - if (!changed) { - textView.Highlight = null; + return highlight; } - UpdateLine(line); - UpdateLine(line2); } + return null; } public void SetDesiredColumn() diff --git a/src/Main/Base/Project/Src/Services/RefactoringService/NRefactoryCodeGenerator.cs b/src/Main/Base/Project/Src/Services/RefactoringService/NRefactoryCodeGenerator.cs index f57202baa7..a30df82608 100644 --- a/src/Main/Base/Project/Src/Services/RefactoringService/NRefactoryCodeGenerator.cs +++ b/src/Main/Base/Project/Src/Services/RefactoringService/NRefactoryCodeGenerator.cs @@ -31,7 +31,10 @@ namespace ICSharpCode.SharpDevelop.Refactoring if (node is Statement) visitor.OutputFormatter.Indent(); node.AcceptVisitor(visitor, null); - return visitor.Text; + string text = visitor.Text; + if (node is Statement && !text.EndsWith("\n")) + text += Environment.NewLine; + return text; } }