[plasma/plasma-setup] modules/language/contents/ui: fix: auto-scroll to preselected language

Kristen McWilliam <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit deea53f925da6f7208a13ee2cde5cbefbd0a6c1e by Kristen McWilliam, on behalf of Tiziano Gaia.
Committed on 06/08/2026 at 15:24.
Pushed by merritt into branch 'master'.

fix: auto-scroll to preselected language

<!--Thank you for submitting a merge request to make KDE Software better! Use the information from the commit message(s) to fill in the template below.

### Original commit message(s)

* fix: auto-scroll to preselected language

The language list was changed from a QStringList to a proxy model in
!109, but scrollToCurrentLanguage() still relied on accessing
instantiated delegates through itemAtIndex().

Since ListView creates delegates lazily, the current language could not
always be found and the language page would not scroll to the selected
language after applying an initial language override.

Use the model data directly to find the current language index.

(For future reference, follow the guidelines at https://cbea.ms/git-commit/#seven-rules)-->

### Reason for the change

fix for the regression reported here: https://invent.kde.org/plasma/plasma-setup/-/merge_requests/109#note_1562066 (i.e.: the language page would not auto-scroll to the preselected language).

The language list was changed from a QStringList to a proxy model in !109, but scrollToCurrentLanguage() still relied on accessing instantiated delegates through itemAtIndex().

This fix uses the model data directly to find the current language index.

### Test plan

Tested manually by running Plasma Setup with "LANG=ja_JP.UTF-8 kde-builder --run plasma-setup"

### Screenshots or screen recordings

<!--If this merge request introduces a visual change, please add before-and-after screenshots in the following format:

| Before | After |
| ------ | ----- |
| [drag "before" screenshot here] | [drag "after" screenshot here] |-->

### Bugs fixed

<!--If the changes in this merge request fix any Bugzilla tickets, add the following keyword for each one:

BUG: [number of the bug report]-->

M  +4    -3    modules/language/contents/ui/main.qml

https://invent.kde.org/plasma/plasma-setup/-/commit/deea53f925da6f7208a13ee2cde5cbefbd0a6c1e

diff --git a/modules/language/contents/ui/main.qml b/modules/language/contents/ui/main.qml
index a52eaa0..3b411d3 100644
--- a/modules/language/contents/ui/main.qml
+++ b/modules/language/contents/ui/main.qml
@@ -105,11 +105,12 @@ PlasmaSetupComponents.SetupModule {
                     function scrollToCurrentLanguage() {
                         // Find the index of the current language
                         const currentLang = Language.LanguageUtil.currentLanguage;
+                        const model = languageListView.model;
 
-                        for (let i = 0; i < languageListView.count; i++) {
-                            const item = languageListView.itemAtIndex(i);
+                        for (let i = 0; i < model.rowCount(); i++) {
+                            const index = model.index(i, 0);
 
-                            if (item && item.languageCode === currentLang) {
+                            if (model.data(index, model.languageCode) === currentLang) {
                                 // Position the view at the current language with some offset
                                 languageListView.positionViewAtIndex(i, ListView.Center);
                                 break;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.