[KBM] Use TSF4 API to support text expand feature#46869
[KBM] Use TSF4 API to support text expand feature#46869
Conversation
Add a new "Expand" trigger type that allows users to define text expansion mappings (type abbreviation → expand to full text) in the Keyboard Manager editor. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Manually sync SwitchPresenter.Value after programmatic ComboBox item changes, since WinUI binding on SelectedItem.Tag does not reliably update when items are cleared and replaced at runtime. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace XAML binding on SwitchPresenter.Value with code-behind sync to avoid binding/direct-assignment conflict when ComboBox items are dynamically replaced for the Expand trigger type. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…eWith case When Text Expand trigger is selected, select the existing "Insert text" ComboBoxItem, override its label/icon to "Replace with", and disable the ComboBox. This avoids dynamic ComboBox item replacement that broke the SwitchPresenter binding. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace `new ResourceLoader()` with a string literal since the EditorUI runs as an unpackaged app where ResourceLoader is not supported. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Implement the engine-side logic for the Text Expand feature using Windows TSF4 (Text Services Framework 4) APIs. When a trigger key is pressed, the engine reads the last N characters from the focused text box via TSF4 and replaces the abbreviation with expanded text — without touching the clipboard. - Add Tsf4TextReplacer (Initialize/TryExpand/Shutdown) with LAF unlock - Add ExpandMapping data structure, JSON load/save in MappingConfiguration - Add HandleExpandTextEvent in keyboard event pipeline - Wire C# editor to persist expand mappings to engine config (default.json) - Add TSF4 support status card in Settings UI (KBM page) - Disable Text Expand option in KBM editor when OS lacks TSF4 support - Register KeyboardManagerEngine in sparse package manifest for identity Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Set IsTsf4Supported() to Build >= 10000 so all Windows 10/11 machines pass the check. This enables testing the Text Expand UI flow on any dev machine. The threshold will be raised to the correct build number before shipping. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
EnableShortcut, DisableShortcut, and HandleShortcutDelete did not recognize ExpandMapping, falling through to incorrect single-key or multi-key branches. Add explicit ExpandMapping handling that calls AddExpandMapping/DeleteExpandMapping on the engine config. Also add DeleteExpandMapping C++ interop (matches by abbreviation + app name). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
| { | ||
| if (shortcut is ExpandMapping) | ||
| { | ||
| ShortcutKeyMapping skm = SettingsManager.EditorSettings.ShortcutSettingsDictionary[shortcut.Id].Shortcut; |
| ShortcutKeyMapping skm = SettingsManager.EditorSettings.ShortcutSettingsDictionary[shortcut.Id].Shortcut; | ||
| if (shortcut.IsActive) | ||
| { | ||
| _mappingService!.DeleteExpandMapping(skm.OriginalKeys, skm.TargetApp); |
| ShortcutKeyMapping skm = SettingsManager.EditorSettings.ShortcutSettingsDictionary[shortcut.Id].Shortcut; | ||
| if (shortcut.IsActive) | ||
| { | ||
| _mappingService!.DeleteExpandMapping(skm.OriginalKeys, skm.TargetApp); |
|
|
||
| if (shortcut is ExpandMapping expandMapping) | ||
| { | ||
| ShortcutKeyMapping skm = SettingsManager.EditorSettings.ShortcutSettingsDictionary[shortcut.Id].Shortcut; |
| if (shortcut is ExpandMapping expandMapping) | ||
| { | ||
| ShortcutKeyMapping skm = SettingsManager.EditorSettings.ShortcutSettingsDictionary[shortcut.Id].Shortcut; | ||
| int triggerKeyVk = KeyboardManagerInterop.GetKeyCodeFromName(skm.TargetKeys); |
| { | ||
| try | ||
| { | ||
| std::wstring attestation = std::wstring(LafPublisherId) + L" has registered their use of " + LafFeatureId + L" with Microsoft and agrees to the terms of use."; |
| auto result = winrt::Windows::ApplicationModel::LimitedAccessFeatures::TryUnlockFeature( | ||
| LafFeatureId, LafToken, attestation); | ||
|
|
||
| Logger::info(L"TSF4 LAF unlock status: {}", static_cast<int>(result.Status())); |
| } | ||
| catch (const winrt::hresult_error& ex) | ||
| { | ||
| Logger::warn(L"TSF4 LAF unlock failed: {}", ex.message().c_str()); |
| } | ||
| catch (...) | ||
| { | ||
| Logger::warn(L"TSF4 LAF unlock failed (no package identity?)"); |
|
|
||
| public ICommand OpenWindowsUpdateCommand => new RelayCommand(() => | ||
| { | ||
| Process.Start(new ProcessStartInfo("ms-settings:windowsupdate") { UseShellExecute = true }); |
This comment has been minimized.
This comment has been minimized.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
# Conflicts: # src/modules/keyboardmanager/KeyboardManagerEditorUI/Controls/UnifiedMappingControl.xaml.cs # src/modules/keyboardmanager/KeyboardManagerEditorUI/Helpers/ValidationHelper.cs # src/modules/keyboardmanager/KeyboardManagerEditorUI/Pages/MainPage.xaml # src/modules/keyboardmanager/KeyboardManagerEditorUI/Pages/MainPage.xaml.cs # src/modules/keyboardmanager/KeyboardManagerEditorUI/Strings/en-US/Resources.resw
@check-spelling-bot Report🔴 Please reviewSee the 📂 files view, the 📜action log, 👼 SARIF report, or 📝 job summary for details.Unrecognized words (1)laf These words are not needed and should be removedIPREVIEW ITHUMBNAIL Laf LPCFHOOKPROC LUMA MAXDWORD MRT suntimes timespan VSyncTo accept these unrecognized words as correct and remove the previously acknowledged and now absent words, you could run the following commands... in a clone of the git@github.com:microsoft/PowerToys.git repository curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/cfb6f7e75bbfc89c71eaa30366d0c166f1bd9c8c/apply.pl' |
perl - 'https://github.com/microsoft/PowerToys/actions/runs/24231427788/attempts/1' &&
git commit -m 'Update check-spelling metadata'OR To have the bot accept them for you, comment in the PR quoting the following line: If the flagged items are 🤯 false positivesIf items relate to a ...
|
Summary of the Pull Request
Currently only on MVP stage.
TBD;
Requirement:
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed