fix: fix focus on previous tag after tag deletion

This commit is contained in:
Antonella Sgarlatta
2021-06-02 18:59:43 -03:00
parent f9c2b19eac
commit 54fbb606eb
2 changed files with 7 additions and 8 deletions

View File

@@ -28,14 +28,8 @@ export const NoteTag: FunctionalComponent<Props> = ({ appState, tag }) => {
const [closeOnBlur] = useCloseOnBlur(contextMenuRef, setContextMenuOpen);
useCloseOnClickOutside(contextMenuRef, setContextMenuOpen);
const deleteTag = async () => {
await appState.activeNote.removeTagFromActiveNote(tag);
const previousTag = appState.activeNote.getPreviousTag(tag);
if (previousTag) {
const previousTagElement = appState.activeNote.getTagElement(previousTag);
previousTagElement?.focus();
}
const deleteTag = () => {
appState.activeNote.removeTagFromActiveNote(tag);
};
const onTagClick = () => {

View File

@@ -203,10 +203,15 @@ export class ActiveNoteState {
async removeTagFromActiveNote(tag: SNTag): Promise<void> {
const { activeNote } = this;
if (activeNote) {
const previousTag = this.getPreviousTag(tag);
await this.application.changeItem(tag.uuid, (mutator) => {
mutator.removeItemAsRelationship(activeNote);
});
this.application.sync();
if (previousTag) {
const previousTagElement = this.getTagElement(previousTag);
previousTagElement?.focus();
}
this.reloadTags();
}
}