search bar
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
@echo off
|
||||
|
||||
cd /D "%~dp0" rem cd into script dir
|
||||
|
||||
if not exist build\build_tool.exe (
|
||||
mkdir build
|
||||
cd build
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
void LoadBigText(Buffer *buffer, int size = 5000000) {
|
||||
for (int i = 0; i < size; i += 1) {
|
||||
RawReplaceText(buffer, GetEndAsRange(buffer), u"Line number or something of the sort which is here or there or maybe somewhere else\n");
|
||||
}
|
||||
}
|
||||
|
||||
void LoadBigLine(Buffer *buffer, int size = 5000000) {
|
||||
for (int i = 0; i < size; i += 1) {
|
||||
RawReplaceText(buffer, GetEndAsRange(buffer), u"Line number or something of the sort which is here or there or maybe somewhere else | ");
|
||||
}
|
||||
}
|
||||
|
||||
void LoadBigTextAndBigLine(Buffer *buffer, int size = 2500000) {
|
||||
LoadBigLine(buffer, size);
|
||||
LoadBigText(buffer, size);
|
||||
}
|
||||
|
||||
void LoadTextA(Buffer *buffer) {
|
||||
Scratch scratch;
|
||||
for (int i = 0; i < 1000; i += 1) {
|
||||
String s = Format(scratch, "line1: %d line2: %d line3: %d line4: %d line5: %d line6: %d line1: %d line2: %d line3: %d line4: %d line5: %d line6: %d\r\n", i, i, i, i, i, i, i, i, i, i, i, i);
|
||||
String16 s16 = ToString16(scratch, s);
|
||||
RawReplaceText(buffer, GetEndAsRange(buffer), s16);
|
||||
}
|
||||
}
|
||||
|
||||
void LoadLine(Buffer *buffer) {
|
||||
Scratch scratch;
|
||||
String s = "Line number and so on óźćż";
|
||||
RawReplaceText(buffer, {}, ToString16(scratch, s));
|
||||
}
|
||||
|
||||
void LoadUnicode(Buffer *buffer) {
|
||||
String text = R"===(
|
||||
This page contains characters from each of the Unicode character blocks.
|
||||
|
||||
See also Unicode 3.2 test page.
|
||||
|
||||
commit 225d1ffc067da0723898ade68fb9492bbe308feb
|
||||
https://www.lua.org/manual/5.4/
|
||||
D:/dev/
|
||||
D:\dev\
|
||||
|
||||
)===";
|
||||
Scratch scratch;
|
||||
RawReplaceText(buffer, {}, ToString16(scratch, text));
|
||||
|
||||
|
||||
// RawReplaceText(buffer, GetEndAsRange(buffer), ToString16(scratch, text));
|
||||
}
|
||||
@@ -1,3 +1,17 @@
|
||||
String16 GetSearchString(Window *window) {
|
||||
if (!window->is_search_bar) {
|
||||
if (window->search_bar_window.id == 0) {
|
||||
return {};
|
||||
}
|
||||
window = GetWindow(window->search_bar_window);
|
||||
}
|
||||
|
||||
View *view = GetView(window->active_view);
|
||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||
String16 string = GetString(buffer);
|
||||
return string;
|
||||
}
|
||||
|
||||
void OnCommand(Event event) {
|
||||
ProfileFunction();
|
||||
WindowID start_command_active_window = ActiveWindow;
|
||||
@@ -278,6 +292,8 @@ void OnCommand(Event event) {
|
||||
WindowOpenBufferView(active.window, event.text);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (CtrlAltPress(SDLK_DOWN)) {
|
||||
Command_DuplicateLine(active.view, DIR_DOWN);
|
||||
} else if (AltShiftPress(SDLK_DOWN)) {
|
||||
@@ -418,13 +434,13 @@ void OnCommand(Event event) {
|
||||
if (ShiftPress(SDLK_F3)) {
|
||||
Scratch scratch;
|
||||
BSet main = GetActiveMainSet();
|
||||
String16 search_string = ToString16(scratch, main.window->search_string);
|
||||
String16 search_string = GetSearchString(main.window);
|
||||
Caret caret = FindPrev(main.buffer, search_string, main.view->carets[0]);
|
||||
Command_SelectRangeOneCursor(main.view, caret);
|
||||
} else if (Press(SDLK_F3)) {
|
||||
Scratch scratch;
|
||||
BSet main = GetActiveMainSet();
|
||||
String16 search_string = ToString16(scratch, main.window->search_string);
|
||||
String16 search_string = GetSearchString(main.window);
|
||||
Caret caret = FindNext(main.buffer, search_string, main.view->carets[0]);
|
||||
Command_SelectRangeOneCursor(main.view, caret);
|
||||
}
|
||||
@@ -447,7 +463,18 @@ void OnCommand(Event event) {
|
||||
}
|
||||
|
||||
if (CtrlPress(SDLK_F)) {
|
||||
// @todo: Search in current buffer
|
||||
if (!active.window->is_search_bar) {
|
||||
BSet main = GetActiveMainSet();
|
||||
BSet search = GetBSet(main.window->search_bar_window);
|
||||
String16 string = GetString(main.buffer, main.view->carets[0].range);
|
||||
if (string.len) {
|
||||
Command_SelectEntireBuffer(search.view);
|
||||
Command_Replace(search.view, string);
|
||||
}
|
||||
Command_SelectEntireBuffer(search.view);
|
||||
search.window->visible = 1;
|
||||
ActiveWindow = search.window->id;
|
||||
}
|
||||
}
|
||||
|
||||
if (CtrlPress(SDLK_S)) {
|
||||
@@ -485,7 +512,10 @@ void OnCommand(Event event) {
|
||||
}
|
||||
|
||||
if (Press(SDLK_ESCAPE)) {
|
||||
if (active.window->deactivate_on_escape) {
|
||||
if (active.window->is_search_bar) {
|
||||
ActiveWindow = GetActiveMainSet().window->id;
|
||||
active.window->visible = 0;
|
||||
} else if (active.window->deactivate_on_escape) {
|
||||
ActiveWindow = GetActiveMainSet().window->id;
|
||||
} else {
|
||||
active.view->carets.len = 1;
|
||||
@@ -493,6 +523,13 @@ void OnCommand(Event event) {
|
||||
}
|
||||
}
|
||||
|
||||
if (active.window->is_search_bar && buffer_change_id != active.buffer->change_id) {
|
||||
BSet main = GetActiveMainSet();
|
||||
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);
|
||||
IF_DEBUG(AssertRanges(active.view->carets));
|
||||
}
|
||||
|
||||
@@ -452,7 +452,7 @@ void ReloadLuaConfigs() {
|
||||
ReloadFont();
|
||||
For(Windows) {
|
||||
Window *window = it.o;
|
||||
if (!window->visible || window->absolute_position || window->is_title_bar) continue;
|
||||
if (!window->visible || window->absolute_position || window->is_title_bar || window->is_search_bar) continue;
|
||||
window->draw_scrollbar = StyleDrawScrollbar;
|
||||
window->draw_line_numbers = StyleDrawLineNumbers;
|
||||
}
|
||||
|
||||
@@ -12,9 +12,6 @@ ViewID NullViewID;
|
||||
WindowID DebugWindowID; // +debug
|
||||
BufferID DebugBufferID;
|
||||
|
||||
WindowID SearchWindowID;
|
||||
BufferID SearchBufferID;
|
||||
|
||||
WindowID ActiveWindow;
|
||||
|
||||
WindowID ScrollbarSelected = {-1};
|
||||
@@ -224,6 +221,7 @@ BSet GetActiveSet() {
|
||||
BSet GetActiveMainSet() {
|
||||
Window *window = GetWindow(ActiveWindow);
|
||||
if (window->is_title_bar) window = GetWindow(window->title_bar_window);
|
||||
if (window->is_search_bar) window = GetWindow(window->search_bar_window);
|
||||
return GetBSet(window);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ int FullScreenPositionX, FullScreenPositionY;
|
||||
#include "buffer.h"
|
||||
#include "text_editor.h"
|
||||
#include "buffer.cpp"
|
||||
#include "buffer_test_load.cpp"
|
||||
|
||||
#include "intern_table.cpp"
|
||||
#include "management.cpp"
|
||||
@@ -348,7 +347,9 @@ int main(int argc, char **argv)
|
||||
// :Tests
|
||||
// StyleWaitForEvents = false;
|
||||
// AddCo(Test);
|
||||
#if _WIN32
|
||||
AddCo(Windows_SetupVCVarsall);
|
||||
#endif
|
||||
|
||||
Serializer ser = {EventBuffer};
|
||||
while (AppIsRunning) {
|
||||
|
||||
@@ -23,7 +23,9 @@ struct Window {
|
||||
ViewID active_view;
|
||||
|
||||
WindowID title_bar_window;
|
||||
Int title_bar_last_buffer_change_id;
|
||||
Int title_bar_last_buffer_change_id; // @todo: bring back the changes to title bar?
|
||||
|
||||
WindowID search_bar_window;
|
||||
|
||||
Rect2I total_rect;
|
||||
Rect2I scrollbar_rect;
|
||||
@@ -33,8 +35,6 @@ struct Window {
|
||||
Array<GotoCrumb> goto_history;
|
||||
Array<GotoCrumb> goto_redo;
|
||||
|
||||
// @todo: consider making this String16
|
||||
String search_string;
|
||||
ViewID active_goto_list;
|
||||
|
||||
double mouse_scroller_offset;
|
||||
@@ -43,10 +43,11 @@ struct Window {
|
||||
struct {
|
||||
bool draw_scrollbar : 1;
|
||||
bool draw_line_numbers : 1;
|
||||
|
||||
bool visible : 1;
|
||||
|
||||
bool absolute_position : 1;
|
||||
bool is_title_bar : 1;
|
||||
bool is_search_bar : 1;
|
||||
bool is_column : 1;
|
||||
|
||||
bool deactivate_on_escape : 1;
|
||||
|
||||
@@ -28,10 +28,6 @@ void ReplaceTitleBarData(Window *window) {
|
||||
|
||||
if (window->id == ActiveWindow) return;
|
||||
|
||||
// @idea: maybe we could allow user to change window titles which would
|
||||
// make them special in some way.
|
||||
if (window->title_bar_window == SearchWindowID) return;
|
||||
|
||||
BSet main = GetMainSet(window);
|
||||
Scratch scratch;
|
||||
Caret caret = main.view->carets[0];
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
- search
|
||||
- maybe we could allow user to change window titles which would make them special in some way.
|
||||
- decouple buffer magic and directory listing, we want names for directory listers
|
||||
|
||||
- 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
|
||||
- shift click inside selection should move the selection
|
||||
|
||||
@@ -7,7 +7,7 @@ Array<VisualColumn> GetVisualColumns(Allocator allocator) {
|
||||
Array<VisualColumn> columns = {allocator};
|
||||
For(Windows) {
|
||||
Window *window = it.o;
|
||||
if (!window->visible || window->absolute_position || window->is_title_bar) continue;
|
||||
if (!window->visible || window->absolute_position || window->is_title_bar || window->is_search_bar) continue;
|
||||
|
||||
if (window->is_column) {
|
||||
Add(&columns, {window, {allocator}});
|
||||
@@ -25,7 +25,7 @@ Window *GetLayoutWindow(int n) {
|
||||
int i = 0;
|
||||
For(Windows) {
|
||||
Window *window = it.o;
|
||||
if (!window->is_column || !window->visible || window->absolute_position || window->is_title_bar) continue;
|
||||
if (!window->is_column || !window->visible || window->absolute_position || window->is_title_bar || window->is_search_bar) continue;
|
||||
|
||||
if (n == i) return window;
|
||||
i += 1;
|
||||
@@ -37,7 +37,7 @@ Window *GetNextLayoutWindow(Window *input_window) {
|
||||
bool found = false;
|
||||
For(Windows) {
|
||||
Window *window = it.o;
|
||||
if (!window->is_column || !window->visible || window->absolute_position || window->is_title_bar) continue;
|
||||
if (!window->is_column || !window->visible || window->absolute_position || window->is_title_bar || window->is_search_bar) continue;
|
||||
if (found) return window;
|
||||
if (window->id == input_window->id) found = true;
|
||||
}
|
||||
@@ -52,6 +52,29 @@ Array<Int> GetWindowZOrder(Allocator allocator) {
|
||||
return order;
|
||||
}
|
||||
|
||||
Window *CreateSearchBar(WindowID parent_window_id) {
|
||||
Window *window = CreateWindow();
|
||||
window->draw_scrollbar = false;
|
||||
window->deactivate_on_escape = true;
|
||||
window->is_search_bar = true;
|
||||
|
||||
static int BarCount;
|
||||
Allocator sys_allocator = GetSystemAllocator();
|
||||
String name = Format(sys_allocator, "%.*s/searchbar%d", FmtString(WorkingDir), ++BarCount);
|
||||
|
||||
Buffer *b = CreateBuffer(sys_allocator, name);
|
||||
View *v = CreateView(b->id);
|
||||
window->active_view = v->id;
|
||||
|
||||
Window *parent_window = GetWindow(parent_window_id);
|
||||
parent_window->search_bar_window = window->id;
|
||||
window->search_bar_window = parent_window->id;
|
||||
window->z = parent_window->z + 1;
|
||||
window->visible = false;
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
Window *CreateTitlebar(WindowID parent_window_id) {
|
||||
Window *window = CreateWindow();
|
||||
window->draw_scrollbar = false;
|
||||
@@ -60,7 +83,7 @@ Window *CreateTitlebar(WindowID parent_window_id) {
|
||||
|
||||
static int TitlebarCount;
|
||||
Allocator sys_allocator = GetSystemAllocator();
|
||||
String name = Format(sys_allocator, "+titlebar%d", ++TitlebarCount);
|
||||
String name = Format(sys_allocator, "%.*s/titlebar%d", FmtString(WorkingDir), ++TitlebarCount);
|
||||
|
||||
Buffer *b = CreateBuffer(sys_allocator, name);
|
||||
View *v = CreateView(b->id);
|
||||
@@ -89,6 +112,7 @@ void AddColumnWindow() {
|
||||
View *view = OpenBufferView("+scratch");
|
||||
window->active_view = view->id;
|
||||
CreateTitlebar(window->id);
|
||||
CreateSearchBar(window->id);
|
||||
}
|
||||
|
||||
Int GetWindowIndex(WindowID window_id) {
|
||||
@@ -106,6 +130,7 @@ void AddRowWindow() {
|
||||
View *view = OpenBufferView("+scratch");
|
||||
window->active_view = view->id;
|
||||
CreateTitlebar(window->id);
|
||||
CreateSearchBar(window->id);
|
||||
|
||||
Int i0 = GetWindowIndex(window->id);
|
||||
RemoveByIndex(&Windows, i0);
|
||||
@@ -122,6 +147,10 @@ void SetVisibility(WindowID window_id, bool v) {
|
||||
Window *title_bar = GetWindow(window->title_bar_window);
|
||||
title_bar->visible = v;
|
||||
}
|
||||
if (window->search_bar_window.id != 0) {
|
||||
Window *search_bar = GetWindow(window->search_bar_window);
|
||||
search_bar->visible = v;
|
||||
}
|
||||
}
|
||||
|
||||
bool ToggleVisibility(WindowID window_id) {
|
||||
@@ -131,6 +160,51 @@ bool ToggleVisibility(WindowID window_id) {
|
||||
return visible;
|
||||
}
|
||||
|
||||
void LoadBigText(Buffer *buffer, int size = 5000000) {
|
||||
for (int i = 0; i < size; i += 1) {
|
||||
RawReplaceText(buffer, GetEndAsRange(buffer), u"Line number or something of the sort which is here or there or maybe somewhere else\n");
|
||||
}
|
||||
}
|
||||
|
||||
void LoadBigLine(Buffer *buffer, int size = 5000000) {
|
||||
for (int i = 0; i < size; i += 1) {
|
||||
RawReplaceText(buffer, GetEndAsRange(buffer), u"Line number or something of the sort which is here or there or maybe somewhere else | ");
|
||||
}
|
||||
}
|
||||
|
||||
void LoadBigTextAndBigLine(Buffer *buffer, int size = 2500000) {
|
||||
LoadBigLine(buffer, size);
|
||||
LoadBigText(buffer, size);
|
||||
}
|
||||
|
||||
void LoadTextA(Buffer *buffer) {
|
||||
Scratch scratch;
|
||||
for (int i = 0; i < 1000; i += 1) {
|
||||
String s = Format(scratch, "line1: %d line2: %d line3: %d line4: %d line5: %d line6: %d line1: %d line2: %d line3: %d line4: %d line5: %d line6: %d\r\n", i, i, i, i, i, i, i, i, i, i, i, i);
|
||||
String16 s16 = ToString16(scratch, s);
|
||||
RawReplaceText(buffer, GetEndAsRange(buffer), s16);
|
||||
}
|
||||
}
|
||||
|
||||
void LoadLine(Buffer *buffer) {
|
||||
Scratch scratch;
|
||||
String s = "Line number and so on óźćż";
|
||||
RawReplaceText(buffer, {}, ToString16(scratch, s));
|
||||
}
|
||||
|
||||
void LoadTestBufferMessage(Buffer *buffer) {
|
||||
String text = R"===(
|
||||
|
||||
commit 225d1ffc067da0723898ade68fb9492bbe308feb
|
||||
https://www.lua.org/manual/5.4/
|
||||
|
||||
)===";
|
||||
Scratch scratch;
|
||||
RawReplaceText(buffer, {}, ToString16(scratch, text));
|
||||
|
||||
// RawReplaceText(buffer, GetEndAsRange(buffer), ToString16(scratch, text));
|
||||
}
|
||||
|
||||
void InitWindows() {
|
||||
Allocator sys_allocator = Perm;
|
||||
#if !ARRAY_DEBUG
|
||||
@@ -145,32 +219,10 @@ void InitWindows() {
|
||||
window->is_column = true;
|
||||
Buffer *buffer = CreateBuffer(sys_allocator, BuffCWD("+test_buffer"));
|
||||
View *view = CreateView(buffer->id);
|
||||
LoadUnicode(buffer);
|
||||
LoadTestBufferMessage(buffer);
|
||||
window->active_view = view->id;
|
||||
CreateTitlebar(window_id);
|
||||
}
|
||||
|
||||
{
|
||||
Window *window = CreateWindow();
|
||||
WindowID window_id = window->id;
|
||||
SearchWindowID = window->id;
|
||||
window->draw_line_numbers = false;
|
||||
window->absolute_position = true;
|
||||
window->draw_scrollbar = false;
|
||||
window->z = 2;
|
||||
|
||||
Buffer *buffer = CreateBuffer(sys_allocator, BuffCWD("+search"));
|
||||
SearchBufferID = buffer->id;
|
||||
|
||||
View *view = CreateView(buffer->id);
|
||||
window->active_view = view->id;
|
||||
|
||||
Window *titlebar = CreateTitlebar(window_id);
|
||||
BSet tb = GetBSet(titlebar);
|
||||
RawAppendf(tb.buffer, "Search:");
|
||||
titlebar->z = 2;
|
||||
|
||||
SetVisibility(window_id, false);
|
||||
CreateSearchBar(window->id);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -191,7 +243,9 @@ void InitWindows() {
|
||||
window->active_view = view->id;
|
||||
|
||||
Window *titlebar = CreateTitlebar(window_id);
|
||||
titlebar->z = 2;
|
||||
Window *searchbar = CreateSearchBar(window->id);
|
||||
titlebar->z = 2;
|
||||
searchbar->z = 2;
|
||||
|
||||
SetVisibility(window_id, false);
|
||||
}
|
||||
@@ -199,7 +253,8 @@ void InitWindows() {
|
||||
ActiveWindow = {0};
|
||||
}
|
||||
|
||||
void LayoutWindows(int16_t wx, int16_t wy) {
|
||||
void
|
||||
LayoutWindows(int16_t wx, int16_t wy) {
|
||||
float ScrollBarSize = (10.f * DPIScale);
|
||||
Rect2I screen_rect = RectI0Size(wx, wy);
|
||||
float line_numbers_size = (float)FontCharSpacing * 10;
|
||||
@@ -223,12 +278,18 @@ void LayoutWindows(int16_t wx, int16_t wy) {
|
||||
|
||||
For(Windows) {
|
||||
Window *window = it.o;
|
||||
if (!window->visible || window->absolute_position || window->is_title_bar) continue;
|
||||
if (!window->visible || window->absolute_position || window->is_title_bar || window->is_search_bar) continue;
|
||||
|
||||
Window *title_bar_window = GetWindow(window->title_bar_window);
|
||||
title_bar_window->total_rect = CutBottom(&window->total_rect, GetTitleBarSize(title_bar_window));
|
||||
title_bar_window->document_rect = title_bar_window->total_rect;
|
||||
|
||||
Rect2I save_rect = window->document_rect;
|
||||
CutLeft(&save_rect, GetSize(save_rect).x/2);
|
||||
Window *search_bar_window = GetWindow(window->search_bar_window);
|
||||
search_bar_window->total_rect = CutTop(&save_rect, GetTitleBarSize(search_bar_window));
|
||||
search_bar_window->document_rect = search_bar_window->total_rect;
|
||||
|
||||
window->document_rect = window->total_rect;
|
||||
if (window->draw_scrollbar) window->scrollbar_rect = CutRight(&window->document_rect, (Int)ScrollBarSize);
|
||||
if (window->draw_line_numbers) window->line_numbers_rect = CutLeft(&window->document_rect, (Int)line_numbers_size);
|
||||
@@ -249,22 +310,13 @@ void LayoutWindows(int16_t wx, int16_t wy) {
|
||||
title_bar_window->total_rect = CutBottom(&window->total_rect, GetTitleBarSize(title_bar_window));
|
||||
title_bar_window->document_rect = title_bar_window->total_rect;
|
||||
|
||||
window->document_rect = window->total_rect;
|
||||
}
|
||||
|
||||
{
|
||||
Window *window = GetWindow(SearchWindowID);
|
||||
Rect2 screen_rect = Rect0Size(wx, wy);
|
||||
Vec2 size = GetSize(screen_rect);
|
||||
|
||||
Rect2 rect = CutBottom(&screen_rect, (float)FontLineSpacing);
|
||||
window->total_rect = ToRect2I(rect);
|
||||
|
||||
Window *title_bar_window = GetWindow(window->title_bar_window);
|
||||
BSet tb = GetBSet(title_bar_window);
|
||||
title_bar_window->total_rect = CutLeft(&window->total_rect, tb.buffer->len * FontCharSpacing);
|
||||
title_bar_window->document_rect = title_bar_window->total_rect;
|
||||
Rect2I save_rect = window->document_rect;
|
||||
CutLeft(&save_rect, GetSize(save_rect).x/2);
|
||||
Window *search_bar_window = GetWindow(window->search_bar_window);
|
||||
search_bar_window->total_rect = CutTop(&save_rect, GetTitleBarSize(search_bar_window));
|
||||
search_bar_window->document_rect = search_bar_window->total_rect;
|
||||
|
||||
window->document_rect = window->total_rect;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -111,7 +111,7 @@ void DrawWindow(Window *window, Event &event) {
|
||||
Rect2 screen_rect = Rect0Size(event.xwindow, event.ywindow);
|
||||
SetScissor(screen_rect);
|
||||
|
||||
bool is_actib = window->id == ActiveWindow || window->title_bar_window == ActiveWindow;
|
||||
bool is_actib = window->id == ActiveWindow || window->title_bar_window == ActiveWindow || window->search_bar_window == ActiveWindow;
|
||||
bool is_active = window->id == ActiveWindow;
|
||||
|
||||
Color color_whitespace_during_selection = ColorWhitespaceDuringSelection;
|
||||
|
||||
Reference in New Issue
Block a user