Bug 478960

Summary: Incorrect IME position when window wider than editor width
Product: [Applications] ghostwriter Reporter: jichu4n
Component: generalAssignee: megan.conkle
Status: RESOLVED FIXED    
Severity: normal CC: jichu4n
Priority: NOR    
Version: 23.08.4   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
See Also: https://bugs.kde.org/show_bug.cgi?id=460158
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: Screenshots showing correct and incorrect IME positions

Description jichu4n 2023-12-24 07:46:08 UTC
Created attachment 164417 [details]
Screenshots showing correct and incorrect IME positions

SUMMARY

This is similar / related to bug 460158 (https://bugs.kde.org/show_bug.cgi?id=460158), but while the commit linked in the bug fixed IME window positioning in some cases, there are other cases where it's still not working correctly.

Specifically:
- When the editor width is set to "Full", or the window is narrower than the selected editor width, the IME window is positioned correctly right below the cursor.
- However, when the editor width is set to anything other than "Full", e.g. "Narrow", "Medium" or "Wide", and the window is wider than the selected editor width, the IME window is positioned way off to the left of where the cursor is. This is not the expected behavior as the IME window should be positioned in the same way right below the cursor.

STEPS TO REPRODUCE

1. Set editor width to anything other than "Full", e.g. "Narrow".
2. Maximize the window, or otherwise resize the window to be wide enough to produce margins to the left and right of the content.
3. Enable an IME for CJK languages such as fcitx and start typing.

OBSERVED RESULT

The IME window (showing CJK word candidates) appears far to the left of where the cursor is - see 3rd screenshot in attached file.

EXPECTED RESULT

The IME window should appear right below the cursor, as it does when editor width is set to "Full" - see 1st and 2nd screenshots in attached file.

SOFTWARE/OS VERSIONS
Windows: 
macOS: 
Linux/KDE Plasma: 6.6.7-arch1-1
(available in About System)
KDE Plasma Version: 5.27.10
KDE Frameworks Version: 5.113.0
Qt Version: 5.15.11

ADDITIONAL INFORMATION
Comment 1 jichu4n 2023-12-24 08:24:08 UTC
From playing around with the code locally, my understanding is that we just need to add one extra line in `MarkdownEditor::inputMethodQuery()` after `r.translate(contentOffset().toPoint());` :

r.translate(this->viewportMargins().left(), 0);

This is my first time contributing to the KDE project so I'm new to the process, but I'd be happy to create a pull request if that would help!

Thanks!
Comment 2 jichu4n 2024-02-16 06:34:30 UTC
Sent merge request to fix: https://invent.kde.org/office/ghostwriter/-/merge_requests/34
Comment 3 Emir SARI 2024-03-04 07:59:51 UTC
Git commit c6e9f7fbd8414502a657a6977c9c94d19ac846e5 by Emir SARI, on behalf of Chuan Ji.
Committed on 04/03/2024 at 07:59.
Pushed by esari into branch 'master'.

Fix IME position when window is wider than editor width.

Before: ![Screenshot_20240215_223011.png](/uploads/df07e1418a4b7e7119736e7f018afc2c/Screenshot_20240215_223011.png)

After: ![Screenshot_20240215_222810.png](/uploads/5e1ea8867680e69d055bc1e40280b14c/Screenshot_20240215_222810.png)

M  +1    -0    src/editor/markdowneditor.cpp

https://invent.kde.org/office/ghostwriter/-/commit/c6e9f7fbd8414502a657a6977c9c94d19ac846e5
Comment 4 Emir SARI 2024-03-04 08:03:52 UTC
Git commit 25b2227182eba975a09fb5a1f419ae2ba16ea697 by Emir SARI, on behalf of Chuan Ji.
Committed on 04/03/2024 at 08:00.
Pushed by esari into branch 'release/24.02'.

Fix IME position when window is wider than editor width.

Before: ![Screenshot_20240215_223011.png](/uploads/df07e1418a4b7e7119736e7f018afc2c/Screenshot_20240215_223011.png)

After: ![Screenshot_20240215_222810.png](/uploads/5e1ea8867680e69d055bc1e40280b14c/Screenshot_20240215_222810.png)


(cherry picked from commit c6e9f7fbd8414502a657a6977c9c94d19ac846e5)

deda426c Fix IME position when window is wider than editor width.

M  +1    -0    src/editor/markdowneditor.cpp

https://invent.kde.org/office/ghostwriter/-/commit/25b2227182eba975a09fb5a1f419ae2ba16ea697