Make `n visible in editbox... Any better way? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
kunkel321
Posts: 969
Joined: 30 Nov 2015, 21:19

Make `n visible in editbox... Any better way?

Post by kunkel321 » 19 Mar 2023, 20:38

I have a tool, and I'd like to toggle visibility of white space (mostly {Enter} characters) in a multi-line edit box.

Below is a "fakey/klugey" way to do it. Newly typed {Enter}s are not visible though. I guess I could try to update the string every time the user presses {Enter} ?? I don't know. Is there a more elegant way to make these symbols viewable?

How would you guys do it?

Code: Select all

#SingleInstance Force
vtext =
(
Top is here
New Line
new also

)
vtext := StrReplace(StrReplace(vtext,"`r`n","`n"),"`n","┘`n")
gui, font, s12
gui, add, edit, w200 h200, %vtext%
gui, Show
ste(phen|ve) kunkel

off
Posts: 176
Joined: 18 Nov 2022, 21:54

Re: Make `n visible in editbox... Any better way?

Post by off » 19 Mar 2023, 21:29

Hello, maybe something like this?

Code: Select all

#SingleInstance Force
vtext =
(
Top is here
New Line
new also

)
vtext := StrReplace(StrReplace(vtext,"`r`n","`n"),"`n","¶`n")
gui, font, s12
gui, add, edit, w200 h200, %vtext%
gui, Show

Enter::
GuiControlGet, FControl, Focus ; you can also use IfWinActive instead
If FControl=Edit1
{
Send, ¶{enter}
}
Else
{
Send, {enter}
}
Return
My Creations
IMG2HotString - Send image file easily with your hotstring!
CtrlSend - A small solution for sending keys to window in background that doesn't accept ControlSend's key
ControlProcess

User avatar
kunkel321
Posts: 969
Joined: 30 Nov 2015, 21:19

Re: Make `n visible in editbox... Any better way?

Post by kunkel321 » 20 Mar 2023, 08:40

Hey very nice!

I was also thinking of just making the edit box 'read-only' when the symbols are showing. I could use the above technique for adding Enters, Tabs, and Spaces. But I think it would be pretty hard to detect when the user Backspaces or Deletes one of the paragraph symbols.
ste(phen|ve) kunkel

User avatar
kunkel321
Posts: 969
Joined: 30 Nov 2015, 21:19

Re: Make `n visible in editbox... Any better way?

Post by kunkel321 » 20 Mar 2023, 10:35

Here I have it toggling nicely. It locks the edit box and adds/removes the symbols. It's not preserving text edits though... If I unlock it, then type more stuff in, then lock it, the text reverts to default. I tried putting Gui, Submit, NoHide in a couple places, but no luck. Will experiment more later.

Code: Select all

#SingleInstance Force
; NOT WORKING !!!!!!!!!!!!!!!!!
vtext =
(
Top is here
New Line
new also

)

gui, font, s12
gui, add, edit, w200 h200 vRO -Readonly, %vtext%
gui, add, button, gButTog vSymbut, +Symbols
gui, Show
Return

ButTog:
Gui, Submit, NoHide
	GuiControlGet, Symbut
If (Symbut = "+Symbols")
{

	vtext := StrReplace(StrReplace(vtext,"`r`n","`n"),"`n","¶`n")
	GuiControl, +Readonly, RO,
	GuiControl,, RO, %vtext%
	Guicontrol,,Symbut, -Symbols
}
else
{
	;Gui, Submit, NoHide
	vtext := StrReplace(vtext,"¶`n","`n")
	GuiControl, -Readonly, RO,
	GuiControl,, RO, %vtext%
	Guicontrol,,Symbut, +Symbols
}
Return
EDIT:
Got it working. It was because the %vtext% variable should only be used for initially populating the Edit Box. After that, everything passes to %RO%, which I've renamed %MyString%, since it does more than help me monitor readonly status.

Code: Select all

#SingleInstance Force

vtext =
(
Top is here
New Line
new also

)

gui, font, s12
gui, add, edit, w200 h200 vMyString -Readonly, %vtext%
gui, add, button, gButTog vSymbut, +Symbols
gui, Show
Return

ButTog:
Gui, Submit, NoHide
	GuiControlGet, Symbut
