First hooks

This commit is contained in:
Krzosa Karol
2025-12-18 08:29:54 +01:00
parent 29002c965c
commit 7720176e60
8 changed files with 185 additions and 188 deletions

View File

@@ -1,12 +1,3 @@
REDESIGN and DELETE CODE
- Reduce the amount of actions needed to navigate using keyboard
- Make mouse important but much less so
Needs to change:
- Make it more similar to sublime like editors
- Need Ctrl + P
- Clickable title bar may be cool or whatever but it's pretty bad
- Executing lua commands is clunky, need a real Ctrl+P and keybind actions, popups: remove a lot of the lua functionality, just for config files
- Window, View, Buffer + flags design (or is completely new kind based approach needed for Windows/Views?) - Window, View, Buffer + flags design (or is completely new kind based approach needed for Windows/Views?)
- How to make non-editable, informative, with different font size, title bar. Which might also contain tabs - How to make non-editable, informative, with different font size, title bar. Which might also contain tabs
- How to design clickable tree view in this way? - How to design clickable tree view in this way?
@@ -14,17 +5,9 @@ Needs to change:
- How to design popup view (input field)? - How to design popup view (input field)?
- How to design search view? or search and replace view? - How to design search view? or search and replace view?
Things I like:
- Basic editing
- Configurable Open
- Lua config files work pretty well
Splits: Splits:
- Buffer16 Buffer8?
- Why constraint that name of buffer needs to be unique? For Open() and default behavior but is this required? - Why constraint that name of buffer needs to be unique? For Open() and default behavior but is this required?
- Try to add Tracking Allocator and rewrite the app, free all memory at the end of the app and check all is well - Try to add Tracking Allocator and rewrite the app, free all memory at the end of the app and check all is well
- move titlebar, search to splits?
Commands TODO: Commands TODO:
- Search - Search
@@ -41,31 +24,8 @@ Commands TODO:
- CONSIDER AUTOMATING: CheckpointBeforeGoto - CONSIDER AUTOMATING: CheckpointBeforeGoto
- GotoBackward how to handle that in case we want to automate and create on every move? - GotoBackward how to handle that in case we want to automate and create on every move?
## Hooks and bindings
```
struct Hook {
String name;
String trigger;
HookFunction function;
};
void Command_New() {
...
} RegisterCommand(Command_New, "ctrl-n", NOT_VISIBLE_IN_LISTING);
// How do we handle Command_Delete variations????
void Hook_FormatOnSave() {
} RegisterHook(Hook_FormatOnSave, "onsave");
Array<Hook> Hooks;
```
backlog
DESIGN try to make console less special, make stuff reusable etc. DESIGN try to make console less special, make stuff reusable etc.
DESIGN Config file versions, when loading should be checked, at the top of the file, what to do when old version? DESIGN Config file versions, when loading should be checked, at the top of the file, what to do when old version?
ISSUE Ctrl+Alt+Down (DuplicateLine) doesn't work on ubuntu ISSUE Ctrl+Alt+Down (DuplicateLine) doesn't work on ubuntu
@@ -98,7 +58,6 @@ FEATURE group history entries so the you can rollback through multiple ones at o
- code sections, visual demarkation if beginning of line has a very specific text + goto next / goto prev section hotkey! - code sections, visual demarkation if beginning of line has a very specific text + goto next / goto prev section hotkey!
- combine glyph and selection rendering - combine glyph and selection rendering
backlog
- expose a coroutine based scripting enviorment where user can execute shell commands wait for them and perform actions in very linear manner - expose a coroutine based scripting enviorment where user can execute shell commands wait for them and perform actions in very linear manner
- Test stdin writing code - Test stdin writing code
- Implement shell interaction (the valid cmd lines should start with '>' or '$', user can add more lines like this to expand the command size maybe?, if we have a case where we have a line with '>' but the last line doesn't have (just a space) then it should execute?) - Implement shell interaction (the valid cmd lines should start with '>' or '$', user can add more lines like this to expand the command size maybe?, if we have a case where we have a line with '>' but the last line doesn't have (just a space) then it should execute?)

View File

