Convert to LF during copy paste
This commit is contained in:
@@ -42,8 +42,12 @@ void Command_Paste(View *view) {
|
|||||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||||
const char *text = SDL_GetClipboardText();
|
const char *text = SDL_GetClipboardText();
|
||||||
defer { SDL_free((void *)text); };
|
defer { SDL_free((void *)text); };
|
||||||
String string_ = text;
|
String string_ = text;
|
||||||
String16 string = ToString16(scratch, string_);
|
|
||||||
|
Int cap = string_.len * 3;
|
||||||
|
wchar_t *string16_buffer = AllocArray(scratch, wchar_t, cap);
|
||||||
|
Int len = ConvertUTF8ToUTF16UnixLine(string_, string16_buffer, cap);
|
||||||
|
String16 string = {string16_buffer, len};
|
||||||
|
|
||||||
// Regular paste
|
// Regular paste
|
||||||
if (string != SavedClipboardString || SavedClipboardCursors.len != view->carets.len) {
|
if (string != SavedClipboardString || SavedClipboardCursors.len != view->carets.len) {
|
||||||
|
|||||||
@@ -196,6 +196,43 @@ String GetCurrentBufferDir() {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Int ConvertUTF8ToUTF16UnixLine(String string, wchar_t *buffer, Int buffer_cap) {
|
||||||
|
Int buffer_len = 0;
|
||||||
|
Assert(buffer_cap > string.len * 2);
|
||||||
|
for (Int i = 0; i < string.len;) {
|
||||||
|
if (string.data[i] == '\r') {
|
||||||
|
i += 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (string.data[i] == '\t') {
|
||||||
|
// @WARNING: DONT INCREASE THE SIZE CARELESSLY, WE NEED TO ADJUST BUFFER SIZE
|
||||||
|
for (Int i = 0; i < 4; i += 1) buffer[buffer_len++] = L' ';
|
||||||
|
i += 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t u32 = '?';
|
||||||
|
UTF32Result decode = UTF8ToUTF32(string.data + i, (int64_t)(string.len - i));
|
||||||
|
if (!decode.error) {
|
||||||
|
i += decode.advance;
|
||||||
|
u32 = decode.out_str;
|
||||||
|
} else {
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
UTF16Result encode = UTF32ToUTF16(u32);
|
||||||
|
if (!encode.error) {
|
||||||
|
for (int64_t encode_i = 0; encode_i < encode.len; encode_i += 1) {
|
||||||
|
buffer[buffer_len++] = encode.out_str[encode_i];
|
||||||
|
Assert(buffer_len < buffer_cap);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
buffer[buffer_len++] = L'?';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return buffer_len;
|
||||||
|
}
|
||||||
|
|
||||||
// This function as name suggests tries to open a buffer,
|
// This function as name suggests tries to open a buffer,
|
||||||
// there is no name resolution here, path should already be resolved etc.
|
// there is no name resolution here, path should already be resolved etc.
|
||||||
//
|
//
|
||||||
@@ -231,38 +268,7 @@ Buffer *BufferOpenFile(String path) {
|
|||||||
path = Intern(&GlobalInternTable, path);
|
path = Intern(&GlobalInternTable, path);
|
||||||
String string = ReadFile(scratch, path);
|
String string = ReadFile(scratch, path);
|
||||||
buffer = CreateBuffer(sys_allocator, path, string.len * 4);
|
buffer = CreateBuffer(sys_allocator, path, string.len * 4);
|
||||||
|
buffer->len = ConvertUTF8ToUTF16UnixLine(string, buffer->str, buffer->cap);
|
||||||
for (Int i = 0; i < string.len;) {
|
|
||||||
if (string.data[i] == '\r') {
|
|
||||||
i += 1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (string.data[i] == '\t') {
|
|
||||||
// @WARNING: DONT INCREASE THE SIZE CARELESSLY, WE NEED TO ADJUST BUFFER SIZE
|
|
||||||
for (Int i = 0; i < 4; i += 1) buffer->data[buffer->len++] = L' ';
|
|
||||||
i += 1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t u32 = '?';
|
|
||||||
UTF32Result decode = UTF8ToUTF32(string.data + i, (int64_t)(string.len - i));
|
|
||||||
if (!decode.error) {
|
|
||||||
i += decode.advance;
|
|
||||||
u32 = decode.out_str;
|
|
||||||
} else {
|
|
||||||
i += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
UTF16Result encode = UTF32ToUTF16(u32);
|
|
||||||
if (!encode.error) {
|
|
||||||
for (int64_t encode_i = 0; encode_i < encode.len; encode_i += 1) {
|
|
||||||
buffer->data[buffer->len++] = encode.out_str[encode_i];
|
|
||||||
Assert(buffer->len < buffer->cap);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
buffer->data[buffer->len++] = L'?';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
UpdateLines(buffer, {}, String16{(wchar_t *)buffer->data, buffer->len});
|
UpdateLines(buffer, {}, String16{(wchar_t *)buffer->data, buffer->len});
|
||||||
}
|
}
|
||||||
return buffer;
|
return buffer;
|
||||||
|
|||||||
@@ -1,18 +1,16 @@
|
|||||||
- Exec word should try to match lua function calls (first match word, then expand selection right)
|
|
||||||
- Remove pointers and use ViewIDs (enable array debug while doing this)
|
- Remove pointers and use ViewIDs (enable array debug while doing this)
|
||||||
- try using git grep for search for now, combine with fuzzy search buffer
|
- try using git grep for search for now, combine with fuzzy search buffer
|
||||||
- need to rewrite the path matching in lua
|
- need to rewrite the path matching in lua
|
||||||
- I think clipboard adds \r\n, let's execute the conversion on that
|
|
||||||
- prevent lua from infinite looping
|
- prevent lua from infinite looping
|
||||||
- Append to console and change console directory
|
- Append to console and change console directory
|
||||||
- hotkey to select window title
|
- win32: change all stack buffers to arena
|
||||||
- the 'invisible when inactive' flag does it apply to title bar windows??
|
|
||||||
|
|
||||||
- search as a command to execute which is going to be in the title bar
|
- search as a command to execute which is going to be in the title bar
|
||||||
- search backwards
|
- search backwards
|
||||||
- braces enclose should be performed even if we put the mouse out of bounds!
|
- braces enclose should be performed even if we put the mouse out of bounds!
|
||||||
- select until
|
- select until
|
||||||
- some split selection commands
|
- some split selection commands
|
||||||
|
- assign commands or lua functions to F1-F12 keys
|
||||||
|
|
||||||
- word complete
|
- word complete
|
||||||
- Search all buffers in 10X style, incrementally searched results popping up on every key press (maybe we need coroutine library in C so this is easier?)
|
- Search all buffers in 10X style, incrementally searched results popping up on every key press (maybe we need coroutine library in C so this is easier?)
|
||||||
|
|||||||
Reference in New Issue
Block a user