Respect cursor position when pasting.

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1829 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Adrien Destugues 2011-09-25 12:03:06 +00:00
parent d34c3d9df5
commit 87b7c45da4
2 changed files with 19 additions and 2 deletions

View File

@ -46,6 +46,7 @@ char* haiku_get_clipboard()
ssize_t len;
be_clipboard->Data()->FindData("text/plain", B_MIME_TYPE, &(const void*)value, &len);
be_clipboard->Unlock();
return strdup(value);
}
return NULL;

View File

@ -85,6 +85,21 @@ void Insert_character(char * str, char letter, byte position)
str[position]='\0';
}
void Prepend_string(char* dest, char* src, int max)
{
// Insert src before dest
int sized = strlen(dest);
int sizes = strlen(src);
if (sized + sizes >= max)
{
sizes = max - sized;
}
memmove(dest+sizes, dest, sized);
memcpy(dest, src, sizes);
}
int Valid_character(int c)
{
// Sous Linux: Seul le / est strictement interdit, mais beaucoup
@ -466,10 +481,11 @@ byte Readline_ex(word x_pos,word y_pos,char * str,byte visible_size,byte max_siz
{
char* data = getClipboard();
if (data == NULL) continue; // No clipboard data
// TODO Insert it at the cursor position, not at the end
// Insert it at the cursor position
Prepend_string(str + position, data, max_size - position);
// TODO Update cursor position
// TODO This doesn't respect the "allowed chars" restriction
strncat(str, data, max_size - size);
//strncat(str, data, max_size - size);
free(data);
goto affichage;
}