Skip to content

Commit

Permalink
Updated MultiEditText.jsx
Browse files Browse the repository at this point in the history
Added Shift+Enter shortcut to insert soft line break
  • Loading branch information
creold committed Apr 10, 2024
1 parent ab09e1c commit bd3e288
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ Click the category name to learn more about the scripts in the selected category

* [AlignTextBaseline](https://github.com/creold/illustrator-scripts/blob/master/md/Text.md#aligntextbaseline) `upd, 09.02.2024`
* [MakeNumbersSequence](https://github.com/creold/illustrator-scripts/blob/master/md/Text.md#makenumberssequence) `upd, 26.03.2024`
* [MultiEditText](https://github.com/creold/illustrator-scripts/blob/master/md/Text.md#multiedittext) `upd, 04.04.2024`
* [MultiEditText](https://github.com/creold/illustrator-scripts/blob/master/md/Text.md#multiedittext) `upd, 10.04.2024`
* [ReplaceFormattedText](https://github.com/creold/illustrator-scripts/blob/master/md/Text.md#replaceformattedtext) `29.12.2022`

### [Utility](md/Utility.md)
Expand Down
2 changes: 1 addition & 1 deletion README.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@

* [AlignTextBaseline](https://github.com/creold/illustrator-scripts/blob/master/md/Text.ru.md#aligntextbaseline) `upd, 09.02.2024`
* [MakeNumbersSequence](https://github.com/creold/illustrator-scripts/blob/master/md/Text.ru.md#makenumberssequence) `upd, 26.03.2024`
* [MultiEditText](https://github.com/creold/illustrator-scripts/blob/master/md/Text.ru.md#multiedittext) `upd, 04.04.2024`
* [MultiEditText](https://github.com/creold/illustrator-scripts/blob/master/md/Text.ru.md#multiedittext) `upd, 10.04.2024`
* [ReplaceFormattedText](https://github.com/creold/illustrator-scripts/blob/master/md/Text.ru.md#replaceformattedtext) `29.12.2022`

### [Utility](md/Utility.ru.md)
Expand Down
46 changes: 32 additions & 14 deletions jsx/MultiEditText.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*******************************************************************************************
Release notes:
0.2.1 Added Shift+Enter shortcut to insert soft line break
0.2 Added option to keep paragraph formatting (experimental)
0.1 Initial version
Expand Down Expand Up @@ -40,14 +41,15 @@ app.preferences.setBooleanPreference('ShowExternalJSXWarning', false); // Fix dr
function main() {
var SCRIPT = {
name: 'Multi-edit Text',
version: 'v0.2'
version: 'v0.2.1'
};

var CFG = {
width: 300, // Text area width, px
height: 240, // Text area height, px
ph: '<text>', // Content display placeholder
divider: '\n@@@\n', // Symbol for separating multiple text frames
softBreak: '@#', // Soft line break char
coordTolerance: 10, // Object alignment tolerance for sorting
aiVers: parseFloat(app.version),
is2020: parseInt(app.version) == 24, // Current AI is CC 2020
Expand All @@ -71,17 +73,18 @@ function main() {
var sortedTfs = [].concat(tfs);
sortByPosition(sortedTfs, CFG.coordTolerance);

var tfContents = extractContents(tfs);
var sortedTfContents = extractContents(sortedTfs);
var tfContents = extractContents(tfs, CFG.softBreak);
var sortedTfContents = extractContents(sortedTfs, CFG.softBreak);

var placeholder = isEqualContents(tfs) ? tfs[0].contents : CFG.ph;
var placeholder = isEqualContents(tfs, CFG.softBreak) ? tfs[0].contents.replace(/\x03/g, CFG.softBreak) : CFG.ph;

// DIALOG
var win = new Window('dialog', SCRIPT.name + ' ' + SCRIPT.version);
win.orientation = 'row';
win.alignChildren = ['fill', 'top'];

var input = win.add('edittext', [0, 0, CFG.width, CFG.height], placeholder, {multiline: true, scrolling: true });
input.helpTip = 'Use Shift+Enter to insert soft line break special char';
if (CFG.isMac || CFG.aiVers >= 26.4 || CFG.aiVers <= 17) {
input.active = true;
}
Expand Down Expand Up @@ -119,14 +122,14 @@ function main() {
var copyright = opt.add('statictext', undefined, 'Visit Github');
copyright.justify = 'center';

loadSettings(SETTINGS);

// CC 2020 v24.3 crashes when undoing text frame changes
if (CFG.is2020) {
isPreview.enabled = false;
isPreview.helpTip = "Preview disabled for CC 2020\ndue to critical bug";
}

loadSettings(SETTINGS);

isFormat.onClick = function () {
isPreview.enabled = !this.value;
preview();
Expand All @@ -153,8 +156,19 @@ function main() {
}

input.onChange = input.onChanging = preview;

isPreview.onClick = preview;

// Insert soft line break char
input.addEventListener('keydown', function (kd) {
var isShift = ScriptUI.environment.keyboardState['shiftKey'];
if (isShift && kd.keyName === 'Enter') {
this.textselection = CFG.softBreak;
kd.preventDefault();
preview();
}
});

cancel.onClick = win.close;

ok.onClick = function () {
Expand Down Expand Up @@ -198,10 +212,11 @@ function main() {
tmpPath.name = 'Remove_Path';

if (isEmpty(input.text)) return;
var regex = new RegExp(CFG.softBreak, 'gmi');

if (isSeparate.value) {
var srcTfs = [].concat(isSort.value ? sortedTfs : tfs);
var texts = input.text.split(CFG.divider);
var texts = input.text.replace(regex, '\x03').split(CFG.divider);
var min = Math.min(srcTfs.length, texts.length);

for (var i = 0; i < min; i++) {
Expand All @@ -213,7 +228,7 @@ function main() {
} else {
for (var i = 0, len = tfs.length; i < len; i++) {
var tf = tfs[i];
var str = input.text.replace(/<text>/gi, tfContents[i]);
var str = input.text.replace(/<text>/gi, tfContents[i]).replace(regex, '\x03');
if (tf.contents !== str) {
replaceContent(tf, str, isFormat.value);
}
Expand Down Expand Up @@ -375,13 +390,15 @@ function sortByPosition(coll, tolerance) {
* Extract the contents of TextFrames from a given collection
*
* @param {Array} coll - The collection of TextFrames
* @param {string} softBreak - The soft line break special char
* @returns {Array} - An array containing the contents of TextFrames
*/
function extractContents(coll) {
function extractContents(coll, softBreak) {
var result = [];

for (var i = 0, len = coll.length; i < len; i++) {
result.push(coll[i].contents);
// Replace End of Text (ETX) to line break
result.push(coll[i].contents.replace(/\x03/g, softBreak));
}

return result;
Expand All @@ -391,13 +408,14 @@ function extractContents(coll) {
* Check if the contents of all TextFrames in the collection are equal
*
* @param {Array} coll - The collection of TextFrames to compare
* @returns {boolean} - Returns true if all TextFrames have equal contents, otherwise false
* @param {string} softBreak - The soft line break special char
* @returns {boolean} - Return true if all TextFrames have equal contents, otherwise false
*/
function isEqualContents(coll) {
var str = coll[0].contents;
function isEqualContents(coll, softBreak) {
var str = coll[0].contents.replace(/\x03/g, softBreak);

for (var i = 1, len = coll.length; i < len; i++) {
if (coll[i].contents !== str) return false;
if (coll[i].contents.replace(/\x03/g, softBreak) !== str) return false;
}

return true;
Expand Down
9 changes: 6 additions & 3 deletions md/Text.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
## Scripts
* [AlignTextBaseline](https://github.com/creold/illustrator-scripts/blob/master/md/Text.md#aligntextbaseline) `upd, 09.02.2024`
* [MakeNumbersSequence](https://github.com/creold/illustrator-scripts/blob/master/md/Text.md#makenumberssequence) `upd, 26.03.2024`
* [MultiEditText](https://github.com/creold/illustrator-scripts/blob/master/md/Text.md#multiedittext) `upd, 04.04.2024`
* [MultiEditText](https://github.com/creold/illustrator-scripts/blob/master/md/Text.md#multiedittext) `upd, 10.04.2024`
* [ReplaceFormattedText](https://github.com/creold/illustrator-scripts/blob/master/md/Text.md#replaceformattedtext) `29.12.2022`

## AlignTextBaseline
Expand Down Expand Up @@ -49,13 +49,16 @@ Multi-editing of selected text frames. The script allows you to enter the same t
* Reverse Apply - replace contents in reverse order

> [!TIP]
> If you want to change the size of the text area, open the script file with a text editor and change the CFG `width: 300` and `height: 210` to another value. The key to displaying different content is `ph: '<text>'` and the text divider `divider: '\n@@@@@\n'`, where `\n` is a line break.
> If you want to change the size of the text area, open the script file with a text editor and change the CFG `width: 300` and `height: 210` to another value. The key to displaying different content is `ph: '<text>'` and the text divider `divider: '\n@@@@@\n'`, where `\n` is a line break. `softBreak: '@#'` — soft line break char.
> For a line break (new paragraph), use <kbd>Ctrl</kbd> + <kbd>Enter</kbd> on a PC or <kbd>Enter</kbd> on Mac OS. To insert a soft line break chat (no paragraph indent), press <kbd>Shift</kbd> + <kbd>Enter</kbd>.
<a href="https://youtu.be/PcyT0KmuepI">
<img width="122" height="47" src="https://i.ibb.co/fqdwXL6/youtube-badge.png">
</a>

![MultiTextEdit](https://i.ibb.co/JmBVHCy/Multi-Edit-Text.gif)
See also [Adobe Photoshop version](https://github.com/creold/photoshop-scripts)

![MultiTextEdit](https://i.ibb.co/58HHRFK/Multi-Edit-Text.gif)

## ReplaceFormattedText
[![Direct](https://img.shields.io/badge/Direct%20Link-ReplaceFormattedText.jsx-FF6900.svg)](https://rebrand.ly/rplcfmtdtxt) [![Download](https://img.shields.io/badge/Download%20All-Zip%20archive-0088CC.svg)](https://bit.ly/2M0j95N)
Expand Down
9 changes: 6 additions & 3 deletions md/Text.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
## Scripts
* [AlignTextBaseline](https://github.com/creold/illustrator-scripts/blob/master/md/Text.ru.md#aligntextbaseline) `upd, 09.02.2024`
* [MakeNumbersSequence](https://github.com/creold/illustrator-scripts/blob/master/md/Text.ru.md#makenumberssequence) `upd, 26.03.2024`
* [MultiEditText](https://github.com/creold/illustrator-scripts/blob/master/md/Text.ru.md#multiedittext) `upd, 04.04.2024`
* [MultiEditText](https://github.com/creold/illustrator-scripts/blob/master/md/Text.ru.md#multiedittext) `upd, 10.04.2024`
* [ReplaceFormattedText](https://github.com/creold/illustrator-scripts/blob/master/md/Text.ru.md#replaceformattedtext) `29.12.2022`

## AlignTextBaseline
Expand Down Expand Up @@ -49,13 +49,16 @@
* Reverse Apply - заменить контент в обратном порядке

> [!TIP]
> Если хотите изменить размер текстовой области, то откройте файл скрипта текстовым редактором и поменяйте CFG `width: 300` и `height: 210` на другое число. Ключ для отображения разного контента `ph: '<text>'` и разделитель текстов `divider: '\n@@@\n'`, где `\n` — перенос строки.
> Если хотите изменить размер текстовой области, то откройте файл скрипта текстовым редактором и поменяйте CFG `width: 300` и `height: 210` на другое число. Ключ для отображения разного контента `ph: '<text>'` и разделитель текстов `divider: '\n@@@\n'`, где `\n` — перенос строки.`softBreak: '@#'` — символ мягкого переноса.
> Для переноса строки (новый абзац) используйте <kbd>Ctrl</kbd> + <kbd>Enter</kbd> на ПК или <kbd>Enter</kbd> на Mac OS. Для вставки специального символа мягкого переноса (без абзацного отступа) нажмите <kbd>Shift</kbd> + <kbd>Enter</kbd>.
<a href="https://youtu.be/PcyT0KmuepI">
<img width="122" height="47" src="https://i.ibb.co/fqdwXL6/youtube-badge.png">
</a>

![MultiTextEdit](https://i.ibb.co/JmBVHCy/Multi-Edit-Text.gif)
Смотрите также [версию для Adobe Photoshop](https://github.com/creold/photoshop-scripts)

![MultiTextEdit](https://i.ibb.co/58HHRFK/Multi-Edit-Text.gif)

## ReplaceFormattedText
[![Direct](https://img.shields.io/badge/Прямая%20ссылка-ReplaceFormattedText.jsx-FF6900.svg)](https://rebrand.ly/rplcfmtdtxt) [![Download](https://img.shields.io/badge/Скачать%20все-Zip--архив-0088CC.svg)](https://bit.ly/2M0j95N)
Expand Down

0 comments on commit bd3e288

Please sign in to comment.