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,56 +734,15 @@ 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;
|
||||||
cmd.params = AllocArray!(Parameter)(&cmd.cmd_arena, ctx.file_names.length);
|
case SaveFile:
|
||||||
cmd.opt_strs = AllocArray!(u8[])(&cmd.cmd_arena, ctx.file_names.length);
|
{
|
||||||
|
u8[] param = GetParam(cmd);
|
||||||
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];
|
|
||||||
}
|
|
||||||
} break;
|
} break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
@ -790,6 +750,11 @@ HandleCmdMode(EditorCtx* ctx, InputEvent ev)
|
|||||||
|
|
||||||
CmdInputEnd:
|
CmdInputEnd:
|
||||||
|
|
||||||
|
if(cmd.selected >= cmd.opt_strs.length)
|
||||||
|
{
|
||||||
|
cmd.selected = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return taken;
|
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
|
void
|
||||||
DrawBuffer(Editor* ed, f32 x, f32 y, f32 px, FlatBuffer* fb)
|
DrawBuffer(Editor* ed, f32 x, f32 y, f32 px, FlatBuffer* fb)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user