Substantially revised after feedback from @SeeminglyScience.
PS version: 6.1.0-preview.4
PSReadline version: 2.0.0-beta2
os: Linux vm-ub16 4.4.0-131-generic #157-Ubuntu SMP Thu Jul 12 15:51:36 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
PS file version:
If you have a key handler installed that inserts a matching parenthesis/bracket/brace, pasting multiline strings _breaks_:
{
'hi'
}
results in:
PS>{}
PS> 'hi'
hi
PS> }
At line:1 char:1
+ }
+ ~
Unexpected token '}' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken
It seems that pasting triggers the same behaviors as when _typing_, which is undesired.
That is, the {
that is pasted on the first line causes a matching }
to be inserted, which breaks the code.
Is it possible this is a profile difference?
The first line PS>{}
makes me think you have this key handler from the sample profile registered.
Same thing happens with me in all platforms with that key handler registered.
@SeeminglyScience:
Great sleuthing, thank you.
Indeed, that was the problem and with that key handler in place it indeed also happens on Windows.
I've updated the original post.
@lzybkr:
Is there a way we can have our cake and eat it too?
I would't want to have to choose between the two features (pasting multiline snippets vs. paren/bracket/brace matching).
Or can you for technical reasons not tell the difference between code being _typed_ vs. being _pasted_?
Or can you for technical reasons not tell the difference between code being typed vs. being _pasted?
That's right unfortunately, unless the paste is handled via a key handler. #579 is tracking that.
Thanks, @SeeminglyScience - I've added a comment there and I'm closing this.