MCPcopy
hub / github.com/micro-editor/micro / UpN

Method UpN

internal/buffer/cursor.go:247–269  ·  view source on GitHub ↗

UpN moves the cursor up N lines (if possible)

(amount int)

Source from the content-addressed store, hash-verified

245
246// UpN moves the cursor up N lines (if possible)
247func (c *Cursor) UpN(amount int) {
248 proposedY := c.Y - amount
249 if proposedY < 0 {
250 proposedY = 0
251 } else if proposedY >= len(c.buf.lines) {
252 proposedY = len(c.buf.lines) - 1
253 }
254
255 bytes := c.buf.LineBytes(proposedY)
256 c.X = c.GetCharPosInLine(bytes, c.LastVisualX)
257
258 if c.X > util.CharacterCount(bytes) || (amount < 0 && proposedY == c.Y) {
259 c.X = util.CharacterCount(bytes)
260 c.StoreVisualX()
261 }
262
263 if c.X < 0 || (amount > 0 && proposedY == c.Y) {
264 c.X = 0
265 c.StoreVisualX()
266 }
267
268 c.Y = proposedY
269}
270
271// DownN moves the cursor down N lines (if possible)
272func (c *Cursor) DownN(amount int) {

Callers 3

DownNMethod · 0.95
UpMethod · 0.95
MoveCursorUpMethod · 0.80

Calls 4

GetCharPosInLineMethod · 0.95
StoreVisualXMethod · 0.95
CharacterCountFunction · 0.92
LineBytesMethod · 0.65

Tested by

no test coverage detected