Files
Momento/memento-note/lib/editor/undo-redo-feedback-extension.ts
Antigravity ce596fa947
Some checks failed
CI / Deploy production (on server) (push) Has been cancelled
CI / Lint, Unit Tests & Build (push) Has been cancelled
fix: i18n complet — mobile, backlinks, undo/redo, content-area
- mobile-action-sheet.tsx: 15 chaînes → t()
- wikilinks-backlinks-panel.tsx: 3 chaînes → t() + import useLanguage
- note-content-area.tsx: 'Cliquez pour éditer' → t()
- undo-redo-feedback-extension.ts: strings → options configurables
- i18n FR/EN: 11 nouvelles clés (mobile.*, editor.*)
- SlashPreview et SlashCommand: déjà OK (i18n via localCommands)
2026-06-20 16:25:49 +00:00

59 lines
1.6 KiB
TypeScript

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',
addOptions() {
return {
undoText: 'Action annulée',
undoHint: 'Faites {key}+Maj+Z pour rétablir.',
redoText: 'Action rétablie',
redoHint: 'Faites {key}+Z pour annuler.',
}
},
addKeyboardShortcuts() {
const isMac = typeof window !== 'undefined' && /Mac|iPod|iPhone|iPad/.test(navigator.userAgent)
const modKey = isMac ? '⌘' : 'Ctrl'
const o = this.options
return {
'Mod-z': () => {
const success = this.editor.commands.undo()
if (success) {
toast.info(o.undoText, {
description: o.undoHint.replace('{key}', modKey),
duration: 2000,
})
}
return success
},
'Mod-y': () => {
const success = this.editor.commands.redo()
if (success) {
toast.info(o.redoText, {
description: o.redoHint.replace('{key}', modKey),
duration: 2000,
})
}
return success
},
'Mod-Shift-z': () => {
const success = this.editor.commands.redo()
if (success) {
toast.info(o.redoText, {
description: o.redoHint.replace('{key}', modKey),
duration: 2000,
})
}
return success
},
}
},
})