diff options
author | Mike Krüger <mkrueger@xamarin.com> | 2017-05-09 16:28:44 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-09 16:28:44 +0300 |
commit | 543a6db7170107cd980984aff94ddd72f5e75a87 (patch) | |
tree | 243d0a3801e65d629e814a26400c4e476965be81 /main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Navigation | |
parent | 4a03be1ada211bb3c72acedc9e5a2f8455e86835 (diff) | |
parent | fa478aa4e654cd40292f532ab9c3e816e894ee11 (diff) |
Merge pull request #2325 from mono/master-navpointfix
[Ide] TextFileNavigation points remove text source version on document
Diffstat (limited to 'main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Navigation')
-rw-r--r-- | main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Navigation/DocumentNavigationPoint.cs | 18 | ||||
-rw-r--r-- | main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Navigation/TextFileNavigationPoint.cs | 30 |
2 files changed, 41 insertions, 7 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Navigation/DocumentNavigationPoint.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Navigation/DocumentNavigationPoint.cs index 7b6b440635..660d7979d5 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Navigation/DocumentNavigationPoint.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Navigation/DocumentNavigationPoint.cs @@ -37,11 +37,23 @@ namespace MonoDevelop.Ide.Navigation public class DocumentNavigationPoint : NavigationPoint { Document doc; + + public Document Document { + get { + return doc; + } + } + FilePath fileName; string project; public DocumentNavigationPoint (Document doc) { + SetDocument (doc); + } + + protected void SetDocument (Document doc) + {
this.doc = doc; doc.Closed += HandleClosed; } @@ -59,10 +71,14 @@ namespace MonoDevelop.Ide.Navigation } base.Dispose (); } - + + protected virtual void OnDocumentClosing () + { + } void HandleClosed (object sender, EventArgs e) { + OnDocumentClosing (); fileName = doc.FileName; project = doc.HasProject ? doc.Project.ItemId : null; if (fileName == FilePath.Null) { diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Navigation/TextFileNavigationPoint.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Navigation/TextFileNavigationPoint.cs index 4cdeddd5be..6d6af2cd85 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Navigation/TextFileNavigationPoint.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Navigation/TextFileNavigationPoint.cs @@ -34,27 +34,39 @@ using MonoDevelop.Ide.Gui; using MonoDevelop.Ide.Editor; using System.Threading.Tasks; using MonoDevelop.Core.Text; +using System.Linq; namespace MonoDevelop.Ide.Navigation { public class TextFileNavigationPoint : DocumentNavigationPoint { - readonly int line; - readonly int column; + int line; + int column; - readonly int offset; - readonly ITextSourceVersion version; + int offset; + ITextSourceVersion version; public TextFileNavigationPoint (Document doc, TextEditor buffer) : base (doc) { var location = buffer.CaretLocation; version = buffer.Version; + offset = buffer.CaretOffset; line = location.Line; column = location.Column; - offset = buffer.CaretOffset; } - + + protected override void OnDocumentClosing () + { + // text source version becomes invalid on document close. + var editor = Document.Editor; + offset = version.MoveOffsetTo (editor.Version, offset); + var location = editor.CaretLocation; + line = location.Line; + column = location.Column; + version = null; + } + public TextFileNavigationPoint (FilePath file, int line, int column) : base (file) { @@ -107,6 +119,12 @@ namespace MonoDevelop.Ide.Navigation var loc = editor.OffsetToLocation (currentOffset); editor.SetCaretLocation (loc); } else { + var doc = IdeApp.Workbench.Documents.FirstOrDefault (d => d.Editor == editor); + if (doc != null) { + version = editor.Version; + offset = editor.LocationToOffset (line, column); + SetDocument (doc); + } editor.SetCaretLocation (Math.Max (line, 1), Math.Max (column, 1)); } } |