void (Editor editor, int selectionStart, int selectionEnd, int moveStartOffset, int moveEndOffset, int insOffset) { int selectionRelativeStartOffset = Math.max(0, selectionStart - moveStartOffset); int selectionRelativeEndOffset = Math.min(moveEndOffset - moveStartOffset, selectionEnd - moveStartOffset); int newSelectionStart = insOffset + selectionRelativeStartOffset; int newSelectionEnd = insOffset + selectionRelativeEndOffset; EditorUtil.setSelectionExpandingFoldedRegionsIfNeeded(editor, newSelectionStart, newSelectionEnd); }