File tree Expand file tree Collapse file tree 1 file changed +18
-25
lines changed Expand file tree Collapse file tree 1 file changed +18
-25
lines changed Original file line number Diff line number Diff line change @@ -1771,33 +1771,26 @@ exports.copyAText = (atext1, atext2) => {
17711771exports . appendATextToAssembler = ( atext , assem ) => {
17721772 // intentionally skips last newline char of atext
17731773 const iter = exports . opIterator ( atext . attribs ) ;
1774+ let lastOp = null ;
17741775 while ( iter . hasNext ( ) ) {
1775- const op = iter . next ( ) ;
1776- if ( ! iter . hasNext ( ) ) {
1777- // last op, exclude final newline
1778- if ( op . lines <= 1 ) {
1779- op . lines = 0 ;
1780- op . chars -- ;
1781- if ( op . chars ) {
1782- assem . append ( op ) ;
1783- }
1784- } else {
1785- const nextToLastNewlineEnd =
1786- atext . text . lastIndexOf ( '\n' , atext . text . length - 2 ) + 1 ;
1787- const lastLineLength = atext . text . length - nextToLastNewlineEnd - 1 ;
1788- op . lines -- ;
1789- op . chars -= ( lastLineLength + 1 ) ;
1790- assem . append ( op ) ;
1791- op . lines = 0 ;
1792- op . chars = lastLineLength ;
1793- if ( op . chars ) {
1794- assem . append ( op ) ;
1795- }
1796- }
1797- } else {
1798- assem . append ( op ) ;
1799- }
1776+ if ( lastOp != null ) assem . append ( lastOp ) ;
1777+ lastOp = iter . next ( ) ;
1778+ }
1779+ if ( lastOp == null ) return ;
1780+ // exclude final newline
1781+ if ( lastOp . lines <= 1 ) {
1782+ lastOp . lines = 0 ;
1783+ lastOp . chars -- ;
1784+ } else {
1785+ const nextToLastNewlineEnd = atext . text . lastIndexOf ( '\n' , atext . text . length - 2 ) + 1 ;
1786+ const lastLineLength = atext . text . length - nextToLastNewlineEnd - 1 ;
1787+ lastOp . lines -- ;
1788+ lastOp . chars -= ( lastLineLength + 1 ) ;
1789+ assem . append ( lastOp ) ;
1790+ lastOp . lines = 0 ;
1791+ lastOp . chars = lastLineLength ;
18001792 }
1793+ if ( lastOp . chars ) assem . append ( lastOp ) ;
18011794} ;
18021795
18031796/**
You can’t perform that action at this time.
0 commit comments