mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-29 22:27:13 +09:00
Improve word movement behavior
This commit is contained in:
@@ -218,10 +218,10 @@ func (c *Cursor) SelectTo(loc int) {
|
|||||||
// WordRight moves the cursor one word to the right
|
// WordRight moves the cursor one word to the right
|
||||||
func (c *Cursor) WordRight() {
|
func (c *Cursor) WordRight() {
|
||||||
c.Right()
|
c.Right()
|
||||||
for !IsWordChar(string(c.RuneUnder(c.x))) {
|
for IsWhitespace(c.RuneUnder(c.x)) {
|
||||||
c.Right()
|
c.Right()
|
||||||
}
|
}
|
||||||
for IsWordChar(string(c.RuneUnder(c.x))) {
|
for !IsWhitespace(c.RuneUnder(c.x)) {
|
||||||
c.Right()
|
c.Right()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -229,10 +229,10 @@ func (c *Cursor) WordRight() {
|
|||||||
// WordLeft moves the cursor one word to the left
|
// WordLeft moves the cursor one word to the left
|
||||||
func (c *Cursor) WordLeft() {
|
func (c *Cursor) WordLeft() {
|
||||||
c.Left()
|
c.Left()
|
||||||
for !IsWordChar(string(c.RuneUnder(c.x))) {
|
for IsWhitespace(c.RuneUnder(c.x)) {
|
||||||
c.Left()
|
c.Left()
|
||||||
}
|
}
|
||||||
for IsWordChar(string(c.RuneUnder(c.x))) {
|
for !IsWhitespace(c.RuneUnder(c.x)) {
|
||||||
c.Left()
|
c.Left()
|
||||||
}
|
}
|
||||||
c.Right()
|
c.Right()
|
||||||
|
|||||||
@@ -62,6 +62,11 @@ func IsWordChar(str string) bool {
|
|||||||
return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c == '_')
|
return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c == '_')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsWhitespace returns true if the given rune is a space, tab, or newline
|
||||||
|
func IsWhitespace(c rune) bool {
|
||||||
|
return c == ' ' || c == '\t' || c == '\n'
|
||||||
|
}
|
||||||
|
|
||||||
// Contains returns whether or not a string array contains a given string
|
// Contains returns whether or not a string array contains a given string
|
||||||
func Contains(list []string, a string) bool {
|
func Contains(list []string, a string) bool {
|
||||||
for _, b := range list {
|
for _, b := range list {
|
||||||
|
|||||||
Reference in New Issue
Block a user