Improve handling of snippet indentations containing no tabs
This commit is contained in:
@@ -42,7 +42,13 @@ public class JavaSnippetBuilder{
|
||||
DocumentEdits edit = new DocumentEdits(doc);
|
||||
String snippet = createSnippet(template);
|
||||
|
||||
String indentedSnippet = indentUtil.applyIndentation(snippet, indentUtil.getReferenceIndent(query.getStart(), doc)) ;
|
||||
String referenceIndent = indentUtil.getReferenceIndent(query.getStart(), doc);
|
||||
|
||||
if (!referenceIndent.contains("\t")) {
|
||||
snippet = indentUtil.covertTabsToSpace(snippet);
|
||||
}
|
||||
String indentedSnippet = indentUtil.applyIndentation(snippet, referenceIndent);
|
||||
|
||||
edit.replace(query.getStart(), query.getEnd(), indentedSnippet);
|
||||
return edit;
|
||||
}
|
||||
|
||||
@@ -15,8 +15,6 @@ import org.springframework.ide.vscode.commons.util.Assert;
|
||||
import org.springframework.ide.vscode.commons.util.text.IDocument;
|
||||
import org.springframework.ide.vscode.commons.util.text.IRegion;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
/**
|
||||
* Helper methods to manipulate indentation levels in yaml content.
|
||||
*
|
||||
@@ -53,4 +51,8 @@ public class IndentUtil {
|
||||
return queryPrefix.leadingWhitespace().toString();
|
||||
}
|
||||
|
||||
|
||||
public String covertTabsToSpace(String snippet) {
|
||||
return snippet.replaceAll("\\t", " ");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user