Compare commits
2 Commits
291171cb0d
...
04311187af
| Author | SHA1 | Date | |
|---|---|---|---|
| 04311187af | |||
| 3ad4176eee |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -3,3 +3,5 @@ bin
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
src/src
|
src/src
|
||||||
scratch
|
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": "."
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -29,7 +29,7 @@ read_file :: proc(path: string) -> (string, bool) {
|
|||||||
|
|
||||||
Viewport :: struct {
|
Viewport :: struct {
|
||||||
start: int,
|
start: int,
|
||||||
end: int,
|
end: int,
|
||||||
}
|
}
|
||||||
|
|
||||||
Cursor :: struct {
|
Cursor :: struct {
|
||||||
@@ -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)
|
||||||
}
|
}
|
||||||
@@ -180,9 +174,10 @@ main :: proc() {
|
|||||||
fmt.println("Wrote file!")
|
fmt.println("Wrote file!")
|
||||||
}
|
}
|
||||||
|
|
||||||
if repeatable_key_pressed(r.KeyboardKey.BACKSPACE) {
|
skip_backspace: if repeatable_key_pressed(r.KeyboardKey.BACKSPACE) {
|
||||||
if cursor.line == 0 && cursor.char == 0 do continue
|
if cursor.line == 0 && cursor.char == 0 do break skip_backspace
|
||||||
if cursor.char == 0 {
|
if cursor.char == 0 {
|
||||||
|
// join lines
|
||||||
old_len := len(lines[cursor.line - 1])
|
old_len := len(lines[cursor.line - 1])
|
||||||
append(&lines[cursor.line - 1], string(current_line()[:]))
|
append(&lines[cursor.line - 1], string(current_line()[:]))
|
||||||
line_to_remove := current_line()^
|
line_to_remove := current_line()^
|
||||||
@@ -191,8 +186,21 @@ main :: proc() {
|
|||||||
cursor.line -= 1
|
cursor.line -= 1
|
||||||
cursor.char = old_len
|
cursor.char = old_len
|
||||||
} else {
|
} else {
|
||||||
ordered_remove(&lines[cursor.line], cursor.char - 1)
|
if r.IsKeyDown(r.KeyboardKey.LEFT_ALT) {
|
||||||
cursor.char -= 1
|
// 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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,3 +276,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