If (Symbut = "+Symbols")
{
	;MsgBox 1 vtext is |%vtext%|`n`nMyString is |%MyString%|
	MyString := StrReplace(StrReplace(MyString,"`r`n","`n"),"`n","¶`n")
	GuiControl,, MyString, %MyString%
	;Gui, Submit, NoHide
	GuiControl, +Readonly, MyString,
	GuiControl,,Symbut, -Symbols
	;MsgBox 2vtext is |%vtext%|`n`nMyString is |%MyString%|
}
else
{
	;MsgBox 3 vtext is |%vtext%|`n`nMyString is |%MyString%|
	MyString := StrReplace(MyString,"¶`n","`n")
	GuiControl, -Readonly, MyString,
	GuiControl,, MyString, %MyString%
	GuiControl,,Symbut, +Symbols
	;MsgBox 4vtext is |%vtext%|`n`nMyString is |%MyString%|
}
Return
ste(phen|ve) kunkel

User avatar
kunkel321
Posts: 969
Joined: 30 Nov 2015, 21:19

Re: Make `n visible in editbox... Any better way?

Post by kunkel321 » 20 Mar 2023, 15:08

I got it mostly working the way I want...
I can't seem to strReplace that Tab back to a tab though... The space arrow space just stays there.

Code: Select all

#SingleInstance Force

vtext =
(
Top is here
	A tab
  spaces
Name	Val
Name	Val

)

gui, font, s12
;gui, add, edit, w200 h200 vMyString +wantTab, %vtext%
gui, add, edit, w200 h200 vMyString, %vtext%
gui, add, button, gButTog vSymbut, +Symbols
gui, Show
Return

ButTog:
Gui, Submit, NoHide
	GuiControlGet, Symbut
If (Symbut = "+Symbols")
{
	MyString := StrReplace(StrReplace(MyString,"`r`n","`n"),"`n","¶`n") ; Pilcrow for Enter
	MyString := StrReplace(MyString, A_Tab," → ") ; space arrow space for Tab
	MyString := StrReplace(MyString, A_Space,"·") ; middle dot for Space
	GuiControl,, MyString, %MyString%
	GuiControl, +Readonly, MyString,
	GuiControl,,Symbut, -Symbols
}
else
{
	MyString := StrReplace(MyString,"¶`n","`n")
	MyString := StrReplace(MyString," → ",A_Tab) ; This line not working...
	MyString := StrReplace(MyString, "·",A_Space)
	GuiControl, -Readonly, MyString,
	GuiControl,, MyString, %MyString%
	GuiControl,,Symbut, +Symbols
}
Return
ste(phen|ve) kunkel

User avatar
kunkel321
Posts: 969
Joined: 30 Nov 2015, 21:19

Re: Make `n visible in editbox... Any better way?  Topic is solved

Post by kunkel321 » 20 Mar 2023, 15:09

I got it mostly working the way I want...
I can't seem to strReplace that Tab back to a tab though... The space arrow space just stays there.
Fixed... I had a logic problem. I was replacing Tab with Space Tab Space (to make it wider). But then I was replacing the spaces with dots. Thus "Space Tab Space" no longer existed... So I couldn't change it back. :facepalm:

Code: Select all

#SingleInstance Force

vtext =
(
Top is here
	A tab
  spaces
Name	Val
Name	Val

)

gui, font, s12
;gui, add, edit, w200 h200 vMyString +wantTab, %vtext%
gui, add, edit, w200 h200 vMyString wantTab, %vtext%
gui, add, button, gButTog vSymbut, +Symbols
gui, Show
Return

ButTog:
Gui, Submit, NoHide
	GuiControlGet, Symbut
If (Symbut = "+Symbols")
{
	MyString := StrReplace(StrReplace(MyString,"`r`n","`n"),"`n","¶`n") ; Pilcrow for Enter
	MyString := StrReplace(MyString, A_Space,"·") ; middle dot for Space
	MyString := StrReplace(MyString, A_Tab," → ") ; space arrow space for Tab
	GuiControl,, MyString, %MyString%
	GuiControl, +Readonly, MyString,
	GuiControl,,Symbut, -Symbols
}
else
{
	MyString := StrReplace(MyString,"¶`n","`n")
	MyString := StrReplace(MyString, "·",A_Space)
	MyString := StrReplace(MyString," → ",A_Tab)
	GuiControl, -Readonly, MyString,
	GuiControl,, MyString, %MyString%
	GuiControl,,Symbut, +Symbols
}
Return
I'm still open to better ways to display those symbols... Otherwise: Thread inactive.

EDIT: Upon integrating this into my version of Hotstring Helper, I ran into a problem... The whole reason for this, was to be able to visually tell if text is getting wrapped due to the edge of the edit box, or due to a new line. Ironically, that is the exact thing that gets messed up. When you replace all of the {Space}s with dots, then Windows thinks it's all one long word (a no brainer really). This messes the text wrapping all up.
ste(phen|ve) kunkel

off
Posts: 176
Joined: 18 Nov 2022, 21:54

