mirror of
https://github.com/laurent22/joplin.git
synced 2026-10-25 02:47:28 +00:00
Desktop: Fixes #16205: Fix regression which causes text to be lost if switching to another note immediately after typing in the Rich Text editor (#16213)
This commit is contained in:
1 parent
561ab70c5e
commit
7e66fbff34
5 files changed
+87
-3
No files matched your search
@@ -33,6 +33,7 @@ export default class AsyncActionQueue<Context = void> {
|
||||
|
||||
private processingFinishedPromise_: Promise<void>;
|
||||
private onProcessingFinished_: ()=> void;
|
||||
private onProcessingFailed_: (error: Error)=> void;
|
||||
|
||||
public constructor(interval = 100, intervalType: IntervalType = IntervalType.Debounce) {
|
||||
this.interval_ = interval;
|
||||
@@ -40,10 +41,21 @@ export default class AsyncActionQueue<Context = void> {
|
||||
this.resetFinishProcessingPromise_();
|
||||
}
|
||||
|
||||
private async handleProcessingFailure_(promise: Promise<void>) {
|
||||
try {
|
||||
await promise;
|
||||
} catch {
|
||||
// processQueue logs the error. This handler prevents fire-and-forget queues
|
||||
// from causing an unhandled rejection.
|
||||
}
|
||||
}
|
||||
|
||||
private resetFinishProcessingPromise_() {
|
||||
this.processingFinishedPromise_ = new Promise<void>(resolve => {
|
||||
this.processingFinishedPromise_ = new Promise<void>((resolve, reject) => {
|
||||
this.onProcessingFinished_ = resolve;
|
||||
this.onProcessingFailed_ = reject;
|
||||
});
|
||||
void this.handleProcessingFailure_(this.processingFinishedPromise_);
|
||||
}
|
||||
|
||||
// Determines whether an item can be skipped in the queue. Prevents data loss in the case that
|
||||
@@ -91,6 +103,8 @@ export default class AsyncActionQueue<Context = void> {
|
||||
this.processing_ = true;
|
||||
|
||||
let i = 0;
|
||||
let processingFailed = false;
|
||||
let processingError: Error = null;
|
||||
try {
|
||||
for (i = 0; i < itemCount; i++) {
|
||||
const current = this.queue_[i];
|
||||
@@ -102,13 +116,21 @@ export default class AsyncActionQueue<Context = void> {
|
||||
} catch (error) {
|
||||
i ++; // Don't repeat the failed task.
|
||||
logger.warn('Unhandled error:', error);
|
||||
throw error;
|
||||
processingFailed = true;
|
||||
processingError = error;
|
||||
} finally {
|
||||
// Removing processed items in a try {} finally {...} prevents
|
||||
// items from being processed twice, even if one throws an Error.
|
||||
this.queue_.splice(0, i);
|
||||
this.processing_ = false;
|
||||
}
|
||||
|
||||
if (processingFailed) {
|
||||
this.onProcessingFailed_(processingError);
|
||||
this.resetFinishProcessingPromise_();
|
||||
if (this.queue_.length) this.scheduleProcessing();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.queue_.length === 0) {
|
||||
|
||||
Reference in new issue
Block a user