@ -22,7 +22,10 @@ export class EditorMonitor extends Disposable {
super ( ) ;
// create store
this . _store = new EditMemoryStorage ( doc . docId ( ) , store ) ;
const userId = doc . app . topAppModel . appObs . get ( ) ? . currentUser ? . id ? ? null ;
// use document id and user id as a key for storage
const key = doc . docId ( ) + userId ;
this . _store = new EditMemoryStorage ( key , store ) ;
// listen to document events to handle view load event
this . _listenToReload ( doc ) ;
@ -58,8 +61,8 @@ export class EditorMonitor extends Disposable {
// will be invoked only once
let executed = false ;
// don't restore on readonly mode
if ( doc . isReadonly . get ( ) ) { return ; }
// don't restore on readonly mode or when there is custom nav
if ( doc . isReadonly . get ( ) || doc . hasCustomNav . get ( ) ) { return ; }
// on view shown
this . _currentViewListener . autoDispose ( doc . currentView . addListener ( async view = > {
@ -114,7 +117,7 @@ class EditMemoryStorage {
private _entry : LastEditData | null = null ;
private _timestamp = 0 ;
constructor ( private _ docId : string , private _storage = getStorage ( ) ) {
constructor ( private _ key : string , private _storage = getStorage ( ) ) {
}
public updateValue ( pos : CellPosition , value : EditorState ) : void {
@ -136,13 +139,13 @@ class EditMemoryStorage {
return this . _timestamp ;
}
protected _ k ey() {
return ` grist-last-edit- ${ this . _ docId } ` ;
protected _ storageK ey() {
return ` grist-last-edit- ${ this . _ key } ` ;
}
protected load() {
const storage = this . _storage ;
const data = storage . getItem ( this . _ k ey( ) ) ;
const data = storage . getItem ( this . _ storageK ey( ) ) ;
this . _entry = null ;
this . _timestamp = 0 ;
@ -166,14 +169,14 @@ class EditMemoryStorage {
// if entry was removed - clear the storage
if ( ! this . _entry ) {
storage . removeItem ( this . _ k ey( ) ) ;
storage . removeItem ( this . _ storageK ey( ) ) ;
return ;
}
try {
this . _timestamp = Date . now ( ) ;
const data = { timestamp : this._timestamp , entry : this._entry } ;
storage . setItem ( this . _ k ey( ) , JSON . stringify ( data ) ) ;
storage . setItem ( this . _ storageK ey( ) , JSON . stringify ( data ) ) ;
} catch ( ex ) {
console . error ( "Can't save current edited cell state. Error message: " + ex ? . message ) ;
}