cursorForwardWord moves the cursor forward by words
(steps int)
| 210 | |
| 211 | // cursorForwardWord moves the cursor forward by words |
| 212 | func (ed *Editor) cursorForwardWord(steps int) { |
| 213 | ed.validateCursor() |
| 214 | org := ed.CursorPos |
| 215 | for i := 0; i < steps; i++ { |
| 216 | txt := ed.Buffer.Line(ed.CursorPos.Ln) |
| 217 | sz := len(txt) |
| 218 | if sz > 0 && ed.CursorPos.Ch < sz { |
| 219 | ch := ed.CursorPos.Ch |
| 220 | var done = false |
| 221 | for ch < sz && !done { // if on a wb, go past |
| 222 | r1 := txt[ch] |
| 223 | r2 := rune(-1) |
| 224 | if ch < sz-1 { |
| 225 | r2 = txt[ch+1] |
| 226 | } |
| 227 | if core.IsWordBreak(r1, r2) { |
| 228 | ch++ |
| 229 | } else { |
| 230 | done = true |
| 231 | } |
| 232 | } |
| 233 | done = false |
| 234 | for ch < sz && !done { |
| 235 | r1 := txt[ch] |
| 236 | r2 := rune(-1) |
| 237 | if ch < sz-1 { |
| 238 | r2 = txt[ch+1] |
| 239 | } |
| 240 | if !core.IsWordBreak(r1, r2) { |
| 241 | ch++ |
| 242 | } else { |
| 243 | done = true |
| 244 | } |
| 245 | } |
| 246 | ed.CursorPos.Ch = ch |
| 247 | } else { |
| 248 | if ed.CursorPos.Ln < ed.NumLines-1 { |
| 249 | ed.CursorPos.Ch = 0 |
| 250 | ed.CursorPos.Ln++ |
| 251 | } else { |
| 252 | ed.CursorPos.Ch = ed.Buffer.LineLen(ed.CursorPos.Ln) |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | ed.setCursorColumn(ed.CursorPos) |
| 257 | ed.SetCursorShow(ed.CursorPos) |
| 258 | ed.cursorSelect(org) |
| 259 | ed.NeedsRender() |
| 260 | } |
| 261 | |
| 262 | // cursorDown moves the cursor down line(s) |
| 263 | func (ed *Editor) cursorDown(steps int) { |
no test coverage detected