From 598b8260b69f10939972d921cad1c523c58c0e27 Mon Sep 17 00:00:00 2001 From: Janet Vorobyeva Date: Tue, 12 Sep 2023 00:42:47 -0700 Subject: [PATCH] Fixed cursorEdited() for properRowId() Previously I updated cursorEdited on rowIndex() change However, this ran into the exact same bug that properRowId was created for, namely that if the data changes (filtered out), then rowIndex won't update. Switched the dependency to properRowId seems to fix it. Also, weird timing/dependency stuff, need to subscribe version AFTER subscribing activeRowId --- app/client/components/Cursor.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/client/components/Cursor.ts b/app/client/components/Cursor.ts index 1d3f07cc..947d1c39 100644 --- a/app/client/components/Cursor.ts +++ b/app/client/components/Cursor.ts @@ -100,12 +100,10 @@ export class Cursor extends Disposable { write: (index) => { const rowIndex = index === null ? null : this.viewData.clampIndex(index); this._rowId(rowIndex == null ? null : this.viewData.getRowId(rowIndex)); - this.cursorEdited(); }, })); this.fieldIndex = baseView.viewSection.viewFields().makeLiveIndex(optCursorPos.fieldIndex || 0); - this.fieldIndex.subscribe(() => { this.cursorEdited(); }); this.autoDispose(commands.createGroup(Cursor.editorCommands, this, baseView.viewSection.hasFocus)); @@ -123,6 +121,13 @@ export class Cursor extends Disposable { this.autoDispose(this._properRowId.subscribe((rowId) => baseView.viewSection.activeRowId(rowId))); this.autoDispose(this._lastEditedAt.subscribe((seqNum) => baseView.viewSection.lastCursorEdit(seqNum))); + // Update the cursor edit time if either the row or column change + // IMPORTANT: need to subscribe AFTER the properRowId->activeRowId subscription. + // (Cursor-linking observables depend on edit-version, and only peek at activeRowId. Therefore, make sure + // we set all values correctly, and only update version after that's been done) + this.autoDispose(this._properRowId.subscribe(() => { this.cursorEdited(); })); + this.autoDispose(this.fieldIndex.subscribe(() => { this.cursorEdited(); })); + // On dispose, save the current cursor position to the section model. this.onDispose(() => { baseView.viewSection.lastCursorPos = this.getCursorPos(); });