mirror of
https://github.com/zyedidia/micro.git
synced 2026-02-04 14:10:23 +09:00
buffer: Improve cursor movement
This commit is contained in:
@@ -601,24 +601,13 @@ func (c *Cursor) SubWordLeft() {
|
||||
|
||||
// RuneUnder returns the rune under the given x position
|
||||
func (c *Cursor) RuneUnder(x int) rune {
|
||||
line := c.buf.LineBytes(c.Y)
|
||||
if len(line) == 0 || x >= util.CharacterCount(line) {
|
||||
line := c.buf.LineCharacters(c.Y)
|
||||
if len(line) == 0 || x >= len(line) {
|
||||
return '\n'
|
||||
} else if x < 0 {
|
||||
x = 0
|
||||
}
|
||||
i := 0
|
||||
for len(line) > 0 {
|
||||
r, _, size := util.DecodeCharacter(line)
|
||||
line = line[size:]
|
||||
|
||||
if i == x {
|
||||
return r
|
||||
}
|
||||
|
||||
i++
|
||||
}
|
||||
return '\n'
|
||||
return line[x].combc[0]
|
||||
}
|
||||
|
||||
func (c *Cursor) StoreVisualX() {
|
||||
|
||||
@@ -371,18 +371,13 @@ func (la *LineArray) End() Loc {
|
||||
return Loc{len(la.lines[numlines-1].runes), numlines - 1}
|
||||
}
|
||||
|
||||
// Line returns line n as an array of runes
|
||||
func (la *LineArray) Line(n int) []rune {
|
||||
// LineCharacters returns line n as an array of characters
|
||||
func (la *LineArray) LineCharacters(n int) []Character {
|
||||
if n >= len(la.lines) || n < 0 {
|
||||
return []rune{}
|
||||
return []Character{}
|
||||
}
|
||||
|
||||
var runes []rune
|
||||
for _, r := range la.lines[n].runes {
|
||||
runes = append(runes, r.combc[0:]...)
|
||||
}
|
||||
|
||||
return runes
|
||||
return la.lines[n].runes
|
||||
}
|
||||
|
||||
// LineBytes returns line n as an array of bytes
|
||||
|
||||
Reference in New Issue
Block a user