mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-21 09:15:35 +00:00
Bug 1593683 - Part 1. Restore caret position after committing composition. r=geckoview-reviewers,esawin
When calling `InputConnection.finishComposingText` commits composition string, but caret position isn't changed. But `RemoveComposition(COMMIT_IME_COMPOSITION)` sets caret position to end of string. So we have to restore caret position after calling `RemoveComposition(COMMIT_IME_COMPOSITION)` via `finishComposingText`. Differential Revision: https://phabricator.services.mozilla.com/D76657
This commit is contained in:
parent
d52843b372
commit
605c87a3ce
@ -1138,12 +1138,56 @@ void GeckoEditableSupport::OnImeRequestCursorUpdates(int aRequestMode) {
|
||||
mIMEMonitorCursor = (aRequestMode == EditableClient::START_MONITOR);
|
||||
}
|
||||
|
||||
class MOZ_STACK_CLASS AutoSelectionRestore final {
|
||||
public:
|
||||
explicit AutoSelectionRestore(nsIWidget* widget) : mWidget(widget) {
|
||||
MOZ_ASSERT(widget);
|
||||
WidgetQueryContentEvent selection(true, eQuerySelectedText, widget);
|
||||
nsEventStatus status = nsEventStatus_eIgnore;
|
||||
widget->DispatchEvent(&selection, status);
|
||||
if (!selection.mSucceeded) {
|
||||
mOffset = UINT32_MAX;
|
||||
mLength = UINT32_MAX;
|
||||
return;
|
||||
}
|
||||
|
||||
mOffset = selection.mReply.mOffset;
|
||||
mLength = selection.mReply.mString.Length();
|
||||
}
|
||||
|
||||
~AutoSelectionRestore() {
|
||||
if (mWidget->Destroyed() || mOffset == UINT32_MAX) {
|
||||
return;
|
||||
}
|
||||
|
||||
WidgetSelectionEvent selection(true, eSetSelection, mWidget);
|
||||
selection.mOffset = mOffset;
|
||||
selection.mLength = mLength;
|
||||
selection.mExpandToClusterBoundary = false;
|
||||
selection.mReason = nsISelectionListener::IME_REASON;
|
||||
nsEventStatus status = nsEventStatus_eIgnore;
|
||||
mWidget->DispatchEvent(&selection, status);
|
||||
}
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIWidget> mWidget;
|
||||
uint32_t mOffset;
|
||||
uint32_t mLength;
|
||||
};
|
||||
|
||||
void GeckoEditableSupport::OnImeRequestCommit() {
|
||||
if (mIMEMaskEventsCount > 0) {
|
||||
// Not focused.
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIWidget> widget = GetWidget();
|
||||
if (NS_WARN_IF(!widget)) {
|
||||
return;
|
||||
}
|
||||
|
||||
AutoSelectionRestore restore(widget);
|
||||
|
||||
RemoveComposition(COMMIT_IME_COMPOSITION);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user