boolean (@NotNull DocumentEvent e, long range) { if (e.isWholeTextReplaced()) { // Perform translation if the whole text is replaced. return true; } if (e.getOffset() >= TextRangeScalarUtil.endOffset(range) || e.getOffset() + e.getOldLength() <= TextRangeScalarUtil.startOffset(range)) { // Don't perform complex processing if the change doesn't affect the target range. return false; } // Perform complex processing only if at least 80% of the document was updated. return Math.max(e.getNewLength(), e.getOldLength()) * 5 >= e.getDocument().getTextLength() * 4; }