mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
text_editor: add magnet cursor position (#6843)
This commit is contained in:
parent
ac8a2ff12d
commit
0c54ebdf41
@ -31,6 +31,7 @@ mut:
|
|||||||
files []string
|
files []string
|
||||||
status string
|
status string
|
||||||
t int
|
t int
|
||||||
|
magnet_x int
|
||||||
footer_height int = 2
|
footer_height int = 2
|
||||||
viewport int
|
viewport int
|
||||||
}
|
}
|
||||||
@ -456,6 +457,17 @@ fn (a &App) view_height() int {
|
|||||||
return a.tui.window_height - a.footer_height - 1
|
return a.tui.window_height - a.footer_height - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// magnet_cursor_x will place the cursor as close to it's last move left or right as possible
|
||||||
|
fn (mut a App) magnet_cursor_x() {
|
||||||
|
mut buffer := a.ed
|
||||||
|
if buffer.cursor.pos_x < a.magnet_x {
|
||||||
|
if a.magnet_x < buffer.cur_line().len {
|
||||||
|
move_x := a.magnet_x - buffer.cursor.pos_x
|
||||||
|
buffer.move_cursor(move_x, .right)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn frame(x voidptr) {
|
fn frame(x voidptr) {
|
||||||
mut a := &App(x)
|
mut a := &App(x)
|
||||||
mut ed := a.ed
|
mut ed := a.ed
|
||||||
@ -494,6 +506,7 @@ fn event(e &tui.Event, x voidptr) {
|
|||||||
} else if e.modifiers == 0 {
|
} else if e.modifiers == 0 {
|
||||||
buffer.move_cursor(1, .left)
|
buffer.move_cursor(1, .left)
|
||||||
}
|
}
|
||||||
|
a.magnet_x = buffer.cursor.pos_x
|
||||||
}
|
}
|
||||||
.right {
|
.right {
|
||||||
if e.modifiers == tui.ctrl {
|
if e.modifiers == tui.ctrl {
|
||||||
@ -501,12 +514,15 @@ fn event(e &tui.Event, x voidptr) {
|
|||||||
} else if e.modifiers == 0 {
|
} else if e.modifiers == 0 {
|
||||||
buffer.move_cursor(1, .right)
|
buffer.move_cursor(1, .right)
|
||||||
}
|
}
|
||||||
|
a.magnet_x = buffer.cursor.pos_x
|
||||||
}
|
}
|
||||||
.up {
|
.up {
|
||||||
buffer.move_cursor(1, .up)
|
buffer.move_cursor(1, .up)
|
||||||
|
a.magnet_cursor_x()
|
||||||
}
|
}
|
||||||
.down {
|
.down {
|
||||||
buffer.move_cursor(1, .down)
|
buffer.move_cursor(1, .down)
|
||||||
|
a.magnet_cursor_x()
|
||||||
}
|
}
|
||||||
.page_up {
|
.page_up {
|
||||||
buffer.move_cursor(a.view_height(), .page_up)
|
buffer.move_cursor(a.view_height(), .page_up)
|
||||||
|
Loading…
Reference in New Issue
Block a user