IDEA-23075 - do not substitute slash-r on value edit

This commit is contained in:
Egor.Ushakov
2016-04-26 18:59:18 +03:00
parent 50719b8448
commit 8e37cda74c
2 changed files with 21 additions and 8 deletions
@@ -574,6 +574,10 @@ public class EditorTextField extends NonOpaquePanel implements DocumentListener,
myIsViewer = !enabled;
}
public boolean isViewer() {
return myIsViewer;
}
@Override
public Color getBackground() {
Color color = getBackgroundColor(isEnabled(), EditorColorsUtil.getGlobalOrDefaultColorScheme());
@@ -18,6 +18,7 @@ package com.intellij.xdebugger.impl.ui;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.EditorFactory;
import com.intellij.openapi.editor.ex.EditorEx;
import com.intellij.openapi.editor.impl.EditorFactoryImpl;
import com.intellij.openapi.fileTypes.FileTypes;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
@@ -31,7 +32,7 @@ public final class TextViewer extends EditorTextField {
private final boolean myEmbeddedIntoDialogWrapper;
public TextViewer(@NotNull String initialText, @NotNull Project project, boolean viewer) {
this(createDocument(initialText), project, true, viewer);
this(createDocument(initialText, viewer), project, true, viewer);
}
public TextViewer(@NotNull String initialText, @NotNull Project project) {
@@ -45,17 +46,25 @@ public final class TextViewer extends EditorTextField {
setFontInheritedFromLAF(false);
}
private static Document createDocument(@NotNull String initialText) {
final Document document = EditorFactory.getInstance().createDocument(StringUtil.convertLineSeparators(initialText));
//if (document instanceof DocumentImpl) {
// ((DocumentImpl)document).setAcceptSlashR(true);
//}
return document;
private static Document createDocument(@NotNull String initialText, boolean viewer) {
if (needSlashRSupport(initialText, viewer)){
return ((EditorFactoryImpl)EditorFactory.getInstance()).createDocument(initialText, true, false);
}
else {
return EditorFactory.getInstance().createDocument(StringUtil.convertLineSeparators(initialText));
}
}
@Override
public void setText(@Nullable String text) {
super.setText(text != null ? StringUtil.convertLineSeparators(text) : null);
if (text != null && !needSlashRSupport(text, isViewer())) {
text = StringUtil.convertLineSeparators(text);
}
super.setText(text);
}
private static boolean needSlashRSupport(String text, boolean viewer) {
return !viewer && text.contains("\r");
}
@Override