@@ -1233,7 +1233,7 @@ API Buffer *CreateTempBuffer(Allocator allocator, Int size = 4096) {
return result; return result;
} }
void RunBufferTest(void *param) { void RunBufferTest() {
{ {
Scratch scratch; Scratch scratch;
Buffer buffer = {}; Buffer buffer = {};

View File

@@ -1085,12 +1085,12 @@ String16 FetchLoadWord(BSet set) {
return string; return string;
} }
void Command_Save(CommandContext *ctx) { void Command_Save() {
BSet active = GetBSet(LastActiveLayoutWindowID); BSet active = GetBSet(LastActiveLayoutWindowID);
SaveBuffer(active.buffer); SaveBuffer(active.buffer);
} RegisterCommand(Command_Save, "ctrl-s"); } RegisterCommand(Command_Save, "ctrl-s");
void Command_SaveAll(CommandContext *ctx) { void Command_SaveAll() {
For(Buffers) { For(Buffers) {
if (it->file_mod_time) { if (it->file_mod_time) {
SaveBuffer(it); SaveBuffer(it);
@@ -1098,18 +1098,18 @@ void Command_SaveAll(CommandContext *ctx) {
} }
} RegisterCommand(Command_SaveAll, "ctrl-shift-s"); } RegisterCommand(Command_SaveAll, "ctrl-shift-s");
void Command_Reopen(CommandContext *ctx) { void Command_Reopen() {
BSet main = GetBSet(LastActiveLayoutWindowID); BSet main = GetBSet(LastActiveLayoutWindowID);
ReopenBuffer(main.buffer); ReopenBuffer(main.buffer);
ActiveWindowID = main.window->id; ActiveWindowID = main.window->id;
} RegisterCommand(Command_Reopen, ""); } RegisterCommand(Command_Reopen, "");
void Command_New(CommandContext *ctx) { void Command_New() {
BSet main = GetBSet(LastActiveLayoutWindowID); BSet main = GetBSet(LastActiveLayoutWindowID);
New(main.window, ""); New(main.window, "");
} RegisterCommand(Command_New, "ctrl-n"); } RegisterCommand(Command_New, "ctrl-n");
void Command_ToggleFullscreen(CommandContext *ctx) { void Command_ToggleFullscreen() {
if (IsInFullscreen) { if (IsInFullscreen) {
SDL_SetWindowSize(SDLWindow, FullScreenSizeX, FullScreenSizeY); SDL_SetWindowSize(SDLWindow, FullScreenSizeX, FullScreenSizeY);
SDL_SetWindowPosition(SDLWindow, FullScreenPositionX, FullScreenPositionY); SDL_SetWindowPosition(SDLWindow, FullScreenPositionX, FullScreenPositionY);
@@ -1126,7 +1126,7 @@ void Command_ToggleFullscreen(CommandContext *ctx) {
IsInFullscreen = !IsInFullscreen; IsInFullscreen = !IsInFullscreen;
} RegisterCommand(Command_ToggleFullscreen, "f11"); } RegisterCommand(Command_ToggleFullscreen, "f11");
void Command_ListCode(CommandContext *ctx) { void Command_ListCode() {
BSet main = GetBSet(LastActiveLayoutWindowID); BSet main = GetBSet(LastActiveLayoutWindowID);
JumpGarbageBuffer(&main); JumpGarbageBuffer(&main);
ListFilesRecursive(main.buffer, WorkDir); ListFilesRecursive(main.buffer, WorkDir);
@@ -1135,7 +1135,7 @@ void Command_ListCode(CommandContext *ctx) {
SelectRange(main.view, GetBufferEndAsRange(main.buffer)); SelectRange(main.view, GetBufferEndAsRange(main.buffer));
} RegisterCommand(Command_ListCode, ""); } RegisterCommand(Command_ListCode, "");
void Command_ShowBufferList(CommandContext *ctx) { void Command_ShowBufferList() {
BSet command_bar = GetBSet(CommandBarWindowID); BSet command_bar = GetBSet(CommandBarWindowID);
command_bar.window->visible = true; command_bar.window->visible = true;
command_bar.window->eval_command = false; command_bar.window->eval_command = false;
@@ -1148,7 +1148,7 @@ void Command_ShowBufferList(CommandContext *ctx) {
SelectRange(command_bar.view, GetBufferEndAsRange(command_bar.buffer)); SelectRange(command_bar.view, GetBufferEndAsRange(command_bar.buffer));
} RegisterCommand(Command_ShowBufferList, "ctrl-p"); } RegisterCommand(Command_ShowBufferList, "ctrl-p");
void Command_ListViews(CommandContext *ctx) { void Command_ListViews() {
BSet command_bar = GetBSet(CommandBarWindowID); BSet command_bar = GetBSet(CommandBarWindowID);
command_bar.window->visible = true; command_bar.window->visible = true;
command_bar.window->eval_command = false; command_bar.window->eval_command = false;
@@ -1163,12 +1163,12 @@ void Command_ListViews(CommandContext *ctx) {
SelectRange(command_bar.view, GetBufferEndAsRange(command_bar.buffer)); SelectRange(command_bar.view, GetBufferEndAsRange(command_bar.buffer));
} RegisterCommand(Command_ListViews, ""); } RegisterCommand(Command_ListViews, "");
void Command_SetProjectFile(CommandContext *ctx) { void Command_SetProjectFile() {
BSet main = GetBSet(LastActiveLayoutWindowID); BSet main = GetBSet(LastActiveLayoutWindowID);
SetProjectFile(main.buffer); SetProjectFile(main.buffer);
} RegisterCommand(Command_SetProjectFile, ""); } RegisterCommand(Command_SetProjectFile, "");
void Command_SetWorkDir(CommandContext *ctx) { void Command_SetWorkDir() {
String dir = lua_tostring(LuaState, -1); String dir = lua_tostring(LuaState, -1);
if (dir.len == 0) { if (dir.len == 0) {
BSet main = GetBSet(LastActiveLayoutWindowID); BSet main = GetBSet(LastActiveLayoutWindowID);
@@ -1178,27 +1178,27 @@ void Command_SetWorkDir(CommandContext *ctx) {
} }
} RegisterCommand(Command_SetWorkDir, ""); } RegisterCommand(Command_SetWorkDir, "");
void Command_SetProject(CommandContext *ctx) { void Command_SetProject() {
Command_SetWorkDir(ctx); Command_SetWorkDir();
Command_SetProjectFile(ctx); Command_SetProjectFile();
} RegisterCommand(Command_SetProject, ""); } RegisterCommand(Command_SetProject, "");
void Command_ToggleDebug(CommandContext *ctx) { void Command_ToggleDebug() {
Window *window = GetWindow(DebugWindowID); Window *window = GetWindow(DebugWindowID);
window->visible = !window->visible; window->visible = !window->visible;
} RegisterCommand(Command_ToggleDebug, "ctrl-0"); } RegisterCommand(Command_ToggleDebug, "ctrl-0");
void Command_KillProcess(CommandContext *ctx) { void Command_KillProcess() {
BSet main = GetBSet(LastActiveLayoutWindowID); BSet main = GetBSet(LastActiveLayoutWindowID);
KillProcess(main.view); KillProcess(main.view);
} RegisterCommand(Command_KillProcess, ""); } RegisterCommand(Command_KillProcess, "");
void Command_KillWindow(CommandContext *ctx) { void Command_KillWindow() {
BSet main = GetBSet(LastActiveLayoutWindowID); BSet main = GetBSet(LastActiveLayoutWindowID);
main.window->kill = true; main.window->kill = true;
} RegisterCommand(Command_KillWindow, "ctrl-w"); } RegisterCommand(Command_KillWindow, "ctrl-w");
void Command_ShowCommands(CommandContext *ctx) { void Command_ShowCommands() {
BSet command_bar = GetBSet(CommandBarWindowID); BSet command_bar = GetBSet(CommandBarWindowID);
command_bar.window->visible = true; command_bar.window->visible = true;
command_bar.window->eval_command = true; command_bar.window->eval_command = true;
@@ -1211,7 +1211,7 @@ void Command_ShowCommands(CommandContext *ctx) {
SelectRange(command_bar.view, GetBufferEndAsRange(command_bar.buffer)); SelectRange(command_bar.view, GetBufferEndAsRange(command_bar.buffer));
} RegisterCommand(Command_ShowCommands, "ctrl-shift-p"); } RegisterCommand(Command_ShowCommands, "ctrl-shift-p");
void Command_ShowLuaFunctions(CommandContext *ctx) { void Command_ShowLuaFunctions() {
BSet command_bar = GetBSet(CommandBarWindowID); BSet command_bar = GetBSet(CommandBarWindowID);
command_bar.window->visible = true; command_bar.window->visible = true;
command_bar.window->eval_command = false; command_bar.window->eval_command = false;
@@ -1224,17 +1224,17 @@ void Command_ShowLuaFunctions(CommandContext *ctx) {
SelectRange(command_bar.view, GetBufferEndAsRange(command_bar.buffer)); SelectRange(command_bar.view, GetBufferEndAsRange(command_bar.buffer));
} RegisterCommand(Command_ShowLuaFunctions, ""); } RegisterCommand(Command_ShowLuaFunctions, "");
void Command_GotoBackward(CommandContext *ctx) { void Command_GotoBackward() {
BSet main = GetBSet(LastActiveLayoutWindowID); BSet main = GetBSet(LastActiveLayoutWindowID);
GotoBackward(main.window); GotoBackward(main.window);
} RegisterCommand(Command_GotoBackward, "alt-q | mousex1"); } RegisterCommand(Command_GotoBackward, "alt-q | mousex1");
void Command_GotoForward(CommandContext *ctx) { void Command_GotoForward() {
BSet main = GetBSet(LastActiveLayoutWindowID); BSet main = GetBSet(LastActiveLayoutWindowID);
GotoForward(main.window); GotoForward(main.window);
} RegisterCommand(Command_GotoForward, "mousex2"); } RegisterCommand(Command_GotoForward, "mousex2");
void Command_OpenUpFolder(CommandContext *ctx) { void Command_OpenUpFolder() {
BSet main = GetBSet(LastActiveLayoutWindowID); BSet main = GetBSet(LastActiveLayoutWindowID);
String name = ChopLastSlash(main.buffer->name); String name = ChopLastSlash(main.buffer->name);
if (EndsWith(main.buffer->name, "dirlisting")) { if (EndsWith(main.buffer->name, "dirlisting")) {
@@ -1243,59 +1243,59 @@ void Command_OpenUpFolder(CommandContext *ctx) {
Open(name); Open(name);
} RegisterCommand(Command_OpenUpFolder, "ctrl-period"); } RegisterCommand(Command_OpenUpFolder, "ctrl-period");
void Command_EncloseLine(CommandContext *ctx) { void Command_EncloseLine() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
EncloseLine(active.view); EncloseLine(active.view);
} RegisterCommand(Command_EncloseLine, "ctrl-l"); } RegisterCommand(Command_EncloseLine, "ctrl-l");
void Command_SelectAll(CommandContext *ctx) { void Command_SelectAll() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
SelectEntireBuffer(active.view); SelectEntireBuffer(active.view);
active.view->update_scroll = false; active.view->update_scroll = false;
} RegisterCommand(Command_SelectAll, "ctrl-a"); } RegisterCommand(Command_SelectAll, "ctrl-a");
void Command_Redo(CommandContext *ctx) { void Command_Redo() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
RedoEdit(active.buffer, &active.view->carets); RedoEdit(active.buffer, &active.view->carets);
} RegisterCommand(Command_Redo, "ctrl-shift-z"); } RegisterCommand(Command_Redo, "ctrl-shift-z");
void Command_Undo(CommandContext *ctx) { void Command_Undo() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
UndoEdit(active.buffer, &active.view->carets); UndoEdit(active.buffer, &active.view->carets);
} RegisterCommand(Command_Undo, "ctrl-z"); } RegisterCommand(Command_Undo, "ctrl-z");
void Command_MakeFontLarger(CommandContext *ctx) { void Command_MakeFontLarger() {
StyleFontSize += 1; StyleFontSize += 1;
ReloadFont(StyleFont, (U32)StyleFontSize); ReloadFont(StyleFont, (U32)StyleFontSize);
} RegisterCommand(Command_MakeFontLarger, "ctrl-equals"); } RegisterCommand(Command_MakeFontLarger, "ctrl-equals");
void Command_MakeFontSmaller(CommandContext *ctx) { void Command_MakeFontSmaller() {
if (StyleFontSize > 4) { if (StyleFontSize > 4) {
StyleFontSize -= 1; StyleFontSize -= 1;
ReloadFont(StyleFont, (U32)StyleFontSize); ReloadFont(StyleFont, (U32)StyleFontSize);
} }
} RegisterCommand(Command_MakeFontSmaller, "ctrl-minus"); } RegisterCommand(Command_MakeFontSmaller, "ctrl-minus");
void Command_Search(CommandContext *ctx) { void Command_Search() {
Window *window = GetWindow(SearchBarWindowID); Window *window = GetWindow(SearchBarWindowID);
window->visible = !window->visible; window->visible = !window->visible;
} RegisterCommand(Command_Search, "ctrl-f"); } RegisterCommand(Command_Search, "ctrl-f");
void EvalCommand(CommandContext *ctx, String command) { void EvalCommand(String command) {
For (CommandFunctions) { For (CommandFunctions) {
if (it.name == command) { if (it.name == command) {
it.function(ctx); it.function();
break; break;
} }
} }
} }
void EvalCommand(CommandContext *ctx, String16 command) { void EvalCommand(String16 command) {
Scratch scratch; Scratch scratch;
EvalCommand(ctx, ToString(scratch, command)); EvalCommand(ToString(scratch, command));
} }
void FuzzySearchOpen(CommandContext *ctx, BSet active) { void FuzzySearchOpen(BSet active) {
Range range = active.view->carets[0].range; Range range = active.view->carets[0].range;
String16 string = FetchLoadWord(active); String16 string = FetchLoadWord(active);
if (GetSize(range) == 0) { if (GetSize(range) == 0) {
@@ -1313,28 +1313,28 @@ void FuzzySearchOpen(CommandContext *ctx, BSet active) {
if (active.window->eval_command) { if (active.window->eval_command) {
BSet main = GetBSet(LastActiveLayoutWindowID); BSet main = GetBSet(LastActiveLayoutWindowID);
ActiveWindowID = main.window->id; ActiveWindowID = main.window->id;
EvalCommand(ctx, string); EvalCommand(string);
} else { } else {
Open(string); Open(string);
} }
} }
void Command_Open(CommandContext *ctx) { void Command_Open() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
if (active.view->fuzzy_search) { if (active.view->fuzzy_search) {
FuzzySearchOpen(ctx, active); FuzzySearchOpen(active);
} else { } else {
BSet active = GetBSet(LastActiveLayoutWindowID); BSet active = GetBSet(LastActiveLayoutWindowID);
Open(FetchLoadWord(active)); Open(FetchLoadWord(active));
} }
} RegisterCommand(Command_Open, "ctrl-q"); } RegisterCommand(Command_Open, "ctrl-q");
void Command_KillSelectedLines(CommandContext *ctx) { void Command_KillSelectedLines() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
KillSelectedLines(active.view); KillSelectedLines(active.view);
} RegisterCommand(Command_KillSelectedLines, "ctrl-shift-k"); } RegisterCommand(Command_KillSelectedLines, "ctrl-shift-k");
void Command_IndentSelectedLines(CommandContext *ctx) { void Command_IndentSelectedLines() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
Event event = *OnCommandEvent; Event event = *OnCommandEvent;
bool left = false; bool left = false;
@@ -1344,226 +1344,226 @@ void Command_IndentSelectedLines(CommandContext *ctx) {
IndentSelectedLines(active.view, left); IndentSelectedLines(active.view, left);
} RegisterCommand(Command_IndentSelectedLines, "ctrl-leftbracket | ctrl-rightbracket | tab | shift-tab"); } RegisterCommand(Command_IndentSelectedLines, "ctrl-leftbracket | ctrl-rightbracket | tab | shift-tab");
void Command_DuplicateLineDown(CommandContext *ctx) { void Command_DuplicateLineDown() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
DuplicateLine(active.view, DIR_DOWN); DuplicateLine(active.view, DIR_DOWN);
} RegisterCommand(Command_DuplicateLineDown, "ctrl-alt-down"); } RegisterCommand(Command_DuplicateLineDown, "ctrl-alt-down");
void Command_CreateCursorDown(CommandContext *ctx) { void Command_CreateCursorDown() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
CreateCursorVertical(active.view, DIR_DOWN); CreateCursorVertical(active.view, DIR_DOWN);
} RegisterCommand(Command_CreateCursorDown, "alt-shift-down"); } RegisterCommand(Command_CreateCursorDown, "alt-shift-down");
void Command_SelectDownToEmptyLine(CommandContext *ctx) { void Command_SelectDownToEmptyLine() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCarets(active.view, DIR_DOWN, CTRL_PRESSED, SHIFT_PRESS); MoveCarets(active.view, DIR_DOWN, CTRL_PRESSED, SHIFT_PRESS);
} RegisterCommand(Command_SelectDownToEmptyLine, "ctrl-shift-down"); } RegisterCommand(Command_SelectDownToEmptyLine, "ctrl-shift-down");
void Command_MoveLineDown(CommandContext *ctx) { void Command_MoveLineDown() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCaretsLine(active.view, DIR_DOWN); MoveCaretsLine(active.view, DIR_DOWN);
} RegisterCommand(Command_MoveLineDown, "alt-down"); } RegisterCommand(Command_MoveLineDown, "alt-down");
void Command_MoveDownToEmptyLine(CommandContext *ctx) { void Command_MoveDownToEmptyLine() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCarets(active.view, DIR_DOWN, CTRL_PRESSED); MoveCarets(active.view, DIR_DOWN, CTRL_PRESSED);
} RegisterCommand(Command_MoveDownToEmptyLine, "ctrl-down"); } RegisterCommand(Command_MoveDownToEmptyLine, "ctrl-down");
void Command_SelectDown(CommandContext *ctx) { void Command_SelectDown() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCarets(active.view, DIR_DOWN, false, SHIFT_PRESS); MoveCarets(active.view, DIR_DOWN, false, SHIFT_PRESS);
} RegisterCommand(Command_SelectDown, "shift-down"); } RegisterCommand(Command_SelectDown, "shift-down");
void Command_MoveDown(CommandContext *ctx) { void Command_MoveDown() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCarets(active.view, DIR_DOWN); MoveCarets(active.view, DIR_DOWN);
} RegisterCommand(Command_MoveDown, "down"); } RegisterCommand(Command_MoveDown, "down");
void Command_DuplicateLineUp(CommandContext *ctx) { void Command_DuplicateLineUp() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
DuplicateLine(active.view, DIR_UP); DuplicateLine(active.view, DIR_UP);
} RegisterCommand(Command_DuplicateLineUp, "ctrl-alt-up"); } RegisterCommand(Command_DuplicateLineUp, "ctrl-alt-up");
void Command_CreateCursorUp(CommandContext *ctx) { void Command_CreateCursorUp() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
CreateCursorVertical(active.view, DIR_UP); CreateCursorVertical(active.view, DIR_UP);
} RegisterCommand(Command_CreateCursorUp, "alt-shift-up"); } RegisterCommand(Command_CreateCursorUp, "alt-shift-up");
void Command_SelectUpToEmptyLine(CommandContext *ctx) { void Command_SelectUpToEmptyLine() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCarets(active.view, DIR_UP, CTRL_PRESSED, SHIFT_PRESS); MoveCarets(active.view, DIR_UP, CTRL_PRESSED, SHIFT_PRESS);
} RegisterCommand(Command_SelectUpToEmptyLine, "ctrl-shift-up"); } RegisterCommand(Command_SelectUpToEmptyLine, "ctrl-shift-up");
void Command_MoveLineUp(CommandContext *ctx) { void Command_MoveLineUp() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCaretsLine(active.view, DIR_UP); MoveCaretsLine(active.view, DIR_UP);
} RegisterCommand(Command_MoveLineUp, "alt-up"); } RegisterCommand(Command_MoveLineUp, "alt-up");
void Command_MoveUpToEmptyLine(CommandContext *ctx) { void Command_MoveUpToEmptyLine() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCarets(active.view, DIR_UP, CTRL_PRESSED); MoveCarets(active.view, DIR_UP, CTRL_PRESSED);
} RegisterCommand(Command_MoveUpToEmptyLine, "ctrl-up"); } RegisterCommand(Command_MoveUpToEmptyLine, "ctrl-up");
void Command_SelectUp(CommandContext *ctx) { void Command_SelectUp() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCarets(active.view, DIR_UP, false, SHIFT_PRESS); MoveCarets(active.view, DIR_UP, false, SHIFT_PRESS);
} RegisterCommand(Command_SelectUp, "shift-up"); } RegisterCommand(Command_SelectUp, "shift-up");
void Command_MoveUp(CommandContext *ctx) { void Command_MoveUp() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCarets(active.view, DIR_UP); MoveCarets(active.view, DIR_UP);
} RegisterCommand(Command_MoveUp, "up"); } RegisterCommand(Command_MoveUp, "up");
void Command_BoundarySelectLeft(CommandContext *ctx) { void Command_BoundarySelectLeft() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCarets(active.view, DIR_LEFT, CTRL_PRESSED, SHIFT_PRESS); MoveCarets(active.view, DIR_LEFT, CTRL_PRESSED, SHIFT_PRESS);
} RegisterCommand(Command_BoundarySelectLeft, "ctrl-shift-left"); } RegisterCommand(Command_BoundarySelectLeft, "ctrl-shift-left");
void Command_BoundaryMoveLeft(CommandContext *ctx) { void Command_BoundaryMoveLeft() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCarets(active.view, DIR_LEFT, CTRL_PRESSED); MoveCarets(active.view, DIR_LEFT, CTRL_PRESSED);
} RegisterCommand(Command_BoundaryMoveLeft, "ctrl-left"); } RegisterCommand(Command_BoundaryMoveLeft, "ctrl-left");
void Command_SelectLeft(CommandContext *ctx) { void Command_SelectLeft() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCarets(active.view, DIR_LEFT, false, SHIFT_PRESS); MoveCarets(active.view, DIR_LEFT, false, SHIFT_PRESS);
} RegisterCommand(Command_SelectLeft, "shift-left"); } RegisterCommand(Command_SelectLeft, "shift-left");
void Command_FocusLeftWindow(CommandContext *ctx) { void Command_FocusLeftWindow() {
ActiveWindowID = SwitchWindow(DIR_LEFT)->id; ActiveWindowID = SwitchWindow(DIR_LEFT)->id;
} RegisterCommand(Command_FocusLeftWindow, "alt-left"); } RegisterCommand(Command_FocusLeftWindow, "alt-left");
void Command_MoveLeft(CommandContext *ctx) { void Command_MoveLeft() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCarets(active.view, DIR_LEFT); MoveCarets(active.view, DIR_LEFT);
} RegisterCommand(Command_MoveLeft, "left"); } RegisterCommand(Command_MoveLeft, "left");
void Command_BoundarySelectRight(CommandContext *ctx) { void Command_BoundarySelectRight() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCarets(active.view, DIR_RIGHT, CTRL_PRESSED, SHIFT_PRESS); MoveCarets(active.view, DIR_RIGHT, CTRL_PRESSED, SHIFT_PRESS);
} RegisterCommand(Command_BoundarySelectRight, "ctrl-shift-right"); } RegisterCommand(Command_BoundarySelectRight, "ctrl-shift-right");
void Command_BoundaryMoveRight(CommandContext *ctx) { void Command_BoundaryMoveRight() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCarets(active.view, DIR_RIGHT, CTRL_PRESSED); MoveCarets(active.view, DIR_RIGHT, CTRL_PRESSED);
} RegisterCommand(Command_BoundaryMoveRight, "ctrl-right"); } RegisterCommand(Command_BoundaryMoveRight, "ctrl-right");
void Command_SelectRight(CommandContext *ctx) { void Command_SelectRight() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCarets(active.view, DIR_RIGHT, false, SHIFT_PRESS); MoveCarets(active.view, DIR_RIGHT, false, SHIFT_PRESS);
} RegisterCommand(Command_SelectRight, "shift-right"); } RegisterCommand(Command_SelectRight, "shift-right");
void Command_FocusRightWindow(CommandContext *ctx) { void Command_FocusRightWindow() {
ActiveWindowID = SwitchWindow(DIR_RIGHT)->id; ActiveWindowID = SwitchWindow(DIR_RIGHT)->id;
} RegisterCommand(Command_FocusRightWindow, "alt-right"); } RegisterCommand(Command_FocusRightWindow, "alt-right");
void Command_MoveRight(CommandContext *ctx) { void Command_MoveRight() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCarets(active.view, DIR_RIGHT); MoveCarets(active.view, DIR_RIGHT);
} RegisterCommand(Command_MoveRight, "right"); } RegisterCommand(Command_MoveRight, "right");
void Command_MoveUpAPage(CommandContext *ctx) { void Command_MoveUpAPage() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCursorByPageSize(active.window, DIR_UP, SHIFT_PRESS); MoveCursorByPageSize(active.window, DIR_UP, SHIFT_PRESS);
} RegisterCommand(Command_MoveUpAPage, "pageup"); } RegisterCommand(Command_MoveUpAPage, "pageup");
void Command_SelectDownPage(CommandContext *ctx) { void Command_SelectDownPage() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCursorByPageSize(active.window, DIR_DOWN, SHIFT_PRESS); MoveCursorByPageSize(active.window, DIR_DOWN, SHIFT_PRESS);
} RegisterCommand(Command_SelectDownPage, "shift-pagedown"); } RegisterCommand(Command_SelectDownPage, "shift-pagedown");
void Command_MoveToEnd(CommandContext *ctx) { void Command_MoveToEnd() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
SelectRange(active.view, MakeRange(active.buffer->len)); SelectRange(active.view, MakeRange(active.buffer->len));
} RegisterCommand(Command_MoveToEnd, "pagedown"); } RegisterCommand(Command_MoveToEnd, "pagedown");
void Command_MoveDownPage(CommandContext *ctx) { void Command_MoveDownPage() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
SelectRange(active.view, MakeRange(active.buffer->len)); SelectRange(active.view, MakeRange(active.buffer->len));
} RegisterCommand(Command_MoveDownPage, "ctrl-pagedown"); } RegisterCommand(Command_MoveDownPage, "ctrl-pagedown");
void Command_SelectUpPage(CommandContext *ctx) { void Command_SelectUpPage() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCursorByPageSize(active.window, DIR_UP, SHIFT_PRESS); MoveCursorByPageSize(active.window, DIR_UP, SHIFT_PRESS);
} RegisterCommand(Command_SelectUpPage, "shift-pageup"); } RegisterCommand(Command_SelectUpPage, "shift-pageup");
void Command_MoveToStart(CommandContext *ctx) { void Command_MoveToStart() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
SelectRange(active.view, MakeRange(0)); SelectRange(active.view, MakeRange(0));
} RegisterCommand(Command_MoveToStart, "ctrl-pageup"); } RegisterCommand(Command_MoveToStart, "ctrl-pageup");
void Command_MoveUpPage(CommandContext *ctx) { void Command_MoveUpPage() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCursorByPageSize(active.window, DIR_UP); MoveCursorByPageSize(active.window, DIR_UP);
} RegisterCommand(Command_MoveUpPage, "pageup"); } RegisterCommand(Command_MoveUpPage, "pageup");
void Command_SelectToLineStart(CommandContext *ctx) { void Command_SelectToLineStart() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCursorToSide(active.view, DIR_LEFT, SHIFT_PRESS); MoveCursorToSide(active.view, DIR_LEFT, SHIFT_PRESS);
} RegisterCommand(Command_SelectToLineStart, "shift-home"); } RegisterCommand(Command_SelectToLineStart, "shift-home");
void Command_MoveToLineStart(CommandContext *ctx) { void Command_MoveToLineStart() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCursorToSide(active.view, DIR_LEFT); MoveCursorToSide(active.view, DIR_LEFT);
} RegisterCommand(Command_MoveToLineStart, "home"); } RegisterCommand(Command_MoveToLineStart, "home");
void Command_MoveToLineEnd(CommandContext *ctx) { void Command_MoveToLineEnd() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCursorToSide(active.view, DIR_RIGHT); MoveCursorToSide(active.view, DIR_RIGHT);
} RegisterCommand(Command_MoveToLineEnd, "end"); } RegisterCommand(Command_MoveToLineEnd, "end");
void Command_SelectToLineEnd(CommandContext *ctx) { void Command_SelectToLineEnd() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCursorToSide(active.view, DIR_RIGHT, SHIFT_PRESS); MoveCursorToSide(active.view, DIR_RIGHT, SHIFT_PRESS);
} RegisterCommand(Command_SelectToLineEnd, "shift-end"); } RegisterCommand(Command_SelectToLineEnd, "shift-end");
void Command_Delete(CommandContext *ctx) { void Command_Delete() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
Delete(active.view, DIR_LEFT); Delete(active.view, DIR_LEFT);
} RegisterCommand(Command_Delete, "backspace"); } RegisterCommand(Command_Delete, "backspace");
void Command_DeleteBoundary(CommandContext *ctx) { void Command_DeleteBoundary() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
Delete(active.view, DIR_LEFT, SHIFT_PRESS); Delete(active.view, DIR_LEFT, SHIFT_PRESS);
} RegisterCommand(Command_DeleteBoundary, "ctrl-backspace"); } RegisterCommand(Command_DeleteBoundary, "ctrl-backspace");
void Command_DeleteForward(CommandContext *ctx) { void Command_DeleteForward() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
Delete(active.view, DIR_RIGHT); Delete(active.view, DIR_RIGHT);
} RegisterCommand(Command_DeleteForward, "delete"); } RegisterCommand(Command_DeleteForward, "delete");
void Command_DeleteForwardBoundary(CommandContext *ctx) { void Command_DeleteForwardBoundary() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
Delete(active.view, DIR_RIGHT, SHIFT_PRESS); Delete(active.view, DIR_RIGHT, SHIFT_PRESS);
} RegisterCommand(Command_DeleteForwardBoundary, "ctrl-delete"); } RegisterCommand(Command_DeleteForwardBoundary, "ctrl-delete");
void Command_InsertNewLineUp(CommandContext *ctx) { void Command_InsertNewLineUp() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCursorToSide(active.view, DIR_LEFT); MoveCursorToSide(active.view, DIR_LEFT);
IdentedNewLine(active.view); IdentedNewLine(active.view);
MoveCarets(active.view, DIR_UP); MoveCarets(active.view, DIR_UP);
} RegisterCommand(Command_InsertNewLineUp, "ctrl-shift-enter"); } RegisterCommand(Command_InsertNewLineUp, "ctrl-shift-enter");
void Command_InsertNewLineDown(CommandContext *ctx) { void Command_InsertNewLineDown() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
MoveCursorToSide(active.view, DIR_RIGHT); MoveCursorToSide(active.view, DIR_RIGHT);
IdentedNewLine(active.view); IdentedNewLine(active.view);
} RegisterCommand(Command_InsertNewLineDown, "ctrl-enter"); } RegisterCommand(Command_InsertNewLineDown, "ctrl-enter");
void Command_SelectFuzzySearchEntry(CommandContext *ctx) { void Command_SelectFuzzySearchEntry() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
if (active.view->fuzzy_search) { if (active.view->fuzzy_search) {
FuzzySearchOpen(ctx, active); FuzzySearchOpen(active);
ctx->out_skip_rem_cmds = true; SkipRemainingCommands = true;
} }
} RegisterCommand(Command_SelectFuzzySearchEntry, "enter"); } RegisterCommand(Command_SelectFuzzySearchEntry, "enter");
void Command_NewLine(CommandContext *ctx) { void Command_NewLine() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
IdentedNewLine(active.view); IdentedNewLine(active.view);
} RegisterCommand(Command_NewLine, "enter"); } RegisterCommand(Command_NewLine, "enter");
void Command_CreateCaretOnNextFind(CommandContext *ctx) { void Command_CreateCaretOnNextFind() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
String16 string = GetString(active.buffer, active.view->carets[0].range); String16 string = GetString(active.buffer, active.view->carets[0].range);
Caret caret = FindNext(active.buffer, string, active.view->carets[0]); Caret caret = FindNext(active.buffer, string, active.view->carets[0]);
@@ -1571,17 +1571,17 @@ void Command_CreateCaretOnNextFind(CommandContext *ctx) {
MergeCarets(active.buffer, &active.view->carets); MergeCarets(active.buffer, &active.view->carets);
} RegisterCommand(Command_CreateCaretOnNextFind, "ctrl-d"); } RegisterCommand(Command_CreateCaretOnNextFind, "ctrl-d");
void Command_FocusWindow1(CommandContext *ctx) { void Command_FocusWindow1() {
ActiveWindowID = GetOverlappingWindow({0,0}, GetWindow(ActiveWindowID))->id; ActiveWindowID = GetOverlappingWindow({0,0}, GetWindow(ActiveWindowID))->id;
} RegisterCommand(Command_FocusWindow1, "ctrl-1"); } RegisterCommand(Command_FocusWindow1, "ctrl-1");
void Command_FocusWindow2(CommandContext *ctx) { void Command_FocusWindow2() {
Window *first = GetOverlappingWindow({0,0}, GetWindow(ActiveWindowID)); Window *first = GetOverlappingWindow({0,0}, GetWindow(ActiveWindowID));
Vec2I p = GetSideOfWindow(first, DIR_RIGHT); Vec2I p = GetSideOfWindow(first, DIR_RIGHT);
ActiveWindowID = GetOverlappingWindow(p, GetWindow(ActiveWindowID))->id; ActiveWindowID = GetOverlappingWindow(p, GetWindow(ActiveWindowID))->id;
} RegisterCommand(Command_FocusWindow2, "ctrl-2"); } RegisterCommand(Command_FocusWindow2, "ctrl-2");
void Command_FocusWindow3(CommandContext *ctx) { void Command_FocusWindow3() {
Window *first = GetOverlappingWindow({0,0}); Window *first = GetOverlappingWindow({0,0});
if (first) { if (first) {
Window *second = GetOverlappingWindow(GetSideOfWindow(first, DIR_RIGHT)); Window *second = GetOverlappingWindow(GetSideOfWindow(first, DIR_RIGHT));
@@ -1594,7 +1594,7 @@ void Command_FocusWindow3(CommandContext *ctx) {
} }
} RegisterCommand(Command_FocusWindow3, "ctrl-3"); } RegisterCommand(Command_FocusWindow3, "ctrl-3");
void Command_ClearCarets(CommandContext *ctx) { void Command_ClearCarets() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
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]));
@@ -1608,3 +1608,44 @@ void Command_ClearCarets(CommandContext *ctx) {
} }
} }
} RegisterCommand(Command_ClearCarets, "escape"); } RegisterCommand(Command_ClearCarets, "escape");
void Hook_OnDropFile(String *text) {
BSet active = GetBSet(ActiveWindowID);
WindowOpenBufferView(active.window, *text);
} RegisterHook(&OnDropFileHooks, Hook_OnDropFile);
void Hook_OnTextInput(String *text) {
BSet active = GetBSet(ActiveWindowID);
Scratch scratch;
String16 string16 = ToString16(scratch, *text);
Replace(active.view, string16);
} RegisterHook(&OnTextInputHooks, Hook_OnTextInput);
void Hook_PostCommandFuzzySearchUpdate(void *param) {
BSet active = GetBSet(ActiveWindowID);
if (active.view->fuzzy_search) {
if (!ProcessIsActive(active.view->id)) {
Scratch scratch;
String16 last_line_string = GetLineStringWithoutNL(active.buffer, active.buffer->line_starts.len - 1);
if (active.view->prev_search_line != last_line_string) {
active.view->prev_search_line = last_line_string;
Array<FuzzyPair> ratings = FuzzySearchLines(scratch, active.buffer, 0, active.buffer->line_starts.len - 1, last_line_string);
Buffer *temp_buffer = CreateTempBuffer(scratch, active.buffer->cap);
For(IterateInReverse(&ratings)) {
String16 s = GetLineStringWithoutNL(active.buffer, it.index);
if (s.len == 0) continue;
RawReplaceText(temp_buffer, GetBufferEndAsRange(temp_buffer), s);
RawReplaceText(temp_buffer, GetBufferEndAsRange(temp_buffer), u"\n");
}
RawReplaceText(temp_buffer, GetBufferEndAsRange(temp_buffer), last_line_string);
Caret caret = active.view->carets[0];
SaveCaretHistoryBeforeBeginEdit(active.buffer, active.view->carets);
SelectEntireBuffer(active.view);
Replace(active.view, GetString(temp_buffer));
active.view->carets[0] = caret;
}
}
}
} RegisterHook(&PostCommandHooks, Hook_PostCommandFuzzySearchUpdate);

