From e91b04413474cdcd5801250735fad4cb1c4928f2 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 11 Feb 2022 15:48:56 +0100 Subject: [PATCH] components/app: make switchBuffer state changes atomic Instead of calling App.setBufferState inside the App.setState callback invoked when the update is done, call State.updateBuffer. --- components/app.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/components/app.js b/components/app.js index 9b650ec..3786d76 100644 --- a/components/app.js +++ b/components/app.js @@ -402,19 +402,20 @@ export default class App extends Component { if (!buf) { return; } - return { activeBuffer: buf.id }; + + let prevReadReceipt = this.getReceipt(buf.name, ReceiptType.READ); + // TODO: only mark as read if user scrolled at the bottom + let update = State.updateBuffer(state, buf.id, { + unread: Unread.NONE, + prevReadReceipt, + }); + + return { ...update, activeBuffer: buf.id }; }, () => { if (!buf) { return; } - let prevReadReceipt = this.getReceipt(buf.name, ReceiptType.READ); - // TODO: only mark as read if user scrolled at the bottom - this.setBufferState(buf.id, { - unread: Unread.NONE, - prevReadReceipt, - }); - if (this.buffer.current) { this.buffer.current.focus(); }