diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditorView.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditorView.cs index 781d4854cd..762c73f857 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditorView.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditorView.cs @@ -226,6 +226,7 @@ namespace ICSharpCode.AvalonEdit.AddIn if (e.ChangedButton == MouseButton.Left && Keyboard.Modifiers == ModifierKeys.Control) { var position = GetPositionFromPoint(e.GetPosition(this)); if (position != null) { + Core.AnalyticsMonitorService.TrackFeature(typeof(GoToDefinition).FullName, "Ctrl+Click"); GoToDefinition.Run(this.Adapter, this.Document.GetOffset(position.Value)); e.Handled = true; } diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ParserFoldingStrategy.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ParserFoldingStrategy.cs index d12a2a072b..5b5d8e8ed3 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ParserFoldingStrategy.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ParserFoldingStrategy.cs @@ -55,8 +55,8 @@ namespace ICSharpCode.AvalonEdit.AddIn AddClassMembers(c, newFoldMarkers); } foreach (FoldingRegion foldingRegion in parseInfo.CompilationUnit.FoldingRegions) { - NewFolding f = new NewFolding(textArea.Document.GetOffset(foldingRegion.Region.BeginLine, foldingRegion.Region.BeginColumn), - textArea.Document.GetOffset(foldingRegion.Region.EndLine, foldingRegion.Region.EndColumn)); + NewFolding f = new NewFolding(GetOffset(foldingRegion.Region.BeginLine, foldingRegion.Region.BeginColumn), + GetOffset(foldingRegion.Region.EndLine, foldingRegion.Region.EndColumn)); f.DefaultClosed = isFirstUpdate; f.Name = foldingRegion.Name; newFoldMarkers.Add(f); @@ -74,8 +74,8 @@ namespace ICSharpCode.AvalonEdit.AddIn if (cRegion.IsEmpty) cRegion = c.Region; if (cRegion.BeginLine < cRegion.EndLine) { - newFoldMarkers.Add(new NewFolding(textArea.Document.GetOffset(cRegion.BeginLine, cRegion.BeginColumn), - textArea.Document.GetOffset(cRegion.EndLine, cRegion.EndColumn))); + newFoldMarkers.Add(new NewFolding(GetOffset(cRegion.BeginLine, cRegion.BeginColumn), + GetOffset(cRegion.EndLine, cRegion.EndColumn))); } foreach (IClass innerClass in c.InnerClasses) { AddClassMembers(innerClass, newFoldMarkers); @@ -83,10 +83,20 @@ namespace ICSharpCode.AvalonEdit.AddIn foreach (IMember m in c.AllMembers) { if (m.Region.EndLine < m.BodyRegion.EndLine) { - newFoldMarkers.Add(new NewFolding(textArea.Document.GetOffset(m.Region.EndLine, m.Region.EndColumn), - textArea.Document.GetOffset(m.BodyRegion.EndLine, m.BodyRegion.EndColumn))); + newFoldMarkers.Add(new NewFolding(GetOffset(m.Region.EndLine, m.Region.EndColumn), + GetOffset(m.BodyRegion.EndLine, m.BodyRegion.EndColumn))); } } } + + int GetOffset(int line, int column) + { + if (line < 1) + return 0; + var document = textArea.Document; + if (line > document.LineCount) + return document.TextLength; + return document.GetOffset(line, column); + } } } diff --git a/src/Libraries/AvalonDock/ManagedContent.cs b/src/Libraries/AvalonDock/ManagedContent.cs index 53b0c99835..514197a613 100644 --- a/src/Libraries/AvalonDock/ManagedContent.cs +++ b/src/Libraries/AvalonDock/ManagedContent.cs @@ -172,8 +172,6 @@ namespace AvalonDock _dragEnabledArea.MouseMove += new MouseEventHandler(OnDragMouseMove); _dragEnabledArea.MouseUp += new MouseButtonEventHandler(OnDragMouseUp); _dragEnabledArea.MouseLeave += new MouseEventHandler(OnDragMouseLeave); - - _dragEnabledArea.InputBindings.Add(new InputBinding(ApplicationCommands.Close, new MouseGesture(MouseAction.MiddleClick))); } } diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Folding/FoldingManager.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Folding/FoldingManager.cs index 36ef8ece7c..fb7efab36f 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Folding/FoldingManager.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Folding/FoldingManager.cs @@ -201,6 +201,9 @@ namespace ICSharpCode.AvalonEdit.Folding throw new ArgumentException("newFoldings must be sorted by start offset"); previousStartOffset = newFolding.StartOffset; + if (newFolding.StartOffset == newFolding.EndOffset) + continue; // ignore zero-length foldings + // remove old foldings that were skipped while (oldFoldingIndex < oldFoldings.Length && newFolding.StartOffset > oldFoldings[oldFoldingIndex].StartOffset) { this.RemoveFolding(oldFoldings[oldFoldingIndex++]); diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Folding/NewFolding.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Folding/NewFolding.cs index 58c4024125..28776d5376 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Folding/NewFolding.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Folding/NewFolding.cs @@ -55,7 +55,7 @@ namespace ICSharpCode.AvalonEdit.Folding /// public NewFolding(int start, int end) { - if (!(start < end)) + if (!(start <= end)) throw new ArgumentException("'start' must be less than 'end'"); this.StartOffset = start; this.EndOffset = end; diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/V1Loader.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/V1Loader.cs index 88e3561e83..9188883e74 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/V1Loader.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/V1Loader.cs @@ -283,7 +283,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd throw new HighlightingDefinitionInvalidException("Unexpected end of @ sequence, use @@ to look for a single @."); switch (expr[i]) { case 'C': // match whitespace or punctuation - b.Append(@"^[\w\d_]"); + b.Append(@"[^\w\d_]"); break; case '!': // negative lookahead { diff --git a/src/Main/Base/Project/Src/TextEditor/Gui/Dialogs/GotoDialog.cs b/src/Main/Base/Project/Src/TextEditor/Gui/Dialogs/GotoDialog.cs index 0aee902925..8049bb026d 100644 --- a/src/Main/Base/Project/Src/TextEditor/Gui/Dialogs/GotoDialog.cs +++ b/src/Main/Base/Project/Src/TextEditor/Gui/Dialogs/GotoDialog.cs @@ -11,9 +11,11 @@ using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Linq; +using System.Text.RegularExpressions; using System.Windows; using System.Windows.Controls; using System.Windows.Input; +using System.Windows.Media; using ICSharpCode.Core; using ICSharpCode.Core.Presentation; @@ -21,7 +23,6 @@ using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.SharpDevelop.Editor.CodeCompletion; using ICSharpCode.SharpDevelop.Project; -using System.Windows.Media; namespace ICSharpCode.SharpDevelop.Gui { @@ -68,19 +69,24 @@ namespace ICSharpCode.SharpDevelop.Gui public object Tag; public string Text { get; private set; } IImage image; + int matchType; public ImageSource ImageSource { get { return image.ImageSource; } } - public GotoEntry(string text, IImage image) + public GotoEntry(string text, IImage image, int matchType) { this.Text = text; this.image = image; + this.matchType = matchType; } public int CompareTo(GotoEntry other) { + int r = matchType.CompareTo(other.matchType); + if (r != 0) + return -r; return Text.CompareTo(other.Text); } } @@ -112,11 +118,8 @@ namespace ICSharpCode.SharpDevelop.Gui listBox.ScrollIntoView(listBox.Items[index]); } - Dictionary visibleEntries = new Dictionary(); - int bestMatchType; - double bestPriority; + HashSet visibleEntries = new HashSet(); List newItems = new List(); - GotoEntry bestItem; void textBoxTextChanged(object sender, TextChangedEventArgs e) { @@ -124,14 +127,12 @@ namespace ICSharpCode.SharpDevelop.Gui listBox.ItemsSource = null; newItems.Clear(); visibleEntries.Clear(); - bestItem = null; if (text.Length == 0) { return; } if (text.Length == 1 && !char.IsDigit(text, 0)) { return; } - int dotPos = text.IndexOf('.'); int commaPos = text.IndexOf(','); if (commaPos < 0) { // use "File, ##" or "File: ##" syntax for line numbers @@ -142,9 +143,10 @@ namespace ICSharpCode.SharpDevelop.Gui } else if (commaPos > 0) { string file = text.Substring(0, commaPos).Trim(); string line = text.Substring(commaPos + 1).Trim(); - if (line.StartsWith("line")) { - // remove the word "line" - line = line.Substring(4).Trim(); + Match m = Regex.Match(line, @"^\w+ (\d+)$"); + if (m.Success) { + // remove the word "line" (or some localized version of it) + line = m.Groups[1].Value; } int lineNr; if (!int.TryParse(line, out lineNr)) @@ -159,9 +161,8 @@ namespace ICSharpCode.SharpDevelop.Gui } newItems.Sort(); listBox.ItemsSource = newItems; - if (bestItem != null) { - listBox.SelectedItem = bestItem; - listBox.ScrollIntoView(bestItem); + if (newItems.Count > 0) { + listBox.SelectedItem = newItems[0]; } } @@ -225,7 +226,7 @@ namespace ICSharpCode.SharpDevelop.Gui if (item.Project != null) { display += StringParser.Parse(" ${res:MainWindow.Windows.SearchResultPanel.In} ") + item.Project.Name; } - AddItem(display, ClassBrowserIconService.GotoArrow, new FileLineReference(fileName, lineNumber), 0.5, matchType); + AddItem(display, ClassBrowserIconService.GotoArrow, new FileLineReference(fileName, lineNumber), matchType); } } } @@ -237,19 +238,7 @@ namespace ICSharpCode.SharpDevelop.Gui ITextEditor editor = GetEditor(); if (editor != null) { num = Math.Min(editor.Document.TotalNumberOfLines, Math.Max(1, num)); - AddItem(StringParser.Parse("${res:Dialog.Goto.GotoLine} ") + num, ClassBrowserIconService.GotoArrow, num, 0, int.MaxValue); - } - } - } - - void ShowCompletionData(IList dataList, string text) - { - string lowerText = text.ToLowerInvariant(); - foreach (CodeCompletionItem data in dataList.OfType()) { - string dataText = data.Text; - int matchType = GetMatchType(text, dataText); - if (matchType >= 0) { - AddItem(data.Entity, data.Image, data.Priority, matchType); + AddItem(StringParser.Parse("${res:Dialog.Goto.GotoLine} ") + num, ClassBrowserIconService.GotoArrow, num, int.MaxValue); } } } @@ -318,28 +307,18 @@ namespace ICSharpCode.SharpDevelop.Gui } } - void AddItem(string text, IImage image, object tag, double priority, int matchType) + void AddItem(string text, IImage image, object tag, int matchType) { - if (visibleEntries.ContainsKey(text)) + if (!visibleEntries.Add(text)) return; - visibleEntries.Add(text, null); - GotoEntry item = new GotoEntry(text, image); + GotoEntry item = new GotoEntry(text, image, matchType); item.Tag = tag; - if (bestItem == null - || (tag is IMember && bestItem.Tag is IClass) - || (!(tag is IClass && bestItem.Tag is IMember) - && (matchType > bestMatchType || matchType == bestMatchType && priority > bestPriority))) - { - bestItem = item; - bestPriority = priority; - bestMatchType = matchType; - } newItems.Add(item); } void AddItem(IClass c, int matchType) { - AddItem(c, ClassBrowserIconService.GetIcon(c), CodeCompletionDataUsageCache.GetPriority(c.DotNetName, true), matchType); + AddItem(c, ClassBrowserIconService.GetIcon(c), matchType); } void AddItemIfMatchText(string text, IMember member, IImage image) @@ -347,13 +326,13 @@ namespace ICSharpCode.SharpDevelop.Gui string name = member.Name; int matchType = GetMatchType(text, name); if (matchType >= 0) { - AddItem(member, image, CodeCompletionDataUsageCache.GetPriority(member.DotNetName, true), matchType); + AddItem(member, image, matchType); } } - void AddItem(IEntity e, IImage image, double priority, int matchType) + void AddItem(IEntity e, IImage image, int matchType) { - AddItem(e.Name + " (" + e.FullyQualifiedName + ")", image, e, priority, matchType); + AddItem(e.Name + " (" + e.FullyQualifiedName + ")", image, e, matchType); } void cancelButtonClick(object sender, RoutedEventArgs e)