fix: Fixed issue where note context menu would not open if right-clicking multiple times
This commit is contained in:
@@ -43,12 +43,10 @@ const NoteListItem: FunctionComponent<DisplayableListItemProps<SNNote>> = ({
|
|||||||
const hasFiles = application.items.itemsReferencingItem(item).filter(isFile).length > 0
|
const hasFiles = application.items.itemsReferencingItem(item).filter(isFile).length > 0
|
||||||
|
|
||||||
const openNoteContextMenu = (posX: number, posY: number) => {
|
const openNoteContextMenu = (posX: number, posY: number) => {
|
||||||
notesController.setContextMenuOpen(false)
|
|
||||||
notesController.setContextMenuClickLocation({
|
notesController.setContextMenuClickLocation({
|
||||||
x: posX,
|
x: posX,
|
||||||
y: posY,
|
y: posY,
|
||||||
})
|
})
|
||||||
notesController.reloadContextMenuLayout()
|
|
||||||
notesController.setContextMenuOpen(true)
|
notesController.setContextMenuOpen(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import {
|
|||||||
STAR_NOTE_COMMAND,
|
STAR_NOTE_COMMAND,
|
||||||
} from '@standardnotes/ui-services'
|
} from '@standardnotes/ui-services'
|
||||||
import { StringEmptyTrash, Strings, StringUtils } from '@/Constants/Strings'
|
import { StringEmptyTrash, Strings, StringUtils } from '@/Constants/Strings'
|
||||||
import { MENU_MARGIN_FROM_APP_BORDER } from '@/Constants/Constants'
|
|
||||||
import {
|
import {
|
||||||
SNNote,
|
SNNote,
|
||||||
NoteMutator,
|
NoteMutator,
|
||||||
@@ -44,10 +43,6 @@ export class NotesController
|
|||||||
shouldLinkToParentFolders: boolean
|
shouldLinkToParentFolders: boolean
|
||||||
lastSelectedNote: SNNote | undefined
|
lastSelectedNote: SNNote | undefined
|
||||||
contextMenuOpen = false
|
contextMenuOpen = false
|
||||||
contextMenuPosition: { top?: number; left: number; bottom?: number } = {
|
|
||||||
top: 0,
|
|
||||||
left: 0,
|
|
||||||
}
|
|
||||||
contextMenuClickLocation: { x: number; y: number } = { x: 0, y: 0 }
|
contextMenuClickLocation: { x: number; y: number } = { x: 0, y: 0 }
|
||||||
contextMenuMaxHeight: number | 'auto' = 'auto'
|
contextMenuMaxHeight: number | 'auto' = 'auto'
|
||||||
showProtectedWarning = false
|
showProtectedWarning = false
|
||||||
@@ -71,7 +66,6 @@ export class NotesController
|
|||||||
|
|
||||||
makeObservable(this, {
|
makeObservable(this, {
|
||||||
contextMenuOpen: observable,
|
contextMenuOpen: observable,
|
||||||
contextMenuPosition: observable,
|
|
||||||
showProtectedWarning: observable,
|
showProtectedWarning: observable,
|
||||||
|
|
||||||
selectedNotes: computed,
|
selectedNotes: computed,
|
||||||
@@ -81,8 +75,6 @@ export class NotesController
|
|||||||
|
|
||||||
setContextMenuOpen: action,
|
setContextMenuOpen: action,
|
||||||
setContextMenuClickLocation: action,
|
setContextMenuClickLocation: action,
|
||||||
setContextMenuPosition: action,
|
|
||||||
setContextMenuMaxHeight: action,
|
|
||||||
setShowProtectedWarning: action,
|
setShowProtectedWarning: action,
|
||||||
unselectNotes: action,
|
unselectNotes: action,
|
||||||
})
|
})
|
||||||
@@ -175,61 +167,6 @@ export class NotesController
|
|||||||
this.contextMenuClickLocation = location
|
this.contextMenuClickLocation = location
|
||||||
}
|
}
|
||||||
|
|
||||||
setContextMenuPosition(position: { top?: number; left: number; bottom?: number }): void {
|
|
||||||
this.contextMenuPosition = position
|
|
||||||
}
|
|
||||||
|
|
||||||
setContextMenuMaxHeight(maxHeight: number | 'auto'): void {
|
|
||||||
this.contextMenuMaxHeight = maxHeight
|
|
||||||
}
|
|
||||||
|
|
||||||
reloadContextMenuLayout(): void {
|
|
||||||
const { clientHeight } = document.documentElement
|
|
||||||
const defaultFontSize = window.getComputedStyle(document.documentElement).fontSize
|
|
||||||
const maxContextMenuHeight = parseFloat(defaultFontSize) * 30
|
|
||||||
const footerElementRect = document.getElementById('footer-bar')?.getBoundingClientRect()
|
|
||||||
const footerHeightInPx = footerElementRect?.height
|
|
||||||
|
|
||||||
// Open up-bottom is default behavior
|
|
||||||
let openUpBottom = true
|
|
||||||
|
|
||||||
if (footerHeightInPx) {
|
|
||||||
const bottomSpace = clientHeight - footerHeightInPx - this.contextMenuClickLocation.y
|
|
||||||
const upSpace = this.contextMenuClickLocation.y
|
|
||||||
|
|
||||||
// If not enough space to open up-bottom
|
|
||||||
if (maxContextMenuHeight > bottomSpace) {
|
|
||||||
// If there's enough space, open bottom-up
|
|
||||||
if (upSpace > maxContextMenuHeight) {
|
|
||||||
openUpBottom = false
|
|
||||||
this.setContextMenuMaxHeight('auto')
|
|
||||||
// Else, reduce max height (menu will be scrollable) and open in whichever direction there's more space
|
|
||||||
} else {
|
|
||||||
if (upSpace > bottomSpace) {
|
|
||||||
this.setContextMenuMaxHeight(upSpace - MENU_MARGIN_FROM_APP_BORDER)
|
|
||||||
openUpBottom = false
|
|
||||||
} else {
|
|
||||||
this.setContextMenuMaxHeight(bottomSpace - MENU_MARGIN_FROM_APP_BORDER)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.setContextMenuMaxHeight('auto')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (openUpBottom) {
|
|
||||||
this.setContextMenuPosition({
|
|
||||||
top: this.contextMenuClickLocation.y,
|
|
||||||
left: this.contextMenuClickLocation.x,
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
this.setContextMenuPosition({
|
|
||||||
bottom: clientHeight - this.contextMenuClickLocation.y,
|
|
||||||
left: this.contextMenuClickLocation.x,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async changeSelectedNotes(mutate: (mutator: NoteMutator) => void): Promise<void> {
|
async changeSelectedNotes(mutate: (mutator: NoteMutator) => void): Promise<void> {
|
||||||
await this.mutator.changeItems(this.getSelectedNotesList(), mutate, MutationType.NoUpdateUserTimestamps)
|
await this.mutator.changeItems(this.getSelectedNotesList(), mutate, MutationType.NoUpdateUserTimestamps)
|
||||||
this.sync.sync().catch(console.error)
|
this.sync.sync().catch(console.error)
|
||||||
|
|||||||
@@ -62,6 +62,8 @@ export const useLifecycleAnimation = (
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let animation: Animation | undefined
|
||||||
|
|
||||||
if (open) {
|
if (open) {
|
||||||
if (!enter) {
|
if (!enter) {
|
||||||
setIsMounted(true)
|
setIsMounted(true)
|
||||||
@@ -71,7 +73,7 @@ export const useLifecycleAnimation = (
|
|||||||
if (enter.initialStyle) {
|
if (enter.initialStyle) {
|
||||||
Object.assign(element.style, enter.initialStyle)
|
Object.assign(element.style, enter.initialStyle)
|
||||||
}
|
}
|
||||||
const animation = element.animate(
|
animation = element.animate(
|
||||||
prefersReducedMotion && enter.reducedMotionKeyframes ? enter.reducedMotionKeyframes : enter.keyframes,
|
prefersReducedMotion && enter.reducedMotionKeyframes ? enter.reducedMotionKeyframes : enter.keyframes,
|
||||||
{
|
{
|
||||||
...enter.options,
|
...enter.options,
|
||||||
@@ -82,7 +84,12 @@ export const useLifecycleAnimation = (
|
|||||||
.then(() => {
|
.then(() => {
|
||||||
enterCallback?.(element)
|
enterCallback?.(element)
|
||||||
})
|
})
|
||||||
.catch(console.error)
|
.catch((error) => {
|
||||||
|
if (animation?.currentTime === null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
console.error(error)
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
if (!exit) {
|
if (!exit) {
|
||||||
setIsMounted(false)
|
setIsMounted(false)
|
||||||
@@ -92,7 +99,7 @@ export const useLifecycleAnimation = (
|
|||||||
if (exit.initialStyle) {
|
if (exit.initialStyle) {
|
||||||
Object.assign(element.style, exit.initialStyle)
|
Object.assign(element.style, exit.initialStyle)
|
||||||
}
|
}
|
||||||
const animation = element.animate(
|
animation = element.animate(
|
||||||
prefersReducedMotion && exit.reducedMotionKeyframes ? exit.reducedMotionKeyframes : exit.keyframes,
|
prefersReducedMotion && exit.reducedMotionKeyframes ? exit.reducedMotionKeyframes : exit.keyframes,
|
||||||
{
|
{
|
||||||
...exit.options,
|
...exit.options,
|
||||||
@@ -104,7 +111,16 @@ export const useLifecycleAnimation = (
|
|||||||
setIsMounted(false)
|
setIsMounted(false)
|
||||||
exitCallback?.(element)
|
exitCallback?.(element)
|
||||||
})
|
})
|
||||||
.catch(console.error)
|
.catch((error) => {
|
||||||
|
if (animation?.currentTime === null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
console.error(error)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
animation?.cancel()
|
||||||
}
|
}
|
||||||
}, [open, element, enterRef, enterCallbackRef, exitRef, exitCallbackRef, disabled])
|
}, [open, element, enterRef, enterCallbackRef, exitRef, exitCallbackRef, disabled])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user