Fix caret update logic in fourslash tests

This commit is contained in:
Mine Starks 2017-07-11 13:32:56 -07:00
parent 39e4b1f9e3
commit 003c28f1ef
2 changed files with 13 additions and 6 deletions

View file

@ -1790,17 +1790,20 @@ namespace FourSlash {
this.editScriptAndUpdateMarkers(fileName, offsetStart, offsetEnd, edit.newText);
const editDelta = edit.newText.length - edit.span.length;
if (offsetStart <= this.currentCaretPosition) {
this.currentCaretPosition += editDelta;
if (offsetEnd <= this.currentCaretPosition) {
// The entirety of the edit span falls before the caret position, shift the caret accordingly
this.currentCaretPosition += editDelta;
}
else {
// The span being replaced includes the caret position, place the caret at the beginning of the span
this.currentCaretPosition = offsetStart;
}
}
runningOffset += editDelta;
// TODO: Consider doing this at least some of the time for higher fidelity. Currently causes a failure (bug 707150)
// this.languageService.getScriptLexicalStructure(fileName);
}
if (this.currentCaretPosition < 0) {
this.currentCaretPosition = 0;
}
if (isFormattingEdit) {
const newContent = this.getFileContent(fileName);

View file

@ -6,4 +6,8 @@
goTo.marker();
edit.insertLine("");
verify.currentLineContentIs('class bar {');
verify.currentFileContentIs(
`class foo { }
class bar {
}
// new line here`);