use of com.intellij.codeStyle.CodeStyleFacade in project intellij-community by JetBrains.
the class FileDocumentManagerImpl method getLineSeparator.
@Override
@NotNull
public String getLineSeparator(@Nullable VirtualFile file, @Nullable Project project) {
String lineSeparator = file == null ? null : LoadTextUtil.getDetectedLineSeparator(file);
if (lineSeparator == null) {
CodeStyleFacade settingsManager = project == null ? CodeStyleFacade.getInstance() : CodeStyleFacade.getInstance(project);
lineSeparator = settingsManager.getLineSeparator();
}
return lineSeparator;
}
use of com.intellij.codeStyle.CodeStyleFacade in project intellij-community by JetBrains.
the class SmartIndentingBackspaceHandler method doBeforeCharDeleted.
@Override
protected void doBeforeCharDeleted(char c, PsiFile file, Editor editor) {
Project project = file.getProject();
Document document = editor.getDocument();
CharSequence charSequence = document.getImmutableCharSequence();
CaretModel caretModel = editor.getCaretModel();
int caretOffset = caretModel.getOffset();
LogicalPosition pos = caretModel.getLogicalPosition();
int lineStartOffset = document.getLineStartOffset(pos.line);
int beforeWhitespaceOffset = CharArrayUtil.shiftBackward(charSequence, caretOffset - 1, " \t") + 1;
if (beforeWhitespaceOffset != lineStartOffset) {
myReplacement = null;
return;
}
PsiDocumentManager.getInstance(project).commitDocument(document);
CodeStyleFacade codeStyleFacade = CodeStyleFacade.getInstance(project);
myReplacement = codeStyleFacade.getLineIndent(document, lineStartOffset);
if (myReplacement == null) {
return;
}
int tabSize = codeStyleFacade.getTabSize(file.getFileType());
int targetColumn = getWidth(myReplacement, tabSize);
int endOffset = CharArrayUtil.shiftForward(charSequence, caretOffset, " \t");
LogicalPosition logicalPosition = caretOffset < endOffset ? editor.offsetToLogicalPosition(endOffset) : pos;
int currentColumn = logicalPosition.column;
if (currentColumn > targetColumn) {
myStartOffset = lineStartOffset;
} else if (logicalPosition.line == 0) {
myStartOffset = 0;
myReplacement = "";
} else {
int prevLineEndOffset = document.getLineEndOffset(logicalPosition.line - 1);
myStartOffset = CharArrayUtil.shiftBackward(charSequence, prevLineEndOffset - 1, " \t") + 1;
if (myStartOffset != document.getLineStartOffset(logicalPosition.line - 1)) {
int spacing = CodeStyleManager.getInstance(project).getSpacing(file, endOffset);
myReplacement = StringUtil.repeatSymbol(' ', Math.max(0, spacing));
}
}
}
use of com.intellij.codeStyle.CodeStyleFacade in project intellij-community by JetBrains.
the class DiffUtil method setEditorCodeStyle.
public static void setEditorCodeStyle(@Nullable Project project, @NotNull EditorEx editor, @Nullable FileType fileType) {
if (project != null && fileType != null) {
CodeStyleFacade codeStyleFacade = CodeStyleFacade.getInstance(project);
editor.getSettings().setTabSize(codeStyleFacade.getTabSize(fileType));
editor.getSettings().setUseTabCharacter(codeStyleFacade.useTabCharacter(fileType));
}
editor.getSettings().setCaretRowShown(false);
editor.reinitSettings();
}
use of com.intellij.codeStyle.CodeStyleFacade in project intellij-community by JetBrains.
the class DiffUtil method createEditor.
public static EditorEx createEditor(Document document, Project project, boolean isViewer, @Nullable FileType fileType) {
EditorFactory factory = EditorFactory.getInstance();
EditorEx editor = (EditorEx) (isViewer ? factory.createViewer(document, project) : factory.createEditor(document, project));
editor.putUserData(DiffManagerImpl.EDITOR_IS_DIFF_KEY, Boolean.TRUE);
editor.getGutterComponentEx().revalidateMarkup();
if (fileType != null && project != null && !project.isDisposed()) {
CodeStyleFacade codeStyleFacade = CodeStyleFacade.getInstance(project);
editor.getSettings().setTabSize(codeStyleFacade.getTabSize(fileType));
editor.getSettings().setUseTabCharacter(codeStyleFacade.useTabCharacter(fileType));
}
return editor;
}
Aggregations