Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related YouTrack issue: https://youtrack.jetbrains.com/issue/SCL-20209/Scala-REPL-proper-multiline-paste-support-for-Scala-3-indentation-based-syntax
This PR is a suggestion of a temporary fix and contains information about the problem and suggestions for possible fixes.
Scala 3.4.2 updated their JLine version to 3.24.1. JLine has different behavior for different terminal types and if it can't detect a terminal it falls back to a "dumb terminal". JLine supports bracketed paste but they disabled it for dumb terminals in 3.18.0 (commit 542bfb6).
IntelliJ doesn't use bracketed paste for their integrated terminals. If using the "old terminal" in IntelliJ, it directly uses the system's terminal, therefore properly supporting bracketed paste and JLine detects the terminal type:
Scala REPL in IntelliJ:
Switching to the "new terminal" (Enable New Terminal Beta), it still detects the correct terminal type, but because the pasting is handled by IntelliJ, it doesn't use bracketed paste.
The JLine terminal detection checks for TTY access, which fails for the IntelliJ Scala REPL. There are other instances of JLine problems in IntelliJ too ([1], [2]), so the issue is larger than just the REPL. The IntelliJ Scala plugin also sets the dumb flag because it does not work with non-dumb terminals.
As a temporary workaround I decided to just remove all empty lines from the input. In non-bracketed mode, empty lines finish the statement. Removing them should work in most cases, except when there is empty lines in multiline strings
Possible fixes for the problem are:
A possible fix on the IntelliJ side would be to use the same terminal logic that the new terminal uses, but it would require changes in the main IntelliJ codebase, the IntelliJ Scala plugin and possibly JLine.
The custom UI will also make it easier to extend the REPL, for example adding graphics