fix bug with command palette selection being out of range
This commit is contained in:
parent
b8661df5ac
commit
bc708b5cd1
@ -13,6 +13,7 @@ import std.stdio;
|
|||||||
import std.exception;
|
import std.exception;
|
||||||
import std.file;
|
import std.file;
|
||||||
import std.string;
|
import std.string;
|
||||||
|
import core.stdc.stdio;
|
||||||
|
|
||||||
f32 g_delta = 0.0;
|
f32 g_delta = 0.0;
|
||||||
debug bool g_frame_step = false;
|
debug bool g_frame_step = false;
|
||||||
@ -733,40 +734,75 @@ HandleCmdMode(EditorCtx* ctx, InputEvent ev)
|
|||||||
}
|
}
|
||||||
else if(prev_count != cmd.icount)
|
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)
|
switch(cmd.current.type) with(CT)
|
||||||
{
|
{
|
||||||
case OpenFile:
|
case OpenFile:
|
||||||
{
|
{
|
||||||
if(cmd.params.length == 0 || !has_param)
|
PopulateParams(cmd, ctx.file_names);
|
||||||
|
} break;
|
||||||
|
case SaveFile:
|
||||||
{
|
{
|
||||||
cmd.params = AllocArray!(Parameter)(&cmd.cmd_arena, ctx.file_names.length);
|
u8[] param = GetParam(cmd);
|
||||||
cmd.opt_strs = AllocArray!(u8[])(&cmd.cmd_arena, ctx.file_names.length);
|
} break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CmdInputEnd:
|
||||||
|
|
||||||
|
if(cmd.selected >= cmd.opt_strs.length)
|
||||||
|
{
|
||||||
|
cmd.selected = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return taken;
|
||||||
|
}
|
||||||
|
|
||||||
|
pragma(inline) void
|
||||||
|
Check(CmdPalette* cmd, u64 length)
|
||||||
|
{
|
||||||
|
if(cmd.icount+length >= cmd.buffer.length)
|
||||||
|
{
|
||||||
|
cmd.buffer = ReallocArray!(u8)(cmd.buffer, cmd.buffer.length*2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
for(u64 i = 0; i < cmd.params.length; i += 1)
|
||||||
{
|
{
|
||||||
cmd.params[i].value = ctx.file_names[i];
|
cmd.params[i].value = strs[i];
|
||||||
cmd.params[i].visible = true;
|
cmd.params[i].visible = true;
|
||||||
cmd.opt_strs[i] = cmd.params[i].value;
|
cmd.opt_strs[i] = cmd.params[i].value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(has_param)
|
if(param.length)
|
||||||
{
|
{
|
||||||
cmd.opt_strs = AllocArray!(u8[])(&cmd.cmd_arena, ctx.file_names.length);
|
cmd.opt_strs = AllocArray!(u8[])(&cmd.cmd_arena, strs.length);
|
||||||
|
|
||||||
u64 matches;
|
u64 matches;
|
||||||
for(u64 i = 0; i < cmd.params.length; i += 1)
|
for(u64 i = 0; i < cmd.params.length; i += 1)
|
||||||
@ -783,23 +819,6 @@ HandleCmdMode(EditorCtx* ctx, InputEvent ev)
|
|||||||
|
|
||||||
cmd.opt_strs = cmd.opt_strs[0 .. matches];
|
cmd.opt_strs = cmd.opt_strs[0 .. matches];
|
||||||
}
|
}
|
||||||
} break;
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CmdInputEnd:
|
|
||||||
|
|
||||||
return taken;
|
|
||||||
}
|
|
||||||
|
|
||||||
pragma(inline) void
|
|
||||||
Check(CmdPalette* cmd, u64 length)
|
|
||||||
{
|
|
||||||
if(cmd.icount+length >= cmd.buffer.length)
|
|
||||||
{
|
|
||||||
cmd.buffer = ReallocArray!(u8)(cmd.buffer, cmd.buffer.length*2);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user