@@ -163,17 +163,30 @@ && isFollowedBy(doc, command.offset, charPair.close))) {
163163
164164 final var newIndent = registry .getGoodIndentForLine (doc , lineIndex , contentType , IIndentConverter .of (cursorCfg ));
165165 if (newIndent != null ) {
166+ final var normalizedIndent = cursorCfg .normalizeIndentation (newIndent );
166167 final var lineStartOffset = doc .getLineOffset (lineIndex );
167-
168- // check if the content was pasted into a line while the cursor was not at the beginning of the line
169- // but inside or at the end of an existing line indentation
170168 final var offsetInLine = command .offset - lineStartOffset ;
171- if (offsetInLine > 0 && doc .get (lineStartOffset , offsetInLine ).isBlank ()) {
172- command .offset = lineStartOffset ;
173- command .length += offsetInLine ;
169+ final int firstNewline = command .text .indexOf ('\n' );
170+
171+ if (firstNewline >= 0 ) {
172+ final var firstLine = command .text .substring (0 , firstNewline + 1 );
173+ final var reindentedRest = TextUtils .replaceIndent (
174+ command .text .substring (firstNewline + 1 ), cursorCfg .indentSize , normalizedIndent , false );
175+
176+ if (offsetInLine > 0 && !doc .get (lineStartOffset , offsetInLine ).isBlank ()) {
177+ command .text = firstLine + reindentedRest ;
178+ } else {
179+ if (offsetInLine > 0 ) {
180+ command .offset = lineStartOffset ;
181+ command .length += offsetInLine ;
182+ }
183+ command .text = normalizedIndent + firstLine .stripLeading () + reindentedRest ;
184+ }
185+ } else {
186+ command .text = TextUtils
187+ .replaceIndent (command .text , cursorCfg .indentSize , normalizedIndent , false )
188+ .toString ();
174189 }
175- command .text = TextUtils .replaceIndent (command .text , cursorCfg .indentSize ,
176- cursorCfg .normalizeIndentation (newIndent ), false ).toString ();
177190 command .shiftsCaret = true ;
178191 }
179192 }
0 commit comments