From 04311187af87806de306d33493bb110b7234e7ab Mon Sep 17 00:00:00 2001 From: Grant Horner Date: Tue, 9 Dec 2025 12:03:35 -0500 Subject: [PATCH] fix backspace bug --- .gitignore | 2 ++ odit.sublime-project | 26 ++++++++++++++++++++++++++ src/main.odin | 22 ++++++++++++++++++---- 3 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 odit.sublime-project diff --git a/.gitignore b/.gitignore index dfccedf..efa8638 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ bin .DS_Store src/src scratch +src.bin* +*.sublime-workspace \ No newline at end of file diff --git a/odit.sublime-project b/odit.sublime-project new file mode 100644 index 0000000..f6dcd49 --- /dev/null +++ b/odit.sublime-project @@ -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": "." + } + ] +} diff --git a/src/main.odin b/src/main.odin index e51bfdf..d63c6bc 100644 --- a/src/main.odin +++ b/src/main.odin @@ -174,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()^ @@ -185,8 +186,21 @@ main :: proc() { cursor.line -= 1 cursor.char = old_len } else { - ordered_remove(&lines[cursor.line], cursor.char - 1) - cursor.char -= 1 + 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 + } } }