 core/lib/Drupal/Component/Utility/DiffArray.php    | 34 ++++++++++++++++++++++
 core/modules/editor/editor.module                  |  5 ++--
 .../tests/src/Kernel/EditorFileUsageTest.php       | 22 ++++++++++++++
 3 files changed, 59 insertions(+), 2 deletions(-)

diff --git a/core/lib/Drupal/Component/Utility/DiffArray.php b/core/lib/Drupal/Component/Utility/DiffArray.php
index 825648e..e5bc679 100644
--- a/core/lib/Drupal/Component/Utility/DiffArray.php
+++ b/core/lib/Drupal/Component/Utility/DiffArray.php
@@ -47,4 +47,38 @@ public static function diffAssocRecursive(array $array1, array $array2) {
     return $difference;
   }
 
+  /**
+   * Computes the difference of arrays.
+   *
+   * The main difference from the array_diff() is that this method does not
+   * remove duplicates. For example:
+   * @code
+   *   array_diff([1, 1, 1], [1]); // []
+   *   \Drupal\Component\Utility\DiffArray::diffOnce([1, 1, 1], [1]); // [1, 1]
+   * @endcode
+   *
+   * Keys are maintained from the $array1.
+   *
+   * The comparison of items is always performed in the strict (===) mode.
+   *
+   * @param array $array1
+   *   The array to compare from.
+   * @param array $array2
+   *   The array to compare to.
+   *
+   * @return array
+   *   Returns the difference between the two arrays.
+   */
+  public static function diffOnce(array $array1, array $array2) {
+    foreach ($array2 as $item) {
+      // Always use strict mode because otherwise there could be fatal errors on
+      // object conversions.
+      $key = array_search($item, $array1, TRUE);
+      if ($key !== FALSE) {
+        unset($array1[$key]);
+      }
+    }
+    return $array1;
+  }
+
 }
diff --git a/core/modules/editor/editor.module b/core/modules/editor/editor.module
index 7cba938..08f1711 100644
--- a/core/modules/editor/editor.module
+++ b/core/modules/editor/editor.module
@@ -5,6 +5,7 @@
  * Adds bindings for client-side "text editors" to text formats.
  */
 
+use Drupal\Component\Utility\DiffArray;
 use Drupal\Component\Utility\Html;
 use Drupal\editor\Entity\Editor;
 use Drupal\Core\Entity\FieldableEntityInterface;
@@ -386,13 +387,13 @@ function editor_entity_update(EntityInterface $entity) {
 
     // Detect file usages that should be incremented.
     foreach ($uuids_by_field as $field => $uuids) {
-      $added_files = array_diff($uuids_by_field[$field], $original_uuids_by_field[$field]);
+      $added_files = DiffArray::diffOnce($uuids_by_field[$field], $original_uuids_by_field[$field]);
       _editor_record_file_usage($added_files, $entity);
     }
 
     // Detect file usages that should be decremented.
     foreach ($original_uuids_by_field as $field => $uuids) {
-      $removed_files = array_diff($original_uuids_by_field[$field], $uuids_by_field[$field]);
+      $removed_files = DiffArray::diffOnce($original_uuids_by_field[$field], $uuids_by_field[$field]);
       _editor_delete_file_usage($removed_files, $entity, 1);
     }
   }
diff --git a/core/modules/editor/tests/src/Kernel/EditorFileUsageTest.php b/core/modules/editor/tests/src/Kernel/EditorFileUsageTest.php
index aac665d..8b3cb90 100644
--- a/core/modules/editor/tests/src/Kernel/EditorFileUsageTest.php
+++ b/core/modules/editor/tests/src/Kernel/EditorFileUsageTest.php
@@ -114,6 +114,28 @@ public function testEditorEntityHooks() {
       $this->assertIdentical(['editor' => ['node' => [1 => '1']]], $file_usage->listUsage($image_entity), 'The image ' . $image_paths[$key] . ' has 1 usage.');
     }
 
+    // Test editor_entity_update(): increment, by editing the same revision.
+    $node->setNewRevision(FALSE);
+    $original_values = [];
+    for ($i = 0; $i < count($image_entities); $i++) {
+      $original_values[$i] = $node->body[$i]->value;
+      $node->body[$i]->value .= '<p><img data-entity-type="file" data-entity-uuid="' . $image_entities[$i]->uuid() . '" /></p>';
+    }
+    $node->save();
+    foreach ($image_entities as $key => $image_entity) {
+      $this->assertIdentical(['editor' => ['node' => [1 => '2']]], $file_usage->listUsage($image_entity), 'The image ' . $image_paths[$key] . ' has 2 usages.');
+    }
+
+    // Test editor_entity_update(): decrement, by editing the same revision.
+    $node->setNewRevision(FALSE);
+    for ($i = 0; $i < count($original_values); $i++) {
+      $node->body[$i]->value = $original_values[$i];
+    }
+    $node->save();
+    foreach ($image_entities as $key => $image_entity) {
+      $this->assertIdentical(['editor' => ['node' => [1 => '1']]], $file_usage->listUsage($image_entity), 'The image ' . $image_paths[$key] . ' has 1 usage.');
+    }
+
     // Test editor_entity_update(): increment, twice, by creating new revisions.
     $node->setNewRevision(TRUE);
     $node->save();
