Skip to content

Commit f56c44c

Browse files
Pierre Championzephylac
Pierre Champion
authored andcommitted
feat: support for Delete shortcuts
Rework the TextInput shortcuts
1 parent fdcc70a commit f56c44c

File tree

4 files changed

+270
-0
lines changed

4 files changed

+270
-0
lines changed

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
33
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
44
github.com/go-gl/glfw v0.0.0-20190217072633-93b30450e032 h1:WUDJN6o1AZlnNR0UZ11zsr0Quh44CV7svcg6VzEsySc=
55
github.com/go-gl/glfw v0.0.0-20190217072633-93b30450e032/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
6+
github.com/go-gl/glfw v0.0.0-20190519095719-e6da0acd62b1 h1:noz9OnjV5PMOZWNOI+y1cS5rnxuJfpY6leIgQEEdBQw=
7+
github.com/go-gl/glfw v0.0.0-20190519095719-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
68
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
79
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
810
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

textinput_darwin.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package flutter
2+
3+
import "github.com/go-gl/glfw/v3.2/glfw"
4+
5+
func (p *keyboardShortcutsGLFW) isModifier() bool {
6+
return p.mod&glfw.ModSuper != 0
7+
}
8+
9+
func (p *keyboardShortcutsGLFW) isShift() bool {
10+
return p.mod&glfw.ModShift != 0
11+
}
12+
13+
func (p *keyboardShortcutsGLFW) isWordTravel() bool {
14+
return p.mod&glfw.ModAlt != 0
15+
}
16+
17+
func (p *keyboardShortcutsGLFW) isWordTravelShift() bool {
18+
return p.mod&glfw.ModAlt != 0 && p.mod&glfw.ModShift != 0
19+
}
20+
21+
func (p *textinputPlugin) MoveCursorHome(mods keyboardShortcutsGLFW) {
22+
23+
if mods.isShift() {
24+
p.moveCursorHomeSelect()
25+
} else {
26+
p.moveCursorHomeNoSelect()
27+
}
28+
}
29+
30+
func (p *textinputPlugin) MoveCursorEnd(mods keyboardShortcutsGLFW) {
31+
if mods.isShift() {
32+
p.moveCursorEndSelect()
33+
} else {
34+
p.moveCursorEndNoSelect()
35+
}
36+
}
37+
38+
func (p *textinputPlugin) MoveCursorLeft(mods keyboardShortcutsGLFW) {
39+
if mods.isWordTravelShift() {
40+
p.extendSelectionLeftLine()
41+
} else if mods.isWordTravel() {
42+
p.extendSelectionLeftWord()
43+
} else if mods.isShift() {
44+
p.extendSelectionLeftChar()
45+
} else {
46+
p.extendSelectionLeftReset()
47+
}
48+
}
49+
50+
func (p *textinputPlugin) MoveCursorRight(mods keyboardShortcutsGLFW) {
51+
if mods.isWordTravelShift() {
52+
p.extendSelectionRightLine()
53+
} else if mods.isWordTravel() {
54+
p.extendSelectionRightWord()
55+
} else if mods.isShift() {
56+
p.extendSelectionRightChar()
57+
} else {
58+
p.extendSelectionRightReset()
59+
}
60+
}
61+
62+
func (p *textinputPlugin) Backspace(mods keyboardShortcutsGLFW) {
63+
if p.removeSelectedText() {
64+
p.updateEditingState()
65+
return
66+
}
67+
68+
if mods.isModifier() {
69+
p.sliceLeftLine()
70+
} else if mods.isWordTravel() {
71+
p.sliceLeftWord()
72+
} else {
73+
p.sliceLeftChar()
74+
}
75+
}
76+
77+
func (p *textinputPlugin) Delete(mods keyboardShortcutsGLFW) {
78+
if p.removeSelectedText() {
79+
p.updateEditingState()
80+
return
81+
}
82+
83+
if mods.isWordTravelShift() {
84+
p.sliceRightLine()
85+
} else if mods.isWordTravel() {
86+
p.sliceRightWord()
87+
} else {
88+
p.sliceRightChar()
89+
}
90+
}

