fix: fix focus on previous tag after tag deletion
This commit is contained in:
@@ -28,14 +28,8 @@ export const NoteTag: FunctionalComponent<Props> = ({ appState, tag }) => {
|
|||||||
const [closeOnBlur] = useCloseOnBlur(contextMenuRef, setContextMenuOpen);
|
const [closeOnBlur] = useCloseOnBlur(contextMenuRef, setContextMenuOpen);
|
||||||
useCloseOnClickOutside(contextMenuRef, setContextMenuOpen);
|
useCloseOnClickOutside(contextMenuRef, setContextMenuOpen);
|
||||||
|
|
||||||
const deleteTag = async () => {
|
const deleteTag = () => {
|
||||||
await appState.activeNote.removeTagFromActiveNote(tag);
|
appState.activeNote.removeTagFromActiveNote(tag);
|
||||||
const previousTag = appState.activeNote.getPreviousTag(tag);
|
|
||||||
|
|
||||||
if (previousTag) {
|
|
||||||
const previousTagElement = appState.activeNote.getTagElement(previousTag);
|
|
||||||
previousTagElement?.focus();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const onTagClick = () => {
|
const onTagClick = () => {
|
||||||
|
|||||||
@@ -203,10 +203,15 @@ export class ActiveNoteState {
|
|||||||
async removeTagFromActiveNote(tag: SNTag): Promise<void> {
|
async removeTagFromActiveNote(tag: SNTag): Promise<void> {
|
||||||
const { activeNote } = this;
|
const { activeNote } = this;
|
||||||
if (activeNote) {
|
if (activeNote) {
|
||||||
|
const previousTag = this.getPreviousTag(tag);
|
||||||
await this.application.changeItem(tag.uuid, (mutator) => {
|
await this.application.changeItem(tag.uuid, (mutator) => {
|
||||||
mutator.removeItemAsRelationship(activeNote);
|
mutator.removeItemAsRelationship(activeNote);
|
||||||
});
|
});
|
||||||
this.application.sync();
|
this.application.sync();
|
||||||
|
if (previousTag) {
|
||||||
|
const previousTagElement = this.getTagElement(previousTag);
|
||||||
|
previousTagElement?.focus();
|
||||||
|
}
|
||||||
this.reloadTags();
|
this.reloadTags();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user