properly truncate files when saving
parent
838664f2b5
commit
1fdbe7ddaf
|
@ -7,7 +7,6 @@ import "core:reflect"
|
||||||
import "core:fmt"
|
import "core:fmt"
|
||||||
import "core:log"
|
import "core:log"
|
||||||
import "vendor:sdl2"
|
import "vendor:sdl2"
|
||||||
import lua "vendor:lua/5.4"
|
|
||||||
|
|
||||||
import "../util"
|
import "../util"
|
||||||
|
|
||||||
|
@ -19,11 +18,9 @@ Mode :: enum {
|
||||||
Visual,
|
Visual,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
EditorCommandList :: map[string][dynamic]EditorCommand;
|
EditorCommandList :: map[string][dynamic]EditorCommand;
|
||||||
State :: struct {
|
State :: struct {
|
||||||
ctx: runtime.Context,
|
ctx: runtime.Context,
|
||||||
L: ^lua.State,
|
|
||||||
sdl_renderer: ^sdl2.Renderer,
|
sdl_renderer: ^sdl2.Renderer,
|
||||||
font_atlas: FontAtlas,
|
font_atlas: FontAtlas,
|
||||||
ui: rawptr,
|
ui: rawptr,
|
||||||
|
@ -221,9 +218,9 @@ register_key_action_group :: proc(input_map: ^InputActions, key: Key, input_grou
|
||||||
}
|
}
|
||||||
|
|
||||||
register_ctrl_key_action_single :: proc(input_map: ^InputActions, key: Key, action: EditorAction, description: string = "") {
|
register_ctrl_key_action_single :: proc(input_map: ^InputActions, key: Key, action: EditorAction, description: string = "") {
|
||||||
if ok := key in input_map.key_actions; ok {
|
if ok := key in input_map.ctrl_key_actions; ok {
|
||||||
// TODO: log that key is already registered
|
// TODO: log that key is already registered
|
||||||
log.error("key already registered with single action", key);
|
log.error("key already registered with ctrl + single action", key);
|
||||||
}
|
}
|
||||||
|
|
||||||
input_map.ctrl_key_actions[key] = Action {
|
input_map.ctrl_key_actions[key] = Action {
|
||||||
|
@ -233,9 +230,9 @@ register_ctrl_key_action_single :: proc(input_map: ^InputActions, key: Key, acti
|
||||||
}
|
}
|
||||||
|
|
||||||
register_ctrl_key_action_group :: proc(input_map: ^InputActions, key: Key, input_group: InputGroup, description: string = "") {
|
register_ctrl_key_action_group :: proc(input_map: ^InputActions, key: Key, input_group: InputGroup, description: string = "") {
|
||||||
if ok := key in input_map.key_actions; ok {
|
if ok := key in input_map.ctrl_key_actions; ok {
|
||||||
// TODO: log that key is already registered
|
// TODO: log that key is already registered
|
||||||
log.error("key already registered with single action", key);
|
log.error("key already registered with ctrl + single action", key);
|
||||||
}
|
}
|
||||||
|
|
||||||
input_map.ctrl_key_actions[key] = Action {
|
input_map.ctrl_key_actions[key] = Action {
|
||||||
|
|
|
@ -749,12 +749,12 @@ new_file_buffer :: proc(allocator: mem.Allocator, file_path: string, base_dir: s
|
||||||
}
|
}
|
||||||
|
|
||||||
save_buffer_to_disk :: proc(state: ^State, buffer: ^FileBuffer) -> (error: os.Error) {
|
save_buffer_to_disk :: proc(state: ^State, buffer: ^FileBuffer) -> (error: os.Error) {
|
||||||
fd := os.open(buffer.file_path, flags = os.O_RDWR) or_return;
|
fd := os.open(buffer.file_path, flags = os.O_WRONLY | os.O_TRUNC | os.O_CREATE) or_return;
|
||||||
defer os.close(fd);
|
defer os.close(fd);
|
||||||
|
|
||||||
offset: i64 = 0
|
offset: i64 = 0
|
||||||
for content_slice in buffer.content_slices {
|
for content_slice in buffer.content_slices {
|
||||||
os.write_at(fd, content_slice, offset) or_return
|
os.write(fd, content_slice) or_return
|
||||||
|
|
||||||
offset += i64(len(content_slice))
|
offset += i64(len(content_slice))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue