feat(editor): implement US-EDITOR-UX with global block selection, redesigned slash menu (favorites & preview), contextual placeholders, smart paste extended, turn into and undo/redo toasts
This commit is contained in:
48
memento-note/lib/editor/undo-redo-feedback-extension.ts
Normal file
48
memento-note/lib/editor/undo-redo-feedback-extension.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { Extension } from '@tiptap/core'
|
||||
import { toast } from 'sonner'
|
||||
|
||||
/**
|
||||
* Extension TipTap qui intercepte les commandes d'annulation (Undo) et de rétablissement (Redo)
|
||||
* pour lever un toast discret (2 secondes) de confirmation, en indiquant dynamiquement le raccourci de l'action inverse selon l'OS.
|
||||
*/
|
||||
export const UndoRedoFeedbackExtension = Extension.create({
|
||||
name: 'undoRedoFeedback',
|
||||
|
||||
addKeyboardShortcuts() {
|
||||
const isMac = typeof window !== 'undefined' && /Mac|iPod|iPhone|iPad/.test(navigator.userAgent)
|
||||
const modKey = isMac ? '⌘' : 'Ctrl'
|
||||
|
||||
return {
|
||||
'Mod-z': () => {
|
||||
const success = this.editor.commands.undo()
|
||||
if (success) {
|
||||
toast.info('Action annulée', {
|
||||
description: `Faites ${modKey}+Maj+Z pour rétablir.`,
|
||||
duration: 2000,
|
||||
})
|
||||
}
|
||||
return success
|
||||
},
|
||||
'Mod-y': () => {
|
||||
const success = this.editor.commands.redo()
|
||||
if (success) {
|
||||
toast.info('Action rétablie', {
|
||||
description: `Faites ${modKey}+Z pour annuler.`,
|
||||
duration: 2000,
|
||||
})
|
||||
}
|
||||
return success
|
||||
},
|
||||
'Mod-Shift-z': () => {
|
||||
const success = this.editor.commands.redo()
|
||||
if (success) {
|
||||
toast.info('Action rétablie', {
|
||||
description: `Faites ${modKey}+Z pour annuler.`,
|
||||
duration: 2000,
|
||||
})
|
||||
}
|
||||
return success
|
||||
},
|
||||
}
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user