fix(composer): detect autocomplete from onChange for mobile keyboards (#1669)

<!-- Please read
https://github.com/SableClient/Sable/blob/dev/CONTRIBUTING.md before
submitting your pull request -->

### Description

<!-- Please include a summary of the change. Please also include
relevant motivation and context. List any dependencies that are required
for this change. -->

Fixes #1667

#### Type of change

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update

### Checklist:

- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings

### AI disclosure:

- [ ] Partially AI assisted (clarify which code was AI assisted and
briefly explain what it does).
- [ ] Fully AI generated (explain what all the generated code does in
moderate detail).
<!-- Write any explanation required here, but do not generate the
explanation using AI!! You must prove you understand what the code in
this PR does. -->
This commit is contained in:
Erwan Leboucher authored and GitHub committed 2026-08-07 17:25:10 +00:00
commit f99f936564
5 files changed
+69 -44

No files matched your search

+18 -2
View File
@@ -5188,6 +5188,7 @@ dependencies = [
"cookie_store",
"encoding_rs",
"futures-core",
"futures-util",
"h2 0.4.15",
"http 1.4.2",
"http-body 1.1.0",
@@ -5209,12 +5210,14 @@ dependencies = [
"sync_wrapper 1.0.2",
"tokio",
"tokio-rustls",
"tokio-util",
"tower 0.5.3",
"tower-http 0.6.11",
"tower-service",
"url",
"wasm-bindgen",
"wasm-bindgen-futures",
"wasm-streams 0.4.2",
"web-sys",
"webpki-roots",
]
@@ -5254,7 +5257,7 @@ dependencies = [
"url",
"wasm-bindgen",
"wasm-bindgen-futures",
"wasm-streams",
"wasm-streams 0.5.0",
"web-sys",
]
@@ -5462,7 +5465,7 @@ dependencies = [
"objc2-photos",
"percent-encoding",
"regex",
"reqwest 0.13.4",
"reqwest 0.12.28",
"sentry",
"serde",
"serde_json",
@@ -8190,6 +8193,19 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "wasm-streams"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15053d8d85c7eccdbefef60f06769760a563c7f0a9d6902a13d35c7800b0ad65"
dependencies = [
"futures-util",
"js-sys",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
]
[[package]]
name = "wasm-streams"
version = "0.5.0"
+1 -1
View File
@@ -41,7 +41,7 @@ percent-encoding = "2"
# Enables `stream` (for native_upload's `Body::wrap_stream`) on the reqwest that
# tauri-plugin-http pulls in without it. default-features = false keeps
# openssl-sys out of the Android cross-compile.
reqwest = { version = "0.13", default-features = false, features = ["stream"] }
reqwest = { version = "0.12", default-features = false, features = ["stream"] }
async-stream = "0.3"
base64 = "0.23"
tokio-util = { version = "0.7", features = ["codec"] }
+3 -3
View File
@@ -7,12 +7,12 @@ use std::{
use base64::Engine;
use futures_util::StreamExt;
use reqwest::{
use serde::Serialize;
use tauri::{ipc::Channel, AppHandle, Manager, Runtime};
use tauri_plugin_http::reqwest::{
header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE},
Body, Client, ClientBuilder, Method, Url,
};
use serde::Serialize;
use tauri::{ipc::Channel, AppHandle, Manager, Runtime};
use tokio::{
fs::{File, OpenOptions},
io::AsyncWriteExt,
+37 -32
View File
@@ -607,8 +607,42 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
const dropZoneVisible = useFileDropZone(fileDropContainerRef, handleFiles);
const [hasText, setHasText] = useState(false);
const lastEncryptionPreparationAt = useRef(0);
const detectAutocomplete = useCallback(() => {
const firstPosition = Editor.start(editor, []);
const secondChar = Editor.after(editor, firstPosition, {
distance: 2,
unit: 'character',
});
const quickReactPrefix = Editor.string(
editor,
Editor.range(editor, firstPosition, secondChar)
);
if (quickReactPrefix === '+#') {
setQuickTextReact(true);
setAutocompleteQuery(undefined);
return;
}
setQuickTextReact(false);
const prevWordRange = getPrevWorldRange(editor);
if (!prevWordRange) {
setAutocompleteQuery(undefined);
return;
}
const isRangeAtBeginning = !Point.isAfter(Range.start(prevWordRange), firstPosition);
const query =
(isRangeAtBeginning
? getAutocompleteQuery(editor, prevWordRange, BEGINNING_AUTOCOMPLETE_PREFIXES)
: undefined) ??
getAutocompleteQuery(editor, prevWordRange, ANYWHERE_AUTOCOMPLETE_PREFIXES);
setAutocompleteQuery(query);
}, [editor]);
const handleEditorChange = useCallback(() => {
setHasText(!isEmptyEditor(editor));
detectAutocomplete();
if (!room.hasEncryptionStateEvent()) return;
const now = Date.now();
@@ -616,7 +650,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
lastEncryptionPreparationAt.current = now;
mx.getCrypto()?.prepareToEncrypt(room);
}, [editor, mx, room]);
}, [editor, detectAutocomplete, mx, room]);
const hasContent = hasText || selectedFiles.length > 0;
const isComposing = useComposingCheck();
@@ -1774,38 +1808,9 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
sendTypingStatus(!isEmptyEditor(editor));
}
const firstPosition = Editor.start(editor, []);
const secondChar = Editor.after(editor, firstPosition, {
distance: 2,
unit: 'character',
});
const quickReactPrefix = Editor.string(
editor,
Editor.range(editor, firstPosition, secondChar)
);
if (quickReactPrefix === '+#') {
setQuickTextReact(true);
setAutocompleteQuery(undefined);
return;
}
setQuickTextReact(false);
const prevWordRange = getPrevWorldRange(editor);
if (!prevWordRange) {
setAutocompleteQuery(undefined);
return;
}
const isRangeAtBeginning = !Point.isAfter(Range.start(prevWordRange), firstPosition);
const query =
(isRangeAtBeginning
? getAutocompleteQuery(editor, prevWordRange, BEGINNING_AUTOCOMPLETE_PREFIXES)
: undefined) ??
getAutocompleteQuery(editor, prevWordRange, ANYWHERE_AUTOCOMPLETE_PREFIXES);
setAutocompleteQuery(query);
detectAutocomplete();
},
[editor, sendTypingStatus, hideActivity]
[editor, sendTypingStatus, hideActivity, detectAutocomplete]
);
const handleEmoticonSelect = (key: string, shortcode: string) => {
@@ -337,6 +337,14 @@ export const MessageEditor = as<'div', MessageEditorProps>(
[enterForNewline, isComposing, editor, handleSave, onCancel]
);
const detectAutocomplete = useCallback(() => {
const prevWordRange = getPrevWorldRange(editor);
const query = prevWordRange
? getAutocompleteQuery(editor, prevWordRange, ANYWHERE_AUTOCOMPLETE_PREFIXES)
: undefined;
setAutocompleteQuery(query);
}, [editor]);
const handleKeyUp: KeyboardEventHandler = useCallback(
(evt) => {
if (isKeyHotkey('escape', evt)) {
@@ -344,13 +352,9 @@ export const MessageEditor = as<'div', MessageEditorProps>(
return;
}
const prevWordRange = getPrevWorldRange(editor);
const query = prevWordRange
? getAutocompleteQuery(editor, prevWordRange, ANYWHERE_AUTOCOMPLETE_PREFIXES)
: undefined;
setAutocompleteQuery(query);
detectAutocomplete();
},
[editor]
[detectAutocomplete]
);
const handleCloseAutocomplete = useCallback(() => {