String (@NotNull String text, @NotNull PsiFile file, @NotNull Editor editor, int caretOffset, int indent) { if (!text.matches(CONFIG_KEY_SEQUENCE_PATTERN)) { return null; } List<String> keys = separateCompositeKey(text); assert !keys.isEmpty(); for (String key: keys) { if (!YamlKeyValueRenameInputValidator.IDENTIFIER_PATTERN.matcher(key).matches()) { return null; } } PsiElement element = file.findElementAt(caretOffset); if (element != null) { String result = tryToPasteAsKeySequenceAtMapping(editor, keys, element, caretOffset, indent); if (result != null) { return result; } } if ((element == null || element.getTextRange().getStartOffset() == caretOffset) && caretOffset > 0) { // check the previous token element = file.findElementAt(caretOffset - 1); if (element != null) { // If we are in the end of map then add element to it: // top: // key1: value 1 // <caret> String result = tryToPasteAsKeySequenceAtMapping(editor, keys, element, caretOffset, indent); if (result != null) { return result; } // disputable: insert keys into empty key-value // key: // <caret> // anotherKey: some value YAMLKeyValue keyValue = getPreviousKeyValuePairBeforeEOL(element); if (keyValue != null && keyValue.getValue() == null) { // we insert new value int parentIndent = YAMLUtil.getIndentToThisElement(keyValue); if (indent > parentIndent) { return YAMLElementGenerator.createChainedKey(keys, indent); } } } } return null; }