void (@NotNull AnActionEvent e) { PsiFile targetPsiFile = handler.getPsiFile(); if (targetPsiFile == null) return; Project project = field.getProject(); String newValue = field.getText(); Editor fieldEditor = field.getEditor(); if (fieldEditor == null) return; int valueOffset = fieldEditor.getCaretModel().getOffset(); Editor editor = foldRegion.getEditor(); JComponent editorComponent = editor.getContentComponent(); focusAndRun(editorComponent, () -> { WriteCommandAction.runWriteCommandAction(project, JavaI18nBundle.message("command.name.edit.property.value"), null, () -> { handler.setValue(newValue.replace("\n", "\\n")); String oldPlaceholder = foldRegion.getPlaceholderText(); String newPlaceholder = handler.getPlaceholder(); editor.getFoldingModel().runBatchFoldingOperation(() -> foldRegion.setPlaceholderText(newPlaceholder)); VisualPosition regionStartPosition = editor.offsetToVisualPosition(foldRegion.getStartOffset()); int placeholderOffset = Math.max(1, Math.min(newPlaceholder.length() - 1, handler.valueToPlaceholderOffset(valueOffset))); int placeholderColumn = ((EditorImpl)editor).offsetToVisualColumnInFoldRegion(foldRegion, placeholderOffset, false); editor.getCaretModel().moveToVisualPosition( new VisualPosition(regionStartPosition.line, regionStartPosition.column + placeholderColumn)); editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); UndoManager.getInstance(project).undoableActionPerformed(new UndoableAction() { @Override public void undo() { if (foldRegion.isValid()) { editor.getFoldingModel().runBatchFoldingOperation(() -> foldRegion.setPlaceholderText(oldPlaceholder)); } } @Override public void redo() { if (foldRegion.isValid()) { editor.getFoldingModel().runBatchFoldingOperation(() -> foldRegion.setPlaceholderText(newPlaceholder)); } } @Override public DocumentReference @Nullable [] getAffectedDocuments() { return null; } @Override public boolean isGlobal() { return false; } }); }, targetPsiFile); editorComponent.paintImmediately(new Rectangle(editorComponent.getSize())); popup.cancel(); }); }