Skip to content

Commit 6c51a30

Browse files
authored
Merge pull request #100 from inokawa/skip-if-equal
Skip pushing to history if documents are equal
2 parents f4fcef7 + 8d2e634 commit 6c51a30

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

.size-limit.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
"name": "editable",
44
"path": "lib/index.mjs",
55
"import": "{ editable }",
6-
"limit": "3.45 kB"
6+
"limit": "3.5 kB"
77
},
88
{
99
"name": "Total",
1010
"path": "lib/index.mjs",
1111
"import": "*",
12-
"limit": "4 kB"
12+
"limit": "5 kB"
1313
}
1414
]

src/core/editable.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,18 @@ export const editable = <T>(
228228
[doc, selection] = flatten(doc, selection);
229229
}
230230

231-
history.set([history.get()[0], prevSelection]);
232-
history.push([doc, selection]);
233231
currentSelection = selection;
234-
onChange(docToJS(doc));
232+
233+
// TODO improve
234+
const prevDoc = history.get()[0];
235+
if (
236+
doc.length !== prevDoc.length ||
237+
doc.some((l, i) => l !== prevDoc[i])
238+
) {
239+
history.set([prevDoc, prevSelection]);
240+
history.push([doc, selection]);
241+
onChange(docToJS(doc));
242+
}
235243
}
236244

237245
restoreSelectionOnTimeout();

0 commit comments

Comments
 (0)