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

Commit

Permalink
Merge pull request #1313 from ABouzo/issue_1309-multiline
Browse files Browse the repository at this point in the history
Fix for Multi-line pasting is broken #1309
  • Loading branch information
le0pard authored Aug 31, 2018
2 parents 02d7701 + 8a65e0b commit da8b1c7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/shell/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export abstract class ASTNode {
abstract get fullEnd(): number;
}

const isEndOfCommand = (token: Scanner.Token) => token instanceof Scanner.Semicolon || token instanceof Scanner.NewLine;

abstract class LeafNode extends ASTNode {
constructor(private token: Scanner.Token) {
super();
Expand Down Expand Up @@ -86,11 +88,14 @@ abstract class BranchNode extends ASTNode {
}
}

/**
* The whole command, the input string.
*/
export class CompleteCommand extends BranchNode {
@memoizeAccessor
get children(): ASTNode[] {
const lastChild = _.last(this.tokens)!;
const endsWithSeparator = lastChild instanceof Scanner.Semicolon;
const endsWithSeparator = isEndOfCommand(lastChild);

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

if (separatorOpIndex !== -1) {
return [
Expand Down
16 changes: 16 additions & 0 deletions src/shell/Scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,16 @@ export class DoubleQuotedStringLiteral extends StringLiteral {
}
}

export class NewLine extends Token {
get value() {
return this.raw;
}

get escapedValue() {
return this.value as EscapedShellWord;
}
}

export class Invalid extends Token {
get value() {
return this.raw.trim();
Expand All @@ -157,7 +167,13 @@ export class Invalid extends Token {
}
}

// All these regex start ^ so that we can look only at the first token. Maybe that should
// be part of the scanner so that the regex can be just for the token
const patterns = [
{
regularExpression: /^(\n)/,
tokenConstructor: NewLine,
},
{
regularExpression: /^(\s*\|\s*)/,
tokenConstructor: Pipe,
Expand Down
4 changes: 4 additions & 0 deletions src/views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@
color: var(--green-color);
}

.job-header div {
white-space: pre;
}

.output {
white-space: pre-wrap;
position: relative;
Expand Down

0 comments on commit da8b1c7

Please sign in to comment.