Skip to content

Commit

Permalink
fix: check if the deleted item is the last focussed one
Browse files Browse the repository at this point in the history
  • Loading branch information
oae committed Sep 11, 2022
1 parent c35203d commit 84671a0
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/components/panoScrollView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ export class PanoScrollView extends ScrollView {

private connectOnRemove(panoItem: PanoItem) {
panoItem.connect('on-remove', () => {
if (this.currentFocus === panoItem) {
this.focusNext() || this.focusPrev();
}
this.removeItem(panoItem);
this.fillRemainingItems();
this.filter(this.currentFilter);
Expand Down Expand Up @@ -185,29 +188,33 @@ export class PanoScrollView extends ScrollView {
private focusNext() {
const lastFocus = this.currentFocus;
if (!lastFocus) {
this.focusOnClosest();
return;
return this.focusOnClosest();
}

const index = this.getVisibleItems().findIndex((item) => item.dbItem.id === lastFocus.dbItem.id);
if (index + 1 < this.getVisibleItems().length) {
this.currentFocus = this.getVisibleItems()[index + 1];
this.currentFocus.grab_key_focus();
return true;
}

return false;
}

private focusPrev() {
const lastFocus = this.currentFocus;
if (!lastFocus) {
this.focusOnClosest();
return;
return this.focusOnClosest();
}

const index = this.getVisibleItems().findIndex((item) => item.dbItem.id === lastFocus.dbItem.id);
if (index - 1 >= 0) {
this.currentFocus = this.getVisibleItems()[index - 1];
this.currentFocus.grab_key_focus();
return true;
}

return false;
}

filter(text: string) {
Expand All @@ -234,6 +241,7 @@ export class PanoScrollView extends ScrollView {
if (lastFocus !== null) {
if (lastFocus.get_parent() === this.list && lastFocus.is_visible()) {
lastFocus.grab_key_focus();
return true;
} else {
let nextFocus = this.getVisibleItems().find((item) => item.dbItem.copyDate <= lastFocus.dbItem.copyDate);
if (!nextFocus) {
Expand All @@ -244,12 +252,16 @@ export class PanoScrollView extends ScrollView {
if (nextFocus) {
this.currentFocus = nextFocus;
nextFocus.grab_key_focus();
return true;
}
}
} else if (this.getVisibleItems().length > 0) {
this.currentFocus = this.getVisibleItems()[0];
this.currentFocus.grab_key_focus();
return true;
}

return false;
}

scrollToFirstItem() {
Expand Down

0 comments on commit 84671a0

Please sign in to comment.