RegExReplace turning line feeds into zero-pixel characters in an Edit control Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Baconfry
Posts: 14
Joined: 07 Jan 2022, 04:07

RegExReplace turning line feeds into zero-pixel characters in an Edit control

Post by Baconfry » 01 Feb 2023, 02:45

The example below demonstrates this behavior. It turns word characters into "C", and shouldn't touch line feeds at all.

Code: Select all

#Requires AutoHotkey v2.0

myGui := Gui()
editControl := myGui.AddEdit("w300 h100 vMyEdit", "a`n`n`n`nb")
myGui.AddButton(, "Format Text").OnEvent("Click", FormatText)
myGui.Show

FormatText(*)
{
    saved := myGui.Submit(0)
    newText := RegExReplace(saved.MyEdit, "\w", "C")
    editControl.Text := newText
}
The expected output should be:

Code: Select all

C



C
But the actual output is:

Code: Select all

CC
However, if you traverse across the CC with arrow keys, the line feeds are still there, but it's like they have shrunk down to zero pixels. Is this a bug or am I missing something? Thanks!

teadrinker
Posts: 4326
Joined: 29 Mar 2015, 09:41
Contact:

Re: RegExReplace turning line feeds into zero-pixel characters in an Edit control  Topic is solved

Post by teadrinker » 01 Feb 2023, 04:09

I don't know the reason of such behavior, but for me this works correctly:

Code: Select all

#Requires AutoHotkey v2.0

myGui := Gui()
editControl := myGui.AddEdit("w300 h100 vMyEdit", "a`n`n`n`nb")
myGui.AddButton(, "Format Text").OnEvent("Click", FormatText)
myGui.Show

FormatText(*)
{
    editControl.Text := RegExReplace(editControl.Text, "\w", "C")
}

Baconfry
Posts: 14
Joined: 07 Jan 2022, 04:07

Re: RegExReplace turning line feeds into zero-pixel characters in an Edit control

Post by Baconfry » 01 Feb 2023, 05:15

Thanks, teadrinker. Didn't know that we can directly grab the controls' texts in v2 without needing to submit the Gui. It also looks like myGui.Submit(0) is causing the issue.

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: RegExReplace turning line feeds into zero-pixel characters in an Edit control

Post by swagfag » 01 Feb 2023, 06:07

Edit.Value performs CLRF translations
Edit.Text doesnt perform CLRF translations

Gui.Submit() fetches from GuiControl.Value
then u reassign back to Edit.Text, so u get a mismatch. if u grabbed the .Text and reassigned back to the .Text, u dont get any mismatches. same as if u grabbed .Submit() or .Value and reassigned back to .Value

why this distinctions exists, i cant say. might be a windows thing, might be an ahk "feature". either way, i dont care enough about Edits to research it

Baconfry
Posts: 14
Joined: 07 Jan 2022, 04:07

Re: RegExReplace turning line feeds into zero-pixel characters in an Edit control

Post by Baconfry » 01 Feb 2023, 07:07

Thanks for that, swagfag. It was in the docs this entire time. From: https://www.autohotkey.com/docs/v2/lib/GuiControl.htm#Text
Edit: As with other controls, the text is retrieved or set as-is; no end-of-line translation is performed. To retrieve or set the text of a multi-line Edit control while also translating between `r`n and `n, use GuiCtrl.Value.
I guess the Text property is used if the author wants to work with the stuff in the Edit as it really is.

Post Reply

Return to “Ask for Help (v2)”