Add soft line home
This commit is contained in:
parent
9079aca993
commit
1c38ed2d87
@ -405,7 +405,7 @@ func (this *textBox) handleKeyDown (key input.Key, numberPad bool) bool {
|
|||||||
|
|
||||||
switch {
|
switch {
|
||||||
case key == input.KeyHome || (modifiers.Alt && key == input.KeyLeft):
|
case key == input.KeyHome || (modifiers.Alt && key == input.KeyLeft):
|
||||||
dot.End = lineHome(this.runes, dot.End)
|
dot.End = lineHomeSoft(this.runes, dot.End)
|
||||||
if !sel { dot.Start = dot.End }
|
if !sel { dot.Start = dot.End }
|
||||||
this.Select(dot)
|
this.Select(dot)
|
||||||
return true
|
return true
|
||||||
@ -618,8 +618,6 @@ func nextParagraph (text []rune, index int) int {
|
|||||||
return index
|
return index
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: make functions on top of these that support soft home/end
|
|
||||||
|
|
||||||
func lineHome (text []rune, index int) int {
|
func lineHome (text []rune, index int) int {
|
||||||
liminal := index < len(text) && text[index] == '\n'
|
liminal := index < len(text) && text[index] == '\n'
|
||||||
if index >= len(text) { index = len(text) - 1 }
|
if index >= len(text) { index = len(text) - 1 }
|
||||||
@ -633,6 +631,19 @@ func lineHome (text []rune, index int) int {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func lineHomeSoft (text []rune, index int) int {
|
||||||
|
home := lineHome(text, index)
|
||||||
|
start := home
|
||||||
|
for start < len(text) && unicode.IsSpace(text[start]) {
|
||||||
|
start ++
|
||||||
|
}
|
||||||
|
if index == start {
|
||||||
|
return home
|
||||||
|
} else {
|
||||||
|
return start
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func lineEnd (text []rune, index int) int {
|
func lineEnd (text []rune, index int) int {
|
||||||
for ; index < len(text); index ++ {
|
for ; index < len(text); index ++ {
|
||||||
char := text[index]
|
char := text[index]
|
||||||
|
Loading…
Reference in New Issue
Block a user