Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/configurable-input-method-preedit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wry": minor
---

On Linux, add `WebViewBuilderExtUnix::with_input_method_preedit(bool)` to make the input method preedit configurable. Defaults to `false`, preserving the behavior introduced in wry 0.29.0 (see tauri-apps/tauri#5986). Apps targeting modern webkit2gtk (≥ 2.50) can opt in to inline preedit, which CJK IMEs use to render composition state inside editable elements.
26 changes: 26 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1920,6 +1920,7 @@ impl WebViewBuilderExtAndroid for WebViewBuilder<'_> {
pub(crate) struct PlatformSpecificWebViewAttributes {
extension_path: Option<PathBuf>,
related_view: Option<webkit2gtk::WebView>,
input_method_preedit: bool,
}

#[cfg(any(
Expand Down Expand Up @@ -1950,6 +1951,26 @@ pub trait WebViewBuilderExtUnix<'a> {
/// Creates a new webview sharing the same web process with the provided webview.
/// Useful if you need to link a webview to another, for instance when using the [`WebViewBuilder::with_new_window_req_handler`].
fn with_related_view(self, webview: webkit2gtk::WebView) -> Self;

/// Set whether the WebView's input method context should report
/// preedit text to the application during composition.
///
/// When `true`, IME composition events (`compositionstart`,
/// `compositionupdate`, `compositionend`) fire in the DOM and
/// CJK input methods can render their preedit inline in editable
/// elements. When `false` (the default), preedit is suppressed
/// and the IM falls back to its own popup UI; this matches the
/// behavior introduced in wry 0.29.0 to mitigate
/// popup-positioning issues on older webkit2gtk versions (see
/// [tauri-apps/tauri#5986]).
///
/// On modern webkit2gtk-4.1 (≥ 2.50) inline preedit works
/// correctly with major IMEs (fcitx5, ibus, etc.); apps targeting
/// those environments can opt in here to match the IME UX of
/// native GTK / Firefox / Chromium-based apps.
///
/// [tauri-apps/tauri#5986]: https://github.com/tauri-apps/tauri/issues/5986
fn with_input_method_preedit(self, enabled: bool) -> Self;
}

#[cfg(any(
Expand Down Expand Up @@ -1979,6 +2000,11 @@ impl<'a> WebViewBuilderExtUnix<'a> for WebViewBuilder<'a> {
self.platform_specific.related_view.replace(webview);
self
}

fn with_input_method_preedit(mut self, enabled: bool) -> Self {
self.platform_specific.input_method_preedit = enabled;
self
}
}

/// The fundamental type to present a [`WebView`].
Expand Down
17 changes: 13 additions & 4 deletions src/webkitgtk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ impl InnerWebView {
}

// Webview Settings
Self::set_webview_settings(&webview, &attributes);
Self::set_webview_settings(&webview, &attributes, &pl_attrs);

// Webview handlers
Self::attach_handlers(&webview, web_context, &mut attributes);
Expand Down Expand Up @@ -411,10 +411,19 @@ impl InnerWebView {
builder.build()
}

fn set_webview_settings(webview: &WebView, attributes: &WebViewAttributes) {
// Disable input preedit,fcitx input editor can anchor at edit cursor position
fn set_webview_settings(
webview: &WebView,
attributes: &WebViewAttributes,
pl_attrs: &super::PlatformSpecificWebViewAttributes,
) {
// Configure input method preedit per the platform-specific
// attribute. Default is `false` (disabled) — fcitx-style IMEs
// anchor their popup at the edit cursor (see
// tauri-apps/tauri#5986 for the original motivation). When
// `true`, WebKit reports composition events to the DOM and
// CJK IMEs render preedit inline.
if let Some(input_context) = webview.input_method_context() {
input_context.set_enable_preedit(false);
input_context.set_enable_preedit(pl_attrs.input_method_preedit);
}

// use system scrollbars
Expand Down
Loading