int (int startOffset, int visualColumn) { FoldRegion[] regions = myFoldingModel.fetchTopLevel(); if (regions == null) { return startOffset + visualColumn; } int low = 0; int high = regions.length - 1; int i = -1; while (low <= high) { int mid = low + high >>> 1; FoldRegion midVal = regions[mid]; if (midVal.getStartOffset() <= startOffset && midVal.getEndOffset() > startOffset) { i = mid; break; } if (midVal.getStartOffset() < startOffset) low = mid + 1; else if (midVal.getStartOffset() > startOffset) high = mid - 1; } if (i < 0) { i = low; } int result = startOffset; int columnsToProcess = visualColumn; for (; i < regions.length; i++) { FoldRegion region = regions[i]; // Process text between the last fold region end and current fold region start. int nonFoldTextColumnsNumber = region.getStartOffset() - result; if (nonFoldTextColumnsNumber >= columnsToProcess) { return result + columnsToProcess; } columnsToProcess -= nonFoldTextColumnsNumber; // Process fold region. int placeHolderLength = region.getPlaceholderText().length(); if (placeHolderLength >= columnsToProcess) { return region.getEndOffset(); } result = region.getEndOffset(); columnsToProcess -= placeHolderLength; } return result + columnsToProcess; }