fix: select next item when trashing or deleting item (#1218)
This commit is contained in:
@@ -37,7 +37,7 @@ const ContentList: FunctionComponent<Props> = ({
|
|||||||
selectedItems,
|
selectedItems,
|
||||||
paginate,
|
paginate,
|
||||||
}) => {
|
}) => {
|
||||||
const { selectPreviousItem, selectNextItem } = itemListController
|
const { selectPreviousItem, selectNextItem } = selectionController
|
||||||
const { hideTags, hideDate, hideNotePreview, hideEditorIcon } = itemListController.webDisplayOptions
|
const { hideTags, hideDate, hideNotePreview, hideEditorIcon } = itemListController.webDisplayOptions
|
||||||
const { sortBy } = itemListController.displayOptions
|
const { sortBy } = itemListController.displayOptions
|
||||||
|
|
||||||
|
|||||||
@@ -57,11 +57,9 @@ const ContentListView: FunctionComponent<Props> = ({
|
|||||||
panelWidth,
|
panelWidth,
|
||||||
renderedItems,
|
renderedItems,
|
||||||
searchBarElement,
|
searchBarElement,
|
||||||
selectNextItem,
|
|
||||||
selectPreviousItem,
|
|
||||||
} = itemListController
|
} = itemListController
|
||||||
|
|
||||||
const { selectedItems } = selectionController
|
const { selectedItems, selectNextItem, selectPreviousItem } = selectionController
|
||||||
|
|
||||||
const isFilesSmartView = useMemo(
|
const isFilesSmartView = useMemo(
|
||||||
() => navigationController.selected?.uuid === SystemViewId.Files,
|
() => navigationController.selected?.uuid === SystemViewId.Files,
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ const NoteTag = ({ viewControllerManager, tag }: Props) => {
|
|||||||
if (autocompleteInputFocused) {
|
if (autocompleteInputFocused) {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
return tags[0].uuid === tag.uuid ? 0 : -1
|
return tags[0]?.uuid === tag.uuid ? 0 : -1
|
||||||
}, [autocompleteInputFocused, tags, tag, focusedTagUuid])
|
}, [autocompleteInputFocused, tags, tag, focusedTagUuid])
|
||||||
|
|
||||||
const onKeyDown: KeyboardEventHandler = useCallback(
|
const onKeyDown: KeyboardEventHandler = useCallback(
|
||||||
|
|||||||
@@ -370,7 +370,7 @@ export class ItemListController extends AbstractViewController implements Intern
|
|||||||
await this.selectFirstItem()
|
await this.selectFirstItem()
|
||||||
} else if (this.shouldCloseActiveItem(activeItem) && activeController) {
|
} else if (this.shouldCloseActiveItem(activeItem) && activeController) {
|
||||||
this.closeItemController(activeController)
|
this.closeItemController(activeController)
|
||||||
this.selectNextItem()
|
this.selectionController.selectNextItem()
|
||||||
} else if (this.shouldSelectNextItemOrCreateNewNote(activeItem)) {
|
} else if (this.shouldSelectNextItemOrCreateNewNote(activeItem)) {
|
||||||
await this.selectNextItemOrCreateNewNote()
|
await this.selectNextItemOrCreateNewNote()
|
||||||
} else if (this.shouldSelectActiveItem(activeItem) && activeItem) {
|
} else if (this.shouldSelectActiveItem(activeItem) && activeItem) {
|
||||||
@@ -547,27 +547,11 @@ export class ItemListController extends AbstractViewController implements Intern
|
|||||||
return document.getElementById(ElementIdScrollContainer)
|
return document.getElementById(ElementIdScrollContainer)
|
||||||
}
|
}
|
||||||
|
|
||||||
selectItemWithScrollHandling = async (
|
|
||||||
item: {
|
|
||||||
uuid: ListableContentItem['uuid']
|
|
||||||
},
|
|
||||||
{ userTriggered = false, scrollIntoView = true },
|
|
||||||
): Promise<void> => {
|
|
||||||
await this.selectionController.selectItem(item.uuid, userTriggered)
|
|
||||||
|
|
||||||
if (scrollIntoView) {
|
|
||||||
const itemElement = document.getElementById(item.uuid)
|
|
||||||
itemElement?.scrollIntoView({
|
|
||||||
behavior: 'smooth',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
selectFirstItem = async () => {
|
selectFirstItem = async () => {
|
||||||
const item = this.getFirstNonProtectedItem()
|
const item = this.getFirstNonProtectedItem()
|
||||||
|
|
||||||
if (item) {
|
if (item) {
|
||||||
await this.selectItemWithScrollHandling(item, {
|
await this.selectionController.selectItemWithScrollHandling(item, {
|
||||||
userTriggered: false,
|
userTriggered: false,
|
||||||
scrollIntoView: false,
|
scrollIntoView: false,
|
||||||
})
|
})
|
||||||
@@ -576,77 +560,21 @@ export class ItemListController extends AbstractViewController implements Intern
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
selectNextItem = () => {
|
|
||||||
const displayableItems = this.items
|
|
||||||
|
|
||||||
const currentIndex = displayableItems.findIndex((candidate) => {
|
|
||||||
return candidate.uuid === this.selectionController.lastSelectedItem?.uuid
|
|
||||||
})
|
|
||||||
|
|
||||||
let nextIndex = currentIndex + 1
|
|
||||||
|
|
||||||
while (nextIndex < displayableItems.length) {
|
|
||||||
const nextItem = displayableItems[nextIndex]
|
|
||||||
|
|
||||||
nextIndex++
|
|
||||||
|
|
||||||
if (nextItem.protected) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
this.selectItemWithScrollHandling(nextItem, { userTriggered: true }).catch(console.error)
|
|
||||||
|
|
||||||
const nextNoteElement = document.getElementById(nextItem.uuid)
|
|
||||||
|
|
||||||
nextNoteElement?.focus()
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
selectNextItemOrCreateNewNote = async () => {
|
selectNextItemOrCreateNewNote = async () => {
|
||||||
const item = this.getFirstNonProtectedItem()
|
const item = this.getFirstNonProtectedItem()
|
||||||
|
|
||||||
if (item) {
|
if (item) {
|
||||||
await this.selectItemWithScrollHandling(item, {
|
await this.selectionController
|
||||||
userTriggered: false,
|
.selectItemWithScrollHandling(item, {
|
||||||
scrollIntoView: false,
|
userTriggered: false,
|
||||||
}).catch(console.error)
|
scrollIntoView: false,
|
||||||
|
})
|
||||||
|
.catch(console.error)
|
||||||
} else {
|
} else {
|
||||||
await this.createNewNote()
|
await this.createNewNote()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
selectPreviousItem = () => {
|
|
||||||
const displayableItems = this.items
|
|
||||||
|
|
||||||
if (!this.selectionController.lastSelectedItem) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const currentIndex = displayableItems.indexOf(this.selectionController.lastSelectedItem)
|
|
||||||
|
|
||||||
let previousIndex = currentIndex - 1
|
|
||||||
|
|
||||||
while (previousIndex >= 0) {
|
|
||||||
const previousItem = displayableItems[previousIndex]
|
|
||||||
|
|
||||||
previousIndex--
|
|
||||||
|
|
||||||
if (previousItem.protected) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
this.selectItemWithScrollHandling(previousItem, { userTriggered: true }).catch(console.error)
|
|
||||||
|
|
||||||
const previousNoteElement = document.getElementById(previousItem.uuid)
|
|
||||||
|
|
||||||
previousNoteElement?.focus()
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setNoteFilterText = (text: string) => {
|
setNoteFilterText = (text: string) => {
|
||||||
if (text === this.noteFilterText) {
|
if (text === this.noteFilterText) {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -201,7 +201,6 @@ export class NotesController extends AbstractViewController {
|
|||||||
const notesDeleted = await this.deleteNotes(false)
|
const notesDeleted = await this.deleteNotes(false)
|
||||||
if (notesDeleted) {
|
if (notesDeleted) {
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
this.unselectNotes()
|
|
||||||
this.contextMenuOpen = false
|
this.contextMenuOpen = false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -210,7 +209,6 @@ export class NotesController extends AbstractViewController {
|
|||||||
mutator.trashed = trashed
|
mutator.trashed = trashed
|
||||||
})
|
})
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
this.unselectNotes()
|
|
||||||
this.contextMenuOpen = false
|
this.contextMenuOpen = false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -242,10 +240,10 @@ export class NotesController extends AbstractViewController {
|
|||||||
confirmButtonStyle: 'danger',
|
confirmButtonStyle: 'danger',
|
||||||
})
|
})
|
||||||
) {
|
) {
|
||||||
|
this.selectionController.selectNextItem()
|
||||||
if (permanently) {
|
if (permanently) {
|
||||||
for (const note of this.getSelectedNotesList()) {
|
for (const note of this.getSelectedNotesList()) {
|
||||||
await this.application.mutator.deleteItem(note)
|
await this.application.mutator.deleteItem(note)
|
||||||
this.selectionController.deselectItem(note)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
await this.changeSelectedNotes((mutator) => {
|
await this.changeSelectedNotes((mutator) => {
|
||||||
|
|||||||
@@ -221,4 +221,78 @@ export class SelectedItemsController extends AbstractViewController {
|
|||||||
didSelect: this.selectedItems[uuid] != undefined,
|
didSelect: this.selectedItems[uuid] != undefined,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
selectItemWithScrollHandling = async (
|
||||||
|
item: {
|
||||||
|
uuid: ListableContentItem['uuid']
|
||||||
|
},
|
||||||
|
{ userTriggered = false, scrollIntoView = true },
|
||||||
|
): Promise<void> => {
|
||||||
|
const { didSelect } = await this.selectItem(item.uuid, userTriggered)
|
||||||
|
|
||||||
|
if (didSelect && scrollIntoView) {
|
||||||
|
const itemElement = document.getElementById(item.uuid)
|
||||||
|
itemElement?.scrollIntoView({
|
||||||
|
behavior: 'smooth',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
selectNextItem = () => {
|
||||||
|
const displayableItems = this.itemListController.items
|
||||||
|
|
||||||
|
const currentIndex = displayableItems.findIndex((candidate) => {
|
||||||
|
return candidate.uuid === this.lastSelectedItem?.uuid
|
||||||
|
})
|
||||||
|
|
||||||
|
let nextIndex = currentIndex + 1
|
||||||
|
|
||||||
|
while (nextIndex < displayableItems.length) {
|
||||||
|
const nextItem = displayableItems[nextIndex]
|
||||||
|
|
||||||
|
nextIndex++
|
||||||
|
|
||||||
|
if (nextItem.protected) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
this.selectItemWithScrollHandling(nextItem, { userTriggered: true }).catch(console.error)
|
||||||
|
|
||||||
|
const nextNoteElement = document.getElementById(nextItem.uuid)
|
||||||
|
|
||||||
|
nextNoteElement?.focus()
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
selectPreviousItem = () => {
|
||||||
|
const displayableItems = this.itemListController.items
|
||||||
|
|
||||||
|
if (!this.lastSelectedItem) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentIndex = displayableItems.indexOf(this.lastSelectedItem)
|
||||||
|
|
||||||
|
let previousIndex = currentIndex - 1
|
||||||
|
|
||||||
|
while (previousIndex >= 0) {
|
||||||
|
const previousItem = displayableItems[previousIndex]
|
||||||
|
|
||||||
|
previousIndex--
|
||||||
|
|
||||||
|
if (previousItem.protected) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
this.selectItemWithScrollHandling(previousItem, { userTriggered: true }).catch(console.error)
|
||||||
|
|
||||||
|
const previousNoteElement = document.getElementById(previousItem.uuid)
|
||||||
|
|
||||||
|
previousNoteElement?.focus()
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user