wordBefore returns the word before the lexer.Pos uses IsWordBreak to determine the bounds of the word
(tp lexer.Pos)
| 88 | // wordBefore returns the word before the lexer.Pos |
| 89 | // uses IsWordBreak to determine the bounds of the word |
| 90 | func (ed *Editor) wordBefore(tp lexer.Pos) *text.Edit { |
| 91 | txt := ed.Buffer.Line(tp.Ln) |
| 92 | ch := tp.Ch |
| 93 | ch = min(ch, len(txt)) |
| 94 | st := ch |
| 95 | for i := ch - 1; i >= 0; i-- { |
| 96 | if i == 0 { // start of line |
| 97 | st = 0 |
| 98 | break |
| 99 | } |
| 100 | r1 := txt[i] |
| 101 | r2 := txt[i-1] |
| 102 | if core.IsWordBreak(r1, r2) { |
| 103 | st = i + 1 |
| 104 | break |
| 105 | } |
| 106 | } |
| 107 | if st != ch { |
| 108 | return ed.Buffer.Region(lexer.Pos{Ln: tp.Ln, Ch: st}, tp) |
| 109 | } |
| 110 | return nil |
| 111 | } |
| 112 | |
| 113 | // isWordEnd returns true if the cursor is just past the last letter of a word |
| 114 | // word is a string of characters none of which are classified as a word break |
no test coverage detected