Get info for lua commands on buffer, ctrl shift Q thing, packaging
This commit is contained in:
21
.gitignore
vendored
21
.gitignore
vendored
@@ -1,9 +1,12 @@
|
|||||||
x64/Debug
|
x64/Debug
|
||||||
x64/Release
|
x64/Release
|
||||||
.vs/
|
.vs/
|
||||||
|
|
||||||
src/external/SDL/
|
src/external/SDL/
|
||||||
build/
|
build/
|
||||||
*.rdbg
|
package/
|
||||||
*.spall
|
*.rdbg
|
||||||
*.sublime-workspace
|
*.spall
|
||||||
|
*.sublime-workspace
|
||||||
|
te.exe
|
||||||
|
te.pdb
|
||||||
@@ -165,6 +165,12 @@ int CompileTextEditor() {
|
|||||||
Run("rc icon.rc");
|
Run("rc icon.rc");
|
||||||
}
|
}
|
||||||
result += Run(cmd);
|
result += Run(cmd);
|
||||||
|
if (result == 0) {
|
||||||
|
OS_MakeDir("../package");
|
||||||
|
OS_CopyFile("../build/te.exe", "../package/te.exe", true);
|
||||||
|
OS_CopyFile("../build/te.pdb", "../package/te.pdb", true);
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -422,7 +428,9 @@ function IsLoadWord(w)
|
|||||||
w == string.byte('_') or
|
w == string.byte('_') or
|
||||||
w == string.byte('.') or
|
w == string.byte('.') or
|
||||||
w == string.byte('-') or
|
w == string.byte('-') or
|
||||||
w == string.byte(',')
|
w == string.byte(',') or
|
||||||
|
w == string.byte('"') or
|
||||||
|
w == string.byte("'")
|
||||||
if not result then
|
if not result then
|
||||||
result = not (IsSymbol(w) or IsWhitespace(w))
|
result = not (IsSymbol(w) or IsWhitespace(w))
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -136,6 +136,13 @@ bool Seek(String16 string, String16 find, int64_t *index_out = NULL, SeekFlag fl
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String16 CutLastSlash(String16 *s) {
|
||||||
|
String16 result = *s;
|
||||||
|
Seek(*s, u"/", &s->len, SeekFlag_MatchFindLast);
|
||||||
|
result = Skip(result, s->len);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
String16 ChopLastSlash(String16 s) {
|
String16 ChopLastSlash(String16 s) {
|
||||||
String16 result = s;
|
String16 result = s;
|
||||||
Seek(s, u"/", &result.len, SeekFlag_MatchFindLast);
|
Seek(s, u"/", &result.len, SeekFlag_MatchFindLast);
|
||||||
@@ -297,26 +304,3 @@ String16 SkipWhitespace(String16 *string) {
|
|||||||
}
|
}
|
||||||
return begin;
|
return begin;
|
||||||
}
|
}
|
||||||
|
|
||||||
String16 Format16V(Allocator allocator, const char16_t *data, va_list args1) {
|
|
||||||
va_list args2;
|
|
||||||
va_copy(args2, args1);
|
|
||||||
int64_t len = vswprintf(0, 0, (wchar_t *)data, args2); // @todo: check this type
|
|
||||||
va_end(args2);
|
|
||||||
|
|
||||||
char16_t *result = (char16_t *)AllocSize(allocator, sizeof(char16_t) * (len + 1));
|
|
||||||
vswprintf((wchar_t *)result, (int)(len + 1), (wchar_t *)data, args1); // @todo: check this type
|
|
||||||
String16 res = {result, len};
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define STRING16_FORMAT(allocator, data, result) \
|
|
||||||
va_list args1; \
|
|
||||||
va_start(args1, data); \
|
|
||||||
String16 result = Format16V(allocator, data, args1); \
|
|
||||||
va_end(args1)
|
|
||||||
|
|
||||||
String16 Format16(Allocator allocator, const char16_t *data, ...) {
|
|
||||||
STRING16_FORMAT(allocator, data, result);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
@@ -99,7 +99,7 @@ void Command_ListBuffers() {
|
|||||||
Command_SelectRangeOneCursor(new_view, {});
|
Command_SelectRangeOneCursor(new_view, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
void MouseLoadWord(Event event) {
|
void MouseLoadWord(Event event, bool cut_path) {
|
||||||
Vec2I mouse = MouseVec2I();
|
Vec2I mouse = MouseVec2I();
|
||||||
BSet active = GetActiveSet();
|
BSet active = GetActiveSet();
|
||||||
|
|
||||||
@@ -110,6 +110,14 @@ void MouseLoadWord(Event event) {
|
|||||||
Range enclose = EncloseLoadWord(active.buffer, p);
|
Range enclose = EncloseLoadWord(active.buffer, p);
|
||||||
if (InBounds(active.view->carets[0].range, p)) enclose = active.view->carets[0].range;
|
if (InBounds(active.view->carets[0].range, p)) enclose = active.view->carets[0].range;
|
||||||
String16 string = GetString(active.buffer, enclose);
|
String16 string = GetString(active.buffer, enclose);
|
||||||
|
Scratch scratch;
|
||||||
|
if (cut_path) {
|
||||||
|
string = NormalizePath(scratch, string);
|
||||||
|
String16 right_part = CutLastSlash(&string);
|
||||||
|
if (right_part.len > 1 && right_part.data[1] == u'+') {
|
||||||
|
CutLastSlash(&string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
active.view->carets.len = 1;
|
active.view->carets.len = 1;
|
||||||
active.view->carets[0] = MakeCaret(p);
|
active.view->carets[0] = MakeCaret(p);
|
||||||
|
|||||||
@@ -175,13 +175,11 @@ void OnCommand(Event event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @todo: maybe move some of this stuff to window command ???
|
if (Shift() && Ctrl() && Mouse(LEFT)) {
|
||||||
// for now let's leave it because we are relaying on global state
|
MouseLoadWord(event, true);
|
||||||
// - maybe just do the check if active window is matching the DocumentSelected window
|
} else if (Ctrl() && Mouse(LEFT)) {
|
||||||
// - if scrollbar selected then don't invoke window command
|
MouseLoadWord(event, false);
|
||||||
if (Ctrl() && Mouse(LEFT)) {
|
} else if (Mouse(LEFT)) { // Uses Alt and shift
|
||||||
MouseLoadWord(event);
|
|
||||||
} else if (Mouse(LEFT)) { // CTRL SHIFT
|
|
||||||
Vec2I mouse = MouseVec2I();
|
Vec2I mouse = MouseVec2I();
|
||||||
{
|
{
|
||||||
Assert(ScrollbarSelected.id == -1);
|
Assert(ScrollbarSelected.id == -1);
|
||||||
@@ -282,6 +280,7 @@ void OnCommand(Event event) {
|
|||||||
if (window) ActiveWindow = window->id;
|
if (window) ActiveWindow = window->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BSet main = GetActiveMainSet();
|
||||||
BSet active = GetActiveSet();
|
BSet active = GetActiveSet();
|
||||||
Int buffer_change_id = active.buffer->change_id;
|
Int buffer_change_id = active.buffer->change_id;
|
||||||
|
|
||||||
@@ -392,11 +391,11 @@ void OnCommand(Event event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (CtrlShiftPress(SDLK_TAB)) {
|
if (CtrlShiftPress(SDLK_TAB)) {
|
||||||
GotoForward(GetActiveMainSet().window);
|
GotoForward(main.window);
|
||||||
} else if (ShiftPress(SDLK_TAB)) {
|
} else if (ShiftPress(SDLK_TAB)) {
|
||||||
Command_IndentSelectedLines(active.view, SHIFT_PRESSED);
|
Command_IndentSelectedLines(active.view, SHIFT_PRESSED);
|
||||||
} else if (CtrlPress(SDLK_TAB)) {
|
} else if (CtrlPress(SDLK_TAB)) {
|
||||||
GotoBackward(GetActiveMainSet().window);
|
GotoBackward(main.window);
|
||||||
} else if (Press(SDLK_TAB)) {
|
} else if (Press(SDLK_TAB)) {
|
||||||
Command_IndentSelectedLines(active.view);
|
Command_IndentSelectedLines(active.view);
|
||||||
}
|
}
|
||||||
@@ -433,13 +432,11 @@ void OnCommand(Event event) {
|
|||||||
|
|
||||||
if (ShiftPress(SDLK_F3)) {
|
if (ShiftPress(SDLK_F3)) {
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
BSet main = GetActiveMainSet();
|
|
||||||
String16 search_string = GetSearchString(main.window);
|
String16 search_string = GetSearchString(main.window);
|
||||||
Caret caret = FindPrev(main.buffer, search_string, main.view->carets[0]);
|
Caret caret = FindPrev(main.buffer, search_string, main.view->carets[0]);
|
||||||
Command_SelectRangeOneCursor(main.view, caret);
|
Command_SelectRangeOneCursor(main.view, caret);
|
||||||
} else if (Press(SDLK_F3)) {
|
} else if (Press(SDLK_F3)) {
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
BSet main = GetActiveMainSet();
|
|
||||||
String16 search_string = GetSearchString(main.window);
|
String16 search_string = GetSearchString(main.window);
|
||||||
Caret caret = FindNext(main.buffer, search_string, main.view->carets[0]);
|
Caret caret = FindNext(main.buffer, search_string, main.view->carets[0]);
|
||||||
Command_SelectRangeOneCursor(main.view, caret);
|
Command_SelectRangeOneCursor(main.view, caret);
|
||||||
@@ -464,7 +461,6 @@ void OnCommand(Event event) {
|
|||||||
|
|
||||||
if (CtrlPress(SDLK_F)) {
|
if (CtrlPress(SDLK_F)) {
|
||||||
if (!active.window->is_search_bar) {
|
if (!active.window->is_search_bar) {
|
||||||
BSet main = GetActiveMainSet();
|
|
||||||
BSet search = GetBSet(main.window->search_bar_window);
|
BSet search = GetBSet(main.window->search_bar_window);
|
||||||
String16 string = GetString(main.buffer, main.view->carets[0].range);
|
String16 string = GetString(main.buffer, main.view->carets[0].range);
|
||||||
if (string.len) {
|
if (string.len) {
|
||||||
@@ -482,9 +478,7 @@ void OnCommand(Event event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (CtrlPress(SDLK_PERIOD)) {
|
if (CtrlPress(SDLK_PERIOD)) {
|
||||||
BSet main = GetActiveMainSet();
|
Open(ChopLastSlash(main.buffer->name));
|
||||||
String name = ChopLastSlash(main.buffer->name);
|
|
||||||
Open(name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CtrlPress(SDLK_T)) {
|
if (CtrlPress(SDLK_T)) {
|
||||||
@@ -496,13 +490,19 @@ void OnCommand(Event event) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (CtrlShiftPress(SDLK_W)) {
|
if (CtrlShiftPress(SDLK_Q)) {
|
||||||
// GotoForward(GetActiveMainSet().window);
|
Scratch scratch;
|
||||||
// } else if (CtrlPress(SDLK_W)) {
|
Caret caret = active.view->carets[0];
|
||||||
// GotoBackward(GetActiveMainSet().window);
|
Range range = caret.range;
|
||||||
// }
|
if (GetSize(caret.range) == 0) range = EncloseLoadWord(active.buffer, GetFront(caret));
|
||||||
|
String16 string = NormalizePath(scratch, GetString(active.buffer, range));
|
||||||
|
String16 right_part = CutLastSlash(&string);
|
||||||
|
if (right_part.len > 1 && right_part.data[1] == u'+') {
|
||||||
|
CutLastSlash(&string);
|
||||||
|
}
|
||||||
|
|
||||||
if (CtrlPress(SDLK_Q)) {
|
Open(string);
|
||||||
|
} else if (CtrlPress(SDLK_Q)) {
|
||||||
Caret caret = active.view->carets[0];
|
Caret caret = active.view->carets[0];
|
||||||
Range range = caret.range;
|
Range range = caret.range;
|
||||||
if (GetSize(caret.range) == 0) range = EncloseLoadWord(active.buffer, GetFront(caret));
|
if (GetSize(caret.range) == 0) range = EncloseLoadWord(active.buffer, GetFront(caret));
|
||||||
@@ -513,21 +513,21 @@ void OnCommand(Event event) {
|
|||||||
|
|
||||||
if (Press(SDLK_ESCAPE)) {
|
if (Press(SDLK_ESCAPE)) {
|
||||||
if (active.window->is_search_bar) {
|
if (active.window->is_search_bar) {
|
||||||
ActiveWindow = GetActiveMainSet().window->id;
|
ActiveWindow = main.window->id;
|
||||||
active.window->visible = 0;
|
active.window->visible = 0;
|
||||||
} else if (active.window->deactivate_on_escape) {
|
} else if (active.window->deactivate_on_escape) {
|
||||||
ActiveWindow = GetActiveMainSet().window->id;
|
ActiveWindow = main.window->id;
|
||||||
} else {
|
} else {
|
||||||
active.view->carets.len = 1;
|
active.view->carets.len = 1;
|
||||||
active.view->carets[0] = MakeCaret(GetFront(active.view->carets[0]));
|
active.view->carets[0] = MakeCaret(GetFront(active.view->carets[0]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (active.window->is_title_bar && buffer_change_id != active.buffer->change_id) {
|
||||||
|
}
|
||||||
|
|
||||||
if (active.window->is_search_bar && buffer_change_id != active.buffer->change_id) {
|
if (active.window->is_search_bar && buffer_change_id != active.buffer->change_id) {
|
||||||
BSet main = GetActiveMainSet();
|
Command_Find(main.view, GetSearchString(main.window), true);
|
||||||
String16 search_string = GetSearchString(main.window);
|
|
||||||
Caret caret = FindNext(main.buffer, search_string, main.view->carets[0]);
|
|
||||||
Command_SelectRangeOneCursor(main.view, caret);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MergeCarets(active.buffer, &active.view->carets);
|
MergeCarets(active.buffer, &active.view->carets);
|
||||||
|
|||||||
@@ -312,7 +312,9 @@ function IsLoadWord(w)
|
|||||||
w == string.byte('_') or
|
w == string.byte('_') or
|
||||||
w == string.byte('.') or
|
w == string.byte('.') or
|
||||||
w == string.byte('-') or
|
w == string.byte('-') or
|
||||||
w == string.byte(',')
|
w == string.byte(',') or
|
||||||
|
w == string.byte('"') or
|
||||||
|
w == string.byte("'")
|
||||||
if not result then
|
if not result then
|
||||||
result = not (IsSymbol(w) or IsWhitespace(w))
|
result = not (IsSymbol(w) or IsWhitespace(w))
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ int Lua_Open(lua_State *L) {
|
|||||||
int Lua_SetProjectFile(lua_State *L) {
|
int Lua_SetProjectFile(lua_State *L) {
|
||||||
String name = luaL_checkstring(L, 1);
|
String name = luaL_checkstring(L, 1);
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
LuaProjectBuffer = BufferOpenFile(name);
|
LuaProjectBuffer = BufferOpenFile(name);
|
||||||
LuaProjectBuffer->user_change_id = -1;
|
LuaProjectBuffer->user_change_id = -1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -296,6 +296,38 @@ int Lua_Rename(lua_State *L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Lua_GetSelection(lua_State *L) {
|
||||||
|
Scratch scratch;
|
||||||
|
BSet main = GetActiveMainSet();
|
||||||
|
String16 string16 = GetString(main.buffer, main.view->carets[0].range);
|
||||||
|
String string = ToString(scratch, string16);
|
||||||
|
lua_pushlstring(L, string.data, string.len);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Lua_GetEntireBuffer(lua_State *L) {
|
||||||
|
Scratch scratch;
|
||||||
|
BSet main = GetActiveMainSet();
|
||||||
|
String16 string16 = GetString(main.buffer);
|
||||||
|
String string = ToString(scratch, string16);
|
||||||
|
lua_pushlstring(L, string.data, string.len);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Lua_GetClipboard(lua_State *L) {
|
||||||
|
Scratch scratch;
|
||||||
|
BSet main = GetActiveMainSet();
|
||||||
|
String string = ToString(scratch, SavedClipboardString);
|
||||||
|
lua_pushlstring(L, string.data, string.len);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Lua_GetFilename(lua_State *L) {
|
||||||
|
BSet main = GetActiveMainSet();
|
||||||
|
lua_pushlstring(L, main.buffer->name.data, main.buffer->name.len);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static void HookLuaForceExit(lua_State *L, lua_Debug *debug) {
|
static void HookLuaForceExit(lua_State *L, lua_Debug *debug) {
|
||||||
SDL_PumpEvents();
|
SDL_PumpEvents();
|
||||||
int numkeys = 0;
|
int numkeys = 0;
|
||||||
|
|||||||
@@ -19,6 +19,10 @@ luaL_Reg LuaFunctions[] = {
|
|||||||
{"GetActiveMainWindowBufferDir", Lua_GetActiveMainWindowBufferDir},
|
{"GetActiveMainWindowBufferDir", Lua_GetActiveMainWindowBufferDir},
|
||||||
{"Ls", Lua_Ls},
|
{"Ls", Lua_Ls},
|
||||||
{"Rename", Lua_Rename},
|
{"Rename", Lua_Rename},
|
||||||
|
{"GetSelection", Lua_GetSelection},
|
||||||
|
{"GetEntireBuffer", Lua_GetEntireBuffer},
|
||||||
|
{"GetClipboard", Lua_GetClipboard},
|
||||||
|
{"GetFilename", Lua_GetFilename},
|
||||||
{"Play", Lua_Play},
|
{"Play", Lua_Play},
|
||||||
{NULL, NULL},
|
{NULL, NULL},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -333,6 +333,7 @@ Buffer *BufferOpenFile(String path) {
|
|||||||
String buffer_name = GetUniqueBufferName(scratch, path, "+dir-");
|
String buffer_name = GetUniqueBufferName(scratch, path, "+dir-");
|
||||||
buffer = CreateBuffer(sys_allocator, buffer_name, 4096 * 2);
|
buffer = CreateBuffer(sys_allocator, buffer_name, 4096 * 2);
|
||||||
|
|
||||||
|
RawAppendf(buffer, "..\n");
|
||||||
for (FileIter it = IterateFiles(scratch, path); IsValid(it); Advance(&it)) {
|
for (FileIter it = IterateFiles(scratch, path); IsValid(it); Advance(&it)) {
|
||||||
RawAppendf(buffer, "%.*s\n", FmtString(it.filename));
|
RawAppendf(buffer, "%.*s\n", FmtString(it.filename));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
- maybe we could allow user to change window titles which would make them special in some way.
|
- maybe we could allow user to change window titles which would make them special in some way. A:/text_editor/+test_buffer:1:1:ADE |
|
||||||
|
|
||||||
- dump text editor state to file, restore state
|
- dump text editor state to file, restore state
|
||||||
- help menu popup when for example in process buffer, on tile bar buffer and stuff like that
|
- help menu popup when for example in process buffer, on tile bar buffer and stuff like that
|
||||||
@@ -7,10 +7,8 @@
|
|||||||
- proper lister
|
- proper lister
|
||||||
|
|
||||||
- adding items to directory should create files on save - it should ask the user (syntax: dir/ | file)
|
- adding items to directory should create files on save - it should ask the user (syntax: dir/ | file)
|
||||||
- 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 | we could just show ForceClose() in the titlebar
|
||||||
- test the code editor: try writing in it, try browsing in it, create test tooling
|
|
||||||
- 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
|
||||||
- need a way to pipe the buffer content as input into command, then it would be easy
|
|
||||||
- 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
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ void InitWindows() {
|
|||||||
Window *window = CreateWindow();
|
Window *window = CreateWindow();
|
||||||
WindowID window_id = window->id;
|
WindowID window_id = window->id;
|
||||||
window->is_column = true;
|
window->is_column = true;
|
||||||
Buffer *buffer = CreateBuffer(sys_allocator, BuffCWD("+test_buffer"));
|
Buffer *buffer = CreateBuffer(sys_allocator, BuffCWD("test_buffer"));
|
||||||
View *view = CreateView(buffer->id);
|
View *view = CreateView(buffer->id);
|
||||||
LoadTestBufferMessage(buffer);
|
LoadTestBufferMessage(buffer);
|
||||||
window->active_view = view->id;
|
window->active_view = view->id;
|
||||||
|
|||||||
Reference in New Issue
Block a user