mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-12-02 16:59:32 +01:00
fix(tmux): drop a leading blank line made of spaces, not only line breaks
`" \nfix it\r"` still pasted a blank first line, because the leading strip only matched `\n`. /^\s*\n/ drops everything up to the last leading line break, mirroring the trimEnd() at the other end, and the first real line keeps its indentation. The test row fails with the old pattern. Co-Authored-By: Christian Haberl <116439789+christianhaberl@users.noreply.github.com> Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
2fe9105bab
commit
9a00c2feaa
2 files changed
+13
-3
No files matched your search
+8
-3
@@ -3863,9 +3863,14 @@ export class TmuxManager extends EventEmitter implements TerminalMultiplexer {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const hasCarriageReturn = input.includes('\r');
|
const hasCarriageReturn = input.includes('\r');
|
||||||
// Leading and trailing line breaks are dropped, so `"\nfix it\r"` does not paste
|
// Leading and trailing blank lines are dropped, so neither `"\nfix it\r"` nor
|
||||||
// an empty first line (nor `"fix it\n\r"` an empty last one).
|
// `" \nfix it\r"` pastes an empty first line (nor `"fix it\n\r"` an empty last
|
||||||
const textPart = input.replace(/\r/g, '').replace(/^\n+/, '').trimEnd();
|
// one). The leading match ends at a line break, so the first real line keeps its
|
||||||
|
// indentation.
|
||||||
|
const textPart = input
|
||||||
|
.replace(/\r/g, '')
|
||||||
|
.replace(/^\s*\n/, '')
|
||||||
|
.trimEnd();
|
||||||
|
|
||||||
if (textPart && hasCarriageReturn) {
|
if (textPart && hasCarriageReturn) {
|
||||||
// Send text first, then Enter as a SEPARATE tmux command after a short delay.
|
// Send text first, then Enter as a SEPARATE tmux command after a short delay.
|
||||||
|
|||||||
@@ -261,6 +261,11 @@ describe('sendInput line breaks', () => {
|
|||||||
await multi.sendInput('s1', '\r\n\r\none\ntwo\r');
|
await multi.sendInput('s1', '\r\n\r\none\ntwo\r');
|
||||||
expect(bufferText(multi.ran[0])).toBe('one\ntwo');
|
expect(bufferText(multi.ran[0])).toBe('one\ntwo');
|
||||||
|
|
||||||
|
// A blank first line made of spaces is dropped too; the first real line keeps its indentation.
|
||||||
|
const spaced = managerWithSession();
|
||||||
|
await spaced.sendInput('s1', ' \n\t\n fix it\nnow\r');
|
||||||
|
expect(bufferText(spaced.ran[0])).toBe(' fix it\nnow');
|
||||||
|
|
||||||
// Without an Enter, what is left is one line, so it is typed like any other.
|
// Without an Enter, what is left is one line, so it is typed like any other.
|
||||||
const typed = managerWithSession();
|
const typed = managerWithSession();
|
||||||
await typed.sendInput('s1', '\n\njust type');
|
await typed.sendInput('s1', '\n\njust type');
|
||||||
|
|||||||
Reference in new issue
Block a user