Re: Make `n visible in editbox... Any better way?

Post by off » 20 Mar 2023, 21:35

I modified the middle dot for space and right arrow for tab into the slightly more visible..
And about your Hotstring Helper, i have a suggestion.. since the Append button will append whole string into the script it self, make the button disabled if Show Symbol button used.. This will prevent appending the preview symbol in the edit box to the script.

*Modified symbol, more visible.

Code: Select all

Btsymb:
Gui, Submit, NoHide
	GuiControlGet, TogSymb
If (TogSymb = "show ¶")
{
	RepStr := StrReplace(StrReplace(RepStr,"`r`n","`n"),"`n","¶`n") ; Pilcrow for Enter
	RepStr := StrReplace(RepStr, A_Space,"•") ; middle dot for Space
	RepStr := StrReplace(RepStr, A_Tab," ➔ ") ; space arrow space for Tab
	GuiControl,, RepStr, %RepStr%
	GuiControl, +Readonly, RepStr,
	GuiControl,, TogSymb, hide ¶
}
else
{
	RepStr := StrReplace(RepStr,"¶`n","`n")
	RepStr := StrReplace(RepStr, "•",A_Space)
	RepStr := StrReplace(RepStr," ➔ ",A_Tab)
	GuiControl, -Readonly, RepStr,
	GuiControl,, RepStr, %RepStr%
	GuiControl,, TogSymb, show ¶
}
Return
*First hotstring if Show Symbol not used, Second hotstring if Show Symbol used.

Code: Select all

::;showtest1::
(
Space Space
Enter

	Tab
Space 	Tab
	Tab Space
 Space
)
::;showtests2::
(
Space•Space¶
Enter¶
¶
 ➔ Tab¶
Space• ➔ Tab¶
 ➔ Tab•Space¶
•Space
)
*My suggestion.

Code: Select all

Btsymb:
Gui, Submit, NoHide
	GuiControlGet, TogSymb
If (TogSymb = "show ¶")
{
	RepStr := StrReplace(StrReplace(RepStr,"`r`n","`n"),"`n","¶`n") ; Pilcrow for Enter
	RepStr := StrReplace(RepStr, A_Space,"•") ; middle dot for Space
	RepStr := StrReplace(RepStr, A_Tab," ➔ ") ; space arrow space for Tab
	GuiControl,, RepStr, %RepStr%
	GuiControl, +Readonly, RepStr,
	GuiControl,, TogSymb, hide ¶
	GuiControl, Disable, Btappend
}
else
{
	RepStr := StrReplace(RepStr,"¶`n","`n")
	RepStr := StrReplace(RepStr, "•",A_Space)
	RepStr := StrReplace(RepStr," ➔ ",A_Tab)
	GuiControl, -Readonly, RepStr,
	GuiControl,, RepStr, %RepStr%
	GuiControl,, TogSymb, show ¶
	GuiControl, Enable, Btappend
}
Return
image.png
Append Button Enabled
image.png (17.93 KiB) Viewed 907 times
image.png
Append Button Disabled
image.png (18.37 KiB) Viewed 907 times
My Creations
IMG2HotString - Send image file easily with your hotstring!
CtrlSend - A small solution for sending keys to window in background that doesn't accept ControlSend's key
ControlProcess

User avatar
kunkel321
Posts: 969
Joined: 30 Nov 2015, 21:19

Re: Make `n visible in editbox... Any better way?

Post by kunkel321 » 21 Mar 2023, 15:34

@off This is excellent, thanks! And good call on disabling the Append button.

I'm curious where you got the dot and arrow symbols(?) Supposedly the Windows default font is Segoe UI, so I thought I'd be clever and get the symbols from that font group. The ones you found are better though.

There is still the problem of replacing spaces with dots, and how it makes the text like one long word. Select this
The five boxing wizards jump (quickly and the quick brown fox) jumps over the lazy (dog, so pack my box with five dozen) liquor jugs.
and toggle the symbols, and the place at which the text wraps gets weird. Windows apparently prefers to wrap at a parenth... which makes sense... I guess.

Regarding the Append button, Pressing Enter when the options box or the hotstring box are active also appends the text (Line 146 in other code.) That's okay though. I'll figure out a work around.

EDIT: This seems to address the issue of GoSubing to the hhButtonAppend label when pressing Enter.

Code: Select all

#IfWinActive, HotStrHelper-ML ; Allows window-specific behavior.=======
$Enter:: ; When Enter is pressed, but only in this GUI. "$" prevents accidental Enter key loop.
  GuiControlGet, hhControl, hh:Focus ; Determine which part of GUI is active.
  GuiControlGet, TogSymb
    ; MsgBox hhControl is |%hhControl%|`n`nTogSymb is |%TogSymb%|
  if (TogSymb = "show ¶")
  {
    ;MsgBox togSymp is 'show' so just return
    return
  }
  Else if (hhControl = "Edit1") || (hhControl = "Edit2") ; Edit1 is Opts box, Edit2 is the Hotstring box
  {
    Gosub, hhButtonAppend ; Opts box or HotStr box is active, so press Append button.
    return
  }
  else ; Replacement text box must be active, so...
  {
    send {Enter} ; Just normal typing; Enter yields Enter key press.
    Return
  }
Esc::
  Gui, hh:Destroy
  Clipboard = %ClipboardOld%  ; Restore previous contents of clipboard.
return
#IfWinActive ; Turn off window-specific behavior.======================
Will update the other thread shortly.
ste(phen|ve) kunkel

off
Posts: 176
Joined: 18 Nov 2022, 21:54

Re: Make `n visible in editbox... Any better way?

