Improve reopen buffer
This commit is contained in:
@@ -58,12 +58,8 @@ 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;
|
|
||||||
|
|
||||||
Int cap = string_.len * 3;
|
String16 string = ToUnixString16(scratch, text);
|
||||||
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 || SavedClipboardCarets.len != view->carets.len) {
|
if (string != SavedClipboardString || SavedClipboardCarets.len != view->carets.len) {
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ int Lua_Open(lua_State *L) {
|
|||||||
|
|
||||||
int Lua_Reopen(lua_State *L) {
|
int Lua_Reopen(lua_State *L) {
|
||||||
BSet main = GetActiveMainSet();
|
BSet main = GetActiveMainSet();
|
||||||
ReopenBuffer(main.buffer);
|
ReopenBuffer(main.view, main.buffer);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -280,6 +280,23 @@ Int ConvertUTF8ToUTF16UnixLine(String string, wchar_t *buffer, Int buffer_cap) {
|
|||||||
return buffer_len;
|
return buffer_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String16 ToUnixString16(Allocator allocator, String string_) {
|
||||||
|
Int cap = string_.len * 3;
|
||||||
|
wchar_t *string16_buffer = AllocArray(allocator, wchar_t, cap);
|
||||||
|
Int len = ConvertUTF8ToUTF16UnixLine(string_, string16_buffer, cap);
|
||||||
|
String16 string = {string16_buffer, len};
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ReopenBuffer(View *view, Buffer *buffer) {
|
||||||
|
Scratch scratch;
|
||||||
|
String string = ReadFile(scratch, buffer->name);
|
||||||
|
if (string.len == 0) return;
|
||||||
|
String16 string16 = ToUnixString16(scratch, string);
|
||||||
|
Command_ReplaceWithoutMovingCarets(view, GetRange(buffer), string16);
|
||||||
|
buffer->file_mod_time = GetFileModTime(buffer->name);
|
||||||
|
}
|
||||||
|
|
||||||
// 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.
|
||||||
//
|
//
|
||||||
@@ -326,17 +343,6 @@ void ResetBuffer(Buffer *buffer) {
|
|||||||
DeallocHistoryEntries(&buffer->undo_stack);
|
DeallocHistoryEntries(&buffer->undo_stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReopenBuffer(Buffer *buffer) {
|
|
||||||
Scratch scratch;
|
|
||||||
String string = ReadFile(scratch, buffer->name);
|
|
||||||
if (string.len) {
|
|
||||||
ResetBuffer(buffer);
|
|
||||||
buffer->len = ConvertUTF8ToUTF16UnixLine(string, buffer->str, buffer->cap);
|
|
||||||
buffer->file_mod_time = GetFileModTime(buffer->name);
|
|
||||||
UpdateLines(buffer, {}, String16{(wchar_t *)buffer->data, buffer->len});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
View *OpenBufferView(String name) {
|
View *OpenBufferView(String name) {
|
||||||
Buffer *buffer = BufferOpenFile(name);
|
Buffer *buffer = BufferOpenFile(name);
|
||||||
View *view = CreateView(buffer->id);
|
View *view = CreateView(buffer->id);
|
||||||
|
|||||||
@@ -3,14 +3,15 @@
|
|||||||
- ask user if he really wants to quit even though he has an unsaved buffer - popup window
|
- ask user if he really wants to quit even though he has an unsaved buffer - popup window
|
||||||
- add plumb rules for some web stuff
|
- add plumb rules for some web stuff
|
||||||
- test the code editor: try writing in it, try browsing in it, create test tooling
|
- test the code editor: try writing in it, try browsing in it, create test tooling
|
||||||
- event serialization to lua object format
|
|
||||||
- Execute enclosure which is going to execute on every keypress, modification
|
- Execute enclosure which is going to execute on every keypress, modification
|
||||||
- Store editor metadata in user accessible buffers? (read only)
|
|
||||||
- Find matches using grep, change things in that buffer then apply those changes to all items
|
- Find matches using grep, change things in that buffer then apply those changes to all items
|
||||||
- group history entries so the you can rollback through multiple ones at once and not waste time on skipping whitespace trimming or deleting every character
|
- group history entries so the you can rollback through multiple ones at once and not waste time on skipping whitespace trimming or deleting every character
|
||||||
|
|
||||||
|
- Fuzzy search buffer which uses titlebar as query!
|
||||||
- Check if file exists in ApplyRules otherwise return null
|
- Check if file exists in ApplyRules otherwise return null
|
||||||
|
- Store editor metadata in user accessible buffers? (read only)
|
||||||
- Add the event buffer with serialized events
|
- Add the event buffer with serialized events
|
||||||
|
- event serialization to lua object format
|
||||||
- Gotos, jumping between views should preserve cursors
|
- Gotos, jumping between views should preserve cursors
|
||||||
|
|
||||||
- OnWindowCommand allow config user to overwrite the WindowCommand keybinding, introduce his own
|
- OnWindowCommand allow config user to overwrite the WindowCommand keybinding, introduce his own
|
||||||
|
|||||||
Reference in New Issue
Block a user