mirror of
https://github.com/zyedidia/micro.git
synced 2026-02-04 22:20:20 +09:00
Implemented SubWordRight, SubWordLeft, SelectSubWordRight, SelectSubWordLeft and DeleteSubWordRight, DeleteSubWordLeft
This commit is contained in:
@@ -438,6 +438,127 @@ func (c *Cursor) WordLeft() {
|
||||
c.Right()
|
||||
}
|
||||
|
||||
// SubWordRight moves the cursor one sub-word to the right
|
||||
func (c *Cursor) SubWordRight() {
|
||||
if util.IsWhitespace(c.RuneUnder(c.X)) {
|
||||
for util.IsWhitespace(c.RuneUnder(c.X)) {
|
||||
if c.X == util.CharacterCount(c.buf.LineBytes(c.Y)) {
|
||||
c.Right()
|
||||
return
|
||||
}
|
||||
c.Right()
|
||||
}
|
||||
return
|
||||
}
|
||||
if util.IsNonWordChar(c.RuneUnder(c.X)) && !util.IsWhitespace(c.RuneUnder(c.X)) {
|
||||
for util.IsNonWordChar(c.RuneUnder(c.X)) && !util.IsWhitespace(c.RuneUnder(c.X)) {
|
||||
if c.X == util.CharacterCount(c.buf.LineBytes(c.Y)) {
|
||||
c.Right()
|
||||
return
|
||||
}
|
||||
c.Right()
|
||||
}
|
||||
return
|
||||
}
|
||||
if util.IsSubwordDelimiter(c.RuneUnder(c.X)) {
|
||||
for util.IsSubwordDelimiter(c.RuneUnder(c.X)) {
|
||||
if c.X == util.CharacterCount(c.buf.LineBytes(c.Y)) {
|
||||
c.Right()
|
||||
return
|
||||
}
|
||||
c.Right()
|
||||
}
|
||||
if util.IsWhitespace(c.RuneUnder(c.X)) {
|
||||
return
|
||||
}
|
||||
}
|
||||
if c.X == util.CharacterCount(c.buf.LineBytes(c.Y)) {
|
||||
return
|
||||
}
|
||||
if util.IsUpperLetter(c.RuneUnder(c.X)) &&
|
||||
util.IsUpperLetter(c.RuneUnder(c.X+1)) {
|
||||
for util.IsUpperAlphanumeric(c.RuneUnder(c.X)) {
|
||||
if c.X == util.CharacterCount(c.buf.LineBytes(c.Y)) {
|
||||
return
|
||||
}
|
||||
c.Right()
|
||||
}
|
||||
if util.IsLowerAlphanumeric(c.RuneUnder(c.X)) {
|
||||
c.Left()
|
||||
}
|
||||
} else {
|
||||
c.Right()
|
||||
for util.IsLowerAlphanumeric(c.RuneUnder(c.X)) {
|
||||
if c.X == util.CharacterCount(c.buf.LineBytes(c.Y)) {
|
||||
return
|
||||
}
|
||||
c.Right()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SubWordLeft moves the cursor one sub-word to the left
|
||||
func (c *Cursor) SubWordLeft() {
|
||||
c.Left()
|
||||
if util.IsWhitespace(c.RuneUnder(c.X)) {
|
||||
for util.IsWhitespace(c.RuneUnder(c.X)) {
|
||||
if c.X == 0 {
|
||||
return
|
||||
}
|
||||
c.Left()
|
||||
}
|
||||
c.Right()
|
||||
return
|
||||
}
|
||||
if util.IsNonWordChar(c.RuneUnder(c.X)) && !util.IsWhitespace(c.RuneUnder(c.X)) {
|
||||
for util.IsNonWordChar(c.RuneUnder(c.X)) && !util.IsWhitespace(c.RuneUnder(c.X)) {
|
||||
if c.X == 0 {
|
||||
return
|
||||
}
|
||||
c.Left()
|
||||
}
|
||||
c.Right()
|
||||
return
|
||||
}
|
||||
if util.IsSubwordDelimiter(c.RuneUnder(c.X)) {
|
||||
for util.IsSubwordDelimiter(c.RuneUnder(c.X)) {
|
||||
if c.X == 0 {
|
||||
return
|
||||
}
|
||||
c.Left()
|
||||
}
|
||||
if util.IsWhitespace(c.RuneUnder(c.X)) {
|
||||
c.Right()
|
||||
return
|
||||
}
|
||||
}
|
||||
if c.X == 0 {
|
||||
return
|
||||
}
|
||||
if util.IsUpperLetter(c.RuneUnder(c.X)) &&
|
||||
util.IsUpperLetter(c.RuneUnder(c.X-1)) {
|
||||
for util.IsUpperAlphanumeric(c.RuneUnder(c.X)) {
|
||||
if c.X == 0 {
|
||||
return
|
||||
}
|
||||
c.Left()
|
||||
}
|
||||
if !util.IsUpperAlphanumeric(c.RuneUnder(c.X)) {
|
||||
c.Right()
|
||||
}
|
||||
} else {
|
||||
for util.IsLowerAlphanumeric(c.RuneUnder(c.X)) {
|
||||
if c.X == 0 {
|
||||
return
|
||||
}
|
||||
c.Left()
|
||||
}
|
||||
if !util.IsAlphanumeric(c.RuneUnder(c.X)) {
|
||||
c.Right()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// RuneUnder returns the rune under the given x position
|
||||
func (c *Cursor) RuneUnder(x int) rune {
|
||||
line := c.buf.LineBytes(c.Y)
|
||||
|
||||
Reference in New Issue
Block a user