Skip to content

Custom AI keys: {clipboard} placeholder and "Prepend result" - #1032

Open
4di-hello wants to merge 1 commit into
LeanBitLab:mainfrom
4di-hello:pr/ai-key-clipboard-prepend
Open

4di-hello wants to merge 1 commit into
LeanBitLab:mainfrom
4di-hello:pr/ai-key-clipboard-prepend

Conversation

@4di-hello

Copy link
Copy Markdown
Contributor

Adds {clipboard} placeholder support and a #prepend ("Prepend result") modifier for custom AI keys:

  • {clipboard} placeholder: Inserts the current clipboard text into the prompt (for example, to draft a reply to a copied message without pasting it into the field first). Clips marked sensitive (EXTRA_IS_SENSITIVE) and image clips (image/* or image URIs) are skipped.
  • Safe placeholder handling: Placeholders ignore case and whitespace ({Text}, { clipboard }). When a prompt uses {clipboard} without {text}, the field text is not sent and the key also works in an empty field (both offline and standard). When both {text} and {clipboard} are used, they are substituted in a single pass so placeholders inside either text are not expanded twice; an empty field is caught when {text} is used. {text} is now also supported in the standard (online) ProofreadService (offline/ProofreadService.kt is left untouched to avoid conflicts with Offline AI: performance settings, thinking mode, speed display and real cancel (for plugin 1.1.0) #994).
  • #prepend ("Prepend result"): Inserts the AI result at the cursor, or before the selected text (including backwards selections), separated by empty lines (handling LF and CRLF) while keeping the rest of the text intact. #append and #prepend are mutually exclusive in the configuration UI and normalized on load.

Tested

  • ./gradlew testOfflineDebugUnitTest --tests helium314.keyboard.latin.utils.CustomAIKeyTextTest --tests helium314.keyboard.latin.InputLogicTest — passed (12/12 + 191/192, 1 pre-existing @Ignore skipped)
  • ./gradlew testStandardDebugUnitTest --tests helium314.keyboard.latin.utils.CustomAIKeyTextTest --tests helium314.keyboard.latin.InputLogicTest — passed (12/12 + 191/192, 1 pre-existing @Ignore skipped)
  • Feature in daily use in my fork (LeanType+); the v4.4.0 port and review fixes above have not been manually tested on a physical device yet.

- {clipboard} inserts the clipboard text into the prompt (useful e.g. to draft a reply to a copied message without pasting it into the field). Clips marked sensitive (EXTRA_IS_SENSITIVE) and image clips (image/* or image URIs) are skipped.
- If a prompt uses {clipboard} without {text}, the field text is not sent and the key also works in an empty field (offline & standard). When both {text} and {clipboard} are present, they are substituted in a single pass so placeholders inside either text are not expanded twice; an empty field is caught when {text} is used.
- {text} placeholder is now also supported in the standard (online) ProofreadService, and placeholders ignore case and whitespace ({Text}, { clipboard }).
- #prepend ("Prepend result") inserts the result at the cursor, or before the selection (including backwards selections), separated by empty lines (handling both LF and CRLF); the rest of the text stays. #append and #prepend are mutually exclusive in the UI and normalized on load.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant