aboutsummaryrefslogtreecommitdiff
path: root/line.c
Commit message (Collapse)AuthorAgeFilesLines
* Remove obsolated functions and tests about line_get_stringdilluti0n2026-07-171-8/+0
|
* fix: double-free of line object in eb_backspace and eb_delete_linedilluti0n2025-05-141-1/+1
| | | | | | | | 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: replace #ifdef DEBUG printf to log_printfdilluti0n2025-05-141-6/+4
| | | | - fix log_printf to not automatically insert newline
* refactor: introduce mem.h; wrappers for allocatorsdilluti0n2025-05-101-6/+6
| | | | This patch removes the dependency on raylib when allocating memory.
* fix: Memory Leak in eb_delete_linedilluti0n2025-05-101-7/+7
| | | | | | 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-14/+2
| | | | | | | | | 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.
* fix: line_split allocating newline but not initializing correctlydilluti0n2025-04-291-0/+4
| | | | | The bug caused UB on splited newline. (especially when is_lazy = 1 unluckly)
* fix: SEGSEGV on line_get_last; NULL check for li should be first.dilluti0n2025-04-291-1/+3
|
* feat: add slice-based accessors for line and editor bufferdilluti0n2025-04-291-0/+14
| | | | | | | | | | | | | | | | | 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: `line_free` to handle lazy-loaded line appropriately.dilluti0n2025-04-291-5/+9
| | | | | | | fix `line_cat` to handle lazy-loaded `src` line too [minor] add const keyword for line_get_last since it is.
* refactor: introduce lazy loading to each line buffer.dilluti0n2025-04-291-15/+35
| | | | | | | | | | | | | | | | | 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.
* implement: produce_vec_from_buf to use it lazy loading.dilluti0n2025-04-291-6/+13
|
* remove: line->last to reduce ambiguity.dilluti0n2025-04-291-23/+24
| | | | | | | | | | vec_len is O(1) and it would be fast enough to use it. introduce line_lazy_init for lazy load (allocate each line when actually edit it!) per line. [minor] remove obsolate line_delete_trailing.
* perf: reduce to a single allocation in line_init_from_bufdilluti0n2025-04-291-4/+19
| | | | | | | | Previously, line_init_from_buf called line_init followed by vec_resize, which could result in up to two separate allocations. This patch introduces vec_init_with_capacity, allowing the vector to be initialized with the required capacity in a single step, reducing allocation overhead.
* perf: make line from buf directly instead of append each charactersdilluti0n2025-04-291-0/+13
| | | | implement line_init_from_buf for this.
* fix: asser fail in eb_backspace, eb_newline due to invalid accessdilluti0n2025-04-281-1/+1
| | | | | | | | | | | | | | | | | | | | | 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`
* add: DEBUG variable on makefiledilluti0n2025-04-281-0/+1
| | | | add assertion on line_insert
* refactor: introduce helper function ensure_line for eb_insertdilluti0n2025-04-271-0/+3
|
* fix: eb_backspace possable memory leakdilluti0n2025-04-271-1/+7
| | | | | | | | | | | Before deleting curr, it does not freeing it! [minor] optimize vec_delete; if sizeof v is 0, do not call memmove. refactor line_init to clearly indicates both value are initialized to 0. optimize line_cat; if src is empty (['\0']), do not call Vec_char_delete or something.
* implement: eb_set_cur_back and eb_set_cur_prevdilluti0n2025-04-271-0/+4
|
* fix: line_split update newline->last properlydilluti0n2025-04-271-2/+2
| | | | maybe caused by just coping and pasting line_init code
* modify: eb_newline to actually increase the vec when newlinedilluti0n2025-04-271-0/+4
| | | | | | | | | | | | | This is important because eb_backspace remove lines by the index of vector. Although there is pro for lazy allocation for actual line buffer, no-allocating line vector itself increase ambiguty too much. Also this commit removes the feature that eb_get_line returns NULL when its index is not correct, because this is ambiguouse with actual line pointer is NULL on line vector and causes unfindable bug. [minor] add assert on line_split
* fix: line_cat handle src->last correctlydilluti0n2025-04-271-1/+1
| | | | | | | "123456\0" -> last = 6 "789\0" -> last = 3 "123456789\0" -> last = 9 (6 + 3), not 8 (6 + (3 - 1))
* add: ASSERT on line_catdilluti0n2025-04-271-2/+4
| | | | | [minor] add documentation on line->vec
* implement: line_catdilluti0n2025-04-271-1/+12
| | | | | | [minor] remove 'raylin.h' on makefile fix vector.h to able to compile... (just a minor issues)
* fix: line_append were not updating li->last!!!!!!dilluti0n2025-04-271-0/+1
| | | | OMG...
* implement: eb_backspace; line_cat still TODOdilluti0n2025-04-271-0/+4
| | | | line_cat should be implemented; markd it TODO
* refactor: move debugs to config.h and handle build gracefullydilluti0n2025-04-271-0/+1
| | | | | | | makefile now handle each object and sources seperately to handle header change gracefully. and from now on, #DEBUG should declared inside of config.h
* implement: eb_newlinedilluti0n2025-04-271-1/+30
| | | | | | | | | | | | | I move around most of because it did not update eb->cur_col correctly. implement line_split which use vec_split for it [minor] implement eb_get_line and eb_line_num refactor main routine to use them add DEBUG symbol to makefile and remove lines.o for OBJS move declaration struct line to line.c from line.h for enhanced OOP
* implement: line_deletedilluti0n2025-04-271-1/+4
| | | | | | | fix eb_backspace to actually backspace char, not delete it [minor] fix line_insert to handle li->last correctly
* change: vector.h now alloc/free its own handledilluti0n2025-04-241-2/+1
|
* implement: eb_backspacedilluti0n2025-04-241-0/+4
|
* fix: vector memory allocation and insert logic; cleanup eb handlingdilluti0n2025-04-211-1/+5
| | | | | | | | - Fixed incorrect `MemAlloc(sizeof(type *))` usage to properly allocate `sizeof(type)` for vector structs. - Corrected `memmove` call in vector insert to account for type size and copy full range. - Added `line_set_cursor()` to set line's cursor position before inserting new lines. - Replaced `line_arr` with `line_vec` in editor buffer for clearer naming. - Improved `DrawText` fallback behavior for NULL lines.
* refactor: line handling and implement basic editor buffer abstractiondilluti0n2025-04-211-11/+15
| | | | | | | | | | | | - Rename vector type VEC -> Vec_char for clarity - Update line.c to use renamed Vec_char API - Add `line_insert` function for character insertion at arbitrary positions - Define Vec_slinep as vector of line pointers in main.c - Introduce `struct ed_buf` as an abstraction for a text buffer - Implement `eb_insert`, `eb_free` and stub `eb_newline`, `eb_backspace` - Update main loop to use `ed_buf` instead of standalone line/lines - Fix vector insertion logic to support gaps and non-contiguous positions - Change optimization level in makefile to -O0 for easier debugging
* tabify, gitignoredilluti0n2025-04-181-9/+9
|
* Introduce vector template and migrate line moduledilluti0n2025-04-181-11/+11
| | | | | | | | | | | | * vector.h: Add DEFINE_VECTOR macro for a header-only generic vector template - Implements common operations: init, push, pop, set, get, len, grow * line.[ch]: - Replace fixed char-only vec with VEC (DEFINE_VECTOR(char)) instance - Refactor memory allocation and method calls to use VEC_* macros * makefile: - Remove vec.o from OBJS (vec module is no longer used) * vec.[ch] is now obsolete; new vector types (e.g., line *) can be defined easily using a single DEFINE_VECTOR invocation
* refactor: Extract line handling logic into separate line moduledilluti0n2025-04-181-0/+39
- Moved line-related functions (init, append, clear, delete, free) out of main.c - Created new files: line.c and line.h to encapsulate `struct line` and its operations - Updated main.c to use the new line module - Simplified main.c by removing inline struct and function definitions - Adjusted makefile to compile line.o