Skip to content

Commit

Permalink
Fixed #146 Keep empty lines when pasting multi line.
Browse files Browse the repository at this point in the history
  • Loading branch information
ylussaud committed Mar 14, 2024
1 parent 6f129b2 commit d7d7c92
Showing 1 changed file with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023 Obeo.
* Copyright (c) 2023, 2024 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand All @@ -12,6 +12,7 @@

import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

import org.eclipse.acceleo.aql.parser.AcceleoParser;
import org.eclipse.jface.text.BadLocationException;
Expand All @@ -24,8 +25,21 @@

public class AcceleoAutoEditStrategy implements IAutoEditStrategy {

/**
* The {@link Set} of all possible block starts.
*/
private static final Set<String> BLOCK_STARTS = initBlockStarts();

/**
* The new line {@link String}.
*/
private static final String NEW_LINE = System.lineSeparator();

/**
* Initializes the block starts.
*
* @return the {@link Set} of all possible block starts.
*/
private static Set<String> initBlockStarts() {
final Set<String> res = new HashSet<>();

Expand Down Expand Up @@ -174,10 +188,21 @@ private void shiftBlock(IDocument document, DocumentCommand command) {
final IRegion lineInfo = document.getLineInformationOfOffset(command.offset);
final String indentation = document.get(lineInfo.getOffset(), lineInfo.getLength());
command.text = command.text.substring(blockIndentation.length());
final String emptyLineReplacement;
if (blockIndentation.isEmpty()) {
emptyLineReplacement = UUID.randomUUID().toString() + UUID.randomUUID().toString() + UUID
.randomUUID().toString();
command.text = command.text.replaceAll("(\\r\\n|\\n)(\\r\\n|\\n)", emptyLineReplacement);
} else {
emptyLineReplacement = null;
}
for (String lineDelimiter : document.getLegalLineDelimiters()) {
command.text = command.text.replace(lineDelimiter + blockIndentation, lineDelimiter
+ indentation);
}
if (emptyLineReplacement != null) {
command.text = command.text.replace(emptyLineReplacement, NEW_LINE + NEW_LINE + indentation);
}
if (TextUtilities.endsWith(document.getLegalLineDelimiters(), command.text) != -1) {
command.text = command.text + indentation;
}
Expand Down

0 comments on commit d7d7c92

Please sign in to comment.