@Override
  public YAMLScalarImpl handleContentChange(@NotNull YAMLScalarImpl element, @NotNull TextRange range, String newContent)
    throws IncorrectOperationException {
    
    try {
      final List<Pair<TextRange, String>> encodeReplacements = element.getEncodeReplacements(newContent);
      final StringBuilder builder = new StringBuilder();
      final String oldText = element.getText();

      builder.append(oldText.subSequence(0, range.getStartOffset()));
      builder.append(YAMLScalarImpl.processReplacements(newContent, encodeReplacements));
      builder.append(oldText.subSequence(range.getEndOffset(), oldText.length()));

      final YAMLFile dummyYamlFile = YAMLElementGenerator.getInstance(element.getProject()).createDummyYamlWithText(builder.toString());
      final YAMLScalar newScalar = PsiTreeUtil.collectElementsOfType(dummyYamlFile, YAMLScalar.class).iterator().next();

      final PsiElement result = element.replace(newScalar);
      if (!(result instanceof YAMLScalarImpl)) {
        throw new AssertionError("Inserted YAML scalar, but it isn't a scalar after insertion :(");
      }
      
      // it is a hack to preserve the `QUICK_EDIT_HANDLERS` key, 
      // actually `element.replace` should have done it, but for some reason didn't
      ((UserDataHolderBase)element.getNode()).copyCopyableDataTo((UserDataHolderBase)result.getNode());
      CodeEditUtil.setNodeGenerated(result.getNode(), true);
      
      return ((YAMLScalarImpl)result);
    }
    catch (IllegalArgumentException e) {
      final PsiElement newElement = element.replace(YAMLElementGenerator.getInstance(element.getProject()).createYamlDoubleQuotedString());
      if (!(newElement instanceof YAMLQuotedTextImpl)) {
        throw new AssertionError("Could not replace with dummy scalar");
      }
      return handleContentChange((YAMLScalarImpl)newElement, newContent);
    }
  }
@Override
  public YAMLScalarImpl handleContentChange(@NotNull YAMLScalarImpl element, @NotNull TextRange range, String newContent)