void () { if (targetSelectionState.isExists && documentOfPagesModel.getPagesAmount() != 0) { int docLength = documentOfPagesModel.getDocument().getTextLength(); int startOffset = Math.min(documentOfPagesModel.absoluteSymbolPositionToOffset(targetSelectionState.start), docLength); int endOffset = Math.min(documentOfPagesModel.absoluteSymbolPositionToOffset(targetSelectionState.end), docLength); runCaretAndSelectionListeningTransparentCommand(() -> { if (startOffset == endOffset) { editor.getSelectionModel().removeSelection(); } else { editor.getSelectionModel().setSelection(startOffset, endOffset); } }); } }