Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

notepad.prompt() window and multiline input #261

Open
alankilborn opened this issue Nov 22, 2022 · 6 comments
Open

notepad.prompt() window and multiline input #261

alankilborn opened this issue Nov 22, 2022 · 6 comments

Comments

@alankilborn
Copy link

alankilborn commented Nov 22, 2022

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.

@Ekopalypse
Copy link
Contributor

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

@alankilborn
Copy link
Author

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 :-(

@chcg
Copy link
Collaborator

chcg commented Dec 10, 2022

The relevant code for the text selection is at

::SendMessage(::GetDlgItem(m_hSelf, IDC_USERTEXT), EM_SETSEL, 0, -1);

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?

@alankilborn
Copy link
Author

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.

chcg added a commit that referenced this issue Dec 11, 2022
- avoid that input text in prompt edit control is automatically selected
@Ekopalypse
Copy link
Contributor

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.

@alankilborn
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants