Skip to content

Commit 7456b2c

Browse files
committed
fix #98, only notify on OOB change if doc is open & visible
1 parent 54a95a1 commit 7456b2c

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/docprovider/yprovider.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -219,22 +219,29 @@ export class WebSocketProvider implements IDocumentProvider {
219219

220220
/**
221221
* Handles an out-of-band change indicated by close code 4000. This requires
222-
* resetting the YDoc, re-connecting, then emitting a notification to the user.
222+
* resetting the YDoc and re-connecting. A notification is emitted to the user
223+
* if the document widget containing the shared model is open & visible.
223224
*/
224225
private _handleOobChange() {
225226
// Reset YDoc
226227
// TODO: is it safe to assume that we only need YFile & YNotebook?
227228
const sharedModel = this._sharedModel as YFile | YNotebook;
228229
sharedModel.reset();
229230

230-
// Re-connect and display a notification to the user
231+
// Re-connect
231232
this.reconnect();
232-
Notification.info(
233-
'The contents of this file were changed on disk. The document state has been reset.',
234-
{
235-
autoClose: false
236-
}
237-
);
233+
234+
// Emit notification if document is open & visible to the user (i.e. the tab
235+
// exists & the content of that tab is being shown)
236+
const docWidget = this.parentDocumentWidget;
237+
if (docWidget && docWidget.isVisible) {
238+
Notification.info(
239+
`The file '${this._path}' was modified on disk. The document tab has been reset.`,
240+
{
241+
autoClose: 10000
242+
}
243+
);
244+
}
238245
}
239246

240247
/**
@@ -249,7 +256,7 @@ export class WebSocketProvider implements IDocumentProvider {
249256
*/
250257
private _handleOobMove() {
251258
this._stopCloseAndNotify(
252-
`The file at '${this._path}' no longer exists, and was either moved or deleted. The document tab has been closed.`
259+
`The file '${this._path}' no longer exists, and was either moved or deleted. The document tab has been closed.`
253260
);
254261
}
255262

@@ -259,7 +266,7 @@ export class WebSocketProvider implements IDocumentProvider {
259266
*/
260267
private _handleIbDeletion() {
261268
this._stopCloseAndNotify(
262-
`The file at '${this._path}' was deleted. The document tab has been closed.`
269+
`The file '${this._path}' was deleted. The document tab has been closed.`
263270
);
264271
}
265272

0 commit comments

Comments
 (0)