diff options
author | Lluis Sanchez <llsan@microsoft.com> | 2019-02-19 13:02:50 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-19 13:02:50 +0300 |
commit | 5040c83aaebd09556e8e9b75d602ec5d48fe3803 (patch) | |
tree | fe7b82693a1f18eadced7a45c0677d958915dc0c /main/src/core/Mono.TextEditor.Shared/Mono.TextEditor | |
parent | 128580b617e66a754369d574b71de54baada4d54 (diff) | |
parent | 8dde9897a2e9048da84563f76359ac16004dd0d0 (diff) |
Merge pull request #7069 from mono/master-vsts749965
Fixes VSTS Bug 749965: Fatal error on copy + paste in
Diffstat (limited to 'main/src/core/Mono.TextEditor.Shared/Mono.TextEditor')
-rw-r--r-- | main/src/core/Mono.TextEditor.Shared/Mono.TextEditor/CaretImpl.ITextCaret.cs | 11 | ||||
-rw-r--r-- | main/src/core/Mono.TextEditor.Shared/Mono.TextEditor/CaretImpl.cs | 19 |
2 files changed, 20 insertions, 10 deletions
diff --git a/main/src/core/Mono.TextEditor.Shared/Mono.TextEditor/CaretImpl.ITextCaret.cs b/main/src/core/Mono.TextEditor.Shared/Mono.TextEditor/CaretImpl.ITextCaret.cs index 6f121254c2..113f6992ac 100644 --- a/main/src/core/Mono.TextEditor.Shared/Mono.TextEditor/CaretImpl.ITextCaret.cs +++ b/main/src/core/Mono.TextEditor.Shared/Mono.TextEditor/CaretImpl.ITextCaret.cs @@ -29,6 +29,7 @@ using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Text.Editor; using Microsoft.VisualStudio.Text.Formatting; using MonoDevelop.Ide.Editor; +using MonoDevelop.Core; namespace Mono.TextEditor { @@ -116,8 +117,14 @@ namespace Mono.TextEditor insertionPoint = vsp; if (args.CaretChangeReason == CaretChangeReason.Movement) { oldCaretLocation = args.Location; - var oldOffset = TextEditor.LocationToOffset (args.Location); - var snapshotPoint = new SnapshotPoint (TextEditor.TextSnapshot, oldOffset); + var snapShot = args.Snapshot; + var snapshotLine = snapShot.GetLineFromLineNumber (args.Location.Line - 1); + if (snapshotLine == null) { + LoggingService.LogError ("PositionChanged_ITextCaret line number : " + args.Location.Line + " is out of range."); + return; + } + var oldOffset = snapshotLine.Start.Position + Math.Min (snapshotLine.Length, args.Location.Column - 1); + var snapshotPoint = new SnapshotPoint (snapShot, oldOffset); var mappingPoint = TextEditor.BufferGraph.CreateMappingPoint (snapshotPoint, PointTrackingMode.Positive); var oldCaretPosition = new CaretPosition (vsp, mappingPoint, _caretAffinity); var eventArgs = new CaretPositionChangedEventArgs (TextEditor, oldCaretPosition, ((ITextCaret)this).Position); diff --git a/main/src/core/Mono.TextEditor.Shared/Mono.TextEditor/CaretImpl.cs b/main/src/core/Mono.TextEditor.Shared/Mono.TextEditor/CaretImpl.cs index 798c42b28d..7ad29ede3d 100644 --- a/main/src/core/Mono.TextEditor.Shared/Mono.TextEditor/CaretImpl.cs +++ b/main/src/core/Mono.TextEditor.Shared/Mono.TextEditor/CaretImpl.cs @@ -39,7 +39,9 @@ namespace Mono.TextEditor bool autoScrollToCaret = true; CaretMode mode; - + + ITextSnapshot currentBuffer; + int line = DocumentLocation.MinLine; public override int Line { get { @@ -54,7 +56,7 @@ namespace Mono.TextEditor CheckLine (); SetColumn (); UpdateCaretOffset (); - OnPositionChanged (new CaretLocationEventArgs (old, CaretChangeReason.Movement)); + OnPositionChanged (new CaretLocationEventArgs (old, currentBuffer ?? TextEditorData.Document.TextBuffer.CurrentSnapshot, CaretChangeReason.Movement)); } } } @@ -73,7 +75,7 @@ namespace Mono.TextEditor CheckColumn (); SetDesiredColumn (); UpdateCaretOffset (); - OnPositionChanged (new CaretLocationEventArgs (old, CaretChangeReason.Movement)); + OnPositionChanged (new CaretLocationEventArgs (old, currentBuffer ?? TextEditorData.Document.TextBuffer.CurrentSnapshot, CaretChangeReason.Movement)); } } } @@ -93,7 +95,7 @@ namespace Mono.TextEditor CheckColumn (); SetDesiredColumn (); UpdateCaretOffset (); - OnPositionChanged (new CaretLocationEventArgs (old, CaretChangeReason.Movement)); + OnPositionChanged (new CaretLocationEventArgs (old, currentBuffer ?? TextEditorData.Document.TextBuffer.CurrentSnapshot, CaretChangeReason.Movement)); } } } @@ -119,7 +121,7 @@ namespace Mono.TextEditor CheckLine (); CheckColumn (); SetDesiredColumn (); - OnPositionChanged (new CaretLocationEventArgs (old, CaretChangeReason.Movement)); + OnPositionChanged (new CaretLocationEventArgs (old, currentBuffer ?? TextEditorData.Document.TextBuffer.CurrentSnapshot, CaretChangeReason.Movement)); } } @@ -270,7 +272,7 @@ namespace Mono.TextEditor } UpdateCaretOffset (); - OnPositionChanged (new CaretLocationEventArgs (old, CaretChangeReason.Movement)); + OnPositionChanged (new CaretLocationEventArgs (old, currentBuffer ?? TextEditorData.Document.TextBuffer.CurrentSnapshot, CaretChangeReason.Movement)); } void SetDesiredColumn () @@ -301,7 +303,7 @@ namespace Mono.TextEditor var old = Location; DesiredColumn = desiredColumn; SetColumn (); - OnPositionChanged (new CaretLocationEventArgs (old, CaretChangeReason.Movement)); + OnPositionChanged (new CaretLocationEventArgs (old, currentBuffer ?? TextEditorData.Document.TextBuffer.CurrentSnapshot, CaretChangeReason.Movement)); } public override string ToString () @@ -330,6 +332,7 @@ namespace Mono.TextEditor TextEditorData.Document.EnsureOffsetIsUnfolded (Offset); base.OnPositionChanged (args); PositionChanged_ITextCaret (args); + currentBuffer = TextEditorData.Document.TextBuffer.CurrentSnapshot; } protected virtual void OnModeChanged () @@ -386,7 +389,7 @@ namespace Mono.TextEditor SetDesiredColumn (); UpdateCaretOffset (); - OnPositionChanged (new CaretLocationEventArgs (old, CaretChangeReason.BufferChange)); + OnPositionChanged (new CaretLocationEventArgs (old, currentBuffer ?? TextEditorData.Document.TextBuffer.CurrentSnapshot, CaretChangeReason.BufferChange)); } public void SetDocument (TextDocument doc) |