PythonScript icon indicating copy to clipboard operation
PythonScript copied to clipboard

notepad.prompt() window and multiline input

Open alankilborn opened this issue 2 years ago • 6 comments
trafficstars

I noticed that when I put some text in a notepad.prompt() window, e.g.:

notepad.prompt('', '', 'this is the default first line')

it correctly shows:

image

But then if I want to accept the first line and move input to a second line, using Ctrl+Enter, it erases my first line:

image

I have to remember to FIRST clear the selection (perhaps by pressing the End key) to obtain:

image

and then my Ctrl+Enter movement to the second line goes well:

image

But I always forget to do this unselect manually, so I was wondering if the plugin could handle this for me? Or maybe this is just how Windows' multiline edit boxes work, and the plugin can't handle it.

In that case, I'd ask for an option to not show the text in the box as selected when the prompt window first appears.

Using PS 2.0.

alankilborn avatar Nov 22 '22 19:11 alankilborn

Something like a 4th parameter unselect, set to false by default, would be helpful.

Ekopalypse avatar Nov 25 '22 09:11 Ekopalypse

a 4th parameter unselect, set to false by default, would be helpful.

Yes, I've often thought this.

Another use case is a poor-man's UI made out of the notepad.prompt() box, example (imitation checkboxes):

[   ]option1     [ x ]option2

Here, if the text is selected when the box appears, it is easy for the user to hit an unintended key -- maybe arrowing was intended to move to where a "checkbox" could be ticked, but... If that happens the "UI" is destroyed :-(

alankilborn avatar Nov 25 '22 11:11 alankilborn

The relevant code for the text selection is at https://github.com/bruderstein/PythonScript/blob/d0b420e1201fb062eaf60c0d8bf58e80ffe92fd4/PythonScript/src/PromptDialog.cpp#L69

Removing that line will leave the caret at the beginning of the unselected text. See https://cplusplus.com/forum/windows/40365/ for the further necessary calls to avoid that.

::SendMessage(::GetDlgItem(m_hSelf, IDC_USERTEXT), EM_SETSEL, static_cast<WPARAM>(-1), -1);
::SendMessage(::GetDlgItem(m_hSelf, IDC_USERTEXT), EM_SCROLLCARET, 0, 0);

@alankilborn @Ekopalypse Do you see any advantage to keep the current behaviour with the selection of the text?

chcg avatar Dec 10 '22 20:12 chcg

Do you see any advantage to keep the current behaviour with the selection of the text?

If it could be made an optional behavior, that would be nice. But I think in general it is unexpected behavior to be selected. And yes, caret should be at end of unselected text.

alankilborn avatar Dec 10 '22 21:12 alankilborn

The only advantage I see right now is if someone uses it with a default value that needs to be overwritten from time to time.

Ekopalypse avatar Dec 12 '22 08:12 Ekopalypse

I'd ask for an option to not show the text in the box as selected when the prompt window first appears.

Workaround:

import threading
import SendKeys as sk
threading.Timer(0.25, lambda : sk.SendKeys("{RIGHT}")).start()  # remove highlight from prompted text
notepad.prompt('', '', 'Notice that I am not selected when the prompt box appears!')

Produces:

image

alankilborn avatar Dec 24 '22 20:12 alankilborn