Moving Open code to C

This commit is contained in:
Krzosa Karol
2025-12-21 19:04:19 +01:00
parent 56b8b09f35
commit 0a315760f7
11 changed files with 141 additions and 631 deletions

View File

@@ -1,481 +0,0 @@
local GruvboxDark0Hard = 0x1d2021ff
local GruvboxDark0 = 0x282828ff
local GruvboxDark0Soft = 0x32302fff
local GruvboxDark1 = 0x3c3836ff
local GruvboxDark2 = 0x504945ff
local GruvboxDark3 = 0x665c54ff
local GruvboxDark4 = 0x7c6f64ff
local GruvboxGray245 = 0x928374ff
local GruvboxGray244 = 0x928374ff
local GruvboxLight0Hard = 0xf9f5d7ff
local GruvboxLight0 = 0xfbf1c7ff
local GruvboxLight0Soft = 0xf2e5bcff
local GruvboxLight1 = 0xebdbb2ff
local GruvboxLight2 = 0xd5c4a1ff
local GruvboxLight3 = 0xbdae93ff
local GruvboxLight4 = 0xa89984ff
local GruvboxBrightRed = 0xfb4934ff
local GruvboxBrightGreen = 0xb8bb26ff
local GruvboxBrightYellow = 0xfabd2fff
local GruvboxBrightBlue = 0x83a598ff
local GruvboxBrightPurple = 0xd3869bff
local GruvboxBrightAqua = 0x8ec07cff
local GruvboxBrightOrange = 0xfe8019ff
local GruvboxNeutralRed = 0xcc241dff
local GruvboxNeutralGreen = 0x98971aff
local GruvboxNeutralYellow = 0xd79921ff
local GruvboxNeutralBlue = 0x458588ff
local GruvboxNeutralPurple = 0xb16286ff
local GruvboxNeutralAqua = 0x689d6aff
local GruvboxNeutralOrange = 0xd65d0eff
local GruvboxFadedRed = 0x9d0006ff
local GruvboxFadedGreen = 0x79740eff
local GruvboxFadedYellow = 0xb57614ff
local GruvboxFadedBlue = 0x076678ff
local GruvboxFadedPurple = 0x8f3f71ff
local GruvboxFadedAqua = 0x427b58ff
local GruvboxFadedOrange = 0xaf3a03ff
Color = {}
Color.Text = GruvboxDark0Hard
Color.LoadTextHighlight = 0x0000000F
Color.Background = GruvboxLight0Hard
Color.InactiveWindow = 0x0000000F
Color.TextLineNumbers = GruvboxDark4
Color.LineHighlight = GruvboxLight0Soft
Color.MainCaret = GruvboxDark0Hard
Color.SubCaret = GruvboxGray245
Color.Selection = GruvboxLight1
Color.WhitespaceDuringSelection = GruvboxLight4
Color.MouseUnderline = GruvboxDark0Hard
Color.CaretUnderline = GruvboxGray245
Color.FuzzySearchLineHighlight = GruvboxDark0
Color.ScrollbarBackground = GruvboxLight2
Color.ScrollbarScroller = GruvboxLight1
Color.ScrollbarScrollerSelected = GruvboxLight0Hard
Color.TitleBarText = GruvboxDark2
Color.TitleBarBackground = GruvboxLight1
Color.TitleBarActiveBackground = 0xfefefefe
Color.TitleBarSelection = GruvboxLight3
Color.ResizerBackground = GruvboxLight0Hard
Color.ResizerOutline = GruvboxLight3
Style = {}
Style.WaitForEvents = 1
Style.DrawLineNumbers = 1
Style.DrawScrollbar = 1
Style.IndentSize = 4
Style.FontSize = 15
Style.Font = GetExeDir().."/CascadiaMono.ttf"
Style.VCVarsall = "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvars64.bat"
Style.TrimWhitespaceOnSave = true
Style.ClangFormatOnSave = false
Style.StyleUndoMergeTimeout = 0.3
INTERNET_BROWSER = 'C:/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe'
OS_WINDOWS = 0
OS_UNIX = 1
SDLK_CTRL = 1073742048
SDLK_PAGE_DOWN = 1073741902
SDLK_PAGE_UP = 1073741899
SDLK_DOWN = 1073741905 -- 0x40000051
SDLK_UP = 1073741906 -- 0x40000052u
SDLK_RIGHT = 1073741903
SDLK_LEFT = 1073741904
SDLK_Q = 113
SDLK_BACKSLASH = 0x5c
SDLK_RETURN = 13
SDLK_EQUALS = 0x0000003d
SDLK_MINUS = 0x0000002d
SDLK_F1 = 0x4000003a
SDLK_F2 = 0x4000003b
SDLK_F3 = 0x4000003c
SDLK_F4 = 0x4000003d
SDLK_F5 = 0x4000003e
SDLK_F6 = 0x4000003f
SDLK_F7 = 0x40000040
SDLK_F8 = 0x40000041
SDLK_F9 = 0x40000042
SDLK_F10 = 0x40000043
SDLK_F11 = 0x40000044
SDLK_F12 = 0x40000045
SDLK_A = 0x00000061
SDLK_B = 0x00000062
SDLK_C = 0x00000063
SDLK_D = 0x00000064
SDLK_E = 0x00000065
SDLK_F = 0x00000066
SDLK_G = 0x00000067
SDLK_H = 0x00000068
SDLK_I = 0x00000069
SDLK_J = 0x0000006a
SDLK_K = 0x0000006b
SDLK_L = 0x0000006c
SDLK_M = 0x0000006d
SDLK_N = 0x0000006e
SDLK_O = 0x0000006f
SDLK_P = 0x00000070
SDLK_Q = 0x00000071
SDLK_R = 0x00000072
SDLK_S = 0x00000073
SDLK_T = 0x00000074
SDLK_U = 0x00000075
SDLK_V = 0x00000076
SDLK_W = 0x00000077
SDLK_X = 0x00000078
SDLK_Y = 0x00000079
SDLK_Z = 0x0000007a
VERTICAL = 1
HORIZONTAL = 2
function IsAlpha(a)
if a == nil then
return false
end
local x = string.byte(a)
local result = (x >= string.byte('a') and x <= string.byte('z')) or (x >= string.byte('A') and x <= string.byte('Z'))
return result
end
function SkipLineAndColumn(s)
local line, col = "-1", "-1"
function parse_line_and_column(line_and_col, delimiter)
ic, jc = line_and_col:find(delimiter)
line = line_and_col:sub(1, ic - 1)
col = line_and_col:sub(ic + 1)
return line, col
end
do -- :line:column
local i, j = s:find("^:%d+:%d+")
if i then
skip_pattern = s:sub(j + 1)
line, col = parse_line_and_column(s:sub(2, j), ":")
return line, col, skip_pattern
end
end
do -- :line
local i, j = s:find("^:%d+")
if i then
skip_pattern = s:sub(j + 1)
line = s:sub(2, j)
return line, col, skip_pattern
end
end
do -- (line,column)
local i, j = s:find("^%(%d+,%d+%)")
if i then
skip_pattern = s:sub(j + 1)
line, col = parse_line_and_column(s:sub(2, j - 1), ",")
return line, col, skip_pattern
end
end
do -- (line)
local i, j = s:find("^%(%d+%)")
if i then
skip_pattern = s:sub(j + 1)
line = s:sub(2, j - 1)
return line, col, skip_pattern
end
end
return line, col, s
end
function SkipSlashes(s)
found_slash = false
while s:sub(1,1) == '/' or s:sub(1,1) == '\\' do
s = s:sub(2)
found_slash = true
end
return s, found_slash
end
function SkipDrive(s)
local i, j = s:find("^%a:")
if not i then
return s, nil, true
end
local drive = s:sub(i, j)
local new_s = s:sub(j + 1)
new_s, found_slash = SkipSlashes(new_s)
if not found_slash then
return s, drive, false
end
return new_s, drive, true
end
function WindowsSkipPathCell(s)
local i, j = s:find("^[%w_%.-% +]+")
if not i then return s, nil, false end
local word = s:sub(i, j)
local new_s = s:sub(j + 1)
local new_s, found_slash = SkipSlashes(new_s)
return new_s, word, found_slash
end
function WindowsSkipPath(s)
local input_s = s
local s, drive, ok = SkipDrive(s)
if not ok then return s end
local cells = {}
if drive ~= nil then
table.insert(cells, drive)
end
while true do
s, word, slash_eaten = WindowsSkipPathCell(s)
if word then cells[#cells + 1] = word end
if not slash_eaten then break end
end
if #cells == 0 then return s end
local skip_size = input_s:len() - s:len()
local path = input_s:sub(1, skip_size)
return s, path, drive, cells
end
function MatchWindowsPath(_s, meta)
local s, file_path, drive = WindowsSkipPath(_s)
if not file_path and FileExists(drive) then
return {kind = "text", file_path = drive, line = line, col = col}
end
if not file_path then
return nil
end
if not drive then
local d = GetMainDir()
file_path = d..'/'..file_path
end
local line, col, s = SkipLineAndColumn(s)
local exists = FileExists(file_path) or BufferExists(file_path)
if not exists then return nil end
return {kind = "text", file_path = file_path, line = line, col = col}
end
function MatchUnixPath(s, meta)
local i, j = s:find("^[%w_%.-% %/]+")
local path = s:sub(i, j)
local rest = s:sub(j + 1, -1)
local line, col, s = SkipLineAndColumn(rest)
Print(path, rest, line, col)
return {kind = "text", file_path = path, line = line, col = col}
end
if OS_VALUE == OS_WINDOWS then
MatchPath = MatchWindowsPath
else
MatchPath = MatchUnixPath
end
function MatchGitCommit(s, meta)
local i, j = string.find(s, "^commit ([a-zA-Z0-9]+)")
if i then
s = s:sub(8)
local command = "git --no-pager show "..s
return {kind = "exec", cmd = command, working_dir = GetMainDir()}
end
return nil
end
function MatchURL(s, meta)
local i, j = string.find(s, "^https://")
if i then
return {kind = "exec_console", cmd = '"'..INTERNET_BROWSER..'" '..s, working_dir = GetMainDir()}
end
return nil
end
function MatchGotoBuild(s, meta)
if meta ~= "goto_build" then
return nil
end
local windows_path = IsAlpha(s:sub(1,1)) and s:sub(2,2) == ':'
local windows_rela = s:sub(1,1) == '.' and s:sub(2,2) == '\\'
local unix_path = s:sub(1,1) == '/'
local unix_rela = s:sub(1,1) == '.' and s:sub(2,2) == '/'
if not windows_path and not windows_rela and not unix_path and not windows_rela then
return {kind = "skip"}
end
return nil
end
function MatchExec(s, meta)
if s:match(".exe$") or s:match(".bat$") or s:match(".sh$") then
return {kind = "exec_console", cmd = s, working_dir = GetMainDir()}
end
if s:match("^%$") then
return {kind = "exec_console", cmd = s:sub(2, -1), working_dir = GetMainDir()}
end
return nil
end
BuiltinOnOpenMatchers = {
MatchPath,
MatchGitCommit,
MatchURL,
MatchGotoBuild,
MatchExec,
}
OnOpenMatchers = BuiltinOnOpenMatchers
function OnOpen(path, meta)
for i = #OnOpenMatchers,1,-1 do
rule = OnOpenMatchers[i]
result = rule(path, meta)
if result then
return result
end
end
return nil
end
Coroutines = {}
function CoAdd(f)
local i = #Coroutines + 1
Coroutines[i] = coroutine.create(f)
coroutine.resume(Coroutines[i])
return Coroutines[i]
end
function OnUpdate(e)
local new_co_list = {}
for key, co in pairs(Coroutines) do
local status = coroutine.status(co)
if status ~= "dead" then
coroutine.resume(co, e)
new_co_list[#new_co_list + 1] = co
end
end
Coroutines = new_co_list
end
function KeybindsBasic(e)
if e.key == SDLK_F and e.ctrl == 1 and e.shift == 1 then
C("git grep -n "..GetLoadWord().." :/")
return true
end
return false
end
function BasicBuild()
SaveAll()
if OS_VALUE == OS_WINDOWS then
return "build.bat"
else
return "./build.sh"
end
end
FKey = {BasicBuild, "", "", "", "", "", "", "", "", "", "", ""}
FKeySDLK = {SDLK_F1, SDLK_F2, SDLK_F3, SDLK_F4, SDLK_F5, SDLK_F6, SDLK_F7, SDLK_F8, SDLK_F9, SDLK_F10, SDLK_F11, SDLK_F12}
function KeybindsFKeys(e)
for i = #FKey,1,-1 do
if FKey[i] ~= "" then
if e.key == FKeySDLK[i] then
local cmdline = FKey[i]
if type(cmdline) == "function" then cmdline = FKey[i]() end
Cmd { working_dir = GetWorkDir(), kind = "console", cmd = cmdline }
return true
end
end
end
return false
end
BuiltinOnCommandCallbacks = {
KeybindsBasic,
KeybindsFKeys,
}
OnCommandCallbacks = BuiltinOnCommandCallbacks
function OnCommand(e)
for i = #OnCommandCallbacks,1,-1 do
on_command = OnCommandCallbacks[i]
local result = on_command(e)
if result then
return true
end
end
return false
end
function OnInit()
end
function OnSave(buffer_id)
local dont_trim_lines_with_caret = false
ConvertLineEndingsToLF(buffer_id, dont_trim_lines_with_caret)
if Style.TrimWhitespaceOnSave then
TrimTrailingWhitespace(buffer_id, dont_trim_lines_with_caret)
end
local name = GetBufferNameByID(buffer_id)
if Style.ClangFormatOnSave and (name:match(".c$") or name:match(".h$") or name:match(".cpp$") or name:match(".hpp$")) then
ApplyClangFormat(buffer_id)
end
end
function IsCodeExclude(s, meta)
if s:match("/.git$") or s:match("\\.git$") or
s:match(".exe$") or
s:match(".bin$") or
s:match(".obj$") or
s:match(".o$") or
s:match(".lib$") or
s:match(".ilk$") or
s:match(".cache$") or
s:match(".exp$") or
s:match(".pdb$") or
s:match("/external/") or s:match("\\external\\")
then
return false
end
return true
end
BuiltinIsCodeMatchers = {
IsCodeExclude,
}
IsCodeMatchers = BuiltinIsCodeMatchers
function IsCode(path, meta)
for i = #IsCodeMatchers,1,-1 do
rule = IsCodeMatchers[i]
result = rule(path, meta)
if result then
return result
end
end
return false
end

View File

@@ -1,25 +0,0 @@
-- Style.WaitForEvents = 0
-- CoAdd(function()
-- Play{
-- {kind = 10, key = KEY_DOWN, xwindow = 1280, ywindow = 720},
-- {kind = 10, key = KEY_DOWN, xwindow = 1280, ywindow = 720},
-- {kind = 10, key = KEY_DOWN, xwindow = 1280, ywindow = 720},
-- {kind = 10, key = KEY_DOWN, xwindow = 1280, ywindow = 720},
-- {kind = 10, key = KEY_DOWN, xwindow = 1280, ywindow = 720},
-- {kind = 10, key = KEY_DOWN, xwindow = 1280, ywindow = 720},
-- {kind = 10, key = KEY_DOWN, xwindow = 1280, ywindow = 720},
-- {kind = 10, key = KEY_Q , xwindow = 1280, ywindow = 720, ctrl = 1},
-- {kind = 10, key = KEY_PAGE_DOWN, xmouse = 0, ymouse = 0, xwindow = 1280, ywindow = 720},
-- {kind = 111},
-- }
-- -- for i = 1,8 do coroutine.CoYield() end
-- while coroutine.CoYield().kind ~= 111 do end
-- local buffer_name = GetActiveMainWindowBufferName()
-- Print("buffer name = "..buffer_name)
-- if buffer_name == "C:/Work/text_editor/src/text_editor/buffer_history.cpp" then
-- Play{{kind = 2}}
-- end
-- end)

View File

@@ -334,3 +334,33 @@ API Int GetSize(Array<String> array) {
For (array) result += it.len;
return result;
}
API bool Chop(String *string, String ending) {
if (EndsWith(*string, ending)) {
*string = Chop(*string, ending.len);
return true;
}
return false;
}
API String ChopNumberEx(String *string) {
String col = {};
for (int64_t i = string->len - 1; i >= 0; i -= 1) {
if (IsDigit(string->data[i])) {
col.data = string->data + i;
col.len += 1;
} else {
break;
}
}
*string = Chop(*string, col.len);
return col;
}
API Int ChopNumber(String *string) {
Scratch scratch;
String col = ChopNumberEx(string);
if (col.len == 0) return -1;
Int result = strtoll(col.data, NULL, 10) - 1;
return result;
}

View File

@@ -394,20 +394,18 @@ API String16 SkipWhitespace(String16 *string) {
return begin;
}
// chop this - :324
// chop this - 324
API String16 ChopNumberEx(String16 *string) {
String16 col = {};
for (int64_t i = string->len - 1; i >= 0; i -= 1) {
if (IsDigit(string->data[i])) {
col.data = string->data + i;
col.len += 1;
} else if (string->data[i] == L':') {
break;
} else {
return {};
break;
}
}
*string = Chop(*string, col.len + 1);
*string = Chop(*string, col.len);
return col;
}
@@ -417,6 +415,5 @@ API Int ChopNumber(String16 *string) {
if (col.len == 0) return -1;
String num_string = ToString(scratch, col);
Int result = strtoll(num_string.data, NULL, 10) - 1;
return result;
}

View File

@@ -1414,39 +1414,25 @@ void RunBufferTest() {
///////////////////////////////
// Management
inline BufferID AllocBufferID(Buffer *buffer) {
BufferID AllocBufferID(Buffer *buffer) {
return {BufferIDs++, buffer};
}
inline Buffer *GetBuffer(BufferID id) {
Buffer *GetBuffer(BufferID id, Buffer *default_buffer = Buffers[0]) {
For(Buffers) {
if (it->id == id) return it;
}
return Buffers[0];
return default_buffer;
}
inline Buffer *FindBuffer(BufferID id) {
For(Buffers) {
if (it->id == id) return it;
}
return NULL;
}
inline Buffer *GetBuffer(String name) {
Buffer *GetBuffer(String name, Buffer *default_buffer = Buffers[0]) {
For(Buffers) {
if (it->name == name) return it;
}
return Buffers[0];
return default_buffer;
}
inline Buffer *FindBuffer(String name) {
For(Buffers) {
if (it->name == name) return it;
}
return NULL;
}
inline bool IsNull(Buffer *buffer) {
bool IsNull(Buffer *buffer) {
return buffer->id.id == 0;
}
@@ -1459,10 +1445,10 @@ Buffer *CreateBuffer(Allocator allocator, String name, Int size) {
String GetUniqueBufferName(String working_dir, String prepend_name, String extension = ".log") {
Scratch scratch;
String buffer_name = {};
for (int i = 1; i < INT_MAX; i += 1) {
for (int i = 1; i < 1000; i += 1) {
buffer_name = Format(scratch, "%S/%S%d%S", working_dir, prepend_name, i, extension);
buffer_name = GetAbsolutePath(scratch, buffer_name);
Buffer *exists = FindBuffer(buffer_name);
Buffer *exists = GetBuffer(buffer_name, NULL);
if (!exists && !FileExists(buffer_name)) {
break;
}

View File

@@ -161,4 +161,3 @@ API void ResetHistory(Buffer *buffer);
API void DeallocHistoryArray(Array<HistoryEntry> *entries);
API void DeallocHistoryEntries(Array<HistoryEntry> *entries);

View File

@@ -35,65 +35,6 @@ String GetMainDir() {
return name;
}
void CheckpointBeforeGoto(Window *window, View *view) {
if (window->jump_history == false) return;
Add(&window->goto_history, {view->id, view->carets[0], GetTimeSeconds()});
window->goto_redo.len = 0;
}
void CheckpointBeforeGoto(Window *window) {
CheckpointBeforeGoto(window, GetView(window->active_view));
}
GotoCrumb GetCrumb(Array<GotoCrumb> *cr) {
for (; cr->len;) {
GotoCrumb c = Pop(cr);
View *view = FindView(c.view_id);
if (view) return c;
}
return {};
}
void GotoBackward(Window *window) {
if (window->jump_history == false) return;
if (window->goto_history.len <= 0) return;
BSet set = GetBSet(window);
Add(&window->goto_redo, {set.view->id, set.view->carets[0], GetTimeSeconds()});
GotoCrumb c = GetCrumb(&window->goto_history);
window->active_view = c.view_id;
View *view = GetView(c.view_id);
view->carets[0] = c.caret;
UpdateScroll(window, true);
if (window->goto_history.len) {
GotoCrumb *next = GetLast(window->goto_history);
if (c.time - next->time <= StyleUndoMergeTimeout) {
GotoBackward(window);
}
}
}
void GotoForward(Window *window) {
if (window->goto_redo.len <= 0) return;
if (window->jump_history == false) return;
BSet set = GetBSet(window);
Add(&window->goto_history, {set.view->id, set.view->carets[0], GetTimeSeconds()});
GotoCrumb c = GetCrumb(&window->goto_redo);
window->active_view = c.view_id;
View *view = GetView(c.view_id);
view->carets[0] = c.caret;
UpdateScroll(window, true);
if (window->goto_redo.len) {
GotoCrumb *next = GetLast(window->goto_redo);
if (c.time - next->time <= StyleUndoMergeTimeout) {
GotoForward(window);
}
}
}
void JumpGarbageBuffer(BSet *set, String buffer_name = "") {
CheckpointBeforeGoto(set->window);
if (buffer_name.len == 0) {
@@ -530,6 +471,7 @@ enum OpenKind {
OpenKind_Invalid,
OpenKind_Skip,
OpenKind_Exec,
OpenKind_BackgroundExec,
OpenKind_Goto,
OpenKind_Command,
};
@@ -540,24 +482,94 @@ struct ResolvedOpen {
Int line, col;
};
ResolvedOpen ResolveOpen(String path, String meta) {
ResolvedOpen ResolveOpen(Allocator scratch, String path, String meta) {
ResolvedOpen result = {};
// Editor command
{
if (StartsWith(path, ":")) {
result = OpenKind_Command;
result.kind = OpenKind_Command;
result.path = Skip(path, 1);
} else if (StartsWith(path, "!")) {
result = OpenKind_Exec;
result.path = Skip(path, 1);
} else if () {
return result;
}
}
// Shell
{
if (StartsWith(path, "!")) {
result.kind = OpenKind_Exec;
result.path = Skip(path, 1);
return result;
}
}
// Web
{
if (StartsWith(path, "https://") || StartsWith(path, "http://")) {
result.path = Format(scratch, "%S %S", ConfigInternetBrowser, path);
result.kind = OpenKind_BackgroundExec;
return result;
}
}
// Commit
{
if (StartsWith(path, "commit ")) {
path = Skip(path, 7);
result.path = Format(scratch, "git --no-pager show %S", path);
result.kind = OpenKind_Exec;
return result;
}
}
// Parse ":line:column"
{
path = NormalizePath(scratch, path);
String p = path;
Int a = ChopNumber(&p);
if (a != -1 && Chop(&p, ":")) {
path = p;
Int b = ChopNumber(&p);
if (b != -1 && Chop(&p, ":")) {
path = p;
result.col = a;
result.line = b;
} else {
result.line = a;
}
}
}
Buffer *existing_buffer = GetBuffer(path, NULL);
if (existing_buffer != NULL) {
result.path = path;
result.kind = OpenKind_Goto;
return result;
}
if (IsAbsolute(path)) {
if (FileExists(path)) {
result.path = path;
result.kind = OpenKind_Goto;
return result;
}
} else {
String rel_path = Format(scratch, "%S/%S", GetMainDir(), path);
if (GetBuffer(rel_path, NULL) || FileExists(rel_path)) {
result.path = rel_path;
result.kind = OpenKind_Goto;
return result;
}
}
return result;
}
BSet Open(Window *window, String path, String meta, bool set_active = true) {
Scratch scratch;
BSet set = GetBSet(window);
path = Trim(path);
ResolvedOpen o = ResolveOpen(path, meta);
ResolvedOpen o = ResolveOpen(scratch, path, meta);
if (o.kind == OpenKind_Goto) {
if (set_active) {
ActiveWindowID = set.window->id;
@@ -584,11 +596,14 @@ BSet Open(Window *window, String path, String meta, bool set_active = true) {
ActiveWindowID = set.window->id;
}
JumpGarbageBuffer(&set);
Exec(set.view->id, true, o.path, WorkDir);
Exec(set.view->id, true, o.path, GetMainDir());
} else if (o.kind == OpenKind_BackgroundExec) {
// this shouldn't change the focus/window/view
Exec(NullViewID, true, o.path, GetMainDir());
} else if (o.kind == OpenKind_Skip) {
return {};
} else {
ReportWarningf("Failed to match any of OnOpen results!");
ReportWarningf("Failed to open: %S", path);
}
return GetBSet(window);
@@ -606,12 +621,6 @@ BSet Open(String16 path, String meta) {
return Open(string, meta);
}
void SetProjectFile(Buffer *buffer) {
WorkDir = ChopLastSlash(buffer->name);
LuaProjectBuffer = buffer;
LuaProjectBuffer->user_change_id = -1;
}
void Command_Save() {
BSet active = GetBSet(LastActiveLayoutWindowID);
SaveBuffer(active.buffer);
@@ -653,21 +662,11 @@ void Command_ToggleFullscreen() {
IsInFullscreen = !IsInFullscreen;
} RegisterCommand(Command_ToggleFullscreen, "f11");
void Command_SetProjectFile() {
BSet main = GetBSet(LastActiveLayoutWindowID);
SetProjectFile(main.buffer);
} RegisterCommand(Command_SetProjectFile, "");
void Command_SetWorkDir() {
BSet main = GetBSet(LastActiveLayoutWindowID);
WorkDir = ChopLastSlash(main.buffer->name);
} RegisterCommand(Command_SetWorkDir, "");
void Command_SetProject() {
Command_SetWorkDir();
Command_SetProjectFile();
} RegisterCommand(Command_SetProject, "");
void Command_KillProcess() {
BSet main = GetBSet(LastActiveLayoutWindowID);
KillProcess(main.view);
@@ -735,7 +734,6 @@ void Command_Open() {
if (active.window->id == CommandBarWindowID) {
CommandWindowOpen(active);
} else {
BSet active = GetBSet(LastActiveLayoutWindowID);
Open(FetchLoadWord(active.view));
}
} RegisterCommand(Command_Open, "ctrl-q");

View File

@@ -454,6 +454,16 @@ Event TranslateSDLEvent(SDL_Event *input_event) {
return event;
}
inline void AddEvent(Array<Event> *events, Event ev) {
if (ev.kind == EVENT_TEXT_INPUT && (ev.ctrl || ev.alt || ev.super)) {
return;
}
if (ev.kind == EVENT_NONE) {
return;
}
Add(events, ev);
}
Array<Event> GetEventsForFrame(Allocator allocator) {
Array<Event> result = {allocator};
if (EventPlayback.len) {
@@ -465,12 +475,12 @@ Array<Event> GetEventsForFrame(Allocator allocator) {
if (WaitForEvents) {
SDL_WaitEvent(&event);
Event ev = TranslateSDLEvent(&event);
if (ev.kind != EVENT_NONE) Add(&result, ev);
AddEvent(&result, ev);
}
while (SDL_PollEvent(&event)) {
Event ev = TranslateSDLEvent(&event);
if (ev.kind != EVENT_NONE) Add(&result, ev);
AddEvent(&result, ev);
}
if (result.len == 0) {

View File

@@ -38,8 +38,6 @@ WindowID ResizerSelected = {-1};
WindowID ResizerHover = {-1};
Caret DocumentAnchor;
Buffer *LuaProjectBuffer;
Buffer *LuaConfigBuffer;
Buffer *GCInfoBuffer;
Buffer *EventBuffer;
Buffer *ScratchBuffer;
@@ -154,3 +152,4 @@ RegisterVariable(Int, StyleFontFilter, 0);
RegisterVariable(String, StyleFont, "/home/krz/text_editor/package/CascadiaMono.ttf");
RegisterVariable(String, StyleVCVarsall, "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvars64.bat");
RegisterVariable(Float, StyleUndoMergeTimeout, 0.3);
RegisterVariable(String, ConfigInternetBrowser, "firefox");

View File

@@ -721,13 +721,11 @@ int main(int argc, char **argv)
for (int i = 1; i < argc; i += 1) {
String it = argv[i];
if (!FileExists(it)) continue;
if (it == "--testing") {
Testing = true;
} else if (EndsWith(it, ".project.lua")) {
SetProjectFile(BufferOpenFile(it));
} else {
if (!FileExists(it)) continue;
Window *window = GetWindow({0});
WindowOpenBufferView(window, it);
}

View File

@@ -102,7 +102,6 @@ void Appendf(View *view, const char *fmt, ...);
Buffer *CreateBuffer(Allocator allocator, String name, Int size = 4096);
View *CreateView(BufferID active_buffer);
void ReopenBuffer(Buffer *buffer);
inline Buffer *FindBuffer(String name);
bool ProcessIsActive(ViewID view);
inline bool operator==(BufferID a, BufferID b) { return a.id == b.id; }