refactor: simplify state methods
This commit is contained in:
@@ -62,34 +62,21 @@ export class ActiveNoteState {
|
|||||||
this.tagsContainerMaxWidth = width;
|
this.tagsContainerMaxWidth = width;
|
||||||
}
|
}
|
||||||
|
|
||||||
getTagElement(tag: SNTag): HTMLButtonElement | undefined {
|
|
||||||
const tagIndex = this.getTagIndex(tag);
|
|
||||||
if (tagIndex > -1 && this.tagElements.length > tagIndex) {
|
|
||||||
return this.tagElements[tagIndex];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getTagIndex(tag: SNTag): number {
|
getTagIndex(tag: SNTag): number {
|
||||||
return this.tags.findIndex(t => t.uuid === tag.uuid);
|
return this.tags.findIndex(t => t.uuid === tag.uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
getPreviousTagElement(tag: SNTag): HTMLButtonElement | undefined {
|
getPreviousTagElement(tag: SNTag): HTMLButtonElement | undefined {
|
||||||
const previousTagIndex = this.getTagIndex(tag) - 1;
|
const previousTagIndex = this.getTagIndex(tag) - 1;
|
||||||
if (previousTagIndex > -1 && this.tags.length > previousTagIndex) {
|
if (previousTagIndex > -1 && this.tagElements.length > previousTagIndex) {
|
||||||
const previousTag = this.tags[previousTagIndex];
|
return this.tagElements[previousTagIndex];
|
||||||
if (previousTag) {
|
|
||||||
return this.getTagElement(previousTag);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getNextTagElement(tag: SNTag): HTMLButtonElement | undefined {
|
getNextTagElement(tag: SNTag): HTMLButtonElement | undefined {
|
||||||
const nextTagIndex = this.getTagIndex(tag) + 1;
|
const nextTagIndex = this.getTagIndex(tag) + 1;
|
||||||
if (nextTagIndex > -1 && this.tags.length > nextTagIndex) {
|
if (nextTagIndex > -1 && this.tagElements.length > nextTagIndex) {
|
||||||
const previousTag = this.tags[nextTagIndex];
|
return this.tagElements[nextTagIndex];
|
||||||
if (previousTag) {
|
|
||||||
return this.getTagElement(previousTag);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user