-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmagnet.v
53 lines (47 loc) · 1.12 KB
/
magnet.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) 2020-2022 Lars Pontoppidan. All rights reserved.
// Use of this source code is governed by the MIT license distributed with this software.
module vee
struct Magnet {
mut:
buffer &Buffer = unsafe { nil }
// record bool = true
x int
}
// str returns a string representation of the `Magnet`.
pub fn (m Magnet) str() string {
mut s := @MOD + '.Magnet{
x: ${m.x}'
s += '\n}'
return s
}
// activate will adjust the cursor to as close valuses as the magnet as possible
pub fn (mut m Magnet) activate() {
if m.x == 0 || isnil(m.buffer) {
return
}
mut b := m.buffer
// x, _ := m.buffer.cursor.xy()
// line := b.cur_line()
// if line.len == 0 {
// b.cursor.pos.x = 0
//} else {
b.cursor.pos.x = m.x
//}
b.sync_cursor()
}
// record will record the placement of the cursor
fn (mut m Magnet) record() {
//!m.record ||
if isnil(m.buffer) {
return
}
m.x = m.buffer.cursor.pos.x
}
/*
fn (mut m Magnet) move_offrecord(amount int, movement Movement) {
if isnil(m.buffer) { return }
prev_recording_state := m.record
m.record = false
m.buffer.move_cursor(amount, movement)
m.record = prev_recording_state
}*/