diff --git a/src/cmds/bind.jl b/src/cmds/bind.jl index 69bf321..d880079 100644 --- a/src/cmds/bind.jl +++ b/src/cmds/bind.jl @@ -7,15 +7,19 @@ function commandBind(ed::Editor, args::String) elseif !( length(arg_arr[1]) == 1 && isalpha(arg_arr[1][1]) ) setStatusMessage(ed, "bind: first arg must be a letter") return - # elseif !Base.isidentifier(arg_arr[2]) - # setStatusMessage(ed, "bind: command $(arg_arr[2]) is invalid") - # return end key = lowercase(arg_arr[1][1]) + command = join(arg_arr[2]) + + # If command is '~', unbind the key + if command == "~" + rmKeyBinding(key) + else + setKeyBinding(key, join(arg_arr[2])) + end - setKeyBinding(key, join(arg_arr[2])) end addCommand(:bind, commandBind, - help="bind : bind ctrl- to command ") + help="bind : bind ctrl- to command . = ~, unbind") diff --git a/test/cmds/test_bind.jl b/test/cmds/test_bind.jl new file mode 100644 index 0000000..848925f --- /dev/null +++ b/test/cmds/test_bind.jl @@ -0,0 +1,17 @@ +import Acorn.EditorConfig + +ed = Acorn.Editor() + +Acorn.commandBind(ed, "h help") +@test EditorConfig.isKeyBound('h') == true +@test EditorConfig.getKeyBinding('h') == "help" + +Acorn.commandBind(ed, "h ~") +@test EditorConfig.isKeyBound('h') == false + +EditorConfig.rmKeyBinding('c') +Acorn.commandBind(ed, "c") +@test EditorConfig.isKeyBound('c') == false + +Acorn.commandBind(ed, "a echo a b c d") +@test EditorConfig.isKeyBound('a') == true diff --git a/test/runtests.jl b/test/runtests.jl index 1a42869..360f8c3 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,11 @@ using Acorn using Base.Test -# write your own tests here -@test 1 == 2 +# Tests for commands +include("cmds/test_bind.jl") +# TODO: include tests for all commands + +# TODO: Include additional tests +# rows.jl +# editor.jl +# EditorCOnfig.jl