From 42ebf8d99244147c489fc805fa587ab75dd8dc62 Mon Sep 17 00:00:00 2001 From: Shawn Yuan <128874481+shuaiyuanxx@users.noreply.github.com> Date: Thu, 13 Nov 2025 10:19:43 +0800 Subject: [PATCH] Fix AP system prompt textbox display issue (#43486) ## Summary of the Pull Request This pull request refactors how the system prompt is managed and displayed in the Advanced Paste settings UI. The main improvements center around normalizing the system prompt value, ensuring placeholder prompts are handled consistently, and updating the logic for switching between advanced and simple AI modes. These changes help prevent placeholder text from being mistakenly saved as a custom system prompt and improve maintainability. **System prompt normalization and placeholder handling:** * Added static normalization for both `AdvancedAISystemPrompt` and `SimpleAISystemPrompt`, and introduced logic to clear the system prompt if it matches a placeholder value. This prevents default placeholder text from being persisted as a custom prompt. [[1]](diffhunk://#diff-14126907329c7fcd49dd33bab32283296c7dd68ddc3902163a482a3b3ce58d36R39-R40) [[2]](diffhunk://#diff-14126907329c7fcd49dd33bab32283296c7dd68ddc3902163a482a3b3ce58d36R942-R982) * Refactored event handlers to use the new normalization logic and updated the placeholder switching mechanism when toggling between advanced and simple AI modes. * Ensured system prompt normalization is applied when saving provider configuration, further enforcing consistent prompt handling. **UI improvements:** * Removed hard-coded placeholder text from the XAML, ensuring that the placeholder is now dynamically set based on the current mode and normalized prompt value. * Updated the logic for setting the system prompt textbox placeholder to use the new normalization and mode detection methods, improving clarity and reducing potential user confusion. ## PR Checklist - [ ] Closes: #xxx - [ ] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [ ] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx ## Detailed Description of the Pull Request / Additional comments ## Validation Steps Performed Signed-off-by: Shawn Yuan (from Dev Box) --- .../SettingsXAML/Views/AdvancedPastePage.xaml | 2 +- .../Views/AdvancedPastePage.xaml.cs | 61 +++++++++++++------ 2 files changed, 42 insertions(+), 21 deletions(-) diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Views/AdvancedPastePage.xaml b/src/settings-ui/Settings.UI/SettingsXAML/Views/AdvancedPastePage.xaml index bc7f8f82fe..948ae49786 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Views/AdvancedPastePage.xaml +++ b/src/settings-ui/Settings.UI/SettingsXAML/Views/AdvancedPastePage.xaml @@ -533,7 +533,7 @@ MinHeight="76" HorizontalAlignment="Stretch" AcceptsReturn="True" - PlaceholderText="You are tasked with reformatting user's clipboard data. Use the user's instructions, and the content of their clipboard below to edit their clipboard content as they have requested it. Do not output anything else besides the reformatted clipboard content." + Header="System prompt" Text="{x:Bind ViewModel.PasteAIProviderDraft.SystemPrompt, Mode=TwoWay}" TextWrapping="Wrap" /> HasServicePrivacyLink(serviceType) ? Visibility.Visible : Visibility.Collapsed; - private void UpdateSystemPromptPlaceholder() + private static bool IsPlaceholderSystemPrompt(string prompt) { - var draft = ViewModel?.PasteAIProviderDraft; - if (draft is null || PasteAISystemPromptTextBox is null) + if (string.IsNullOrWhiteSpace(prompt)) + { + return true; + } + + string trimmedPrompt = prompt.Trim(); + return string.Equals(trimmedPrompt, AdvancedAISystemPromptNormalized, StringComparison.Ordinal) + || string.Equals(trimmedPrompt, SimpleAISystemPromptNormalized, StringComparison.Ordinal); + } + + private static void NormalizeSystemPrompt(PasteAIProviderDefinition draft) + { + if (draft is null) { return; } - PasteAISystemPromptTextBox.PlaceholderText = draft.EnableAdvancedAI + if (IsPlaceholderSystemPrompt(draft.SystemPrompt)) + { + draft.SystemPrompt = string.Empty; + } + } + + private void UpdateSystemPromptPlaceholder() + { + var draft = ViewModel?.PasteAIProviderDraft; + if (draft is null) + { + return; + } + + NormalizeSystemPrompt(draft); + if (PasteAISystemPromptTextBox is null) + { + return; + } + + bool useAdvancedPlaceholder = PasteAIEnableAdvancedAICheckBox?.IsOn ?? draft.EnableAdvancedAI; + PasteAISystemPromptTextBox.PlaceholderText = useAdvancedPlaceholder ? AdvancedAISystemPrompt : SimpleAISystemPrompt; }