mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
remove unused code
This commit is contained in:
@@ -35,7 +35,6 @@ import com.intellij.openapi.editor.ex.EditorEx;
|
||||
import com.intellij.openapi.editor.impl.ComplementaryFontsRegistry;
|
||||
import com.intellij.openapi.editor.impl.EditorImpl;
|
||||
import com.intellij.openapi.editor.impl.FontInfo;
|
||||
import com.intellij.openapi.editor.impl.view.IterationState;
|
||||
import com.intellij.openapi.editor.markup.TextAttributes;
|
||||
import com.intellij.openapi.editor.textarea.TextComponentEditor;
|
||||
import com.intellij.openapi.fileEditor.FileEditor;
|
||||
@@ -246,172 +245,6 @@ public final class EditorUtil {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to match given logical column to the document offset assuming that it's located at <code>[start; end)</code> region.
|
||||
*
|
||||
* @param editor editor that is used to represent target document
|
||||
* @param text target document text
|
||||
* @param start start offset to check (inclusive)
|
||||
* @param end end offset to check (exclusive)
|
||||
* @param columnNumber target logical column number
|
||||
* @param tabSize user-defined desired number of columns to use for tabulation symbol representation
|
||||
* @param x <code>'x'</code> coordinate that corresponds to the given <code>'start'</code> offset
|
||||
* @param currentColumn logical column that corresponds to the given <code>'start'</code> offset
|
||||
* @param debugBuffer buffer to hold debug info during the processing (if any)
|
||||
* @return target offset that belongs to the <code>[start; end)</code> range and points to the target logical
|
||||
* column if any; <code>-1</code> otherwise
|
||||
*/
|
||||
public static int calcSoftWrapUnawareOffset(@NotNull Editor editor,
|
||||
@NotNull CharSequence text,
|
||||
int start,
|
||||
int end,
|
||||
int columnNumber,
|
||||
int tabSize,
|
||||
int x,
|
||||
@NotNull int[] currentColumn,
|
||||
@Nullable StringBuilder debugBuffer) {
|
||||
if (debugBuffer != null) {
|
||||
debugBuffer.append(String.format(
|
||||
"Starting calcSoftWrapUnawareOffset(). Target range: [%d; %d), target column number to map: %d, tab size: %d, "
|
||||
+ "x: %d, current column: %d%n", start, end, columnNumber, tabSize, x, currentColumn[0]));
|
||||
}
|
||||
|
||||
// The main problem in a calculation is that target text may contain tabulation symbols and every such symbol may take different
|
||||
// number of logical columns to represent. E.g. it takes two columns if tab size is four and current column is two; three columns
|
||||
// if tab size is four and current column is one etc. So, first of all we check if there are tabulation symbols at the target
|
||||
// text fragment.
|
||||
boolean useOptimization = true;
|
||||
boolean hasTabs = false;
|
||||
int scanEndOffset = Math.min(end, start + columnNumber - currentColumn[0] + 1);
|
||||
boolean hasNonTabs = false;
|
||||
for (int i = start; i < scanEndOffset; i++) {
|
||||
char c = text.charAt(i);
|
||||
if (debugBuffer != null) {
|
||||
debugBuffer.append(String.format("Found symbol '%c' at the offset %d%n", c, i));
|
||||
}
|
||||
if (c == '\t') {
|
||||
hasTabs = true;
|
||||
if (hasNonTabs) {
|
||||
useOptimization = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
hasNonTabs = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (debugBuffer != null) {
|
||||
debugBuffer.append(String.format("Has tabs: %b, use optimisation: %b%n", hasTabs, useOptimization));
|
||||
}
|
||||
|
||||
// Perform optimized processing if possible. 'Optimized' here means the processing when we exactly know how many logical
|
||||
// columns are occupied by tabulation symbols.
|
||||
if (useOptimization) {
|
||||
if (!hasTabs) {
|
||||
int result = start + columnNumber - currentColumn[0];
|
||||
if (result < end) {
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
currentColumn[0] += end - start;
|
||||
if (debugBuffer != null) {
|
||||
debugBuffer.append(String.format("Incrementing 'current column' by %d (new value is %d)%n", end - start, currentColumn[0]));
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// This variable holds number of 'virtual' tab-introduced columns, e.g. there is a possible case that particular tab owns
|
||||
// three columns, hence, it increases 'shift' by two (3 - 1).
|
||||
int shift = 0;
|
||||
int offset = start;
|
||||
int prevX = x;
|
||||
if (debugBuffer != null) {
|
||||
debugBuffer.append("Processing a string that contains only tabs\n");
|
||||
}
|
||||
for (; offset < end && offset + shift + currentColumn[0] < start + columnNumber; offset++) {
|
||||
final char c = text.charAt(offset);
|
||||
if (c == '\t') {
|
||||
int nextX = nextTabStop(prevX, editor, tabSize);
|
||||
final int columnsShift = columnsNumber(nextX - prevX, getSpaceWidth(Font.PLAIN, editor)) - 1;
|
||||
if (debugBuffer != null) {
|
||||
debugBuffer.append(String.format(
|
||||
"Processing tabulation symbol at the offset %d. Current X: %d, new X: %d, current columns shift: %d, new column shift: %d%n",
|
||||
offset, prevX, nextX, shift, shift + columnsShift
|
||||
));
|
||||
}
|
||||
shift += columnsShift;
|
||||
prevX = nextX;
|
||||
}
|
||||
}
|
||||
int diff = start + columnNumber - offset - shift - currentColumn[0];
|
||||
if (debugBuffer != null) debugBuffer.append(String.format("Resulting diff: %d%n", diff));
|
||||
if (diff < 0) {
|
||||
return offset - 1;
|
||||
}
|
||||
else if (diff == 0) {
|
||||
return offset;
|
||||
}
|
||||
else {
|
||||
final int inc = offset - start + shift;
|
||||
if (debugBuffer != null) {
|
||||
debugBuffer.append(String.format("Incrementing 'current column' by %d (new value is %d)%n", inc, currentColumn[0] + inc));
|
||||
}
|
||||
currentColumn[0] += inc;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// It means that there are tabulation symbols that can't be explicitly mapped to the occupied logical columns number,
|
||||
// hence, we need to perform special calculations to get know that.
|
||||
EditorEx editorImpl = (EditorEx)editor;
|
||||
int offset = start;
|
||||
IterationState state = new IterationState(editorImpl, start, end, null, false, false, true, false);
|
||||
int fontType = state.getMergedAttributes().getFontType();
|
||||
int column = currentColumn[0];
|
||||
int plainSpaceSize = getSpaceWidth(Font.PLAIN, editorImpl);
|
||||
for (; column < columnNumber && offset < end; offset++) {
|
||||
if (offset >= state.getEndOffset()) {
|
||||
state.advance();
|
||||
fontType = state.getMergedAttributes().getFontType();
|
||||
}
|
||||
|
||||
char c = text.charAt(offset);
|
||||
if (c == '\t') {
|
||||
final int newX = nextTabStop(x, editorImpl);
|
||||
final int columns = columnsNumber(newX - x, plainSpaceSize);
|
||||
if (debugBuffer != null) {
|
||||
debugBuffer.append(String.format(
|
||||
"Processing tabulation at the offset %d. Current X: %d, new X: %d, current column: %d, new column: %d%n",
|
||||
offset, x, newX, column, column + columns
|
||||
));
|
||||
}
|
||||
x = newX;
|
||||
column += columns;
|
||||
}
|
||||
else {
|
||||
final int width = charWidth(c, fontType, editorImpl);
|
||||
if (debugBuffer != null) {
|
||||
debugBuffer.append(String.format(
|
||||
"Processing symbol '%c' at the offset %d. Current X: %d, new X: %d%n", c, offset, x, x + width
|
||||
));
|
||||
}
|
||||
x += width;
|
||||
column++;
|
||||
}
|
||||
}
|
||||
|
||||
if (column == columnNumber) {
|
||||
return offset;
|
||||
}
|
||||
if (column > columnNumber && offset > 0 && text.charAt(offset - 1) == '\t') {
|
||||
return offset - 1;
|
||||
}
|
||||
currentColumn[0] = column;
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static int getTabLength(int colNumber, int tabSize) {
|
||||
if (tabSize <= 0) {
|
||||
tabSize = 1;
|
||||
@@ -583,26 +416,6 @@ public final class EditorUtil {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to answer how many columns are necessary for representation of the given char on a screen.
|
||||
*
|
||||
* @param c target char
|
||||
* @param x <code>'x'</code> coordinate of the line where given char is represented that indicates char end location
|
||||
* @param prevX <code>'x'</code> coordinate of the line where given char is represented that indicates char start location
|
||||
* @param plainSpaceSize <code>'space'</code> symbol width (in plain font style)
|
||||
* @return number of columns necessary for representation of the given char on a screen.
|
||||
*/
|
||||
public static int columnsNumber(char c, int x, int prevX, int plainSpaceSize) {
|
||||
if (c != '\t') {
|
||||
return 1;
|
||||
}
|
||||
int result = (x - prevX) / plainSpaceSize;
|
||||
if ((x - prevX) % plainSpaceSize > 0) {
|
||||
result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to answer how many visual columns are occupied by the given width.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user