View File

@@ -268,62 +268,52 @@ void OnCommand(Event event) {
BSet main = GetBSet(LastActiveLayoutWindowID); BSet main = GetBSet(LastActiveLayoutWindowID);
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
// @todo: somehow detect in post command that buffer changed but random buffer can get changed??? Not sure
// maybe we
Int buffer_change_id = active.buffer->change_id; Int buffer_change_id = active.buffer->change_id;
CommandContext ctx = {}; String event_text = event.text;
SkipRemainingCommands = false;
For (CommandFunctions) { For (CommandFunctions) {
if (it.trigger && MatchEvent(it.trigger, &event)) { if (it.trigger && MatchEvent(it.trigger, &event)) {
it.function(&ctx); it.function();
if (SkipRemainingCommands) {
break;
}
}
}
if (event.kind == EVENT_DROP_FILE) {
SkipRemainingCommands = false;
For (OnDropFileHooks) {
it.function(&event_text);
if (SkipRemainingCommands) {
break;
}
}
}
if (event.kind == EVENT_TEXT_INPUT) {
SkipRemainingCommands = false;
For (OnTextInputHooks) {
it.function(&event_text);
if (SkipRemainingCommands) {
break;
}
}
}
MergeCarets(active.buffer, &active.view->carets); MergeCarets(active.buffer, &active.view->carets);
IF_DEBUG(AssertRanges(active.view->carets)); IF_DEBUG(AssertRanges(active.view->carets));
if (ctx.out_skip_rem_cmds) { MergeCarets(main.buffer, &main.view->carets);
IF_DEBUG(AssertRanges(main.view->carets));
SkipRemainingCommands = false;
For (PostCommandHooks) {
it.function(NULL);
if (SkipRemainingCommands) {
return; return;
} }
} }
}
// @todo: do we need the context for commands, maybe skip cmds should be global?
// @todo: hook drop file
if (event.kind == EVENT_DROP_FILE) {
WindowOpenBufferView(active.window, event.text);
}
// @todo: hook on textinput
if (event.kind == EVENT_TEXT_INPUT) {
Scratch scratch;
String string = event.text;
String16 string16 = ToString16(scratch, string);
Replace(active.view, string16);
}
// @todo: hook PostCommand?
// @todo: Detect if edited
if (active.view->fuzzy_search) {
if (!ProcessIsActive(active.view->id)) {
Scratch scratch;
String16 last_line_string = GetLineStringWithoutNL(active.buffer, active.buffer->line_starts.len - 1);
if (active.view->prev_search_line != last_line_string) {
active.view->prev_search_line = last_line_string;
Array<FuzzyPair> ratings = FuzzySearchLines(scratch, active.buffer, 0, active.buffer->line_starts.len - 1, last_line_string);
Buffer *temp_buffer = CreateTempBuffer(scratch, active.buffer->cap);
For(IterateInReverse(&ratings)) {
String16 s = GetLineStringWithoutNL(active.buffer, it.index);
if (s.len == 0) continue;
RawReplaceText(temp_buffer, GetBufferEndAsRange(temp_buffer), s);
RawReplaceText(temp_buffer, GetBufferEndAsRange(temp_buffer), u"\n");
}
RawReplaceText(temp_buffer, GetBufferEndAsRange(temp_buffer), last_line_string);
Caret caret = active.view->carets[0];
SaveCaretHistoryBeforeBeginEdit(active.buffer, active.view->carets);
SelectEntireBuffer(active.view);
Replace(active.view, GetString(temp_buffer));
active.view->carets[0] = caret;
}
}
}
// :OnCommandEnding
MergeCarets(active.buffer, &active.view->carets);
IF_DEBUG(AssertRanges(active.view->carets));
} }

