factor out find previous space logic
This commit is contained in:
@@ -44,7 +44,10 @@ text_height: f32
|
|||||||
cursor: Cursor
|
cursor: Cursor
|
||||||
lines: [dynamic][dynamic]u8
|
lines: [dynamic][dynamic]u8
|
||||||
viewport_size := window_height / int(font_size)
|
viewport_size := window_height / int(font_size)
|
||||||
viewport := Viewport{start = 0, end = viewport_size}
|
viewport := Viewport {
|
||||||
|
start = 0,
|
||||||
|
end = viewport_size,
|
||||||
|
}
|
||||||
|
|
||||||
main :: proc() {
|
main :: proc() {
|
||||||
r.InitWindow(i32(window_width), i32(window_height), "odit")
|
r.InitWindow(i32(window_width), i32(window_height), "odit")
|
||||||
@@ -104,17 +107,8 @@ main :: proc() {
|
|||||||
cursor.char = len(current_line())
|
cursor.char = len(current_line())
|
||||||
}
|
}
|
||||||
if r.IsKeyDown(r.KeyboardKey.LEFT_ALT) && 0 < cursor.char {
|
if r.IsKeyDown(r.KeyboardKey.LEFT_ALT) && 0 < cursor.char {
|
||||||
seen_space := false
|
found := false
|
||||||
#reverse for c, c_index in current_line()[:cursor.char - 1] {
|
preferred_position, found = find_previous_space(cursor.char, current_line()[:])
|
||||||
if is_whitespace(c) {
|
|
||||||
seen_space = true
|
|
||||||
preferred_position = c_index + 1
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !seen_space {
|
|
||||||
preferred_position = 0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
cursor.char = max(preferred_position, 0)
|
cursor.char = max(preferred_position, 0)
|
||||||
}
|
}
|
||||||
@@ -268,3 +262,15 @@ all_whitespace :: proc(cs: []u8) -> bool {
|
|||||||
repeatable_key_pressed :: proc(k: r.KeyboardKey) -> bool {
|
repeatable_key_pressed :: proc(k: r.KeyboardKey) -> bool {
|
||||||
return r.IsKeyPressed(k) || r.IsKeyPressedRepeat(k)
|
return r.IsKeyPressed(k) || r.IsKeyPressedRepeat(k)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
find_previous_space :: proc(current_position: int, line: []u8) -> (result: int, found: bool) {
|
||||||
|
#reverse for c, c_index in line[:current_position - 1] {
|
||||||
|
if is_whitespace(c) {
|
||||||
|
found = true
|
||||||
|
result = c_index + 1
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, found
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user