Skip to content

Commit

Permalink
Merge pull request #507 from bawigga/capital-letter-entry
Browse files Browse the repository at this point in the history
Fix for Capital Letter Entry
  • Loading branch information
zoli committed Feb 28, 2015
2 parents 0b66ebb + 762fb78 commit 38504a6
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 20 deletions.
4 changes: 2 additions & 2 deletions backend/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ func (e *Editor) inputthread() {
goto try_again
} else if kp.IsCharacter() {
p2 := Prof.Enter("hi.character")
log.Finest("kp: %v, pos: %v", kp, possible_actions)
if err := e.CommandHandler().RunTextCommand(v, "insert", Args{"characters": string(rune(kp.Key))}); err != nil {
log.Finest("[editor.inputthread] kp: |%s|, pos: %v", kp.Text, possible_actions)
if err := e.CommandHandler().RunTextCommand(v, "insert", Args{"characters": kp.Text}); err != nil {
log.Debug("Couldn't run textcommand: %s", err)
}
p2.Exit()
Expand Down
16 changes: 8 additions & 8 deletions backend/keys/keypress.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import (
"unicode"
)

type (
// A Key press with the given Key
// and modifiers.
KeyPress struct {
Key Key
Shift, Super, Alt, Ctrl bool
}
)
// KeyPress describes a key press event.
// Note that Key does not distinguish between capital and non-capital letters;
// use the Text property for this purpose.
type KeyPress struct {
Text string // the text representation of the key
Key Key // the code for the key that was pressed
Shift, Super, Alt, Ctrl bool // true if modifier key was pressed
}

// Returns an index used for sorting key presses.
// TODO(.): This is in no way a unique index with quite a lot of collisions and potentially resulting
Expand Down
6 changes: 3 additions & 3 deletions backend/keys/keypress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestKeyPressIsCharacter(t *testing.T) {
}

func TestKeyPressFix(t *testing.T) {
k := KeyPress{'A', false, false, false, false}
k := KeyPress{"A", 'A', false, false, false, false}
k.fix()
if k.Key != 'a' {
t.Errorf("Expected the key to be %q, but it was %q", 'a', k.Key)
Expand All @@ -97,12 +97,12 @@ func TestKeyPressUnmarshalJSON(t *testing.T) {
}

func TestKeyPressString(t *testing.T) {
k1 := KeyPress{'a', true, true, false, false}
k1 := KeyPress{"a", 'a', true, true, false, false}
if k1.String() != "super+shift+a" {
t.Errorf("Expected %q, but got %q", "super+shift+a", k1.String())
}

k2 := KeyPress{'b', true, false, true, true}
k2 := KeyPress{"b", 'b', true, false, true, true}
if k2.String() != "ctrl+alt+shift+b" {
t.Errorf("Expected %q, but got %q", "ctrl+alt+shift+b", k2.String())
}
Expand Down
2 changes: 0 additions & 2 deletions backend/sublime/events_manual.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,6 @@ func (c *OnQueryContextGlue) onQueryContext(v *backend.View, key string, operato
}
defer ret.Decref()

// if ret != nil {
log.Fine("onQueryContext: %v, %v", pv, ret.Base())
if r2, ok := ret.(*py.Bool); ok {
if r2.Bool() {
return backend.True
Expand Down
6 changes: 6 additions & 0 deletions frontend/html/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ func (t *tbfe) render(w io.Writer) {
}
// runes := []rune(t.status_message)
}

// key HandleFunc for the http /key endpoint. This only happens if the client
// doesn't support websockets.
func (t *tbfe) key(w http.ResponseWriter, req *http.Request) {
log.Debug("key: %s", req)
kc := req.FormValue("keyCode")
Expand All @@ -240,10 +243,12 @@ func (t *tbfe) key(w http.ResponseWriter, req *http.Request) {
if req.FormValue("shiftKey") == "true" {
kp.Shift = true
}

if !kp.Shift {
v = int64(unicode.ToLower(rune(v)))
}
kp.Key = keys.Key(v)
kp.Text = string(v)
backend.GetEditor().HandleInput(kp)
}

Expand Down Expand Up @@ -405,6 +410,7 @@ func (t *tbfe) WebsocketServer(ws *websocket.Conn) {
v = int64(unicode.ToLower(rune(v)))
}
kp.Key = keys.Key(v)
kp.Text = string(v)
}

backend.GetEditor().HandleInput(kp)
Expand Down
2 changes: 1 addition & 1 deletion frontend/qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ ApplicationWindow {
anchors.fill: parent
Keys.onPressed: {
view().ctrl = (event.key == Qt.Key_Control) ? true : false;
event.accepted = frontend.handleInput(event.key, event.modifiers)
event.accepted = frontend.handleInput(event.text, event.key, event.modifiers)
}
Keys.onReleased: {
view().ctrl = (event.key == Qt.Key_Control) ? false : view().ctrl;
Expand Down
6 changes: 3 additions & 3 deletions frontend/qml/qml_frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ func (t *qmlfrontend) RunCommandWithArgs(command string, args backend.Args) {
go ed.RunCommand(command, args)
}

func (t *qmlfrontend) HandleInput(keycode int, modifiers int) bool {
log.Debug("qmlfrontend.HandleInput: key=%x, modifiers=%x", keycode, modifiers)
func (t *qmlfrontend) HandleInput(text string, keycode int, modifiers int) bool {
log.Debug("qmlfrontend.HandleInput: text=%v, key=%x, modifiers=%x", text, keycode, modifiers)
shift := false
alt := false
ctrl := false
Expand Down Expand Up @@ -246,7 +246,7 @@ func (t *qmlfrontend) HandleInput(keycode int, modifiers int) bool {
}
}

ed.HandleInput(keys.KeyPress{Key: key, Shift: shift, Alt: alt, Ctrl: ctrl, Super: super})
ed.HandleInput(keys.KeyPress{Text: text, Key: key, Shift: shift, Alt: alt, Ctrl: ctrl, Super: super})
return true
}
return false
Expand Down
3 changes: 2 additions & 1 deletion frontend/termbox/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,6 @@ func (t *tbfe) renderthread() {
}

for range t.dorender {
log.Finest("Rendering")
dorender()
}
}
Expand Down Expand Up @@ -504,8 +503,10 @@ func (t *tbfe) handleInput(ev termbox.Event) {
var kp keys.KeyPress
if ev.Ch != 0 {
kp.Key = keys.Key(ev.Ch)
kp.Text = string(ev.Ch)
} else if v2, ok := lut[ev.Key]; ok {
kp = v2
kp.Text = string(kp.Key)
} else {
return
}
Expand Down

0 comments on commit 38504a6

Please sign in to comment.