View File

@@ -87,17 +87,17 @@ void ClipboardPaste(View *view) {
EndEdit(buffer, &edits, &view->carets, KILL_SELECTION); EndEdit(buffer, &edits, &view->carets, KILL_SELECTION);
} }
void Command_Paste(CommandContext *ctx) { void Command_Paste() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
ClipboardPaste(active.view); ClipboardPaste(active.view);
} RegisterCommand(Command_Paste, "ctrl-v"); } RegisterCommand(Command_Paste, "ctrl-v");
void Command_Copy(CommandContext *ctx) { void Command_Copy() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
ClipboardCopy(active.view); ClipboardCopy(active.view);
} RegisterCommand(Command_Copy, "ctrl-c"); } RegisterCommand(Command_Copy, "ctrl-c");
void Command_Cut(CommandContext *ctx) { void Command_Cut() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
SaveCaretHistoryBeforeBeginEdit(active.buffer, active.view->carets); SaveCaretHistoryBeforeBeginEdit(active.buffer, active.view->carets);
ClipboardCopy(active.view); ClipboardCopy(active.view);

View File

@@ -183,21 +183,23 @@ void ReloadStyle() {
StyleUndoMergeTimeout = GetStyleFloat("UndoMergeTimeout", StyleUndoMergeTimeout); StyleUndoMergeTimeout = GetStyleFloat("UndoMergeTimeout", StyleUndoMergeTimeout);
} }
struct CommandContext { typedef void Function();
bool out_skip_rem_cmds; typedef void PFunction(void *param);
};
typedef void Function(void *param);
typedef void CommandFunction(CommandContext *ctx);
typedef int LuaFunction(lua_State *state); typedef int LuaFunction(lua_State *state);
struct FunctionData { String name; Function *function; }; struct FunctionData { String name; Function *function; };
struct LuaFunctionData { String name; LuaFunction *function; }; struct LuaFunctionData { String name; LuaFunction *function; };
struct CommandData { String name; String binding; CommandFunction *function; struct Trigger *trigger; }; struct CommandData { String name; String binding; Function *function; struct Trigger *trigger; };
struct PFunctionData { String name; PFunction *function; };
bool SkipRemainingCommands;
Array<CommandData> CommandFunctions; Array<CommandData> CommandFunctions;
Array<LuaFunctionData> LuaFunctions; Array<LuaFunctionData> LuaFunctions;
Array<FunctionData> TestFunctions; Array<FunctionData> TestFunctions;
Array<PFunctionData> PostCommandHooks;
Array<PFunctionData> OnTextInputHooks;
Array<PFunctionData> OnDropFileHooks;
struct Register_Function { struct Register_Function {
Register_Function(Array<FunctionData> *functions, String name, Function *f) { Register_Function(Array<FunctionData> *functions, String name, Function *f) {
int64_t pos = 0; int64_t pos = 0;
@@ -208,11 +210,16 @@ struct Register_Function {
} }
}; };
#define RegisterFunction(functions, name) Register_Function RF__##name(functions, #name, name) #define RegisterFunction(functions, name) Register_Function RF__##name(functions, #name, name)
struct Register_Lua { Register_Lua(LuaFunction *function, String name) { if (StartsWith(name, "Lua_")) name = Skip(name, 4); Add(&LuaFunctions, {name, function}); } }; struct Register_Lua { Register_Lua(LuaFunction *function, String name) { if (StartsWith(name, "Lua_")) name = Skip(name, 4); Add(&LuaFunctions, {name, function}); } };
struct Register_Command { Register_Command(CommandFunction *function, String name, String binding) { if (StartsWith(name, "Command_")) name = Skip(name, 8); Add(&CommandFunctions, {name, binding, function}); } };
#define RegisterLua(NAME) Register_Lua RL_##NAME(NAME, #NAME) #define RegisterLua(NAME) Register_Lua RL_##NAME(NAME, #NAME)
struct Register_Command { Register_Command(Function *function, String name, String binding) { if (StartsWith(name, "Command_")) name = Skip(name, 8); Add(&CommandFunctions, {name, binding, function}); } };
#define RegisterCommand(name, binding) Register_Command RC__##name(name, #name, binding) #define RegisterCommand(name, binding) Register_Command RC__##name(name, #name, binding)
struct Register_Hook { Register_Hook(Array<PFunctionData> *functions, PFunction *function, String name) { if (StartsWith(name, "Hook_")) name = Skip(name, 5); Add(functions, {name, function}); } };
#define RegisterHook(functions, name) Register_Hook RC__##name(functions, (PFunction *)name, #name)
const int DIR_RIGHT = 0; const int DIR_RIGHT = 0;
const int DIR_LEFT = 1; const int DIR_LEFT = 1;
const int DIR_DOWN = 2; const int DIR_DOWN = 2;

View File

@@ -181,7 +181,7 @@ bool MatchEvent(Trigger *trigger, Event *event) {
return false; return false;
} }
void TestParser(void *param) { void TestParser() {
Scratch scratch; Scratch scratch;
{ {
char *cmd = "ctrl-b"; char *cmd = "ctrl-b";

View File

@@ -255,7 +255,7 @@ int main(int argc, char **argv)
if (1) { if (1) {
RunArenaTest(); RunArenaTest();
For (TestFunctions) { For (TestFunctions) {
it.function(NULL); it.function();
} }
// ReportErrorf("Testing DONE\n"); // ReportErrorf("Testing DONE\n");