setCursor sets a new cursor position, enforcing it in range. This is the main final pathway for all cursor movement.
(pos lexer.Pos)
| 53 | // setCursor sets a new cursor position, enforcing it in range. |
| 54 | // This is the main final pathway for all cursor movement. |
| 55 | func (ed *Editor) setCursor(pos lexer.Pos) { |
| 56 | if ed.NumLines == 0 || ed.Buffer == nil { |
| 57 | ed.CursorPos = lexer.PosZero |
| 58 | return |
| 59 | } |
| 60 | |
| 61 | ed.clearScopelights() |
| 62 | ed.CursorPos = ed.Buffer.ValidPos(pos) |
| 63 | ed.cursorMovedEvent() |
| 64 | txt := ed.Buffer.Line(ed.CursorPos.Ln) |
| 65 | ch := ed.CursorPos.Ch |
| 66 | if ch < len(txt) { |
| 67 | r := txt[ch] |
| 68 | if r == '{' || r == '}' || r == '(' || r == ')' || r == '[' || r == ']' { |
| 69 | tp, found := ed.Buffer.BraceMatch(txt[ch], ed.CursorPos) |
| 70 | if found { |
| 71 | ed.scopelights = append(ed.scopelights, text.NewRegionPos(ed.CursorPos, lexer.Pos{ed.CursorPos.Ln, ed.CursorPos.Ch + 1})) |
| 72 | ed.scopelights = append(ed.scopelights, text.NewRegionPos(tp, lexer.Pos{tp.Ln, tp.Ch + 1})) |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | ed.NeedsRender() |
| 77 | } |
| 78 | |
| 79 | // SetCursorShow sets a new cursor position, enforcing it in range, and shows |
| 80 | // the cursor (scroll to if hidden, render) |
no test coverage detected