@@ -74,8 +74,8 @@ Your search/replace content here
7474 const lineEnding = originalContent . includes ( '\r\n' ) ? '\r\n' : '\n' ;
7575
7676 // Split content into lines, handling both \n and \r\n
77- const searchLines = searchContent . trim ( ) . split ( / \r ? \n / ) ;
78- const replaceLines = replaceContent . trim ( ) . split ( / \r ? \n / ) ;
77+ const searchLines = searchContent . split ( / \r ? \n / ) ;
78+ const replaceLines = replaceContent . split ( / \r ? \n / ) ;
7979 const originalLines = originalContent . split ( / \r ? \n / ) ;
8080
8181 // Find the search content in the original
@@ -130,39 +130,32 @@ Your search/replace content here
130130 const currentIndentMatch = line . match ( / ^ [ \t ] * / ) ;
131131 const currentIndent = currentIndentMatch ? currentIndentMatch [ 0 ] : '' ;
132132
133- // If this line has the same indentation level as the search block,
134- // use the original indentation. Otherwise, calculate the difference
135- // and preserve the exact type of whitespace characters
136- if ( currentIndent . length === searchIndent . length ) {
137- return originalIndent + line . trim ( ) ;
138- } else {
139- // Get the corresponding search line's indentation
140- const searchLineIndex = Math . min ( i , searchLines . length - 1 ) ;
141- const searchLineIndent = searchIndents [ searchLineIndex ] ;
133+ // Get the corresponding search line's indentation
134+ const searchLineIndex = Math . min ( i , searchLines . length - 1 ) ;
135+ const searchLineIndent = searchIndents [ searchLineIndex ] ;
142136
143- // Get the corresponding original line's indentation
144- const originalLineIndex = Math . min ( i , originalIndents . length - 1 ) ;
145- const originalLineIndent = originalIndents [ originalLineIndex ] ;
137+ // Get the corresponding original line's indentation
138+ const originalLineIndex = Math . min ( i , originalIndents . length - 1 ) ;
139+ const originalLineIndent = originalIndents [ originalLineIndex ] ;
146140
147- // If this line has the same indentation as its corresponding search line,
148- // use the original indentation
149- if ( currentIndent === searchLineIndent ) {
150- return originalLineIndent + line . trim ( ) ;
151- }
141+ // If this line has the same indentation as its corresponding search line,
142+ // use the original indentation
143+ if ( currentIndent === searchLineIndent ) {
144+ return originalLineIndent + line . trim ( ) ;
145+ }
152146
153- // Otherwise, preserve the original indentation structure
154- const indentChar = originalLineIndent . charAt ( 0 ) || '\t' ;
155- const indentLevel = Math . floor ( originalLineIndent . length / indentChar . length ) ;
147+ // Otherwise, preserve the original indentation structure
148+ const indentChar = originalLineIndent . charAt ( 0 ) || '\t' ;
149+ const indentLevel = Math . floor ( originalLineIndent . length / indentChar . length ) ;
156150
157- // Calculate the relative indentation from the search line
158- const searchLevel = Math . floor ( searchLineIndent . length / indentChar . length ) ;
159- const currentLevel = Math . floor ( currentIndent . length / indentChar . length ) ;
160- const relativeLevel = currentLevel - searchLevel ;
151+ // Calculate the relative indentation from the search line
152+ const searchLevel = Math . floor ( searchLineIndent . length / indentChar . length ) ;
153+ const currentLevel = Math . floor ( currentIndent . length / indentChar . length ) ;
154+ const relativeLevel = currentLevel - searchLevel ;
161155
162- // Apply the relative indentation to the original level
163- const targetLevel = Math . max ( 0 , indentLevel + relativeLevel ) ;
164- return indentChar . repeat ( targetLevel ) + line . trim ( ) ;
165- }
156+ // Apply the relative indentation to the original level
157+ const targetLevel = Math . max ( 0 , indentLevel + relativeLevel ) ;
158+ return indentChar . repeat ( targetLevel ) + line . trim ( ) ;
166159 } ) ;
167160
168161 // Construct the final content
0 commit comments