Page up page down

This commit is contained in:
Krzosa Karol
2024-07-04 16:21:02 +02:00
parent 2f52c018cd
commit b48cffd880
2 changed files with 51 additions and 26 deletions

View File

@@ -609,15 +609,15 @@ int64_t MoveLeft(Buffer &buffer, int64_t pos) {
return pos; return pos;
} }
int64_t MoveDown(Buffer &buffer, int64_t pos) { int64_t MoveDown(Buffer &buffer, int64_t pos, int64_t count = 1) {
LineAndColumn info = FindLineAndColumn(buffer, pos); LineAndColumn info = FindLineAndColumn(buffer, pos);
int64_t new_pos = FindPos(buffer, info.line.number + 1, info.column); int64_t new_pos = FindPos(buffer, info.line.number + count, info.column);
return new_pos; return new_pos;
} }
int64_t MoveUp(Buffer &buffer, int64_t pos) { int64_t MoveUp(Buffer &buffer, int64_t pos, int64_t count = 1) {
LineAndColumn info = FindLineAndColumn(buffer, pos); LineAndColumn info = FindLineAndColumn(buffer, pos);
int64_t new_pos = FindPos(buffer, info.line.number - 1, info.column); int64_t new_pos = FindPos(buffer, info.line.number - count, info.column);
return new_pos; return new_pos;
} }

View File

