Compare commits
2 Commits
291171cb0d
...
04311187af
| Author | SHA1 | Date | |
|---|---|---|---|
| 04311187af | |||
| 3ad4176eee |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -3,3 +3,5 @@ bin
|
||||
.DS_Store
|
||||
src/src
|
||||
scratch
|
||||
src.bin*
|
||||
*.sublime-workspace
|
||||
26
odit.sublime-project
Normal file
26
odit.sublime-project
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"debugger_configurations":
|
||||
[
|
||||
{
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"name": "Launch",
|
||||
"program": "${project_path}/src.bin",
|
||||
"args": [],
|
||||
"cwd": "${project_path}"
|
||||
},
|
||||
],
|
||||
"build_systems": [
|
||||
{
|
||||
"cmd": ["odin", "build", "src", "-debug"],
|
||||
"name": "odit",
|
||||
"selector": "source.odin",
|
||||
"working_dir": "${project_path}"
|
||||
}
|
||||
],
|
||||
"folders": [
|
||||
{
|
||||
"path": "."
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -44,7 +44,10 @@ text_height: f32
|
||||
cursor: Cursor
|
||||
lines: [dynamic][dynamic]u8
|
||||
viewport_size := window_height / int(font_size)
|
||||
viewport := Viewport{start = 0, end = viewport_size}
|
||||
viewport := Viewport {
|
||||
start = 0,
|
||||
end = viewport_size,
|
||||
}
|
||||
|
||||
main :: proc() {
|
||||
r.InitWindow(i32(window_width), i32(window_height), "odit")
|
||||
@@ -104,17 +107,8 @@ main :: proc() {
|
||||
cursor.char = len(current_line())
|
||||
}
|
||||
if r.IsKeyDown(r.KeyboardKey.LEFT_ALT) && 0 < cursor.char {
|
||||
seen_space := false
|
||||
#reverse for c, c_index in current_line()[:cursor.char - 1] {
|
||||
if is_whitespace(c) {
|
||||
seen_space = true
|
||||
preferred_position = c_index + 1
|
||||
break
|
||||
}
|
||||
}
|
||||
if !seen_space {
|
||||
preferred_position = 0
|
||||
}
|
||||
found := false
|
||||
preferred_position, found = find_previous_space(cursor.char, current_line()[:])
|
||||
}
|
||||
cursor.char = max(preferred_position, 0)
|
||||
}
|
||||
@@ -180,9 +174,10 @@ main :: proc() {
|
||||
fmt.println("Wrote file!")
|
||||
}
|
||||
|
||||
if repeatable_key_pressed(r.KeyboardKey.BACKSPACE) {
|
||||
if cursor.line == 0 && cursor.char == 0 do continue
|
||||
skip_backspace: if repeatable_key_pressed(r.KeyboardKey.BACKSPACE) {
|
||||
if cursor.line == 0 && cursor.char == 0 do break skip_backspace
|
||||
if cursor.char == 0 {
|
||||
// join lines
|
||||
old_len := len(lines[cursor.line - 1])
|
||||
append(&lines[cursor.line - 1], string(current_line()[:]))
|
||||
line_to_remove := current_line()^
|
||||
@@ -191,10 +186,23 @@ main :: proc() {
|
||||
cursor.line -= 1
|
||||
cursor.char = old_len
|
||||
} else {
|
||||
if r.IsKeyDown(r.KeyboardKey.LEFT_ALT) {
|
||||
// delete by word
|
||||
delete_to, found := find_previous_space(cursor.char, current_line()[:])
|
||||
if found {
|
||||
remove_range(current_line(), delete_to, cursor.char)
|
||||
cursor.char = delete_to
|
||||
} else {
|
||||
remove_range(current_line(), 0, cursor.char)
|
||||
cursor.char = 0
|
||||
}
|
||||
} else {
|
||||
// delete single char
|
||||
ordered_remove(&lines[cursor.line], cursor.char - 1)
|
||||
cursor.char -= 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cursor_padding := 3
|
||||
// move viewport up
|
||||
@@ -268,3 +276,15 @@ all_whitespace :: proc(cs: []u8) -> bool {
|
||||
repeatable_key_pressed :: proc(k: r.KeyboardKey) -> bool {
|
||||
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