examples/text_editor: use mathutil for min/max functions (#9911)
parent
25d9272c84
commit
daff481233
|
@ -3,6 +3,7 @@
|
||||||
// Don't use this editor for any serious work.
|
// Don't use this editor for any serious work.
|
||||||
// A lot of funtionality is missing compared to your favourite editor :)
|
// A lot of funtionality is missing compared to your favourite editor :)
|
||||||
import strings
|
import strings
|
||||||
|
import math.mathutil as mu
|
||||||
import os
|
import os
|
||||||
import term.ui as tui
|
import term.ui as tui
|
||||||
|
|
||||||
|
@ -329,11 +330,11 @@ fn (mut b Buffer) move_cursor(amount int, movement Movement) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.page_up {
|
.page_up {
|
||||||
dlines := imin(b.cursor.pos_y, amount)
|
dlines := mu.min(b.cursor.pos_y, amount)
|
||||||
b.move_updown(-dlines)
|
b.move_updown(-dlines)
|
||||||
}
|
}
|
||||||
.page_down {
|
.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)
|
b.move_updown(dlines)
|
||||||
}
|
}
|
||||||
.left {
|
.left {
|
||||||
|
@ -392,14 +393,6 @@ fn (mut b Buffer) move_to_word(movement Movement) {
|
||||||
b.cursor.set(x, y)
|
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 {
|
struct Cursor {
|
||||||
pub mut:
|
pub mut:
|
||||||
pos_x int
|
pos_x int
|
||||||
|
|
Loading…
Reference in New Issue