@@ -4,7 +4,6 @@
#include "raymath.h" #include "raymath.h"
#include "profiler.cpp" #include "profiler.cpp"
// @todo: highlight all occurences of selected word
// @todo: search for word // @todo: search for word
// @todo: context menu // @todo: context menu
// @todo: toy around with acme ideas // @todo: toy around with acme ideas
@@ -66,6 +65,7 @@ int main() {
BeginProfiler(); BeginProfiler();
InitScratch(); InitScratch();
InitWindow(800, 600, "Hello"); InitWindow(800, 600, "Hello");
SetExitKey(KEY_F1);
// @todo: dpi // @todo: dpi
SetWindowState(FLAG_WINDOW_RESIZABLE); SetWindowState(FLAG_WINDOW_RESIZABLE);
SetTargetFPS(60); SetTargetFPS(60);
@@ -79,7 +79,7 @@ int main() {
InitArena(&PermArena); InitArena(&PermArena);
float font_size = 14; float font_size = 14;
float font_spacing = 1; float font_spacing = 1;
Font font = LoadFontEx("C:/Windows/Fonts/consola.ttf", (int)font_size, NULL, 250); Font font = LoadFontEx("C:/Windows/Fonts/times.ttf", (int)font_size, NULL, 250);
Array<Window> windows = {}; Array<Window> windows = {};
{ {
@@ -119,7 +119,7 @@ int main() {
} }
frame += 1; frame += 1;
Dbg("%lld", (long long)frame); // Dbg("%lld", (long long)frame);
UpdateEventRecording(); UpdateEventRecording();
@@ -137,6 +137,10 @@ int main() {
focused_window->cursors.add(MakeCursor(0, focused_window->buffer.len)); focused_window->cursors.add(MakeCursor(0, focused_window->buffer.len));
} }
if (IsKeyPressed(KEY_ESCAPE)) {
focused_window->cursors.len = 1;
}
if (IsKeyPressed(KEY_LEFT) || IsKeyPressedRepeat(KEY_LEFT)) { if (IsKeyPressed(KEY_LEFT) || IsKeyPressedRepeat(KEY_LEFT)) {
For(focused_window->cursors) { For(focused_window->cursors) {
if (IsKeyDown(KEY_LEFT_CONTROL)) { if (IsKeyDown(KEY_LEFT_CONTROL)) {
@@ -189,6 +193,7 @@ int main() {
} }
} }
// @todo: proper handling of getting out of selection
if (IsKeyPressed(KEY_DOWN) || IsKeyPressedRepeat(KEY_DOWN)) { if (IsKeyPressed(KEY_DOWN) || IsKeyPressedRepeat(KEY_DOWN)) {
if (IsKeyDown(KEY_LEFT_SHIFT) && IsKeyDown(KEY_LEFT_ALT)) { // Default in VSCode seems to be Ctrl + Alt + down if (IsKeyDown(KEY_LEFT_SHIFT) && IsKeyDown(KEY_LEFT_ALT)) { // Default in VSCode seems to be Ctrl + Alt + down
Array<Cursor> cursors_to_add = {FrameArena}; Array<Cursor> cursors_to_add = {FrameArena};
@@ -226,6 +231,7 @@ int main() {
} }
} }
// @todo: proper handling of getting out of selection
if (IsKeyPressed(KEY_UP) || IsKeyPressedRepeat(KEY_UP)) { if (IsKeyPressed(KEY_UP) || IsKeyPressedRepeat(KEY_UP)) {
if (IsKeyDown(KEY_LEFT_SHIFT) && IsKeyDown(KEY_LEFT_ALT)) { // Default in VSCode seems to be Ctrl + Alt + up if (IsKeyDown(KEY_LEFT_SHIFT) && IsKeyDown(KEY_LEFT_ALT)) { // Default in VSCode seems to be Ctrl + Alt + up
Array<Cursor> cursors_to_add = {FrameArena}; Array<Cursor> cursors_to_add = {FrameArena};
@@ -299,18 +305,6 @@ int main() {
it.range.min = it.range.max = line.max_without_new_line; it.range.min = it.range.max = line.max_without_new_line;
} }
} }
if (IsKeyPressed(KEY_PAGE_UP) || IsKeyPressedRepeat(KEY_PAGE_UP)) {
if (IsKeyDown(KEY_LEFT_SHIFT)) {
} else {
}
}
if (IsKeyPressed(KEY_PAGE_DOWN) || IsKeyPressedRepeat(KEY_PAGE_DOWN)) {
if (IsKeyDown(KEY_LEFT_SHIFT)) {
} else {
}
}
} }
if (IsKeyDown(KEY_LEFT_CONTROL) && IsKeyPressed(KEY_C)) { if (IsKeyDown(KEY_LEFT_CONTROL) && IsKeyPressed(KEY_C)) {
@@ -429,7 +423,7 @@ int main() {
AfterEdit(focused_window, edits); AfterEdit(focused_window, edits);
} }
{ if (0) {
Cursor cursor = focused_window->cursors[0]; Cursor cursor = focused_window->cursors[0];
if (GetRangeSize(cursor.range)) { if (GetRangeSize(cursor.range)) {
String seek = GetString(focused_window->buffer, cursor.range); String seek = GetString(focused_window->buffer, cursor.range);
@@ -446,11 +440,13 @@ int main() {
// colored.text_color = RED; // colored.text_color = RED;
// focused_window->colored_strings.add(colored); // focused_window->colored_strings.add(colored);
ColoredString colored = {}; if (!AreEqual(range, cursor.range)) {
colored.range = range; ColoredString colored = {};
colored.use_highlight_background_color = true; colored.range = range;
colored.highlight_background_color = {0, 0, 0, 25}; colored.use_highlight_background_color = true;
focused_window->colored_strings.add(colored); colored.highlight_background_color = {0, 0, 0, 25};
focused_window->colored_strings.add(colored);
}
base_index += index + seek.len; base_index += index + seek.len;
s = s.skip(index + seek.len); s = s.skip(index + seek.len);
@@ -472,6 +468,35 @@ int main() {
Rect2 line_number_rect = CutLeft(&window.rect, MeasureString(window.font, "1234", window.font_size, window.font_spacing).x); Rect2 line_number_rect = CutLeft(&window.rect, MeasureString(window.font, "1234", window.font_size, window.font_spacing).x);
if (!window.not_regen_layout) RegenLayout(&window); if (!window.not_regen_layout) RegenLayout(&window);
bool is_focused = true;
if (is_focused) {
int64_t num = GetRangeSize(window.layout.visible_line_range);
if (IsKeyPressed(KEY_PAGE_UP) || IsKeyPressedRepeat(KEY_PAGE_UP)) {
For(window.cursors) {
int64_t front = GetFront(it);
int64_t new_pos = MoveUp(window.buffer, front, num);
if (IsKeyDown(KEY_LEFT_SHIFT)) {
it = ChangeFront(it, new_pos);
} else {
it.range.min = it.range.max = new_pos;
}
}
}
if (IsKeyPressed(KEY_PAGE_DOWN) || IsKeyPressedRepeat(KEY_PAGE_DOWN)) {
For(window.cursors) {
int64_t front = GetFront(it);
int64_t new_pos = MoveDown(window.buffer, front, num);
if (IsKeyDown(KEY_LEFT_SHIFT)) {
it = ChangeFront(it, new_pos);
} else {
it.range.min = it.range.max = new_pos;
}
}
}
}
// Draw and layout window overlay // Draw and layout window overlay
Vec2 mouse = GetMousePosition(); Vec2 mouse = GetMousePosition();
{ {
@@ -625,7 +650,7 @@ int main() {
float visible_size_y = font_size * (float)visible_lines; float visible_size_y = font_size * (float)visible_lines;
Vec2 rect_size = GetSize(window.rect); Vec2 rect_size = GetSize(window.rect);
float cut_off_y = visible_size_y - rect_size.y; float cut_off_y = Max((float)0, visible_size_y - rect_size.y);
int64_t front = GetFront(window.cursors[0]); int64_t front = GetFront(window.cursors[0]);
Line line = FindLine(window.buffer, front); Line line = FindLine(window.buffer, front);