Bug 152519 - SurroundingText is not working in kf5 VCL
Summary: SurroundingText is not working in kf5 VCL
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
7.4.2.3 release
Hardware: All Linux (All)
: medium normal
Assignee: Michael Weghorn
URL:
Whiteboard: target:26.2.0
Keywords:
Depends on:
Blocks: KDE, KF5 Qt6
  Show dependency treegraph
 
Reported: 2022-12-15 13:25 UTC by trmdi
Modified: 2025-09-10 18:56 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments
working in Kate (5.44 MB, video/x-matroska)
2022-12-19 16:20 UTC, trmdi
Details

Note You need to log in before you can comment on or make changes to this bug.
Description trmdi 2022-12-15 13:25:54 UTC
Description:
SurroundingText capability is used by some input method like fcitx, ibus...
It's broken in kf5 vcl but still works in the gtk mode.

Steps to Reproduce:
1. Install fcitx5-unikey and run it
2. With fcitx5-unikey, in Libre Writer, type: g[space][backspace]ias

Actual Results:
gía

Expected Results:
giá


Reproducible: Always


User Profile Reset: No

Additional Info:
.
Comment 1 Michael Weghorn 2022-12-19 13:20:02 UTC
(In reply to trmdi from comment #0)
> Steps to Reproduce:
> 1. Install fcitx5-unikey and run it

Can you please explain in more detail what "run it" means, i.e. how to (set it up if necessary and) run it?

I have installed package "fcitx5-unikey" in Debian testing, but I don't see any obvious executable to just run in the 'dpkg -L fcitx5-unikey' output, so maybe this needs to be set up and run in a certain way with the fcitx framework that I know little about? A step-by-step description to do so would be very helpful here.
Comment 2 Phoenix 2022-12-19 14:32:06 UTC
1) Install fcitx5-unikey
2) Open Fcitx5 and find and add Unikey to current input
3) Run im-config, choose fcitx5, and set fcitx5 to auto start
4) Log out and log in, Ctrl + Space switch im to Unikey and type in LibreOffice
Fcitx5 similar ibus
Comment 3 Michael Weghorn 2022-12-19 15:19:17 UTC
Thanks, I can reproduce the described difference between the gtk3 VCL plugin on the one side and kf5 or qt6 on the other side.

However, this doesn't look LibreOffice-specific to me, since I can reproduce the same with other Gtk/Qt-based applications:

* When I type "g[space][backspace]ias" in gedit (based on gtk), this results in "giá".

* When I type "g[space][backspace]ias" in kate or Konsole (Qt-based), I get "gía".

Therefore, I tend to think that this is probably rather an issue in either Qt or the fcitx Qt integration (package "libfcitx5-qt1"?) instead of LibreOffice and would suggest to report that there instead.

Closing as NOTOURBUG for now due to these observations, but this can of course be reopened if other findings suggest that something actually needs to be done on LO side.


Version: 7.6.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: d640bfe7767292c8a89de57d378dd752a8ec8342
CPU threads: 12; OS: Linux 6.0; UI render: default; VCL: gtk3
Locale: en-GB (en_GB.UTF-8); UI: en-US
Calc: threaded

Version: 7.6.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: d640bfe7767292c8a89de57d378dd752a8ec8342
CPU threads: 12; OS: Linux 6.0; UI render: default; VCL: kf5 (cairo+xcb)
Locale: en-GB (en_GB.UTF-8); UI: en-US
Calc: threaded

