int (@Nullable Editor editor, @NotNull CharSequence text, final int start, final int offset, final int tabSize) { if (editor instanceof TextComponentEditor) { return offset - start; } boolean useOptimization = true; if (editor != null) { SoftWrap softWrap = editor.getSoftWrapModel().getSoftWrap(start); useOptimization = softWrap == null; } if (useOptimization) { boolean hasNonTabs = false; for (int i = start; i < offset; i++) { if (text.charAt(i) == '\t') { if (hasNonTabs) { useOptimization = false; break; } } else { hasNonTabs = true; } } } if (editor != null && useOptimization) { Document document = editor.getDocument(); if (start < offset - 1 && document.getLineNumber(start) != document.getLineNumber(offset - 1)) { String editorInfo = editor instanceof EditorImpl ? ". Editor info: " + ((EditorImpl)editor).dumpState() : ""; String documentInfo; if (text instanceof Dumpable) { documentInfo = ((Dumpable)text).dumpState(); } else { documentInfo = "Text holder class: " + text.getClass(); } LOG.error("detected incorrect offset -> column number calculation", new Throwable(), AttachmentFactory.createContext( "start: " + start + ", given offset: " + offset + ", given tab size: " + tabSize + ". " + documentInfo + editorInfo)); } } int shift = 0; for (int i = start; i < offset; i++) { char c = text.charAt(i); if (c == '\t') { shift += getTabLength(i + shift - start, tabSize) - 1; } } return offset - start + shift; }