GeezerVison is showing github.com — fix(live-preview): keep CM edits from being undone by stale md viewer… · phcode-dev/phoenix@f2f2382
File tree
Expand file treeCollapse file tree
Open diff view settings
src/extensionsIntegrated/Phoenix-live-preview
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/extensionsIntegrated/Phoenix-live-preview/MarkdownSync.js +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -272,6 +272,7 @@ define(function (require, exports, module) { |
272 | 272 | } |
273 | 273 | clearTimeout(_debounceTimer); |
274 | 274 | _debounceTimer = setTimeout(function () { |
| 275 | + _debounceTimer = null; |
275 | 276 | _sendUpdate(_lastChangeOrigin); |
276 | 277 | _lastChangeOrigin = null; |
277 | 278 | }, DEBOUNCE_TO_IFRAME_MS); |
@@ -359,6 +360,7 @@ define(function (require, exports, module) { |
359 | 360 | } |
360 | 361 |
|
361 | 362 | clearTimeout(_debounceTimer); |
| 363 | + _debounceTimer = null; |
362 | 364 | clearTimeout(_scrollSyncTimer); |
363 | 365 | clearTimeout(_selectionSyncTimer); |
364 | 366 |
|
@@ -672,6 +674,15 @@ define(function (require, exports, module) { |
672 | 674 | return; |
673 | 675 | } |
674 | 676 |
|
| 677 | + // A CM change is still waiting to go to the iframe, so the iframe made this |
| 678 | + // before it had that change: applying it would undo the change. The pending |
| 679 | + // update brings the iframe up to date instead. (e.g. the iframe flushes its |
| 680 | + // own debounced edit when the same file is switched to again, and that can |
| 681 | + // land just after the user's next CM edit.) |
| 682 | + if (_debounceTimer) { |
| 683 | + return; |
| 684 | + } |
| 685 | + |
675 | 686 | const markdown = data.markdown; |
676 | 687 | const remoteSyncId = data._syncId; |
677 | 688 |
|
|