Program: 133321
Project: 133321
Buggy source:
public void actionPerformed(AnActionEvent e){
  final Project project=e.getProject();
  if (project == null)   return;
  final Editor editor=FileEditorManager.getInstance(project).getSelectedTextEditor();
  if (editor == null)   return;
  String initialValue="String_Node_Str";
  final SelectionModel selectionModel=editor.getSelectionModel();
  if (selectionModel.hasSelection()) {
    String selectedText=selectionModel.getSelectedText();
    if (selectedText == null) {
      selectionModel.selectLineAtCaret();
      selectedText=selectionModel.getSelectedText();
      if (selectedText == null)       selectedText="String_Node_Str";
    }
    if (!selectedText.isEmpty()) {
      selectedText=selectedText.trim();
      if (selectedText.contains("String_Node_Str"))       selectedText=selectedText.substring(0,selectedText.indexOf("String_Node_Str"));
    }
    initialValue=selectedText;
  }
  final String text=Messages.showInputDialog(project,null,"String_Node_Str",null,initialValue,null);
  final Runnable readRunner=new Runnable(){
    @Override public void run(){
      int offset=editor.getCaretModel().getOffset();
      final Document document=editor.getDocument();
      if (selectionModel.hasSelection()) {
        int selectionStart=selectionModel.getSelectionStart();
        int selectionEnd=selectionModel.getSelectionEnd();
        selectionModel.removeSelection();
        document.deleteString(selectionStart,selectionEnd);
        offset=selectionStart;
      }
      int lineNumber=document.getLineNumber(offset);
      int lineStartOffset=document.getLineStartOffset(lineNumber);
      int indentLength=offset - lineStartOffset;
      document.insertString(offset,Util.convertTextToAscii(text,indentLength));
    }
  }
;
  ApplicationManager.getApplication().invokeLater(new Runnable(){
    @Override public void run(){
      CommandProcessor.getInstance().executeCommand(project,new Runnable(){
        @Override public void run(){
          ApplicationManager.getApplication().runWriteAction(readRunner);
        }
      }
,"String_Node_Str",null);
    }
  }
);
}

Fixed version (ground truth):
public void actionPerformed(AnActionEvent e){
  final Project project=e.getProject();
  if (project == null)   return;
  final Editor editor=FileEditorManager.getInstance(project).getSelectedTextEditor();
  if (editor == null)   return;
  String initialValue="String_Node_Str";
  final SelectionModel selectionModel=editor.getSelectionModel();
  if (selectionModel.hasSelection()) {
    String selectedText=selectionModel.getSelectedText();
    if (selectedText == null) {
      selectionModel.selectLineAtCaret();
      selectedText=selectionModel.getSelectedText();
      if (selectedText == null)       selectedText="String_Node_Str";
    }
    if (!selectedText.isEmpty()) {
      selectedText=selectedText.trim();
      if (selectedText.contains("String_Node_Str"))       selectedText=selectedText.substring(0,selectedText.indexOf("String_Node_Str"));
    }
    initialValue=selectedText;
  }
  final String text=Messages.showInputDialog(project,null,"String_Node_Str",null,initialValue,null);
  final Runnable readRunner=new Runnable(){
    @Override public void run(){
      if (text == null)       return;
      int offset=editor.getCaretModel().getOffset();
      final Document document=editor.getDocument();
      if (selectionModel.hasSelection()) {
        int selectionStart=selectionModel.getSelectionStart();
        int selectionEnd=selectionModel.getSelectionEnd();
        selectionModel.removeSelection();
        document.deleteString(selectionStart,selectionEnd);
        offset=selectionStart;
      }
      int lineNumber=document.getLineNumber(offset);
      int lineStartOffset=document.getLineStartOffset(lineNumber);
      int indentLength=offset - lineStartOffset;
      document.insertString(offset,Util.convertTextToAscii(text,indentLength));
    }
  }
;
  ApplicationManager.getApplication().invokeLater(new Runnable(){
    @Override public void run(){
      CommandProcessor.getInstance().executeCommand(project,new Runnable(){
        @Override public void run(){
          ApplicationManager.getApplication().runWriteAction(readRunner);
        }
      }
,"String_Node_Str",null);
    }
  }
);
}