Fix rendering of whitespace, continue wasm porting

This commit is contained in:
Krzosa Karol
2025-11-25 09:47:03 +01:00
parent fcefe9f827
commit 38a20bd97a
13 changed files with 43 additions and 23 deletions

View File

@@ -2,7 +2,7 @@
set incs=-Isrc/external/SDL/include -Isrc/external/lua/src -Isrc/external/glad -Lsrc/external/SDL/build_web -Isrc
set wasmflags=-gsource-map -sALLOW_MEMORY_GROWTH=1 -sMAXIMUM_MEMORY=1gb -msimd128 -sTOTAL_STACK=5MB -sINITIAL_MEMORY=256mb -sUSE_WEBGL2 -sFULL_ES3=1 -sASYNCIFY -sASSERTIONS=2
set flags=-Wno-writable-strings -nostdlib++ -fno-exceptions -fdiagnostics-absolute-paths -g -DDEBUG_BUILD=1
set flags=-Wall -Wno-missing-braces -Wno-writable-strings -nostdlib++ -fno-exceptions -fdiagnostics-absolute-paths -g -DDEBUG_BUILD=1
mkdir build
cd build

View File

@@ -59,7 +59,7 @@ Color.TitleBarSelection = GruvboxLight3
Color.ResizerBackground = GruvboxLight0Hard
Color.ResizerOutline = GruvboxLight3
Style = {}
Style.WaitForEvents = 0
Style.WaitForEvents = 1
Style.DrawLineNumbers = 1
Style.DrawScrollbar = 1
Style.IndentSize = 4

View File

