newedit: De-export BindingMap.

This commit is contained in:
Qi Xiao 2019-04-20 16:09:01 +01:00
parent 5adf29b15f
commit a140f3e622
8 changed files with 21 additions and 24 deletions

View File

@ -16,14 +16,13 @@ import (
// TODO(xiaq): Move the implementation into this package.
// BindingMap is a specialized map type for key bindings.
type BindingMap = eddefs.BindingMap
// A specialized map type for key bindings.
type bindingMap = eddefs.BindingMap
// EmptyBindingMap is an empty binding map. It is useful for building binding
// maps.
var EmptyBindingMap = eddefs.EmptyBindingMap
// An empty binding map. It is useful for building binding maps.
var emptyBindingMap = eddefs.EmptyBindingMap
func keyHandlerFromBindings(ed editor, ev *eval.Evaler, bs ...*BindingMap) func(ui.Key) types.HandlerAction {
func keyHandlerFromBindings(ed editor, ev *eval.Evaler, bs ...*bindingMap) func(ui.Key) types.HandlerAction {
return func(k ui.Key) types.HandlerAction {
f := indexLayeredBindings(k, bs...)
// TODO: Make this fallback part of GetOrDefault after moving BindingMap
@ -39,7 +38,7 @@ func keyHandlerFromBindings(ed editor, ev *eval.Evaler, bs ...*BindingMap) func(
// Indexes a series of layered bindings. Returns nil if none of the bindings
// have the required key or a default.
func indexLayeredBindings(k ui.Key, bindings ...*BindingMap) eval.Callable {
func indexLayeredBindings(k ui.Key, bindings ...*bindingMap) eval.Callable {
for _, binding := range bindings {
if binding.HasKey(k) {
return binding.GetKey(k)

View File

@ -44,7 +44,7 @@ func TestKeyHandlerFromBinding_SetsBindingKey(t *testing.T) {
func TestKeyHandlerFromBinding_Unbound(t *testing.T) {
ed := &fakeEditor{}
binding := EmptyBindingMap
binding := emptyBindingMap
handler := keyHandlerFromBindings(ed, eval.NewEvaler(), &binding)
action := handler(ui.Key{Rune: 'a'})
@ -89,7 +89,7 @@ func TestIndexLayeredBindings(t *testing.T) {
// Use lower layer default when upper layer does not have default
b, _ := binding2.Assoc(
ui.Default, eval.NewGoFn("[d2]", func() { called = 2 }))
binding2 = b.(BindingMap)
binding2 = b.(bindingMap)
called = 0
_ = handler(ui.K('d'))
@ -100,7 +100,7 @@ func TestIndexLayeredBindings(t *testing.T) {
// Prefer upper layer default
b, _ = binding1.Assoc(
ui.Default, eval.NewGoFn("[d1]", func() { called = 1 }))
binding1 = b.(BindingMap)
binding1 = b.(bindingMap)
called = 0
_ = handler(ui.K('d'))
@ -111,7 +111,7 @@ func TestIndexLayeredBindings(t *testing.T) {
// Exact matches in all layers are tried before falling back to default
b, _ = binding2.Assoc(
"c", eval.NewGoFn("[c2]", func() { called = 2 }))
binding2 = b.(BindingMap)
binding2 = b.(bindingMap)
called = 0
_ = handler(ui.K('c'))
@ -120,14 +120,14 @@ func TestIndexLayeredBindings(t *testing.T) {
}
}
func buildBinding(data ...interface{}) BindingMap {
binding := EmptyBindingMap
func buildBinding(data ...interface{}) bindingMap {
binding := emptyBindingMap
for i := 0; i < len(data); i += 2 {
result, err := EmptyBindingMap.Assoc(data[i], data[i+1])
result, err := emptyBindingMap.Assoc(data[i], data[i+1])
if err != nil {
panic(err)
}
binding = result.(BindingMap)
binding = result.(bindingMap)
}
return binding
}

View File

@ -7,8 +7,6 @@ import (
"github.com/elves/elvish/util"
)
type renderCb func(*types.RawState, *renderSetup) (notes, main *ui.Buffer)
type renderSetup struct {
height int
width int

View File

@ -15,7 +15,7 @@ import (
func initInsert(ed editor, ev *eval.Evaler) (*insert.Mode, eval.Ns) {
// Underlying abbreviation map and binding map.
abbr := vals.EmptyMap
binding := EmptyBindingMap
binding := emptyBindingMap
m := &insert.Mode{
KeyHandler: keyHandlerFromBindings(ed, ev, &binding),

View File

@ -35,7 +35,7 @@ func TestInitInsert_Abbr(t *testing.T) {
func TestInitInsert_Binding(t *testing.T) {
m, ns := initInsert(&fakeEditor{}, eval.NewEvaler())
called := 0
binding, err := EmptyBindingMap.Assoc("a",
binding, err := emptyBindingMap.Assoc("a",
eval.NewGoFn("test binding", func() { called++ }))
if err != nil {
panic(err)

View File

@ -9,8 +9,8 @@ import (
)
// Initializes states for the lastcmd mode and its API.
func initLastcmd(ed editor, ev *eval.Evaler, st storedefs.Store, lsMode *listing.Mode, lsBinding *BindingMap) eval.Ns {
binding := EmptyBindingMap
func initLastcmd(ed editor, ev *eval.Evaler, st storedefs.Store, lsMode *listing.Mode, lsBinding *bindingMap) eval.Ns {
binding := emptyBindingMap
mode := lastcmd.Mode{
Mode: lsMode,
KeyHandler: keyHandlerFromBindings(ed, ev, &binding, lsBinding),

View File

@ -14,7 +14,7 @@ func TestInitLastCmd_Start(t *testing.T) {
ed := &fakeEditor{}
ev := eval.NewEvaler()
lsMode := listing.Mode{}
lsBinding := EmptyBindingMap
lsBinding := emptyBindingMap
ns := initLastcmd(ed, ev, testStore, &lsMode, &lsBinding)

View File

@ -6,9 +6,9 @@ import (
"github.com/elves/elvish/newedit/listing"
)
func initListing(ed editor) (*listing.Mode, *BindingMap, eval.Ns) {
func initListing(ed editor) (*listing.Mode, *bindingMap, eval.Ns) {
mode := &listing.Mode{}
binding := EmptyBindingMap
binding := emptyBindingMap
ns := eval.Ns{
"binding": vars.FromPtr(&binding),
}.AddGoFns("<edit:listing>:", map[string]interface{}{