Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit69db5f3

Browse files
authored
Getting logic to be identical to Roslyn; also fixes a minor undo bug (dotnet#5074)
1 parent7fce39f commit69db5f3

File tree

1 file changed

+39
-42
lines changed

1 file changed

+39
-42
lines changed

‎vsintegration/src/FSharp.Editor/AutomaticCompletion/BraceCompletionSessionProvider.fs‎

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ type BraceCompletionSession
9999
Debug.Fail("The closing point was not found at the expected position.")
100100
this.EndSession()
101101
else
102-
103102
letopeningSnapshotPoint= closingSnapshotPoint.Subtract(1)
104103

105104
if 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()
110109
else
111-
112110
openingPoint<- snapshot.CreateTrackingPoint(openingSnapshotPoint.Position, PointTrackingMode.Positive)
113111
let_document= snapshot.GetOpenDocumentInCurrentContextWithChanges()
114112

115113
ifnot(session.CheckOpeningPoint(this, cancellationToken))then
116114
this.EndSession()
117115
else
118-
119116
use undo= this.CreateUndoTransaction()
120-
121-
snapshot<-
117+
letnextSnapshot=
122118
use 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
133129
else
134-
edit.Apply()// FIXME: perhaps, it should be ApplyAndLogExceptions()
130+
Some(edit.Apply())// FIXME: perhaps, it should be ApplyAndLogExceptions()
135131

136-
letbeforePoint= 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+
letbeforePoint= 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

151151
member__.HasNoForwardTyping(caretPoint:SnapshotPoint,endPoint:SnapshotPoint)=
152152
Debug.Assert(caretPoint.Snapshot= endPoint.Snapshot,"snapshots do not match")
@@ -194,33 +194,28 @@ type BraceCompletionSession
194194
memberthis.PreBackspace handledCommand=
195195
handledCommand<-false
196196

197-
match tryGetCaretPosition thiswith
198-
| Some caretPos->
199-
letsnapshot= subjectBuffer.CurrentSnapshot
197+
letcaretPos= tryGetCaretPosition this
198+
letsnapshot= 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-
letspan= SnapshotSpan(openingPoint.GetPoint(snapshot), closingPoint.GetPoint(snapshot))
204+
letspan= 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

225220
member__.PostBackspace()=()
226221

@@ -235,15 +230,17 @@ type BraceCompletionSession
235230

236231
letclosingSnapshotPoint= closingPoint.GetPoint(snapshot)
237232
ifnot this.HasForwardTyping&& session.AllowOverType(this, cancellationToken)then
238-
letcaretPosOpt= tryGetCaretPosition this
233+
letcaretPos= 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-
matchcaretPosOptwith
237+
matchcaretPoswith
243238
// ensure that we are within the session before clearing
244239
| Some caretPoswhen caretPos.Position< closingSnapshotPoint.Position&& closingSnapshotPoint.Position>0->
245240
use undo= this.CreateUndoTransaction()
246241

242+
editorOperations.AddBeforeTextBufferChangePrimitive()
243+
247244
letspan= SnapshotSpan(caretPos, closingSnapshotPoint.Subtract(1))
248245

249246
use edit= subjectBuffer.CreateEdit()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp