1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

examples/text_editor: use mathutil for min/max functions (#9911)

This commit is contained in:
Lukas Neubert 2021-04-29 08:42:59 +02:00 committed by GitHub
parent 25d9272c84
commit daff481233
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,6 +3,7 @@
// Don't use this editor for any serious work.
// A lot of funtionality is missing compared to your favourite editor :)
import strings
import math.mathutil as mu
import os
import term.ui as tui
@ -329,11 +330,11 @@ fn (mut b Buffer) move_cursor(amount int, movement Movement) {
}
}
.page_up {
dlines := imin(b.cursor.pos_y, amount)
dlines := mu.min(b.cursor.pos_y, amount)
b.move_updown(-dlines)
}
.page_down {
dlines := imin(b.lines.len - 1, b.cursor.pos_y + amount) - b.cursor.pos_y
dlines := mu.min(b.lines.len - 1, b.cursor.pos_y + amount) - b.cursor.pos_y
b.move_updown(dlines)
}
.left {
@ -392,14 +393,6 @@ fn (mut b Buffer) move_to_word(movement Movement) {
b.cursor.set(x, y)
}
fn imax(x int, y int) int {
return if x < y { y } else { x }
}
fn imin(x int, y int) int {
return if x < y { x } else { y }
}
struct Cursor {
pub mut:
pos_x int