Skip to content

Commit

Permalink
building completion list from all visible buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcin Kulik committed Oct 12, 2009
1 parent bb90c03 commit 1903c9e
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/net/sickill/finishhim/FinishHimCompletor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import org.gjt.sp.jedit.textarea.JEditTextArea
import org.gjt.sp.jedit.textarea.Selection
import org.gjt.sp.util.Log
import org.gjt.sp.jedit.TextUtilities
import org.gjt.sp.jedit.jEdit
import org.gjt.sp.jedit.visitors.JEditVisitorAdapter
import org.gjt.sp.jedit.EditPane
import scala.collection.jcl.ArrayList

class FinishHimCompletor(view: View) {
var wordList: List[String] = List()
Expand All @@ -31,7 +35,7 @@ class FinishHimCompletor(view: View) {
log("found prefix: " + prefix)
prefixLength = prefix.length()
suggestedWordLength = prefixLength
buildWordList(prefix, buffer.getText(0, buffer.getLength()))
buildWordList(prefix, getVisibleBuffers())
} else {
log("empty prefix, leaving")
wordList = List()
Expand Down Expand Up @@ -60,10 +64,24 @@ class FinishHimCompletor(view: View) {
nextWordIndex = (nextWordIndex + 1) % wordList.size
}
}

def getVisibleBuffers() = {
val buffers = new ArrayList[Buffer]()
jEdit.visit(new JEditVisitorAdapter() {
override def visit(editPane: EditPane) : Unit = {
buffers.add(editPane.getBuffer())
}
})
buffers
}

def buildWordList(prefix: String, bufferText: String) = {
def buildWordList(prefix: String, buffers: ArrayList[Buffer]) = {
log("buildWordList()")
wordList = List.fromArray(bufferText.split("[^\\w]+")).removeDuplicates.filter { word => word.startsWith(prefix) } - prefix
var buffersText = ""
for (buffer <- buffers) {
buffersText += " " + buffer.getText(0, buffer.getLength())
}
wordList = List.fromArray(buffersText.split("[^\\w]+")).removeDuplicates.filter { word => word.startsWith(prefix) } - prefix
log("wordList = " + wordList)
}

Expand Down

0 comments on commit 1903c9e

Please sign in to comment.