textinput_linux.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package flutter
2+
3+
import "github.com/go-gl/glfw/v3.2/glfw"
4+
5+
func (p *keyboardShortcutsGLFW) isModifier() bool {
6+
return p.mod&glfw.ModControl != 0
7+
}
8+
9+
func (p *keyboardShortcutsGLFW) isShift() bool {
10+
return p.mod&glfw.ModShift != 0
11+
}
12+
13+
func (p *keyboardShortcutsGLFW) isWordTravel() bool {
14+
return p.mod&glfw.ModControl != 0
15+
}
16+
17+
func (p *keyboardShortcutsGLFW) isWordTravelShift() bool {
18+
return p.mod&glfw.ModControl != 0 && p.mod&glfw.ModShift != 0
19+
}
20+
21+
func (p *textinputPlugin) MoveCursorHome(mods keyboardShortcutsGLFW) {
22+
if mods.isShift() {
23+
p.moveCursorHomeSelect()
24+
} else {
25+
p.moveCursorHomeNoSelect()
26+
}
27+
}
28+
29+
func (p *textinputPlugin) MoveCursorEnd(mods keyboardShortcutsGLFW) {
30+
if mods.isShift() {
31+
p.moveCursorEndSelect()
32+
} else {
33+
p.moveCursorEndNoSelect()
34+
}
35+
}
36+
37+
func (p *textinputPlugin) MoveCursorLeft(mods keyboardShortcutsGLFW) {
38+
if mods.isWordTravelShift() {
39+
p.extendSelectionLeftLine()
40+
} else if mods.isWordTravel() {
41+
p.extendSelectionLeftWord()
42+
} else if mods.isShift() {
43+
p.extendSelectionLeftChar()
44+
} else {
45+
p.extendSelectionLeftReset()
46+
}
47+
}
48+
49+
func (p *textinputPlugin) MoveCursorRight(mods keyboardShortcutsGLFW) {
50+
if mods.isWordTravelShift() {
51+
p.extendSelectionRightLine()
52+
} else if mods.isWordTravel() {
53+
p.extendSelectionRightWord()
54+
} else if mods.isShift() {
55+
p.extendSelectionRightChar()
56+
} else {
57+
p.extendSelectionRightReset()
58+
}
59+
}
60+
61+
func (p *textinputPlugin) Backspace(mods keyboardShortcutsGLFW) {
62+
if p.removeSelectedText() {
63+
p.updateEditingState()
64+
return
65+
}
66+
67+
if mods.isWordTravelShift() {
68+
p.sliceLeftLine()
69+
} else if mods.isWordTravel() {
70+
p.sliceLeftWord()
71+
} else {
72+
p.sliceLeftChar()
73+
}
74+
}
75+
76+
func (p *textinputPlugin) Delete(mods keyboardShortcutsGLFW) {
77+
if p.removeSelectedText() {
78+
p.updateEditingState()
79+
return
80+
}
81+
82+
if mods.isWordTravelShift() {
83+
p.sliceRightLine()
84+
} else if mods.isWordTravel() {
85+
p.sliceRightWord()
86+
} else {
87+
p.sliceRightChar()
88+
}
89+
}

textinput_windows.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package flutter
2+
3+
import "github.com/go-gl/glfw/v3.2/glfw"
4+
5+
func (p *keyboardShortcutsGLFW) isModifier() bool {
6+
return p.mod&glfw.ModControl != 0
7+
}
8+
9+
func (p *keyboardShortcutsGLFW) isShift() bool {
10+
return p.mod&glfw.ModShift != 0
11+
}
12+
13+
func (p *keyboardShortcutsGLFW) isWordTravel() bool {
14+
return p.mod&glfw.ModControl != 0
15+
}
16+
17+
func (p *keyboardShortcutsGLFW) isWordTravelShift() bool {
18+
return p.mod&glfw.ModControl != 0 && p.mod&glfw.ModShift != 0
19+
}
20+
21+
func (p *textinputPlugin) MoveCursorHome(mods keyboardShortcutsGLFW) {
22+
if mods.isShift() {
23+
p.moveCursorHomeSelect()
24+
} else {
25+
p.moveCursorHomeNoSelect()
26+
}
27+
}
28+
29+
func (p *textinputPlugin) MoveCursorEnd(mods keyboardShortcutsGLFW) {
30+
if mods.isShift() {
31+
p.moveCursorEndSelect()
32+
} else {
33+
p.moveCursorEndNoSelect()
34+
}
35+
}
36+
37+
func (p *textinputPlugin) MoveCursorLeft(mods keyboardShortcutsGLFW) {
38+
if mods.isWordTravelShift() {
39+
p.extendSelectionLeftLine()
40+
} else if mods.isWordTravel() {
41+
p.extendSelectionLeftWord()
42+
} else if mods.isShift() {
43+
p.extendSelectionLeftChar()
44+
} else {
45+
p.extendSelectionLeftReset()
46+
}
47+
}
48+
49+
func (p *textinputPlugin) MoveCursorRight(mods keyboardShortcutsGLFW) {
50+
if mods.isWordTravelShift() {
51+
p.extendSelectionRightLine()
52+
} else if mods.isWordTravel() {
53+
p.extendSelectionRightWord()
54+
} else if mods.isShift() {
55+
p.extendSelectionRightChar()
56+
} else {
57+
p.extendSelectionRightReset()
58+
}
59+
}
60+
61+
func (p *textinputPlugin) Backspace(mods keyboardShortcutsGLFW) {
62+
if p.removeSelectedText() {
63+
p.updateEditingState()
64+
return
65+
}
66+
67+
if mods.isWordTravelShift() {
68+
p.sliceLeftLine()
69+
} else if mods.isWordTravel() {
70+
p.sliceLeftWord()
71+
} else {
72+
p.sliceLeftChar()
73+
}
74+
}
75+
76+
func (p *textinputPlugin) Delete(mods keyboardShortcutsGLFW) {
77+
if p.removeSelectedText() {
78+
p.updateEditingState()
79+
return
80+
}
81+
82+
if mods.isWordTravelShift() {
83+
p.sliceRightLine()
84+
} else if mods.isWordTravel() {
85+
p.sliceRightWord()
86+
} else {
87+
p.sliceRightChar()
88+
}
89+
}

0 commit comments

Comments
 (0)