Skip to content

Commit

Permalink
Now we have a cursor (only one)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthieu-Riou committed Nov 28, 2014
1 parent 5ea875b commit 8630fa3
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/main/scala/io/atal/butterfly/Interface.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ object HelloWorld extends SimpleSwingApplication {
var current: Editor = editorManager.currentEditor.get
var isSpec = false

object editor extends Label {
object editor extends EditorPane {
text = current.buffer.content
preferredSize = new Dimension(1000,500)

editable = false
caret.visible = true

focusable = true
requestFocus

Expand All @@ -38,6 +41,16 @@ object HelloWorld extends SimpleSwingApplication {
updateLabel
}

case KeyPressed(_, Key.Left, _, _) => {
isSpec = true
current.moveCursorsLeft()
}

case KeyPressed(_, Key.Right, _, _) => {
isSpec = true
current.moveCursorsRight()
}

case KeyPressed(_, x, _, _) => isSpec = false //Allow for non-specified KeyPressed (like Key.BackSpace) to be match with KeyTyped. It's ugly. Better way ?

case KeyTyped(_, y, _, _) => {
Expand All @@ -56,10 +69,11 @@ object HelloWorld extends SimpleSwingApplication {

}

def updateLabel: Unit = editor.text = bufferToLabel(current.buffer.content)
def updateLabel: Unit = {
editor.text = current.buffer.content
editor.caret.position = current.getIndexPosition(current.cursors.head)
}
}

def bufferToLabel(s: String) : String = return "<html>" + s.replaceAll("\n", "<br/>") + "</html>"

}

0 comments on commit 8630fa3

Please sign in to comment.