Repository navigation
Expand file tree
/
Copy patheditor.h
More file actions
179 lines (141 loc) · 5.22 KB
/
Copy patheditor.h
File metadata and controls
179 lines (141 loc) · 5.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#pragma once
#include <ncurses.h>
#include <time.h>
#include "model.h"
#include "config.h"
/**
* editor.h - The editor system.
*
* This is a core header. The Editor struct is the central
* coordinator that ties together the model subsystem's undo/redo,
* configuration, selection, search/replace state, and autosave.
* with the view and controller subsystems.
*
*/
/* Opaque forward declarations */
typedef struct UndoStack UndoStack;
typedef struct Change Change;
/**
* Change - A single entry in the undo/redo stack.
* Records enough information to reverse or re-apply an edit.
*/
struct Change {
bool is_insert; /* true = this was an insertion, false = deletion */
int line;
int col;
char ch; /* the character involved (or '\n' for line breaks) */
};
/**
* UndoStack - Dynamic array of Changes.
* Owned by the Editor. Capped at 10,000 entries for safety.
*/
struct UndoStack {
Change* changes;
int count;
int capacity;
};
/* Forward declaration of the main Editor type */
typedef struct Editor Editor;
/**
* Editor - The central state of one editing session.
*
* This struct is deliberately large because it owns almost everything
* needed for an interactive editing experience in one place.
*/
struct Editor {
/* Core data model */
Buffer model;
/* Undo / Redo */
UndoStack undo_stack;
UndoStack redo_stack;
/* Viewport / scrolling state (logical, not visual) */
int scroll_row;
int scroll_col;
/* Display toggles (F2/F3 etc.) */
int show_line_numbers;
int syntax_highlight;
/* Cursor position in the model (logical) */
int cursor_line;
int cursor_col;
/* Selection (also logical coordinates) */
int selection_start_line;
int selection_start_col;
int selection_end_line;
int selection_end_col;
int selection_active;
/* Search / Replace mode state */
char search_buffer[256];
int search_mode;
char replace_buffer[256];
int replace_step;
/* Clipboard for cut/copy/paste */
char* clipboard;
/* Current file */
const char* filename;
/* Full configuration (colors, syntax rules, autosave, etc.) */
EditorConfig config;
/* Auto-save subsystem */
int unsaved_keystrokes;
int auto_save_threshold; /* edits before triggering autosave */
int auto_save_timeout; /* seconds of inactivity */
time_t last_save_time;
int backup_count;
/* Transient UI feedback */
char status_message[256];
time_t status_message_time;
/* Dirty flag for the status bar */
int file_modified;
/* Word-wrap related (currently mostly vestigial) */
int total_visual_lines;
/* Timing / double-key detection */
int last_key_us;
int prev_key; /* used for double-Home / double-End */
/* Go-to-line prompt (Ctrl+G). goto_buffer holds "line" or "line:col". */
int goto_mode;
char goto_buffer[64];
/* Set after Ctrl+Q when the buffer is modified. A second Ctrl+Q quits. */
int quit_armed;
/* Esc was pressed; the next key is a word motion (b / f / Backspace). */
int meta_pending;
/* Terminal key codes for Ctrl+Left / Ctrl+Right. 0 if unknown. */
int key_word_left;
int key_word_right;
/* Owns the filename when it was peeled from "path:line". */
char filename_storage[512];
};
/* === Public API === */
/** Initialize a new Editor, optionally loading a file from argv. */
void editor_init(Editor* ed, int argc, char* argv[]);
/** Render the current editor state to the given ncurses windows.
* frame = border window (stdscr), text = inset derwin(frame) for text */
void editor_draw(WINDOW* frame, WINDOW* text, Editor* ed);
/* Compat: single-window wrapper (frame==text==stdscr legacy) */
void editor_draw_compat(WINDOW* win, Editor* ed);
/** Process one keypress. Returns 1 when the session should end (Ctrl+Q). */
int editor_handle_input(Editor* ed, int ch);
/**
* Ctrl+/ when the terminal does not send byte 31.
* Assigned by editor_bind_terminal_keys:
* LED_KEY_SEARCH foot / xterm modifyOtherKeys ESC [ 27 ; 5 ; 47 ~
* LED_KEY_SEARCH_ALT kitty keyboard protocol ESC [ 47 ; 5 u
* Left unrecognized, that sequence is ESC plus characters: a word
* motion starts and the rest is inserted into the buffer.
*/
#define LED_KEY_SEARCH (KEY_MAX + 1)
#define LED_KEY_SEARCH_ALT (KEY_MAX + 2)
/** Bind Ctrl+Left / Ctrl+Right and Ctrl+/ from the terminal. Call after initscr and keypad. */
void editor_bind_terminal_keys(Editor* ed);
/** "+142" -> 142. Returns 1 on success. */
int led_parse_plus_line(const char* arg, int* line);
/** Peel a trailing ":line" or ":line:col" (both 1-based) off arg.
* Does not look at the filesystem. Returns 1 when a suffix was peeled. */
int led_parse_file_location(const char* arg, char* path, size_t path_sz,
int* line, int* col);
/** Move the cursor to a 1-based "line" or "line:col". Returns 0 on success. */
int editor_apply_goto(Editor* ed, const char* spec);
/** Release all resources owned by the Editor. */
void editor_cleanup(Editor* ed);
/** Perform an autosave + backup if conditions are met. */
void auto_save(Editor* ed);
/** Set a temporary message that appears in the status bar. */
void set_status_message(Editor* ed, const char* message);