Post by off » 21 Mar 2023, 18:25

The symbols i get from internet and i saved it a long time ago, so i just use it.

About the wrapping, this is what it like (if im right)

Code: Select all

The•five•boxing•wizards•jump•(q < this one right here
uickly•and•the•quick•brown•fox)
Etc
Im sure if you replace
A_Space with • and a single space
("• ")

Code: Select all

RepStr := StrReplace(RepStr, A_Space,"• ") ; middle dot for Space
;and return it
RepStr := StrReplace(RepStr, "• ",A_Space) ; middle dot for Space
While the symbol act as "visual" A_Space, it still split in between words, same like right arrow for A_Tab.

And like the original text, there is no weird wrapped word. (Or atleast i hope so)

Oh yes, i forgot about Enter outside edit box will append :facepalm:
Nice Hotstring Helper btw, Great Work! :clap:
My Creations
IMG2HotString - Send image file easily with your hotstring!
CtrlSend - A small solution for sending keys to window in background that doesn't accept ControlSend's key
ControlProcess

off
Posts: 176
Joined: 18 Nov 2022, 21:54

Re: Make `n visible in editbox... Any better way?

Post by off » 21 Mar 2023, 20:25

This before i modify the script:
image.png
Before
image.png (14.32 KiB) Viewed 842 times
After i modified the script:
image.png
After changing the dot for A_Space
image.png (14.8 KiB) Viewed 842 times
My Creations
IMG2HotString - Send image file easily with your hotstring!
CtrlSend - A small solution for sending keys to window in background that doesn't accept ControlSend's key
ControlProcess

User avatar
kunkel321
Posts: 969
Joined: 30 Nov 2015, 21:19

Re: Make `n visible in editbox... Any better way?

Post by kunkel321 » 22 Mar 2023, 10:51

Thanks for the kind words. And for the help! I'm not sure which way to go with the 'dot' versus 'dot space'. Dot space does provide better wrapping. It also makes the sting of text longer... Both options are good, but neither is perfect. I guess the end-user can choose which they prefer.

I changed the spacing on the buttons a bit. Now the small toggle buttons are no longer sitting directly on the edit box. Also the 5 bottom buttons are visually vertically equidistant between the bottom of the replacement string box and the bottom of the form. Expanded the name of the form.
Spoiler
Next I want to make the trimming of the Clipboard smarter. If it's a single word (i.e. an autocorrect) then I want to trim it. For multi-line strings though, probably don't trim. Will do that later.
Made the trim command conditional. It's not actually looking for "single words" but rather the absence of newline characters.
Updated code in main thread here: viewtopic.php?f=6&t=114688&p=513490#p513490
ste(phen|ve) kunkel

User avatar
kunkel321
Posts: 969
Joined: 30 Nov 2015, 21:19

Re: Make `n visible in editbox... Any better way?

Post by kunkel321 » 23 Mar 2023, 18:54

Hey Off (or other), when you view the code in the previous post, does that right arrow symbol (the one we're using to show Tab) display correctly on your computer, or does it appear as a question mark ?

For me, it was displaying correctly at first, but not anymore. Same with the previous (harder to see) one that I had.
ste(phen|ve) kunkel

off
Posts: 176
Joined: 18 Nov 2022, 21:54

Re: Make `n visible in editbox... Any better way?

Post by off » 23 Mar 2023, 19:49

About the arrow, even in your thread, the code line show this
The arrow became question mark too
image.png
image.png (51.8 KiB) Viewed 767 times
My Creations
IMG2HotString - Send image file easily with your hotstring!
CtrlSend - A small solution for sending keys to window in background that doesn't accept ControlSend's key
ControlProcess

Post Reply

Return to “Ask for Help (v1)”