dark-eye / com.darkeye.chatGPT

KDE Plasma plasmoid for chatGPT
BSD 3-Clause "New" or "Revised" License
56 stars 16 forks source link

Textbox focus when activating with keyboard shortcut #6

Closed zontafil closed 1 year ago

zontafil commented 1 year ago

Hello,

thank you very much for this extension. I've noticed that when I activate the applet with a keyboard shortcut, the textbox is not automatically in focus, so I need to select it with the mouse before typing anything. This doesn't happen when activating the applet by clicking on it with the mouse.

zontafil commented 1 year ago

I solved by adding a delay in the onExpandedChanged function:

timer.setTimeout(function(){ 
    gptWebView.forceActiveFocus();
    gptWebView.focus=true;
    gptWebView.runJavaScript("document.userScripts.setInputFocus();");
}, 100);

where timer is:

Timer {
    id: timer
    function setTimeout(cb, delayTime) {
        timer.interval = delayTime;
        timer.repeat = false;
        timer.triggered.connect(cb);
        timer.triggered.connect(function release () {
            timer.triggered.disconnect(cb); // This is important
            timer.triggered.disconnect(release); // This is important as well
        });
        timer.start();
    }
} 

not sure if it's a good way as it's the first time that I write some lines of code in QML, but to me it's satisfactory

dnielMantov commented 1 year ago

Where exactly did you put these lines of code?

dark-eye commented 1 year ago

@zontafil Great I`ll add it as a configable work around i didn't wanted to use a timeout method as it provide incositant results.

but you are right it better that it will mostly work then not at all :)

Thank you :+1:

dark-eye commented 1 year ago

Commited workaround in : https://github.com/dark-eye/com.darkeye.chatGPT/commit/3619e53d3f40f86f8d6477f02a42685b9d2479e1

Thanks @zontafil