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

Fix for Multi-line pasting is broken #1309 #1313

Merged
merged 4 commits into from
Aug 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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