Compare commits

...

4 Commits

Author SHA1 Message Date
Krzosa Karol
217659256b Begin design of comment evaluation and {{variables}} 2026-01-31 09:49:44 +01:00
Krzosa Karol
4d9cfcd302 MergeCarets in SelectCOmment 2026-01-31 07:30:40 +01:00
Krzosa Karol
d5099cee38 PageDown PageUp don't change if caret still on screen 2026-01-31 07:30:27 +01:00
Krzosa Karol
017b70f3e6 In debug build set position 2026-01-31 07:30:06 +01:00
8 changed files with 66 additions and 15 deletions

View File

@@ -1172,3 +1172,25 @@ API void CloseStdin(Process *process) {
API double GetTimeSeconds() { API double GetTimeSeconds() {
return GetTimeMicros() / 1000000.0; return GetTimeMicros() / 1000000.0;
} }
API String WriteTempFile(String data) {
Scratch scratch;
#if OS_WINDOWS
int buffer_len = MAX_PATH+1;
char16_t *buffer = AllocArray(scratch, char16_t, buffer_len);
Assert(sizeof(char16_t) == sizeof(wchar_t));
DWORD result = GetTempPath2W(buffer_len, (LPWSTR)buffer);
Assert(result != 0);
String16 temp16 = {buffer, result};
NormalizePathInPlace(temp16);
String temp_directory = ToString(scratch, temp16);
#else
String temp_directory = "/tmp";
#endif
String temp_filename = Format(scratch, "%S/temp%llu", temp_directory, GetTimeNanos());
bool done = WriteFile(temp_filename, data);
Assert(done);
return temp_filename;
}

View File

@@ -310,7 +310,7 @@ API Int GetWordEnd(Buffer *buffer, Int pos) {
} }
API bool IsLoadWord(char16_t w) { API bool IsLoadWord(char16_t w) {
bool result = w == u'-' || w == u'/' || w == u'\\' || w == u':' || w == u'$' || w == u'_' || w == u'.' || w == u'!' || w == u'@'; bool result = w == u'-' || w == u'/' || w == u'\\' || w == u':' || w == u'$' || w == u'_' || w == u'.' || w == u'!' || w == u'@' || w == '{' || w == '}';
if (!result) { if (!result) {
result = !(IsSymbol(w) || IsWhitespace(w)); result = !(IsSymbol(w) || IsWhitespace(w));
} }

View File

@@ -68,6 +68,7 @@ void Appendf(View *view, const char *fmt, ...) {
} }
void ReportErrorf(const char *fmt, ...) { void ReportErrorf(const char *fmt, ...) {
ErrorCount += 1;
Scratch scratch; Scratch scratch;
STRING_FORMAT(scratch, fmt, string); STRING_FORMAT(scratch, fmt, string);
if (BreakOnError) { if (BreakOnError) {
@@ -254,5 +255,6 @@ void CMD_SelectComment() {
Range scope = EncloseScope(active.buffer, it.range.min, it.range.max, u"/*", u"*/"); Range scope = EncloseScope(active.buffer, it.range.min, it.range.max, u"/*", u"*/");
it.range = scope; it.range = scope;
} }
MergeCarets(active.buffer, &active.view->carets);
} RegisterCommand(CMD_SelectComment, "ctrl-shift-l", "Find /* and */ and select the content in between"); } RegisterCommand(CMD_SelectComment, "ctrl-shift-l", "Find /* and */ and select the content in between");

View File

@@ -14,6 +14,11 @@ Int ErrorCount;
String16 InitialScratchContent = uR"==(:OpenProject String16 InitialScratchContent = uR"==(:OpenProject
C:/text_editor/src/text_editor/text_editor.cpp C:/text_editor/src/text_editor/text_editor.cpp
:Set FontSize 70 :Set FontSize 70
/*
!python {{TEMP}}
for it in i:
memes
*/
0 0
1 1
2 2

View File

@@ -56,6 +56,17 @@ void CMD_EvalCommandsLineByLine() {
EvalCommandsLineByLine(set); EvalCommandsLineByLine(set);
} RegisterCommand(CMD_EvalCommandsLineByLine, "", "Goes line by line over a buffer and evaluates every line as a command, ignores empty or lines starting with '//'"); } RegisterCommand(CMD_EvalCommandsLineByLine, "", "Goes line by line over a buffer and evaluates every line as a command, ignores empty or lines starting with '//'");
Variable *GetVariable(String name) {
Variable *var = NULL;
For (Variables) {
if (name == it.name) {
var = ⁢
break;
}
}
return var;
}
BufferID LoadConfig(String config_path) { BufferID LoadConfig(String config_path) {
ReportConsolef("Loading config %S...", config_path); ReportConsolef("Loading config %S...", config_path);
Window *window = GetWindow(NullWindowID); Window *window = GetWindow(NullWindowID);
@@ -69,7 +80,6 @@ BufferID LoadConfig(String config_path) {
return buffer->id; return buffer->id;
} }
#define ExpectP(x, ...) \ #define ExpectP(x, ...) \
if (!(x)) { \ if (!(x)) { \
ReportErrorf("Failed to parse '" __FUNCTION__ "' command, " __VA_ARGS__); \ ReportErrorf("Failed to parse '" __FUNCTION__ "' command, " __VA_ARGS__); \
@@ -80,14 +90,7 @@ void Set(String string) {
String name = SkipIdent(&string); String name = SkipIdent(&string);
ExpectP(name.len != 0, "expected a variable name, instead got '%S'", string); ExpectP(name.len != 0, "expected a variable name, instead got '%S'", string);
Variable *var = NULL; Variable *var = GetVariable(name);
For (Variables) {
if (name == it.name) {
var = ⁢
break;
}
}
if (var) { if (var) {
SkipWhitespace(&string); SkipWhitespace(&string);
if (var->type == VariableType_String) { if (var->type == VariableType_String) {

View File

@@ -854,7 +854,7 @@ int main(int argc, char **argv)
{ {
InitScratch(); InitScratch();
InitOS((OSErrorReport *)printf); InitOS((OSErrorReport *)printf);
#if _WIN32 #if OS_WINDOWS
int argc = __argc; int argc = __argc;
char **argv = __argv; char **argv = __argv;
AttachConsole(ATTACH_PARENT_PROCESS); AttachConsole(ATTACH_PARENT_PROCESS);
@@ -917,11 +917,17 @@ int main(int argc, char **argv)
// int w8 = (int)(display_mode->w * 0.8); // int w8 = (int)(display_mode->w * 0.8);
// int h8 = (int)(display_mode->h * 0.8); // int h8 = (int)(display_mode->h * 0.8);
#if DEBUG_BUILD
int whalf = 1000;
int hhalf = 1000;
int xhalf = 100;
int yhalf = 100;
#else
int whalf = (int)(display_mode->w * 0.5) - 10; int whalf = (int)(display_mode->w * 0.5) - 10;
int hhalf = (int)(display_mode->h) - 120; int hhalf = (int)(display_mode->h) - 120;
int xhalf = whalf; int xhalf = whalf;
int yhalf = 30; int yhalf = 30;
#endif
Uint32 window_flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY; Uint32 window_flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY;
SDLWindow = SDL_CreateWindow("Text editor", whalf, hhalf, window_flags); SDLWindow = SDL_CreateWindow("Text editor", whalf, hhalf, window_flags);

View File

@@ -214,7 +214,7 @@ void MouseLoadWord(Event event, ResolveOpenMeta meta = ResolveOpenMeta_Normal) {
} }
bool IsOpenBoundary(char c) { bool IsOpenBoundary(char c) {
bool result = c == 0 || IsBrace(c) || c == ':' || c == '\t' || c == '\n' || c == '"' || c == '\''; bool result = c == 0 || c == ':' || c == '\t' || c == '\n' || c == '"' || c == '\'';
return result; return result;
} }
@@ -224,6 +224,8 @@ ResolvedOpen ResolveOpen(Allocator alo, Window *window, String path, ResolveOpen
bool exec = !(ResolveOpenMeta_DontExec & meta); bool exec = !(ResolveOpenMeta_DontExec & meta);
#if PLUGIN_CONFIG #if PLUGIN_CONFIG
// @todo: variable substitution {{ProjectDirectory}}/build/te.exe
if (exec && result.kind == OpenKind_Invalid && StartsWith(path, ":Set ")) { if (exec && result.kind == OpenKind_Invalid && StartsWith(path, ":Set ")) {
result.kind = OpenKind_Set; result.kind = OpenKind_Set;
result.path = Skip(path, 5); result.path = Skip(path, 5);
@@ -253,6 +255,15 @@ ResolvedOpen ResolveOpen(Allocator alo, Window *window, String path, ResolveOpen
if (exec && result.kind == OpenKind_Invalid && StartsWith(path, "!")) { if (exec && result.kind == OpenKind_Invalid && StartsWith(path, "!")) {
result.kind = OpenKind_Exec; result.kind = OpenKind_Exec;
result.path = Skip(path, 1); result.path = Skip(path, 1);
Int idx = 0;
String needle = "{{TEMP}}";
if (Seek(result.path, needle, &idx, SeekFlag_None)) {
String rest = Skip(result.path, idx + needle.len);
String begin = GetPrefix(result.path, idx);
String temp_filename = WriteTempFile(rest);
result.path = Format(alo, "%S%S", begin, temp_filename);
}
} }
// https://web // https://web
@@ -291,7 +302,6 @@ ResolvedOpen ResolveOpen(Allocator alo, Window *window, String path, ResolveOpen
} }
path = {pstart.data, (Int)(p.data - pstart.data)}; path = {pstart.data, (Int)(p.data - pstart.data)};
// @todo: verify!
// For (LINE:COLUMN): error: - we can either backtrack at the end since we are including // For (LINE:COLUMN): error: - we can either backtrack at the end since we are including
// the parenthesis and whitespace or alternatively we can look for patterns on every // the parenthesis and whitespace or alternatively we can look for patterns on every
// character move in the loop... For now let's do backtracking. This doesn't handle all paths // character move in the loop... For now let's do backtracking. This doesn't handle all paths

View File

@@ -470,5 +470,8 @@ void MoveCursorByPageSize(Window *window, int direction, bool shift = false) {
} }
} }
IsOnScreenResult r = IsMainCaretOnScreen(window);
if (!r.caret_on_screen) {
SetStoredOffsetFromTop(window, is_on_screen_res); SetStoredOffsetFromTop(window, is_on_screen_res);
} }
}