@Override
  public void handleInsert(@NotNull InsertionContext context, @NotNull T item) {
    // keyValue is created by handler, there is no need in inserting completion char
    context.setAddCompletionChar(false);

    int startOffset = context.getStartOffset();
    PsiFile psiFile = context.getFile();
    YamlOffsetContext offsetContext = new YamlOffsetContext(psiFile, startOffset);
    @SuppressWarnings("DataFlowIssue")
    YAMLValue oldValue = (offsetContext.holdingDocument.getTopLevelValue() instanceof YAMLCompoundValue) ?
                         deleteLookupTextAndRetrieveOldValue(context, offsetContext.currentElement) :
                         null; // Inheritors must handle lookup text removal since otherwise holdingDocument may become invalid.
    if (oldValue instanceof YAMLSequence) {
      trimSequenceItemIndents((YAMLSequence)oldValue);
    }

    if (oldValue == null && !offsetContext.holdingDocument.isValid()) {
      offsetContext = new YamlOffsetContext(psiFile, startOffset);
    }
    @SuppressWarnings("DataFlowIssue") final YAMLKeyValue created =
      createNewEntry(offsetContext.holdingDocument, item, offsetContext.getParentIfValid());

    YAMLValue createdValue = created.getValue();
    if (createdValue != null) {
      context.getEditor().getCaretModel().moveToOffset(createdValue.getTextRange().getStartOffset() - 1);
    }
    else {
      context.getEditor().getCaretModel().moveToOffset(created.getTextRange().getEndOffset());
    }
    if (oldValue != null) {
      WriteCommandAction.runWriteCommandAction(context.getProject(),
                                               YAMLBundle.message("YamlKeyCompletionInsertHandler.insert.value"),
                                               null,
                                               () -> created.setValue(oldValue));
    }

    PsiDocumentManager.getInstance(context.getProject()).doPostponedOperationsAndUnblockDocument(context.getDocument());

    createdValue = created.getValue(); // retrieve restored value
    YAMLSequenceItem valueItem =
      createdValue instanceof YAMLSequence ? ContainerUtil.getFirstItem(((YAMLSequence)createdValue).getItems()) : null;
    if (valueItem != null) {
      context.getEditor().getCaretModel().moveToOffset(valueItem.getTextOffset() + 1);
    }
    if (!isCharAtCaret(context.getEditor(), ' ')) {
      EditorModificationUtilEx.insertStringAtCaret(context.getEditor(), " ");
    }
    else {
      context.getEditor().getCaretModel().moveCaretRelatively(1, 0, false, false, true);
    }
  }
@Override
  public void handleInsert(@NotNull InsertionContext context, @NotNull T item)