diff --git a/src/services/smartSelection.ts b/src/services/smartSelection.ts index d0423ce031e57..3765c39ed7aa5 100644 --- a/src/services/smartSelection.ts +++ b/src/services/smartSelection.ts @@ -64,6 +64,13 @@ namespace ts.SmartSelectionRange { parentNode = node; break; } + + // If we made it to the end of the for loop, we’re done. + // In practice, I’ve only seen this happen at the very end + // of a SourceFile. + if (i === children.length - 1) { + break outer; + } } } diff --git a/tests/baselines/reference/smartSelection_lastBlankLine.baseline b/tests/baselines/reference/smartSelection_lastBlankLine.baseline new file mode 100644 index 0000000000000..3cbad44aac47e --- /dev/null +++ b/tests/baselines/reference/smartSelection_lastBlankLine.baseline @@ -0,0 +1,5 @@ +class C {} +/**/ + + +class C {}↲ diff --git a/tests/cases/fourslash/smartSelection_lastBlankLine.ts b/tests/cases/fourslash/smartSelection_lastBlankLine.ts new file mode 100644 index 0000000000000..2f5cc3f07fc0e --- /dev/null +++ b/tests/cases/fourslash/smartSelection_lastBlankLine.ts @@ -0,0 +1,5 @@ +/// +////class C {} +/////**/ + +verify.baselineSmartSelection();