@@ -99,7 +99,6 @@ type BraceCompletionSession
9999 Debug.Fail( " The closing point was not found at the expected position." )
100100 this.EndSession()
101101else
102-
103102let openingSnapshotPoint = closingSnapshotPoint.Subtract( 1 )
104103
105104if openingSnapshotPoint.GetChar() <> openingBracethen
@@ -108,17 +107,14 @@ type BraceCompletionSession
108107// Debug.Fail("The opening brace was not found at the expected position.");
109108 this.EndSession()
110109else
111-
112110 openingPoint<- snapshot.CreateTrackingPoint( openingSnapshotPoint.Position, PointTrackingMode.Positive)
113111let _document = snapshot.GetOpenDocumentInCurrentContextWithChanges()
114112
115113if not ( session.CheckOpeningPoint( this, cancellationToken)) then
116114 this.EndSession()
117115else
118-
119116use undo= this.CreateUndoTransaction()
120-
121- snapshot<-
117+ let nextSnapshot =
122118use edit= subjectBuffer.CreateEdit()
123119
124120 edit.Insert( closingSnapshotPoint.Position, closingBrace.ToString()) |> ignore
@@ -129,24 +125,28 @@ type BraceCompletionSession
129125// exit without setting the closing point which will take us off the stack
130126 edit.Cancel()
131127 undo.Cancel()
132- snapshot
128+ None
133129else
134- edit.Apply() // FIXME: perhaps, it should be ApplyAndLogExceptions()
130+ Some ( edit.Apply() ) // FIXME: perhaps, it should be ApplyAndLogExceptions()
135131
136- let beforePoint = beforeTrackingPoint.GetPoint( textView.TextSnapshot)
132+ match nextSnapshotwith
133+ | None-> ()
134+ | Some( nextSnapshot) ->
137135
138- // switch from positive to negative tracking so it stays against the closing brace
139- closingPoint<- subjectBuffer.CurrentSnapshot.CreateTrackingPoint( closingPoint.GetPoint( snapshot) .Position, PointTrackingMode.Negative)
136+ let beforePoint = beforeTrackingPoint.GetPoint( textView.TextSnapshot)
140137
141- Debug.Assert ( closingPoint.GetPoint ( snapshot ) .Position > 0 && ( SnapshotSpan ( closingPoint.GetPoint ( snapshot ) .Subtract ( 1 ), 1 )) .GetText () .Equals ( closingBrace.ToString ()),
142- " The closing point does not match the closing brace character " )
138+ // switch from positive to negative tracking so it stays against the closing brace
139+ closingPoint <- subjectBuffer.CurrentSnapshot.CreateTrackingPoint ( closingPoint.GetPoint ( nextSnapshot ) .Position , PointTrackingMode.Negative )
143140
144- // move the caret back between the braces
145- textView.Caret.MoveTo ( beforePoint ) |> ignore
141+ Debug.Assert ( closingPoint.GetPoint ( nextSnapshot ) .Position > 0 && ( SnapshotSpan ( closingPoint.GetPoint ( nextSnapshot ) .Subtract ( 1 ), 1 )) .GetText () .Equals ( closingBrace.ToString ()),
142+ " The closing point does not match the closing brace character " )
146143
147- session.AfterStart( this, cancellationToken)
144+ // move the caret back between the braces
145+ textView.Caret.MoveTo( beforePoint) |> ignore
148146
149- undo.Complete()
147+ session.AfterStart( this, cancellationToken)
148+
149+ undo.Complete()
150150
151151member __.HasNoForwardTyping ( caretPoint : SnapshotPoint , endPoint : SnapshotPoint ) =
152152 Debug.Assert( caretPoint.Snapshot= endPoint.Snapshot, " snapshots do not match" )
@@ -194,33 +194,28 @@ type BraceCompletionSession
194194member this.PreBackspace handledCommand =
195195 handledCommand<- false
196196
197- match tryGetCaretPosition thiswith
198- | Some caretPos->
199- let snapshot = subjectBuffer.CurrentSnapshot
197+ let caretPos = tryGetCaretPosition this
198+ let snapshot = subjectBuffer.CurrentSnapshot
200199
201- if caretPos.Position> 0 &&
202- caretPos.Position- 1 = openingPoint.GetPoint( snapshot) .Position&&
203- not this.HasForwardTypingthen
204-
205- use undo= this.CreateUndoTransaction()
206- use edit= subjectBuffer.CreateEdit()
200+ if caretPos.IsSome&& caretPos.Value.Position> 0 && ( caretPos.Value.Position- 1 ) = openingPoint.GetPoint( snapshot) .Position&& not this.HasForwardTypingthen
201+ use undo= this.CreateUndoTransaction()
202+ use edit= subjectBuffer.CreateEdit()
207203
208- let span = SnapshotSpan( openingPoint.GetPoint( snapshot), closingPoint.GetPoint( snapshot))
204+ let span = SnapshotSpan( openingPoint.GetPoint( snapshot), closingPoint.GetPoint( snapshot))
209205
210- edit.Delete( span.Span) |> ignore
206+ edit.Delete( span.Span) |> ignore
211207
212- if edit.HasFailedChangesthen
213- edit.Cancel()
214- undo.Cancel()
215- Debug.Fail( " Unable to clear braces" )
216- else
217- // handle the command so the backspace does
218- // not go through since we've already cleared the braces
219- handledCommand<- true
220- edit.Apply() |> ignore// FIXME: ApplyAndLogExceptions()
221- undo.Complete()
222- this.EndSession()
223- | _ -> ()
208+ if edit.HasFailedChangesthen
209+ edit.Cancel()
210+ undo.Cancel()
211+ Debug.Fail( " Unable to clear braces" )
212+ else
213+ // handle the command so the backspace does
214+ // not go through since we've already cleared the braces
215+ handledCommand<- true
216+ edit.Apply() |> ignore// FIXME: ApplyAndLogExceptions()
217+ undo.Complete()
218+ this.EndSession()
224219
225220member __.PostBackspace () = ()
226221
@@ -235,15 +230,17 @@ type BraceCompletionSession
235230
236231let closingSnapshotPoint = closingPoint.GetPoint( snapshot)
237232if not this.HasForwardTyping&& session.AllowOverType( this, cancellationToken) then
238- let caretPosOpt = tryGetCaretPosition this
233+ let caretPos = tryGetCaretPosition this
239234
240- Debug.Assert( caretPosOpt .IsSome&& caretPosOpt .Value.Position< closingSnapshotPoint.Position)
235+ Debug.Assert( caretPos .IsSome&& caretPos .Value.Position< closingSnapshotPoint.Position)
241236
242- match caretPosOpt with
237+ match caretPos with
243238// ensure that we are within the session before clearing
244239| Some caretPoswhen caretPos.Position< closingSnapshotPoint.Position&& closingSnapshotPoint.Position> 0 ->
245240use undo= this.CreateUndoTransaction()
246241
242+ editorOperations.AddBeforeTextBufferChangePrimitive()
243+
247244let span = SnapshotSpan( caretPos, closingSnapshotPoint.Subtract( 1 ))
248245
249246use edit= subjectBuffer.CreateEdit()