Better Rename
This commit is contained in:
@@ -709,7 +709,48 @@ void AddHook(Array<CommandData> *arr, String name, String binding, Function *fun
|
|||||||
Add(arr, n);
|
Add(arr, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @todo: rename to temp buffer? but there is already a thing like that...
|
void Coro_Rename(mco_coro *co) {
|
||||||
|
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||||
|
Buffer *buffer = main.buffer;
|
||||||
|
JumpTempBuffer(&main);
|
||||||
|
NextActiveWindowID = main.window->id;
|
||||||
|
RawAppendf(main.buffer, "Rename and click enter to submit: [%S]\n :Rename :Cancel", buffer->name);
|
||||||
|
|
||||||
|
main.view->carets[0] = FindNext(main.buffer, u"]", MakeCaret(0));
|
||||||
|
main.view->carets[0].range.max = main.view->carets[0].range.min;
|
||||||
|
AddHook(&main.view->hooks, "Rename", "enter", [](){BSet active = GetBSet(ActiveWindowID); active.view->hook_cmd = "Rename";});
|
||||||
|
AddHook(&main.view->hooks, "Cancel", "escape", [](){BSet active = GetBSet(ActiveWindowID); active.view->hook_cmd = "Cancel";});
|
||||||
|
String result = "Cancel";
|
||||||
|
for (;;) {
|
||||||
|
if (main.window->active_view != main.view->id || (main.window->id != LastActiveLayoutWindowID && main.window->id != ActiveWindowID) || main.window->close) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (main.view->hook_cmd != "") {
|
||||||
|
result = main.view->hook_cmd;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
CoYield(co);
|
||||||
|
}
|
||||||
|
Close(main.buffer->id);
|
||||||
|
|
||||||
|
if (result == "Rename") {
|
||||||
|
Caret a = FindNext(main.buffer, u"[", MakeCaret(-1));
|
||||||
|
Caret b = FindNext(main.buffer, u"]", MakeCaret(-1));
|
||||||
|
if (a.range.min == -1 || b.range.max == -1) {
|
||||||
|
ReportErrorf("Failed to extract the name for the Rename operation from the buffer");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String16 string16 = GetString(main.buffer, {a.range.max + 1, b.range.max});
|
||||||
|
String string = ToString(CoCurr->arena, string16);
|
||||||
|
buffer->name = Intern(&GlobalInternTable, string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void Command_Rename() {
|
||||||
|
CoAdd(Coro_Rename);
|
||||||
|
} RegisterCommand(Command_Rename, "");
|
||||||
|
|
||||||
String Coro_YesNoCancel(mco_coro *co, BSet main, String question) {
|
String Coro_YesNoCancel(mco_coro *co, BSet main, String question) {
|
||||||
JumpTempBuffer(&main);
|
JumpTempBuffer(&main);
|
||||||
NextActiveWindowID = main.window->id;
|
NextActiveWindowID = main.window->id;
|
||||||
|
|||||||
Reference in New Issue
Block a user