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;
}
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);
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;
}
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);
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;
}

View File

@@ -4,7 +4,6 @@
#include "raymath.h"
#include "profiler.cpp"
// @todo: highlight all occurences of selected word
// @todo: search for word
// @todo: context menu
// @todo: toy around with acme ideas
@@ -66,6 +65,7 @@ int main() {
BeginProfiler();
InitScratch();
InitWindow(800, 600, "Hello");
SetExitKey(KEY_F1);
// @todo: dpi
SetWindowState(FLAG_WINDOW_RESIZABLE);
SetTargetFPS(60);
@@ -79,7 +79,7 @@ int main() {
InitArena(&PermArena);
float font_size = 14;
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 = {};
{
@@ -119,7 +119,7 @@ int main() {
}
frame += 1;
Dbg("%lld", (long long)frame);
// Dbg("%lld", (long long)frame);
UpdateEventRecording();
@@ -137,6 +137,10 @@ int main() {
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)) {
For(focused_window->cursors) {
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 (IsKeyDown(KEY_LEFT_SHIFT) && IsKeyDown(KEY_LEFT_ALT)) { // Default in VSCode seems to be Ctrl + Alt + down
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 (IsKeyDown(KEY_LEFT_SHIFT) && IsKeyDown(KEY_LEFT_ALT)) { // Default in VSCode seems to be Ctrl + Alt + up
Array<Cursor> cursors_to_add = {FrameArena};
@@ -299,18 +305,6 @@ int main() {
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)) {
@@ -429,7 +423,7 @@ int main() {
AfterEdit(focused_window, edits);
}
{
if (0) {
Cursor cursor = focused_window->cursors[0];
if (GetRangeSize(cursor.range)) {
String seek = GetString(focused_window->buffer, cursor.range);
@@ -446,11 +440,13 @@ int main() {
// colored.text_color = RED;
// focused_window->colored_strings.add(colored);
ColoredString colored = {};
colored.range = range;
colored.use_highlight_background_color = true;
colored.highlight_background_color = {0, 0, 0, 25};
focused_window->colored_strings.add(colored);
if (!AreEqual(range, cursor.range)) {
ColoredString colored = {};
colored.range = range;
colored.use_highlight_background_color = true;
colored.highlight_background_color = {0, 0, 0, 25};
focused_window->colored_strings.add(colored);
}
base_index += 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);
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
Vec2 mouse = GetMousePosition();
{
@@ -625,7 +650,7 @@ int main() {
float visible_size_y = font_size * (float)visible_lines;
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]);
Line line = FindLine(window.buffer, front);