bl
This commit is contained in:
parent
41adeeb47f
commit
5b65c4c0e4
11 changed files with 4237 additions and 297 deletions
|
|
@ -14,6 +14,8 @@ Diagnostic :: struct {
|
|||
Editor_Buffer :: struct {
|
||||
path: string,
|
||||
daemon_path: string,
|
||||
scratch: bool, // in-memory tab (e.g. a git diff); never saved or synced
|
||||
diff: ^Diff_Document, // when set, the tab renders a split diff view
|
||||
original_storage: []u8,
|
||||
buffer: Buffer,
|
||||
cursor: Cursor,
|
||||
|
|
@ -60,6 +62,36 @@ editor_open_or_focus_file :: proc(editor: ^Editor, path: string) -> bool {
|
|||
return editor_open_file(editor, path)
|
||||
}
|
||||
|
||||
// Opens (or replaces) an in-memory tab that is not backed by a file.
|
||||
editor_open_scratch :: proc(editor: ^Editor, name, contents: string) {
|
||||
data := make([]u8, len(contents))
|
||||
copy(data, transmute([]u8)contents)
|
||||
|
||||
for &buffer, index in editor.buffers {
|
||||
if buffer.scratch && buffer.path == name {
|
||||
editor_buffer_destroy(&buffer)
|
||||
buffer = Editor_Buffer{
|
||||
path = strings.clone(name),
|
||||
daemon_path = strings.clone(""),
|
||||
original_storage = data,
|
||||
buffer = buffer_make(string(data)),
|
||||
scratch = true,
|
||||
}
|
||||
editor.active = index
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
append(&editor.buffers, Editor_Buffer{
|
||||
path = strings.clone(name),
|
||||
daemon_path = strings.clone(""),
|
||||
original_storage = data,
|
||||
buffer = buffer_make(string(data)),
|
||||
scratch = true,
|
||||
})
|
||||
editor.active = len(editor.buffers) - 1
|
||||
}
|
||||
|
||||
editor_replace_active_file :: proc(editor: ^Editor, path: string) -> bool {
|
||||
active := editor_active_buffer(editor)
|
||||
if active == nil do return false
|
||||
|
|
@ -257,7 +289,7 @@ editor_insert_newline_auto_indent :: proc(active: ^Editor_Buffer) {
|
|||
|
||||
editor_save_active :: proc(editor: ^Editor) -> bool {
|
||||
active := editor_active_buffer(editor)
|
||||
if active == nil do return false
|
||||
if active == nil || active.scratch do return false
|
||||
|
||||
text := buffer_bytes(&active.buffer)
|
||||
defer delete(text)
|
||||
|
|
@ -276,7 +308,7 @@ editor_save_active :: proc(editor: ^Editor) -> bool {
|
|||
editor_save_all :: proc(editor: ^Editor) -> bool {
|
||||
ok := true
|
||||
for &buffer in editor.buffers {
|
||||
if !buffer.dirty do continue
|
||||
if !buffer.dirty || buffer.scratch do continue
|
||||
|
||||
text := buffer_bytes(&buffer.buffer)
|
||||
err := os.write_entire_file(buffer.path, text[:])
|
||||
|
|
@ -432,6 +464,10 @@ editor_destroy :: proc(editor: ^Editor) {
|
|||
}
|
||||
|
||||
editor_buffer_destroy :: proc(editor_buffer: ^Editor_Buffer) {
|
||||
if editor_buffer.diff != nil {
|
||||
diff_document_destroy(editor_buffer.diff)
|
||||
editor_buffer.diff = nil
|
||||
}
|
||||
delete(editor_buffer.path)
|
||||
delete(editor_buffer.daemon_path)
|
||||
buffer_destroy(&editor_buffer.buffer)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue