diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2015-09-10 16:24:26 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2015-09-11 00:21:56 +1000 |
commit | 7719a3cc908464d34d602a7a5a23e943059bb714 (patch) | |
tree | d0ec37077d206e42d27ca33ea3bf127b7cb2c81a /src/repl-jline/scala/tools | |
parent | b89874b7c0bb9ad8e2276b652580f3aaf3e5c621 (diff) | |
download | scala-7719a3cc908464d34d602a7a5a23e943059bb714.tar.gz scala-7719a3cc908464d34d602a7a5a23e943059bb714.tar.bz2 scala-7719a3cc908464d34d602a7a5a23e943059bb714.zip |
Workaround JLine bug for mid-line tab completion
Before:
```
scala> {" ".char<TAB>}
charAt chars
scala> {" ".char<CURSOR>}}
```
I noticed that pressing <SPACE>-<BACKSPACE> re-rendered the line
correctly, so I've added this workaround to our customization of
the JLine console reader.
After:
```
scala> {" ".char<TAB>}
charAt chars
scala> {" ".char<CURSOR>}
```
We can delete this workaround when JLine 2.13.1 is released, but
I haven't heard back about when this might happen.
Diffstat (limited to 'src/repl-jline/scala/tools')
-rw-r--r-- | src/repl-jline/scala/tools/nsc/interpreter/jline/JLineReader.scala | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/repl-jline/scala/tools/nsc/interpreter/jline/JLineReader.scala b/src/repl-jline/scala/tools/nsc/interpreter/jline/JLineReader.scala index 5082c99a76..b5db4c2098 100644 --- a/src/repl-jline/scala/tools/nsc/interpreter/jline/JLineReader.scala +++ b/src/repl-jline/scala/tools/nsc/interpreter/jline/JLineReader.scala @@ -10,7 +10,8 @@ package scala.tools.nsc.interpreter.jline import java.util.{Collection => JCollection, List => JList} import _root_.jline.{console => jconsole} -import jconsole.completer.{Completer, ArgumentCompleter} +import jline.console.ConsoleReader +import jline.console.completer.{CompletionHandler, Completer, ArgumentCompleter} import jconsole.history.{History => JHistory} @@ -142,6 +143,27 @@ private class JLineConsoleReader extends jconsole.ConsoleReader with interpreter case NoCompletion => () case _ => this addCompleter completer } + + // This is a workaround for https://github.com/jline/jline2/issues/208 + // and should not be necessary once we upgrade to JLine 2.13.1 + /// + // Test by: + // scala> {" ".char}<LEFT><TAB> + // + // And checking we don't get an extra } on the line. + /// + val handler = getCompletionHandler + setCompletionHandler(new CompletionHandler { + override def complete(consoleReader: ConsoleReader, list: JList[CharSequence], i: Int): Boolean = { + try { + handler.complete(consoleReader, list, i) + } finally if (getCursorBuffer.cursor != getCursorBuffer.length()) { + print(" ") + getCursorBuffer.write(' ') + backspace() + } + } + }) setAutoprintThreshold(400) // max completion candidates without warning } } |