3

I am working on a script for Photoshop where the user can change some text by entering it in the script panel.

By problem is that when the user hits "enter" to create a new line, the output displays a "missing character" glyph instead of a line break.

topRow.add ("statictext", undefined, "Text layer contents:");
var myText = topRow.add ("edittext", undefined, undefined, {name: 'myText', multiline: true});
    myText.characters = 20;
    myText.preferredSize = [150,60];
    myText.active = true;

Any ideas how to resolve this?

StudioTime
  • 22,603
  • 38
  • 120
  • 207
  • I'm stumped. I know it changed in CS3. To make matters worse, if you add an OK and a Cancel button it automatically selects the OK button instead of adding a carriage return. – Mr Mystery Guest May 22 '17 at 15:06

1 Answers1

2

It's 2,5 years since you've asked this, but I came across your question by searching for the same problem. And here's how I solved it, hope it helps other people searching for an answer:

Its's working like a charm in PSCC20 if you replace all occurances of possible linebreaks with a default carriage return ("\r"). Here's a working demo script:


w = new Window('dialog {text:"Title"}');

var inputText1 = w.add("edittext", [0,0,250,60], "Text 1", {multiline: true, wantReturn: true}); //multiline, uses return for line breaks instead of CTRL-return

var button = w.add('button {text:"Change"}');
button.onClick = function (){
            dummy = app.activeDocument.artLayers.getByName("Text");
            if(dummy.kind == LayerKind.TEXT){
            theText = inputText1.text.replace( /[\r\n]+/gm, "\r" ); 
            dummy.textItem.contents = theText;  
            w.close();
            }
    }

w.center();
w.show();

PS It seems that "\s+" does not work in ExtendScript, so I'm using "/[\r\n]": What is the meaning of (/^\s+|\s+$/gm) in JavaScript?

Corvin
  • 21
  • 3