/ld27

To get this branch, use:
bzr branch http://9ix.org/bzr/ld27

« back to all changes in this revision

Viewing changes to zoetrope/ui/textinput.lua

  • Committer: Josh C
  • Date: 2013-08-24 04:11:48 UTC
  • Revision ID: josh@9ix.org-20130824041148-npjyxboq6urktc8w
switch mazes

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
                        end
66
66
 
67
67
                        -- handle movement keys that repeat
 
68
                        -- we have to simulate repeat rates manually :(
68
69
 
 
70
                        local delay, rate = love.keyboard.getKeyRepeat()
69
71
                        local frameAction
70
72
 
71
73
                        for _, key in pairs{'backspace', 'delete', 'left', 'right'} do
72
74
                                if the.keys:pressed(key) then
73
 
                                        frameAction = key
74
 
                                        if the.keys:alreadyHandled(key) then
75
 
                                                frameAction = nil
 
75
                                        if self._repeatKey == key then
 
76
                                                self._repeatTimer = self._repeatTimer + elapsed
 
77
                                                
 
78
                                                -- if we've made it past the maximum delay, then
 
79
                                                -- we reset the timer and take action
 
80
 
 
81
                                                if self._repeatTimer > delay + rate then
 
82
                                                        self._repeatTimer = delay
 
83
                                                        frameAction = key
 
84
                                                end
 
85
                                        else
 
86
                                                -- we've just started holding down the key
 
87
 
 
88
                                                self._repeatKey = key
 
89
                                                self._repeatTimer = 0
 
90
                                                frameAction = key
 
91
                                        end
 
92
                                else
 
93
                                        if self._repeatKey == key then
 
94
                                                self._repeatKey = nil
76
95
                                        end
77
96
                                end
78
97
                        end
79
98
 
80
 
 
81
99
                        if frameAction == 'backspace' and self.caret > 0 then
82
100
                                self.text = string.sub(self.text, 1, self.caret - 1) .. string.sub(self.text, self.caret + 1)
83
101
                                self.caret = self.caret - 1