You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by re...@apache.org on 2012/06/02 13:27:17 UTC

svn commit: r1345489 - /incubator/clerezza/trunk/parent/shell/src/main/scala/org/apache/clerezza/shell/Shell.scala

Author: reto
Date: Sat Jun  2 11:27:16 2012
New Revision: 1345489

URL: http://svn.apache.org/viewvc?rev=1345489&view=rev
Log:
CLEREZZA-709: autocomplete for common prefix of multiple matches

Modified:
    incubator/clerezza/trunk/parent/shell/src/main/scala/org/apache/clerezza/shell/Shell.scala

Modified: incubator/clerezza/trunk/parent/shell/src/main/scala/org/apache/clerezza/shell/Shell.scala
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/shell/src/main/scala/org/apache/clerezza/shell/Shell.scala?rev=1345489&r1=1345488&r2=1345489&view=diff
==============================================================================
--- incubator/clerezza/trunk/parent/shell/src/main/scala/org/apache/clerezza/shell/Shell.scala (original)
+++ incubator/clerezza/trunk/parent/shell/src/main/scala/org/apache/clerezza/shell/Shell.scala Sat Jun  2 11:27:16 2012
@@ -171,6 +171,18 @@ class Shell(factory: InterpreterFactory,
 								CandidateListCompletionHandler.setBuffer(reader, candidates.get(0).toString, pos)
 							} else {
 								import collection.JavaConversions._
+								def commonHead(a: String,b: String):String = {
+									if (a.isEmpty || b.isEmpty) {
+									  ""
+									} else {
+										if (a(0) == b(0)) {
+											a(0)+commonHead(a.tail, b.tail)
+										} else ""
+									}
+								}
+								val canStrings = candidates.map(_.toString)
+								val longestCommonPrefix = canStrings.tail.foldRight(canStrings.head)((a,b) => commonHead(a,b))
+								CandidateListCompletionHandler.setBuffer(reader, longestCommonPrefix, pos)
 								out.println()
 								out.println(candidates.mkString("\t"))
 								out.print(prompt)