List files and fix scrolling
This commit is contained in:
@@ -741,6 +741,7 @@ UTF8Iter IterateUTF8Ex(char *data, int64_t len);
|
||||
UTF8Iter IterateUTF8(char *data);
|
||||
UTF8Iter IterateUTF8(String string);
|
||||
|
||||
bool IsAlphabetic(char a);
|
||||
#define FmtString(string) (int)(string).len, (string).data
|
||||
bool AreEqual(String a, String b, unsigned ignore_case = false);
|
||||
int64_t CreateWidecharFromChar(wchar_t *buffer, int64_t buffer_size, char *in, int64_t inlen);
|
||||
|
||||
@@ -31,6 +31,8 @@ String GetExeDir(Allocator allocator);
|
||||
bool FileExists(String path);
|
||||
bool IsDir(String path);
|
||||
bool IsFile(String path);
|
||||
String GetWorkingDir(Allocator arena);
|
||||
bool IsAbsolute(String path);
|
||||
|
||||
struct Process {
|
||||
bool is_valid;
|
||||
|
||||
@@ -299,3 +299,21 @@ bool IsFile(String path) {
|
||||
bool is_file = (dwAttrib & FILE_ATTRIBUTE_DIRECTORY) == 0;
|
||||
return dwAttrib != INVALID_FILE_ATTRIBUTES && is_file;
|
||||
}
|
||||
|
||||
String GetWorkingDir(Allocator arena) {
|
||||
wchar_t wbuffer[1024];
|
||||
DWORD wsize = GetCurrentDirectoryW(Lengthof(wbuffer), wbuffer);
|
||||
Assert(wsize != 0);
|
||||
Assert(wsize < 1022);
|
||||
wbuffer[wsize++] = '/';
|
||||
wbuffer[wsize] = 0;
|
||||
|
||||
String path = ToString(arena, wbuffer, wsize);
|
||||
NormalizePathInPlace(path);
|
||||
return path;
|
||||
}
|
||||
|
||||
bool IsAbsolute(String path) {
|
||||
bool result = path.len > 3 && IsAlphabetic(path.data[0]) && path.data[1] == ':' && path.data[2] == '/';
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -447,7 +447,7 @@ void HandleActiveWindowBindings(Window *window) {
|
||||
Vec2I visible_size = visible_cells * Vec2I{FontCharSpacing, FontLineSpacing};
|
||||
Vec2I rect_size = GetSize(window->document_rect);
|
||||
|
||||
if (xy.line > visible.max.y - 2) {
|
||||
if (xy.line >= visible.max.y - 2) {
|
||||
Int set_view_at_line = xy.line - (visible_cells.y - 1);
|
||||
Int cut_off_y = Max((Int)0, visible_size.y - rect_size.y);
|
||||
view.scroll.y = (set_view_at_line * FontLineSpacing) + cut_off_y;
|
||||
|
||||
@@ -9,6 +9,23 @@ int LuaOpenFile(lua_State *L) {
|
||||
return 0; // number of results
|
||||
}
|
||||
|
||||
int LuaListFiles(lua_State *L) {
|
||||
const char *text = luaL_checkstring(L, 1);
|
||||
String path = text;
|
||||
|
||||
Scratch scratch;
|
||||
Array<String> strings = {scratch};
|
||||
for (FileIter iter = IterateFiles(scratch, path); IsValid(iter); Advance(&iter)) {
|
||||
if (iter.is_directory) continue;
|
||||
String string = Format(scratch, "open \"%.*s\"", FmtString(iter.absolute_path));
|
||||
Add(&strings, string);
|
||||
}
|
||||
|
||||
String result = Merge(scratch, strings, "\n");
|
||||
lua_pushlstring(LuaState, result.data, result.len);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int LuaListOpenBuffers(lua_State *L) {
|
||||
Scratch scratch;
|
||||
Array<String> strings = {scratch};
|
||||
@@ -69,6 +86,9 @@ void InitLua() {
|
||||
|
||||
lua_pushcfunction(LuaState, LuaListWindows);
|
||||
lua_setglobal(LuaState, "list_windows");
|
||||
|
||||
lua_pushcfunction(LuaState, LuaListFiles);
|
||||
lua_setglobal(LuaState, "list_files");
|
||||
}
|
||||
|
||||
String16 EvalString(Allocator allocator, String16 string16) {
|
||||
|
||||
@@ -31,13 +31,14 @@
|
||||
#include "lua_api.cpp"
|
||||
|
||||
/*
|
||||
- fix pathing in open, make it predictable
|
||||
|
||||
- Save file (utf16->utf8)
|
||||
- resize windows
|
||||
- list files and open
|
||||
- file dock on left side
|
||||
- We can actually combine this with command window and lua, it's just going to be a buffer of
|
||||
- open "asd/asd/asd/asd"
|
||||
|
||||
- Ctrl + F
|
||||
|
||||
- word completion
|
||||
@@ -184,7 +185,7 @@ int main(void) {
|
||||
CutTop(&screen_rect, size.y * 0.05f);
|
||||
CutLeft(&screen_rect, size.x * 0.2f);
|
||||
CutRight(&screen_rect, size.x * 0.2f);
|
||||
Rect2 r = CutTop(&screen_rect, FontLineSpacing * 10.f);
|
||||
Rect2 r = CutTop(&screen_rect, FontLineSpacing * 30.f);
|
||||
|
||||
Windows[i].z = 1;
|
||||
Windows[i].total_rect = ToRect2I(r);
|
||||
|
||||
Reference in New Issue
Block a user