ソースを参照

fix: preserve current unsaved value in storage editor (#1300)

tophf 4 年 前
コミット
ca6b1995fb
1 ファイル変更6 行追加3 行削除
  1. 6 3
      src/options/views/edit/values.vue

+ 6 - 3
src/options/views/edit/values.vue

@@ -241,13 +241,16 @@ export default {
     onStorageChanged(changes) {
     onStorageChanged(changes) {
       const data = changes[scriptStorageKey]?.newValue;
       const data = changes[scriptStorageKey]?.newValue;
       if (data) {
       if (data) {
-        this.setData(data);
         const { current } = this;
         const { current } = this;
+        const oldText = current && this.getValue(current.key);
+        this.setData(data);
         if (current) {
         if (current) {
           const newText = this.getValue(current.key);
           const newText = this.getValue(current.key);
-          if (newText === current.value) {
+          const curText = current.value;
+          if (curText === newText) {
             current.isNew = false;
             current.isNew = false;
-          } else {
+          } else if (curText === oldText) {
+            // Updating the current value only if it wasn't yet changed by the user.
             // Keeping the same this.current to avoid triggering `watch` observer
             // Keeping the same this.current to avoid triggering `watch` observer
             Object.keys(current)
             Object.keys(current)
             .filter(k => k !== 'key' && k !== 'value')
             .filter(k => k !== 'key' && k !== 'value')