Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,30 @@ && isFollowedBy(doc, command.offset, charPair.close))) {

final var newIndent = registry.getGoodIndentForLine(doc, lineIndex, contentType, IIndentConverter.of(cursorCfg));
if (newIndent != null) {
final var normalizedIndent = cursorCfg.normalizeIndentation(newIndent);
final var lineStartOffset = doc.getLineOffset(lineIndex);

// check if the content was pasted into a line while the cursor was not at the beginning of the line
// but inside or at the end of an existing line indentation
final var offsetInLine = command.offset - lineStartOffset;
if (offsetInLine > 0 && doc.get(lineStartOffset, offsetInLine).isBlank()) {
command.offset = lineStartOffset;
command.length += offsetInLine;
final int firstNewline = command.text.indexOf('\n');

if (firstNewline >= 0) {
final var firstLine = command.text.substring(0, firstNewline + 1);
final var reindentedRest = TextUtils.replaceIndent(
command.text.substring(firstNewline + 1), cursorCfg.indentSize, normalizedIndent, false);

if (offsetInLine > 0 && !doc.get(lineStartOffset, offsetInLine).isBlank()) {
command.text = firstLine + reindentedRest;
} else {
if (offsetInLine > 0) {
command.offset = lineStartOffset;
command.length += offsetInLine;
}
command.text = normalizedIndent + firstLine.stripLeading() + reindentedRest;
}
} else {
command.text = TextUtils
.replaceIndent(command.text, cursorCfg.indentSize, normalizedIndent, false)
.toString();
}
command.text = TextUtils.replaceIndent(command.text, cursorCfg.indentSize,
cursorCfg.normalizeIndentation(newIndent), false).toString();
command.shiftsCaret = true;
}
}
Expand Down
Loading