enable line numbers in editor by default (IDEA-153505)

This commit is contained in:
Dmitry Batrak
2016-03-28 10:52:26 +03:00
parent 3350902f29
commit 26b72fd7e8
3 changed files with 18 additions and 22 deletions
@@ -140,7 +140,6 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse
private String myLastGutterToolTip = null;
@NotNull private TIntFunction myLineNumberConvertor;
@Nullable private TIntFunction myAdditionalLineNumberConvertor;
private TIntFunction myLineNumberAreaWidthFunction;
private boolean myShowDefaultGutterPopup = true;
@Nullable private ActionGroup myCustomGutterPopupGroup;
private TIntObjectHashMap<Color> myTextFgColors = new TIntObjectHashMap<>();
@@ -509,10 +508,17 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse
return color != null ? color : EditorColors.GUTTER_BACKGROUND.getDefaultColor();
}
private Font getFontForLineNumbers() {
Font editorFont = myEditor.getColorsScheme().getFont(EditorFontType.PLAIN);
float editorFontSize = editorFont.getSize2D();
return editorFont.deriveFont(Math.max(1f, editorFontSize - 1f));
}
private int calcLineNumbersAreaWidth(int maxLineNumber) {
return getFontMetrics(getFontForLineNumbers()).stringWidth(Integer.toString(maxLineNumber + 1));
}
private void doPaintLineNumbers(Graphics2D g, Rectangle clip, int offset, @NotNull TIntFunction convertor) {
if (!isLineNumbersShown()) {
return;
}
int startLineNumber = myEditor.yToVisibleLine(clip.y);
int endLineNumber = myEditor.yToVisibleLine(clip.y + clip.height) + 1;
int lastLine = myEditor.logicalToVisualPosition(
@@ -525,7 +531,8 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse
Color color = myEditor.getColorsScheme().getColor(EditorColors.LINE_NUMBERS_COLOR);
g.setColor(color != null ? color : JBColor.blue);
g.setFont(myEditor.getColorsScheme().getFont(EditorFontType.PLAIN));
Font font = getFontForLineNumbers();
g.setFont(font);
AffineTransform old = setMirrorTransformIfNeeded(g, getLineNumberAreaOffset(), getLineNumberAreaWidth());
try {
@@ -545,7 +552,7 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse
int textOffset = isMirrored() ?
offset - getLineNumberAreaWidth() - 1:
offset - myEditor.getFontMetrics(Font.PLAIN).stringWidth(s);
offset - g.getFontMetrics().stringWidth(s);
g.drawString(s,
textOffset,
@@ -1244,20 +1251,16 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse
getGapAfterIconsArea() + getRightFreePaintersAreaWidth() : 0;
}
public void setLineNumberAreaWidthFunction(@NotNull TIntFunction calculator) {
myLineNumberAreaWidthFunction = calculator;
}
private void calcLineNumberAreaWidth() {
if (myLineNumberAreaWidthFunction == null || !isLineNumbersShown()) return;
if (!isLineNumbersShown()) return;
int maxLineNumber = getMaxLineNumber(myLineNumberConvertor);
myLineNumberAreaWidth = myLineNumberAreaWidthFunction.execute(maxLineNumber);
myLineNumberAreaWidth = calcLineNumbersAreaWidth(maxLineNumber);
myAdditionalLineNumberAreaWidth = 0;
if (myAdditionalLineNumberConvertor != null) {
int maxAdditionalLineNumber = getMaxLineNumber(myAdditionalLineNumberConvertor);
myAdditionalLineNumberAreaWidth = myLineNumberAreaWidthFunction.execute(maxAdditionalLineNumber);
myAdditionalLineNumberAreaWidth = calcLineNumbersAreaWidth(maxAdditionalLineNumber);
}
}
@@ -84,7 +84,6 @@ import com.intellij.util.ui.*;
import com.intellij.util.ui.update.Activatable;
import com.intellij.util.ui.update.UiNotifyConnector;
import gnu.trove.TIntArrayList;
import gnu.trove.TIntFunction;
import gnu.trove.TIntHashSet;
import gnu.trove.TIntIntHashMap;
import org.intellij.lang.annotations.JdkConstants;
@@ -570,12 +569,6 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
setFontSize(UISettings.getInstance().PRESENTATION_MODE_FONT_SIZE);
}
myGutterComponent.setLineNumberAreaWidthFunction(new TIntFunction() {
@Override
public int execute(int lineNumber) {
return getFontMetrics(Font.PLAIN).stringWidth(Integer.toString(lineNumber + 1));
}
});
myGutterComponent.updateSize();
Dimension preferredSize = getPreferredSize();
myEditorComponent.setSize(preferredSize);
@@ -14,7 +14,7 @@
<option name="NOTIFICATION_BACKGROUND" value="ffffcc" />
<option name="SELECTED_INDENT_GUIDE" value="c8c8c8"/>
<option name="SELECTION_FOREGROUND" value="ffffff"/>
<option name="LINE_NUMBERS_COLOR" value="800000"/>
<option name="LINE_NUMBERS_COLOR" value="b2b2b2"/>
<option name="ANNOTATIONS_COLOR" value="000080" />
<option name="ANNOTATIONS_MERGED_COLOR" value="008080" />
<option name="CARET_COLOR" value="0"/>
@@ -1032,7 +1032,7 @@
<option name="FILESTATUS_modifiedOutside" value="6897bb" />
<option name="GUTTER_BACKGROUND" value="313335" />
<option name="INDENT_GUIDE" value="373737" />
<option name="LINE_NUMBERS_COLOR" value="888888" />
<option name="LINE_NUMBERS_COLOR" value="515457" />
<option name="METHOD_SEPARATORS_COLOR" value="4d4d4d" />
<option name="MODIFIED_LINES_COLOR" value="374752" deuteranopia="333a4c" protanopia="333a4c"/>
<option name="NOTIFICATION_BACKGROUND" value="5c5c42" />