Improve handling of snippet indentations containing no tabs

This commit is contained in:
nsingh
2017-10-04 15:59:05 -07:00
parent cff34afdd5
commit 4eddb50e63
2 changed files with 11 additions and 3 deletions

View File

@@ -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;
}

View File

@@ -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", " ");
}
}