This code makes assumption that get_script_config(tic)->singleComment is 3 chars long #478
This commit is contained in:
parent
6a19f59b9d
commit
f8af6390ab
27
src/code.c
27
src/code.c
|
@ -1078,13 +1078,8 @@ static void setCodeMode(Code* code, s32 mode)
|
||||||
|
|
||||||
static void commentLine(Code* code)
|
static void commentLine(Code* code)
|
||||||
{
|
{
|
||||||
static char Comment[] = "-- ";
|
const char* comment = code->tic->api.get_script_config(code->tic)->singleComment;
|
||||||
enum {Size = sizeof Comment-1};
|
size_t size = strlen(comment);
|
||||||
|
|
||||||
tic_mem* tic = code->tic;
|
|
||||||
|
|
||||||
memcpy(Comment, tic->api.get_script_config(tic)->singleComment,
|
|
||||||
strlen(tic->api.get_script_config(tic)->singleComment));
|
|
||||||
|
|
||||||
char* line = getLine(code);
|
char* line = getLine(code);
|
||||||
|
|
||||||
|
@ -1092,26 +1087,26 @@ static void commentLine(Code* code)
|
||||||
|
|
||||||
while((*line == ' ' || *line == '\t') && line < end) line++;
|
while((*line == ' ' || *line == '\t') && line < end) line++;
|
||||||
|
|
||||||
if(memcmp(line, Comment, Size))
|
if(memcmp(line, comment, size))
|
||||||
{
|
{
|
||||||
if (strlen(code->src) + Size >= sizeof(tic_code))
|
if (strlen(code->src) + size >= sizeof(tic_code))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
memmove(line + Size, line, strlen(line)+1);
|
memmove(line + size, line, strlen(line)+1);
|
||||||
memcpy(line, Comment, Size);
|
memcpy(line, comment, size);
|
||||||
|
|
||||||
if(code->cursor.position > line)
|
if(code->cursor.position > line)
|
||||||
code->cursor.position += Size;
|
code->cursor.position += size;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
memmove(line, line + Size, strlen(line + Size)+1);
|
memmove(line, line + size, strlen(line + size)+1);
|
||||||
|
|
||||||
if(code->cursor.position > line + Size)
|
if(code->cursor.position > line + size)
|
||||||
code->cursor.position -= Size;
|
code->cursor.position -= size;
|
||||||
}
|
}
|
||||||
|
|
||||||
code->cursor.selection = NULL;
|
code->cursor.selection = NULL;
|
||||||
|
|
||||||
history(code);
|
history(code);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue