diff options
author | Petter Rodhelind <petter.rodhelind@gmail.com> | 2018-02-23 19:35:10 +0100 |
---|---|---|
committer | Petter Rodhelind <petter.rodhelind@gmail.com> | 2018-02-23 19:35:10 +0100 |
commit | 790b4d4e6d20d43cccf4ebf2c4723d3ed5d65733 (patch) | |
tree | 6208705bbbc72359f0d29a8ca4a0eae0a1511c56 | |
parent | 6ba65a24c45ae55e0af5ad9c0b7d65155f551211 (diff) | |
download | poe-790b4d4e6d20d43cccf4ebf2c4723d3ed5d65733.tar.gz poe-790b4d4e6d20d43cccf4ebf2c4723d3ed5d65733.tar.bz2 poe-790b4d4e6d20d43cccf4ebf2c4723d3ed5d65733.zip |
Add Next/Prev Space offset search.
-rw-r--r-- | text.go | 45 |
1 files changed, 45 insertions, 0 deletions
@@ -276,6 +276,51 @@ func (t *Text) Select(offset int) { t.SetDot(start, end) } +func (t *Text) NextSpace(offset int) (n int) { + offset, _ = t.Seek(offset, io.SeekStart) + + r, size, err := t.ReadRune() + if err != nil { + return 0 + } + for !unicode.IsSpace(r) { + n += size + r, size, err = t.ReadRune() + if err != nil { + if err == io.EOF { + return n + } + return 0 + } + } + + return n +} + +func (t *Text) PrevSpace(offset int) (n int) { + offset, _ = t.Seek(offset, io.SeekStart) + + r, size, err := t.ReadRuneAt(offset) + if err != nil { + return 0 + } + for !unicode.IsSpace(r) { + r, size, err = t.UnreadRune() + if err != nil { + if err == gapbuffer.ErrOutOfRange { + return n + } + } + n += size + } + + if n > 0 { + n -= size // remove last iteration + } + + return n +} + func (t *Text) NextWord(offset int) (n int) { offset, _ = t.Seek(offset, io.SeekStart) |