feat(core): moteur PromptKey — bibliothèque .md, variables, injection, raccourcis
- PromptStore/Frontmatter : un prompt = un fichier Markdown, en-tête au sous-ensemble strict du document d'architecture (§7), écriture UTF-8 - VariableEngine : variables typées + automatiques (selection, clipboard, date, app, cursor), résolution et profils de destination - Injector/ClipboardGuard : focus capturé/rendu, presse-papiers sauvegardé puis restauré conditionnellement, aucun envoi automatique par défaut - Search : classement flou insensible aux accents, pondéré par l'usage - UsageStats (usage.json), HotkeyManager (conflits signalés, jamais muets) - Settings : config.ini + profils par IA (claude, chatgpt, qwen, terminal…) - PromptKey.ahk : tray, instance unique, capture du contexte, surveillance de la bibliothèque, installation du pack au premier lancement
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
; ClipboardGuard.ahk — Sauvegarde / restauration sûre du presse-papiers (architecture §11.3).
|
||||
; Règle : on ne restaure que si le presse-papiers contient encore exactement ce qu'on y a mis ;
|
||||
; si l'utilisateur a copié autre chose entre-temps, on abandonne sans rien écraser.
|
||||
|
||||
class ClipboardGuard {
|
||||
Saved := "" ; ClipboardAll sauvegardé
|
||||
HasSaved := false
|
||||
InjectedText := ""
|
||||
|
||||
Save() {
|
||||
try this.Saved := ClipboardAll()
|
||||
this.HasSaved := true
|
||||
}
|
||||
|
||||
ClearSave() {
|
||||
this.Saved := ""
|
||||
this.HasSaved := false
|
||||
this.InjectedText := ""
|
||||
}
|
||||
|
||||
; À appeler après l'injection (via minuterie) : restauration conditionnelle.
|
||||
RestoreIfUnchanged() {
|
||||
if (!this.HasSaved)
|
||||
return
|
||||
current := ""
|
||||
try current := A_Clipboard
|
||||
if (current = this.InjectedText) {
|
||||
try A_Clipboard := this.Saved
|
||||
}
|
||||
this.ClearSave()
|
||||
}
|
||||
|
||||
; Mode sensitive (§18, point 6) : vider plutôt que restaurer.
|
||||
WipeIfUnchanged() {
|
||||
if (!this.HasSaved)
|
||||
return
|
||||
current := ""
|
||||
try current := A_Clipboard
|
||||
if (current = this.InjectedText)
|
||||
A_Clipboard := ""
|
||||
this.ClearSave()
|
||||
}
|
||||
|
||||
; Capture best-effort du texte sélectionné dans l'application active (§11.2).
|
||||
; Sauvegarde le presse-papiers, simule Ctrl+C, lit, restaure immédiatement.
|
||||
; Retourne "" si rien n'est sélectionné ou si la capture échoue — sans jamais lever d'erreur.
|
||||
static CaptureSelection() {
|
||||
saved := ""
|
||||
try saved := ClipboardAll()
|
||||
result := ""
|
||||
try {
|
||||
A_Clipboard := ""
|
||||
Send("^c")
|
||||
if ClipWait(0.25) {
|
||||
if DllCall("IsClipboardFormatAvailable", "UInt", 13) ; CF_UNICODETEXT
|
||||
result := A_Clipboard
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (saved != "")
|
||||
A_Clipboard := saved
|
||||
else
|
||||
A_Clipboard := ""
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
static ClipboardText() {
|
||||
txt := ""
|
||||
try {
|
||||
if DllCall("IsClipboardFormatAvailable", "UInt", 13)
|
||||
txt := A_Clipboard
|
||||
}
|
||||
return txt
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user