When trying to simply rename an item in an anvil, the item will snap back to the first slot and return to its original state.
When trying to rename an item along with an enchantment (or any other anvil uses, such as repairing), the item will retain all changes except the new name.
Duplicate of MC-121638