mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-13 09:57:51 +08:00
newedit/editutil: In BasicHandler, only insert the character when the key is a character.
This commit is contained in:
parent
f798ef1e98
commit
5adf29b15f
|
@ -1,6 +1,7 @@
|
|||
package editutil
|
||||
|
||||
import (
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/elves/elvish/edit/tty"
|
||||
|
@ -57,7 +58,7 @@ func BasicHandler(e tty.Event, st *types.State) types.HandlerAction {
|
|||
_, skip := utf8.DecodeRuneInString(raw.Code[raw.Dot:])
|
||||
raw.Dot += skip
|
||||
default:
|
||||
if k.Mod == 0 {
|
||||
if IsChar(k) {
|
||||
s := string(k.Rune)
|
||||
raw.Code = raw.Code[:raw.Dot] + s + raw.Code[raw.Dot:]
|
||||
raw.Dot += len(s)
|
||||
|
@ -67,3 +68,8 @@ func BasicHandler(e tty.Event, st *types.State) types.HandlerAction {
|
|||
}
|
||||
return types.NoAction
|
||||
}
|
||||
|
||||
// IsChar returns whether the given key is not a character insertion.
|
||||
func IsChar(k ui.Key) bool {
|
||||
return k.Mod == 0 && k.Rune > 0 && unicode.IsGraphic(k.Rune)
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"github.com/elves/elvish/edit/tty"
|
||||
"github.com/elves/elvish/edit/ui"
|
||||
"github.com/elves/elvish/newedit/types"
|
||||
"github.com/elves/elvish/tt"
|
||||
)
|
||||
|
||||
var basicHandlerKeyEventsTests = []struct {
|
||||
|
@ -85,3 +86,12 @@ func TestBasicHandler_IgnoresOtherEvents(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsChar(t *testing.T) {
|
||||
tt.Test(t, tt.Fn("IsChar", IsChar), tt.Table{
|
||||
Args(ui.K(ui.Up)).Rets(false),
|
||||
Args(ui.K('A', ui.Ctrl)).Rets(false),
|
||||
Args(ui.K('a')).Rets(true),
|
||||
Args(ui.K('好')).Rets(true),
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user