Version: 7.6.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: d640bfe7767292c8a89de57d378dd752a8ec8342
CPU threads: 12; OS: Linux 6.0; UI render: default; VCL: qt6 (qfont+xcb)
Locale: en-GB (en_GB.UTF-8); UI: en-US
Calc: threaded
Comment 4 Michael Weghorn 2022-12-19 15:25:48 UTC
(In reply to Michael Weghorn from comment #3)
> Therefore, I tend to think that this is probably rather an issue in either
> Qt or the fcitx Qt integration (package "libfcitx5-qt1"?) instead of
> LibreOffice and would suggest to report that there instead.

i.e., probably here: https://github.com/fcitx/fcitx5-qt/issues (or https://bugreports.qt.io for the Qt case)
Comment 5 trmdi 2022-12-19 16:03:15 UTC
(In reply to Michael Weghorn from comment #3)
> Thanks, I can reproduce the described difference between the gtk3 VCL plugin
> on the one side and kf5 or qt6 on the other side.
> 
> However, this doesn't look LibreOffice-specific to me, since I can reproduce
> the same with other Gtk/Qt-based applications:
> 
> * When I type "g[space][backspace]ias" in gedit (based on gtk), this results
> in "giá".
> 
> * When I type "g[space][backspace]ias" in kate or Konsole (Qt-based), I get
> "gía".
> 
> Therefore, I tend to think that this is probably rather an issue in either
> Qt or the fcitx Qt integration (package "libfcitx5-qt1"?) instead of
> LibreOffice and would suggest to report that there instead.
> 
> Closing as NOTOURBUG for now due to these observations, but this can of
> course be reopened if other findings suggest that something actually needs
> to be done on LO side.
> 
> 
> Version: 7.6.0.0.alpha0+ (X86_64) / LibreOffice Community
> Build ID: d640bfe7767292c8a89de57d378dd752a8ec8342
> CPU threads: 12; OS: Linux 6.0; UI render: default; VCL: gtk3
> Locale: en-GB (en_GB.UTF-8); UI: en-US
> Calc: threaded
> 
> Version: 7.6.0.0.alpha0+ (X86_64) / LibreOffice Community
> Build ID: d640bfe7767292c8a89de57d378dd752a8ec8342
> CPU threads: 12; OS: Linux 6.0; UI render: default; VCL: kf5 (cairo+xcb)
> Locale: en-GB (en_GB.UTF-8); UI: en-US
> Calc: threaded
> 
> Version: 7.6.0.0.alpha0+ (X86_64) / LibreOffice Community
> Build ID: d640bfe7767292c8a89de57d378dd752a8ec8342
> CPU threads: 12; OS: Linux 6.0; UI render: default; VCL: qt6 (qfont+xcb)
> Locale: en-GB (en_GB.UTF-8); UI: en-US
> Calc: threaded

Konsole doesn't support that, but Kate does.
The SurroundingText capability need support from the app. So I opened this request here to get the support from LibreOffice's kf5 vcl.
Comment 6 trmdi 2022-12-19 16:06:18 UTC
> When I type "g[space][backspace]ias" in kate or Konsole (Qt-based), I get "gía".

Probably something's wrong with your setup. It does support that here on my openSUSE Tumbleweed, Kate 22.12.0
Comment 7 trmdi 2022-12-19 16:20:34 UTC
Created attachment 184243 [details]
working in Kate
Comment 8 Xuetian Weng 2022-12-20 00:59:39 UTC
The issue for libreoffice is that, although it implements the surrounding support.
Like: https://github.com/LibreOffice/core/blob/d57836db76fcf3133e6eb54d264c774911015e08/vcl/qt5/QtWidget.cxx#L893

It doesn't seem to notify input method about surrounding changes, which is usually done with QWidget::updateMicroFocus(), or call QGuiApplication::inputMethod()->update(FLAGS).

```
void QWidget::updateMicroFocus()
{
    // updating everything since this is currently called for any kind of state change
    if (this == QGuiApplication::focusObject())
        QGuiApplication::inputMethod()->update(Qt::ImQueryAll);
}
```

I can only find libreoffice's qt implementation notifies about cursor rectangle change at 
https://github.com/LibreOffice/core/blob/d57836db76fcf3133e6eb54d264c774911015e08/vcl/qt5/QtWidget.cxx#L628
Comment 9 Xuetian Weng 2022-12-20 01:35:51 UTC
While it is possible to implement a polling like logic. Retrieving surrounding text is an expensive query, so I'd prefer libreoffice to notify the change instead of letting input method poll it.

Also, the implementation itself seems not working properly. Even if I tried to hack fcitx5-qt to poll the surrounding text by explicitly query the object, it return value for inputMethodQuery(Qt::ImSurroundingText) is still QVariant(Invalid).

So despite of adding qApp->inputMethod()->update(Qt::ImSurroundingText | Qt::ImCursorPosition | Qt::ImAnchorPosition) to a proper place maybe also check if this lcl_retrieveSurrounding actually works.
https://github.com/LibreOffice/core/blob/d57836db76fcf3133e6eb54d264c774911015e08/vcl/qt5/QtWidget.cxx#L897

Gtk counterpart seems to use a different approach for retrieving surrounding
https://github.com/LibreOffice/core/blob/83485052e6cac574754191c59371dbc41383b810/vcl/unx/gtk3/gtkframe.cxx#L5824
Comment 10 Michael Weghorn 2022-12-23 16:18:00 UTC
(In reply to trmdi from comment #6)
> Probably something's wrong with your setup. It does support that here on my
> openSUSE Tumbleweed, Kate 22.12.0

Indeed, was apparently some problem with my setup, since I was using the same Kate version. It works now.

Interestingly, I explicitly have to unset GTK_IM_MODULE (or set it to an empty string) because GTK_IM_MODULE=fcitx breaks the LO Writer use case with gtk3 (still works with Calc or gedit, though...).

(In reply to Xuetian Weng from comment #9)
> While it is possible to implement a polling like logic. Retrieving
> surrounding text is an expensive query, so I'd prefer libreoffice to notify
> the change instead of letting input method poll it.
> 
> Also, the implementation itself seems not working properly. Even if I tried
> to hack fcitx5-qt to poll the surrounding text by explicitly query the
> object, it return value for inputMethodQuery(Qt::ImSurroundingText) is still
> QVariant(Invalid).
> 
> So despite of adding qApp->inputMethod()->update(Qt::ImSurroundingText |
> Qt::ImCursorPosition | Qt::ImAnchorPosition) to a proper place maybe also
> check if this lcl_retrieveSurrounding actually works.
> https://github.com/LibreOffice/core/blob/
> d57836db76fcf3133e6eb54d264c774911015e08/vcl/qt5/QtWidget.cxx#L897
> 
> Gtk counterpart seems to use a different approach for retrieving surrounding
> https://github.com/LibreOffice/core/blob/
> 83485052e6cac574754191c59371dbc41383b810/vcl/unx/gtk3/gtkframe.cxx#L5824

Thank you so much, this is extremely helpful!

I have experimented a bit locally and have had a first quick-and-dirty version that somewhat works (but breaks other things), but needs more work for a proper solution.
Comment 11 QA Administrators 2024-12-23 03:21:38 UTC Comment hidden (obsolete)
Comment 12 trmdi 2024-12-24 12:39:54 UTC
The bug is still present.

Version: 24.8.3.2 (X86_64) / LibreOffice Community
Build ID: 480(Build:2)
CPU threads: 4; OS: Linux 6.11; UI render: default; VCL: kf6 (cairo+wayland)
Locale: en-US (en_US.UTF-8); UI: en-US
Calc: threaded
Comment 13 Phoenix 2025-07-05 04:13:31 UTC
It also don't work on gtk VLC up to now!
Comment 14 Michael Weghorn 2025-07-11 07:02:12 UTC
(In reply to Phoenix from comment #13)
> It also don't work on gtk VLC up to now!

Please create a separate bug report with more details for that, as it was reported to work fine previously (s. initial description here).

And please don't change the version field to a later version just because the problem is still present; it should be set to the earliest version affected.
Comment 15 Michael Weghorn 2025-09-10 10:39:52 UTC
(In reply to Michael Weghorn from comment #10)
> I have experimented a bit locally and have had a first quick-and-dirty
> version that somewhat works (but breaks other things), but needs more work
> for a proper solution.

I'm sorry it took so long, but there is finally a pending change series in Gerrit which makes this work for me:

https://gerrit.libreoffice.org/c/core/+/190748 (and underlying changes)
Comment 16 Commit Notification 2025-09-10 18:45:33 UTC
Michael Weghorn committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/441e80546b54641661d5654f5aa4c3615753733d

tdf#152519 qt: Update more IM query atttributes

It will be available in 26.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 17 Commit Notification 2025-09-10 18:45:36 UTC
Michael Weghorn committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/86bf2e50fc64b8789154f3993567ceeed012e60c

tdf#152519 Distinguish cursor/anchor for IM selection

It will be available in 26.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 18 Commit Notification 2025-09-10 18:45:39 UTC
Michael Weghorn committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/8ebbda5ebe1686f175ed00502d85655ac1977a8e

tdf#152519 vcl: Merge both ImplHandleSalSurroundingTextRequest

It will be available in 26.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 19 Commit Notification 2025-09-10 18:45:41 UTC
Michael Weghorn committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/fc6e57f77e2ba0c6fd2523d8e23e68924963ed76

tdf#152519 vcl: Fix potential copy paste error in IM code

It will be available in 26.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 20 Commit Notification 2025-09-10 18:46:44 UTC
Michael Weghorn committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/ba10746f37b6176d2fa4aca85fc1c786f8e812e2

tdf#152519 vcl: Report IM cursor position

It will be available in 26.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 21 Commit Notification 2025-09-10 18:46:47 UTC
Michael Weghorn committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/d76a7977bc9c808144ce68276ab3509c9dc54865

tdf#152519 qt: Port IM handling from a11y to dedicated API

It will be available in 26.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 22 Michael Weghorn 2025-09-10 18:56:50 UTC
(In reply to Michael Weghorn from comment #15)
> I'm sorry it took so long, but there is finally a pending change series in
> Gerrit which makes this work for me:
> 
> https://gerrit.libreoffice.org/c/core/+/190748 (and underlying changes)

Merged now. Further testing (with daily builds from tomorrow or newer) and feedback very welcome!