Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.

Commit da8b1c7

Browse files
authored
Merge pull request #1313 from ABouzo/issue_1309-multiline
Fix for Multi-line pasting is broken #1309
2 parents 02d7701 + 8a65e0b commit da8b1c7

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src/shell/Parser.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export abstract class ASTNode {
2121
abstract get fullEnd(): number;
2222
}
2323

24+
const isEndOfCommand = (token: Scanner.Token) => token instanceof Scanner.Semicolon || token instanceof Scanner.NewLine;
25+
2426
abstract class LeafNode extends ASTNode {
2527
constructor(private token: Scanner.Token) {
2628
super();
@@ -86,11 +88,14 @@ abstract class BranchNode extends ASTNode {
8688
}
8789
}
8890

91+
/**
92+
* The whole command, the input string.
93+
*/
8994
export class CompleteCommand extends BranchNode {
9095
@memoizeAccessor
9196
get children(): ASTNode[] {
9297
const lastChild = _.last(this.tokens)!;
93-
const endsWithSeparator = lastChild instanceof Scanner.Semicolon;
98+
const endsWithSeparator = isEndOfCommand(lastChild);
9499

95100
if (endsWithSeparator) {
96101
return [
@@ -117,7 +122,7 @@ export class CompleteCommand extends BranchNode {
117122
class List extends BranchNode {
118123
@memoizeAccessor
119124
get children(): ASTNode[] {
120-
const separatorOpIndex = _.findLastIndex(this.tokens, token => token instanceof Scanner.Semicolon);
125+
const separatorOpIndex = _.findLastIndex(this.tokens, isEndOfCommand);
121126

122127
if (separatorOpIndex !== -1) {
123128
return [

src/shell/Scanner.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,16 @@ export class DoubleQuotedStringLiteral extends StringLiteral {
147147
}
148148
}
149149

150+
export class NewLine extends Token {
151+
get value() {
152+
return this.raw;
153+
}
154+
155+
get escapedValue() {
156+
return this.value as EscapedShellWord;
157+
}
158+
}
159+
150160
export class Invalid extends Token {
151161
get value() {
152162
return this.raw.trim();
@@ -157,7 +167,13 @@ export class Invalid extends Token {
157167
}
158168
}
159169

170+
// All these regex start ^ so that we can look only at the first token. Maybe that should
171+
// be part of the scanner so that the regex can be just for the token
160172
const patterns = [
173+
{
174+
regularExpression: /^(\n)/,
175+
tokenConstructor: NewLine,
176+
},
161177
{
162178
regularExpression: /^(\s*\|\s*)/,
163179
tokenConstructor: Pipe,

src/views/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@
289289
color: var(--green-color);
290290
}
291291

292+
.job-header div {
293+
white-space: pre;
294+
}
295+
292296
.output {
293297
white-space: pre-wrap;
294298
position: relative;

0 commit comments

Comments
 (0)