void (@NotNull DocumentEvent event) { List<RangeMarker> scopes = getCurrentScopes(false); if (scopes == null) return; int caretOffset = myEditor.getCaretModel().getOffset(); int changeStart = event.getOffset(); int changeEnd = event.getOffset() + event.getOldLength(); for (Iterator<RangeMarker> it = scopes.iterator(); it.hasNext(); ) { RangeMarker scope = it.next(); // We don't reset scope if the change is completely inside our scope, or if caret is inside, but the change is outside if ((changeStart < scope.getStartOffset() || changeEnd > scope.getEndOffset()) && (caretOffset < scope.getStartOffset() || caretOffset > scope.getEndOffset() || (changeEnd >= scope.getStartOffset() && changeStart <= scope.getEndOffset()))) { it.remove(); } } }