@@ -1829,7 +1829,34 @@ module ts {
1829
1829
if ( version !== sourceFile . version ) {
1830
1830
// Once incremental parsing is ready, then just call into this function.
1831
1831
if ( ! disableIncrementalParsing ) {
1832
- let newSourceFile = updateSourceFile ( sourceFile , scriptSnapshot . getText ( 0 , scriptSnapshot . getLength ( ) ) , textChangeRange , aggressiveChecks ) ;
1832
+ let newText : string ;
1833
+
1834
+ // grab the fragment from the beginning of the original text to the beginning of the span
1835
+ let prefix = textChangeRange . span . start !== 0
1836
+ ? sourceFile . text . substr ( 0 , textChangeRange . span . start )
1837
+ : "" ;
1838
+
1839
+ // grab the fragment from the end of the span till the end of the original text
1840
+ let suffix = textSpanEnd ( textChangeRange . span ) !== sourceFile . text . length
1841
+ ? sourceFile . text . substr ( textSpanEnd ( textChangeRange . span ) )
1842
+ : "" ;
1843
+
1844
+ if ( textChangeRange . newLength === 0 ) {
1845
+ // edit was a deletion - just combine prefix and suffix
1846
+ newText = prefix && suffix ? prefix + suffix : prefix || suffix ;
1847
+ }
1848
+ else {
1849
+ // it was actual edit, fetch the fragment of new text that correspond to new span
1850
+ let changedText = scriptSnapshot . getText ( textChangeRange . span . start , textChangeRange . span . start + textChangeRange . newLength ) ;
1851
+ // combine prefix, changed text and suffix
1852
+ newText = prefix && suffix
1853
+ ? prefix + changedText + suffix
1854
+ : prefix
1855
+ ? ( prefix + changedText )
1856
+ : ( changedText + suffix ) ;
1857
+ }
1858
+
1859
+ let newSourceFile = updateSourceFile ( sourceFile , newText , textChangeRange , aggressiveChecks ) ;
1833
1860
setSourceFileFields ( newSourceFile , scriptSnapshot , version ) ;
1834
1861
// after incremental parsing nameTable might not be up-to-date
1835
1862
// drop it so it can be lazily recreated later
0 commit comments