Fix selection bugs

This commit is contained in:
Zachary Yedidia 2016-04-30 14:06:00 -04:00
parent c3598fd8bd
commit e0f20fbb55
4 changed files with 27 additions and 6 deletions

View file

@ -364,22 +364,30 @@ func (v *View) SelectDown() bool {
// SelectLeft selects the character to the left of the cursor
func (v *View) SelectLeft() bool {
loc := v.cursor.Loc()
count := Count(v.buf.text) - 1
if loc > count {
loc = count
}
if !v.cursor.HasSelection() {
v.cursor.origSelection[0] = loc
}
v.cursor.SelectTo(loc - 1)
v.cursor.Left()
v.cursor.SelectTo(v.cursor.Loc())
return true
}
// SelectRight selects the character to the right of the cursor
func (v *View) SelectRight() bool {
loc := v.cursor.Loc()
count := Count(v.buf.text) - 1
if loc > count {
loc = count
}
if !v.cursor.HasSelection() {
v.cursor.origSelection[0] = loc
}
v.cursor.SelectTo(loc + 1)
v.cursor.Right()
v.cursor.SelectTo(v.cursor.Loc())
return true
}

View file

@ -219,9 +219,15 @@ func (c *Cursor) SelectTo(loc int) {
func (c *Cursor) WordRight() {
c.Right()
for IsWhitespace(c.RuneUnder(c.x)) {
if c.x == Count(c.v.buf.lines[c.y]) {
return
}
c.Right()
}
for !IsWhitespace(c.RuneUnder(c.x)) {
if c.x == Count(c.v.buf.lines[c.y]) {
return
}
c.Right()
}
}
@ -230,9 +236,15 @@ func (c *Cursor) WordRight() {
func (c *Cursor) WordLeft() {
c.Left()
for IsWhitespace(c.RuneUnder(c.x)) {
if c.x == 0 {
return
}
c.Left()
}
for !IsWhitespace(c.RuneUnder(c.x)) {
if c.x == 0 {
return
}
c.Left()
}
c.Right()

File diff suppressed because one or more lines are too long

View file

@ -12,3 +12,4 @@ color-link statusline "black,brightblue"
color-link line-number "brightgreen,black"
color-link gutter-error "black,brightred"
color-link gutter-warning "brightred,default"
color-link selection ",black"