@@ -28,7 +28,7 @@
</style>
</head>
<body>
<canvas id="canvas" oncontextmenu="event.preventDefault()"></canvas>
<canvas class="game" id="canvas" oncontextmenu="event.preventDefault()"></canvas>
<script type='text/javascript'>
var Module = {
preRun: [],

View File

@@ -1721,10 +1721,10 @@ thread_local Arena *ScratchArenaPool[4];
#if OS_WASM
void InitScratch() {
Allocator sys_allocator = GetSystemAllocator();
ScratchArenaPool[0] = AllocArena(sys_allocator, MiB(8));
ScratchArenaPool[1] = AllocArena(sys_allocator, MiB(2));
ScratchArenaPool[0] = AllocArena(sys_allocator, MiB(16));
ScratchArenaPool[1] = AllocArena(sys_allocator, MiB(8));
ScratchArenaPool[3] = AllocArena(sys_allocator, MiB(2));
ScratchArenaPool[3] = AllocArena(sys_allocator, MiB(1));
ScratchArenaPool[3] = AllocArena(sys_allocator, KiB(512));
}
#else
void InitScratch() {

View File

@@ -147,13 +147,11 @@ bool IsAbsolute(String path) {
}
String GetWorkingDir(Allocator al) {
char *buffer = AllocArray(al, char, PATH_MAX);
char *cwd = getcwd(buffer, PATH_MAX);
return cwd;
return Copy(al, "/workingdir");
}
String GetExePath(Allocator al) {
return "/text_editor";
return Copy(al, "/text_editor");
}
String GetExeDir(Allocator al) {

View File

@@ -312,7 +312,6 @@ void Win32CloseProcess(Process *process) {
}
static void Win32ProcessError(Process *process, String msg, String cmd) {
Win32Process *p = (Win32Process *)process->platform;
Win32ReportError(msg, cmd);
Win32CloseProcess(process);
}

View File

@@ -136,7 +136,7 @@ void ReplaceWithoutMovingCarets(Buffer *buffer, Range range, String16 string) {
Scratch scratch;
Command_SelectRangeOneCursor(view, range);
Array<Edit> edits = Command_ReplaceEx(scratch, view, string);
Command_ReplaceEx(scratch, view, string);
Dealloc(&view->carets);
view->carets = carets;
@@ -487,7 +487,6 @@ void Command_DuplicateLine(View *view, int direction) {
Int coef = direction == DIR_UP ? -1 : 1;
for (Int i = 0; i < edits.len; i += 1) {
Edit *edit = edits.data + i;
Caret *caret = view->carets.data + i;
XY xymin = PosToXY(buffer, caret->range.min);
@@ -1097,8 +1096,6 @@ int Lua_ListCode(lua_State *L) {
View *Command_ExecHidden(String buffer_name, String cmd, String working_dir) {
View *view = OpenBufferView(buffer_name);
Buffer *buffer = GetBuffer(view->active_buffer);
// buffer->garbage = true;
Exec(view->id, true, cmd, working_dir);
return view;
}

View File

@@ -519,6 +519,17 @@ void OnCommand(Event event) {
Command_SelectRangeOneCursor(main.view, caret);
}
if (CtrlPress(SDLK_EQUALS)) {
StyleFontSize += 1;
ReloadFont();
}
if (CtrlPress(SDLK_MINUS)) {
if (StyleFontSize > 4) {
StyleFontSize -= 1;
ReloadFont();
}
}
if (CtrlPress(SDLK_E)) {
Command_GotoNextInList(active.window, 1);
} else if (AltPress(SDLK_E)) {

View File

@@ -60,7 +60,7 @@ Color.TitleBarSelection = GruvboxLight3
Color.ResizerBackground = GruvboxLight0Hard
Color.ResizerOutline = GruvboxLight3
Style = {}
Style.WaitForEvents = 0
Style.WaitForEvents = 1
Style.DrawLineNumbers = 1
Style.DrawScrollbar = 1
Style.IndentSize = 4

View File

@@ -70,7 +70,6 @@ int Lua_GetEntireBuffer(lua_State *L) {
int Lua_GetClipboard(lua_State *L) {
Scratch scratch;
BSet main = GetActiveMainSet();
String string = ToString(scratch, SavedClipboardString);
lua_pushlstring(L, string.data, string.len);
return 1;

View File

@@ -441,8 +441,8 @@ int main(int argc, char **argv)
SDL_DisplayID primary_display_id = SDL_GetPrimaryDisplay();
const SDL_DisplayMode *display_mode = SDL_GetCurrentDisplayMode(primary_display_id);
int w8 = (int)(display_mode->w * 0.8);
int h8 = (int)(display_mode->h * 0.8);
// int w8 = (int)(display_mode->w * 0.8);
// int h8 = (int)(display_mode->h * 0.8);
int whalf = (int)(display_mode->w * 0.5) - 10;
int hhalf = (int)(display_mode->h) - 120;

View File

@@ -70,7 +70,6 @@ void ReplaceTitleBarData(Window *window) {
column = 0;
}
bool name_changed = false;
String name = ToString(scratch, buffer_name);
if (name != main.buffer->name) {
name = GetAbsolutePath(scratch, name);

View File

@@ -164,13 +164,30 @@ void DrawWindow(Window *window, Event &event) {
pos += window->document_rect.min;
Rect2 rect = Rect2FromSize({(float)pos.x, (float)pos.y}, {(float)FontCharSpacing, (float)FontLineSpacing});
DrawRect(rect, color_selection);
}
}
// Draw the little artifacts signaling whitespace
// @copypaste
Glyph *xglyph = GetGlyph(&MainFont, 'x');
for (Int line = visible.min.y; line <= visible.max.y && line >= 0 && line < buffer->line_starts.len; line += 1) {
String16 line_string = GetLineString(buffer, line);
for (Int col = visible.min.x; col < visible.max.x && col >= 0 && col < line_string.len; col += 1) {
bool a = line > min.line && line < max.line;
bool b = min.line != max.line && (line == min.line && col >= min.col);
bool c = min.line != max.line && (line == max.line && col < max.col);
bool d = min.line == max.line && line == max.line && col >= min.col && col < max.col;
if (!(a || b || c || d)) continue;
Vec2I pos = {col * FontCharSpacing, line * FontLineSpacing};
pos -= view->scroll;
pos += window->document_rect.min;
if (line_string[col] == ' ' || line_string[col] == '\t') {
DrawCircle({pos.x + (float)FontCharSpacing / 2.f, (float)pos.y + MainFont.ascent - MainFont.descent}, MainFont.size / 8.f, color_whitespace_during_selection);
DrawCircle({pos.x + (float)FontCharSpacing / 2.f, (float)pos.y + xglyph->size.y}, MainFont.size / 16.f, color_whitespace_during_selection);
} else if (line_string[col] == '\n') {
DrawCircle({pos.x + (float)FontCharSpacing / 2.f, pos.y + MainFont.ascent - MainFont.descent}, MainFont.size / 8.f, color_whitespace_during_selection);
DrawCircle({pos.x + (float)FontCharSpacing / 2.f, (float)pos.y + xglyph->size.y}, MainFont.size / 16.f, color_whitespace_during_selection);
} else if (line_string[col] == '\r') {
DrawCircle({pos.x + (float)FontCharSpacing / 2.f, pos.y + MainFont.ascent - MainFont.descent}, MainFont.size / 8.f, color_whitespace_during_selection);
DrawCircle({pos.x + (float)FontCharSpacing / 2.f, (float)pos.y + xglyph->size.y}, MainFont.size / 16.f, color_whitespace_during_selection);
}
}
}