Skip to content

Add "Join Text To One Line" command#125

Open
Alex-duzhichao wants to merge 1 commit intohluk:masterfrom
Alex-duzhichao:master
Open

Add "Join Text To One Line" command#125
Alex-duzhichao wants to merge 1 commit intohluk:masterfrom
Alex-duzhichao:master

Conversation

@Alex-duzhichao
Copy link

No description provided.

@JoyHak
Copy link

JoyHak commented Dec 10, 2025

In that case text\r\ntext will be replaced with textext which is not ok. Its better to use space ' '. Furthermore you should use \R for unicode line breaks...

var text = str(input())
text = text.replace(/[\\r\\n]/g, '');
add(text);
selectItems(0);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may also copy and paste the text, which may be unexpected (neither the description nor the name indicates this).

Also, the new text may be inserted to a different position if there is a pinned item index 0.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the unclear code.
I'm new to copyq commands, should I modify those code as:

var text = str(input())
text = text.replace(/[\r\n]/g, '');
add(text);
copy(text)
toggle()

@Alex-duzhichao
Copy link
Author

In that case text\r\ntext will be replaced with textext which is not ok. Its better to use space ' '. Furthermore you should use \R for unicode line breaks...

Hi JoyHak, I test this command with text\r\ntext on windows and the result is correct texttext. And I test this javascript on linux, and the result is also texttext (sorry for i don't hava a linux desktop environment to test the command with CopyQ directly).

var text = 'text\r\ntext';
console.log(text);
text = text.replace(/[\r\n]/g, '');
console.log(text);

Output:

text
text
texttext

The reason why I add this command is that on windows the terminal sometimes auto split single-line string, like alacritty/alacritty#2093 says. So I use this command to join them back and I don't think it's suitable
for using space ' '. I also test \R on windows but it doesn't work.

Could you explain more detail about why you think the result is textext, and how to use \R ? Thank you very much.

@JoyHak
Copy link

JoyHak commented Dec 22, 2025

I meant texttext. text\r\ntext is readable, because you can differentiate between 2 lines, but texttextis not.

@JoyHak
Copy link

JoyHak commented Dec 22, 2025

\R should match any crlf, technically it allows to find some Unicode line breaks

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

Successfully merging this pull request may close these issues.

3 participants