diff --git a/src/editor/editor.d b/src/editor/editor.d index e0516de..aa9a39a 100644 --- a/src/editor/editor.d +++ b/src/editor/editor.d @@ -13,6 +13,7 @@ import std.stdio; import std.exception; import std.file; import std.string; +import core.stdc.stdio; f32 g_delta = 0.0; debug bool g_frame_step = false; @@ -733,56 +734,15 @@ HandleCmdMode(EditorCtx* ctx, InputEvent ev) } else if(prev_count != cmd.icount) { - u64 start = cmd.current.name.length; - bool has_param; - for(u64 i = start; i < cmd.icount; i += 1) - { - if(cmd.buffer[i] != ' ') - { - start = i; - has_param = true; - break; - } - } - - u8[] param = cmd.buffer[start .. cmd.icount]; - switch(cmd.current.type) with(CT) { case OpenFile: { - if(cmd.params.length == 0 || !has_param) - { - cmd.params = AllocArray!(Parameter)(&cmd.cmd_arena, ctx.file_names.length); - cmd.opt_strs = AllocArray!(u8[])(&cmd.cmd_arena, ctx.file_names.length); - - for(u64 i = 0; i < cmd.params.length; i += 1) - { - cmd.params[i].value = ctx.file_names[i]; - cmd.params[i].visible = true; - cmd.opt_strs[i] = cmd.params[i].value; - } - } - - if(has_param) - { - cmd.opt_strs = AllocArray!(u8[])(&cmd.cmd_arena, ctx.file_names.length); - - u64 matches; - for(u64 i = 0; i < cmd.params.length; i += 1) - { - bool contains = StrContains!(false)(cmd.params[i].value, param); - if(contains) - { - cmd.opt_strs[matches] = cmd.params[i].value; - matches += 1; - } - - cmd.params[i].visible = contains; - } - - cmd.opt_strs = cmd.opt_strs[0 .. matches]; - } + PopulateParams(cmd, ctx.file_names); + } break; + case SaveFile: + { + u8[] param = GetParam(cmd); } break; default: break; } @@ -790,6 +750,11 @@ HandleCmdMode(EditorCtx* ctx, InputEvent ev) CmdInputEnd: + if(cmd.selected >= cmd.opt_strs.length) + { + cmd.selected = 0; + } + return taken; } @@ -802,6 +767,60 @@ Check(CmdPalette* cmd, u64 length) } } +u8[] +GetParam(CmdPalette* cmd) +{ + u8[] param = []; + for(u64 i = cmd.current.name.length; i < cmd.icount; i += 1) + { + if(cmd.buffer[i] != ' ') + { + param = cmd.buffer[i .. cmd.icount]; + break; + } + } + + return param; +} + +void +PopulateParams(CmdPalette* cmd, u8[][] strs) +{ + u8[] param = GetParam(cmd); + if(cmd.params.length == 0 || !param.length) + { + cmd.params = AllocArray!(Parameter)(&cmd.cmd_arena, strs.length); + cmd.opt_strs = AllocArray!(u8[])(&cmd.cmd_arena, strs.length); + + for(u64 i = 0; i < cmd.params.length; i += 1) + { + cmd.params[i].value = strs[i]; + cmd.params[i].visible = true; + cmd.opt_strs[i] = cmd.params[i].value; + } + } + + if(param.length) + { + cmd.opt_strs = AllocArray!(u8[])(&cmd.cmd_arena, strs.length); + + u64 matches; + for(u64 i = 0; i < cmd.params.length; i += 1) + { + bool contains = StrContains!(false)(cmd.params[i].value, param); + if(contains) + { + cmd.opt_strs[matches] = cmd.params[i].value; + matches += 1; + } + + cmd.params[i].visible = contains; + } + + cmd.opt_strs = cmd.opt_strs[0 .. matches]; + } +} + /* void DrawBuffer(Editor* ed, f32 x, f32 y, f32 px, FlatBuffer* fb)