summaryrefslogtreecommitdiff
path: root/editor.c
Commit message (Collapse)AuthorAgeFilesLines
* minor: remove unused scroll_row field on ebdilluti0n2025-06-211-2/+0
|
* minor: remove unused field eb.scroll_rowdilluti0n2025-06-011-2/+0
|
* refactor: consolidate ENAMETOOLONG handling in eb_binddilluti0n2025-05-281-7/+5
| | | | | | | | - Skip unnecessary cwd resolution when realpath returns ENAMETOOLONG. - Drop duplicate error-handling branches and route all failures through bind_fail. - Keep behavior unchanged while shaving a few lines and clarifying the control flow.
* refactor: abstract input/rendering modules from main routinedilluti0n2025-05-281-3/+3
| | | | | | This fetch moves raylib-specific logics to redr_raylib.c and input_raylib.c from main routine. Each apis are defined in redr.h and input.h respectively.
* minor: use log_printf instead of printf when logging saved filedilluti0n2025-05-271-1/+1
|
* refactor: eb_bind to bind absolute path to eb->file_namedilluti0n2025-05-271-9/+49
| | | | | [minor] fix perror("func: ") to perror("func")
* refactor: remove cursor initialization from eb_load_filedilluti0n2025-05-271-2/+3
| | | | | | | | | Cursor initialization is now assumed to be handled by eb_init, eliminating redundant resets in eb_load_file and improving separation of concerns. [minor] add comment to struct ed_buf
* fix: correct CRLF handling guard to avoid ineffective len > 0 checkdilluti0n2025-05-261-1/+1
| | | | len is size_t variable
* fix: double-free of line object in eb_backspace and eb_delete_linedilluti0n2025-05-141-2/+17
| | | | | | | | On eb_backspace, when the upper line was non-null, line_cat followed by line_free, and eb_delete_line only cleared the line_vec. However, commit 2441e78 introduced an additional line_free in eb_delete_line to fix a memory leak, which led to a double-free for that line. This patch resolves that problem.
* refactor: introduce mem.h; wrappers for allocatorsdilluti0n2025-05-101-2/+3
| | | | This patch removes the dependency on raylib when allocating memory.
* fix: Memory Leak in eb_delete_linedilluti0n2025-05-101-7/+40
| | | | | | The function eb_delete_line did not properly free the contents of the entry when deleting an element from eb->line_vec. This patch fixes that issue.
* refactor: deprecate line->cursor; simplify vertical cursor movementdilluti0n2025-05-021-5/+4
| | | | | | | | | This patch removes the per-line cursor cache (`line->cursor`), reducing implementation complexity. Vertical cursor movement (up/down) now uniformly places the cursor at the beginning of the line, instead of trying to restore the previous horizontal position. UX considerations such as column preservation will be revisited after core stabilization.
* perf: use fwrite instead of fputc loop in eb_save_filedilluti0n2025-05-011-2/+1
| | | | | | | | Previously, each character of a line was written using fputc in a loop, resulting in millions of function calls for large lines and poor write performance. Replaced with a single fwrite call per line, significantly reducing overhead and improving save performance dramatically.
* perf: Use eb_get_line_slice on eb_save_file instead line_get_stringdilluti0n2025-05-011-3/+5
| | | | This patch removes obsolated line_get_string on eb_save_file.
* feat: add slice-based accessors for line and editor bufferdilluti0n2025-04-291-1/+11
| | | | | | | | | | | | | | | | | This adds `line_get_slice` and `eb_get_line_slice`, enabling slice-style (pointer + length) access to line contents without requiring materialization into a null-terminated string. - `line_get_slice` returns either the original mmap'd buffer (if the - line is lazy) or the materialized vector contents (if edited). - `eb_get_line_slice` wraps `line_get_slice` to provide safe access at - the editor buffer level. Update `line.h` and `editor.h` headers to - declare the new functions. Minor documentation improvements to - clarify "init", "modify", and "get" function categories. This prepares the codebase for transitioning away from C-string dependency where possible, improving efficiency and avoiding unnecessary memory copies.
* fix: SIGBUS when eb_save_filedilluti0n2025-04-291-4/+20
| | | | | | | | | When eb_save_file is called, it opens the file with fopen(eb->file_name, "w"). Since opening with "w" mode truncates the file size to 0, accessing the memory region previously mmap-ed to that file results in a SIGBUS error. To prevent this, the content is now first written to a temporary file at /tmp/%s.tmpXXXXXX, and then renamed to eb->file_name.
* fix: format string is not a string literal in eb_save_filedilluti0n2025-04-291-1/+1
| | | | Just kill warnings.
* refactor: decouple line.h from main.cdilluti0n2025-04-291-6/+11
| | | | | | | | By making eb_get_line a static function within editor.c and introducing API wrappers that internally delegate to eb_get_line and line_get_string, thereby avoiding direct exposure of the line structure. Considering a future transition from C-style null-terminated strings to explicit length-based string management.
* refactor: introduce lazy loading to each line buffer.dilluti0n2025-04-291-6/+10
| | | | | | | | | | | | | | | | | Each `struct line` now holds a pointer (`origin`) to its corresponding line in the mmap'd file, along with its length (`origin_len`). The `vec` field is no longer allocated for each line during `eb_load_file`. Instead, actual memory allocation and copying into `vec` occurs only when an edit is made or when `line_get_string` is called (since a C string is required). This behavior is handled via the internal inline function `edit_happen`. Also implement `vec_cat_raw` to `line_cat` when lazy `src`. [minor] Remove unused debug messages in editor.c.
* fix: add CRLF handling to eb_load_filedilluti0n2025-04-291-1/+6
|
* perf: make line from buf directly instead of append each charactersdilluti0n2025-04-291-6/+3
| | | | implement line_init_from_buf for this.
* perf: use line_append and push instead of eb_insertdilluti0n2025-04-291-14/+13
|
* perf: replace byte-by-byte scanning with memchr in eb_load_filedilluti0n2025-04-281-6/+16
| | | | | This reduces unnecessary per-byte branching by scanning for newlines more efficiently when loading files.
* implement: eb_load_file using mmapdilluti0n2025-04-281-1/+49
| | | | | [minor] add check for eb_save_file when fopen fails.
* fix: asser fail in eb_backspace, eb_newline due to invalid accessdilluti0n2025-04-281-17/+23
| | | | | | | | | | | | | | | | | | | | | In the current design, `eb->cur_row` can range up to `Vec_slinep_len(eb->line_vec)`, allowing insertion of a new line at the end of the buffer. However, directly accessing this index caused assertion failures, as the `eb_*` series of functions operate on an abstracted structure, not the raw vector. To resolve this, a new abstraction layer `eb_delete_line` was introduced to handle boundary checks properly. The `eb_*` functions now call `eb_delete_line` instead of accessing the vector directly. Similarly, `line_get_last` was modified to return 0 when called on a `NULL` (unallocated) line to avoid unnecessary assertions. From now on, the `eb_*` series should only directly call vector macros when absolutely necessary. [minor] Rename `eb_set_cur_next` and `eb_set_cur_back`
* implement: eb_save_filedilluti0n2025-04-281-10/+24
| | | | | [minor] move eb_free to front of file
* add: basic i/o structure on main rendering loopdilluti0n2025-04-281-0/+15
| | | | | eb_bind binds file path to the ed_buf, eb_load_file loads to the buffer if exists and eb_save_file save the buffer to that path.
* fix: eb_set_cur_next does not recovering cached cursor from line.dilluti0n2025-04-281-5/+4
| | | | | [minor] add argc and argv to main routine.
* fix: possable memory leak on eb_freedilluti0n2025-04-281-1/+1
| | | | since it calls MemFree instead of line_free.
* refactor: move ed_* modules from main.c to editor.cdilluti0n2025-04-281-0/+176