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
This commit is contained in:
Janet Vorobyeva 2023-09-12 00:42:47 -07:00
parent a0d6e44481
commit 598b8260b6

View File

@ -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(); });