Command_Move down

This commit is contained in:
Krzosa Karol
2024-08-04 07:10:36 +02:00
parent 815e3c9670
commit cfad821e8e
4 changed files with 63 additions and 25 deletions

View File

@@ -367,3 +367,13 @@ Int OffsetByLine(Buffer *buffer, Int pos, Int line_offset) {
Int result = XYToPosWithoutNL(*buffer, {xy.col, xy.line + line_offset}); Int result = XYToPosWithoutNL(*buffer, {xy.col, xy.line + line_offset});
return result; return result;
} }
Int GetNextChar(Buffer *buffer, Int pos) {
Int result = Clamp(pos + 1, (Int)0, buffer->len);
return result;
}
Int GetPrevChar(Buffer *buffer, Int pos) {
Int result = Clamp(pos - 1, (Int)0, buffer->len);
return result;
}

View File

@@ -2,6 +2,7 @@ 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;
const int DIR_UP = 3; const int DIR_UP = 3;
const int DIR_COUNT = 4;
const bool CTRL_PRESSED = true; const bool CTRL_PRESSED = true;
@@ -67,7 +68,6 @@ Int MoveOnWhitespaceBoundaryVertical(Buffer &buffer, Int pos, int direction) {
} }
Int MovePos(Buffer &buffer, Int pos, int direction, bool ctrl_pressed = false) { Int MovePos(Buffer &buffer, Int pos, int direction, bool ctrl_pressed = false) {
ProfileFunction();
Assert(direction >= 0 && direction <= 3); Assert(direction >= 0 && direction <= 3);
if (ctrl_pressed) { if (ctrl_pressed) {
switch (direction) { switch (direction) {

View File

@@ -206,17 +206,16 @@ void Command_MoveCursorsByPageSize(Window *window, int direction, bool shift = f
} }
} }
void Command_MoveCursorsToSide(Window *window, int direction, bool shift = false) { void Command_MoveCursorsToSide(View *view, int direction, bool shift = false) {
Assert(direction == DIR_LEFT || direction == DIR_RIGHT); Assert(direction == DIR_LEFT || direction == DIR_RIGHT);
View &view = *GetActiveView(window); Buffer *buffer = GetBuffer(view->active_buffer);
Buffer *buffer = GetBuffer(view.active_buffer);
For(view.carets) { For(view->carets) {
Range line_range = GetLineRangeWithoutNL(*buffer, PosToLine(*buffer, GetFront(it))); Int pos = GetFront(it);
Int pos = line_range.min;
if (direction == DIR_RIGHT) { if (direction == DIR_RIGHT) {
pos = line_range.max; pos = GetLineEnd(buffer, pos);
} else {
pos = GetLineStart(buffer, pos);
} }
if (shift) { if (shift) {
@@ -227,6 +226,41 @@ void Command_MoveCursorsToSide(Window *window, int direction, bool shift = false
} }
} }
void Command_Move(View *view, int direction, bool ctrl = false, bool shift = false) {
Assert(direction < DIR_COUNT);
Buffer *buffer = GetBuffer(view->active_buffer);
For(view->carets) {
Int front = GetFront(it);
switch (direction) {
case DIR_UP: {
} break;
case DIR_DOWN: {
if (ctrl && shift) {
Int pos = GetNextEmptyLineStart(buffer, front);
it = ChangeFront(it, pos);
} else if (ctrl) {
Int pos = GetNextEmptyLineStart(buffer, it.range.max);
it = MakeCaret(pos);
} else if (shift) {
Int pos = OffsetByLine(buffer, front, 1);
it = ChangeFront(it, pos);
} else {
if (GetSize(it.range) == 0) {
Int pos = OffsetByLine(buffer, it.range.max, 1);
it = MakeCaret(pos);
} else {
it = MakeCaret(it.range.max);
}
}
} break;
case DIR_LEFT: {
} break;
case DIR_RIGHT: {
} break;
}
}
}
void Command_Delete(View *view, int direction, bool ctrl = false) { void Command_Delete(View *view, int direction, bool ctrl = false) {
Assert(direction == DIR_LEFT || direction == DIR_RIGHT); Assert(direction == DIR_LEFT || direction == DIR_RIGHT);
Scratch scratch; Scratch scratch;
@@ -407,19 +441,13 @@ void WindowCommand(Event event, Window *window, View *view) {
} else if (AltShift(SDLK_DOWN)) { } else if (AltShift(SDLK_DOWN)) {
Command_CreateCursorVertical(view, DIR_DOWN); Command_CreateCursorVertical(view, DIR_DOWN);
} else if (CtrlShift(SDLK_DOWN)) { } else if (CtrlShift(SDLK_DOWN)) {
For(view->carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_DOWN, true)); Command_Move(view, DIR_DOWN, CTRL_PRESSED, SHIFT_PRESSED);
} else if (Ctrl(SDLK_DOWN)) { } else if (Ctrl(SDLK_DOWN)) {
For(view->carets) it = MakeCaret(MovePos(*buffer, it.range.max, DIR_DOWN, true)); Command_Move(view, DIR_DOWN, CTRL_PRESSED);
} else if (Shift(SDLK_DOWN)) { } else if (Shift(SDLK_DOWN)) {
For(view->carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_DOWN, false)); Command_Move(view, DIR_DOWN, false, SHIFT_PRESSED);
} else if (Press(SDLK_DOWN)) { } else if (Press(SDLK_DOWN)) {
For(view->carets) { Command_Move(view, DIR_DOWN);
if (GetSize(it.range) == 0) {
it = MakeCaret(MovePos(*buffer, it.range.max, DIR_DOWN, false));
} else {
it = MakeCaret(it.range.max);
}
}
} }
if (CtrlAlt(SDLK_UP)) { if (CtrlAlt(SDLK_UP)) {
@@ -519,15 +547,15 @@ void WindowCommand(Event event, Window *window, View *view) {
} }
if (Shift(SDLK_HOME)) { if (Shift(SDLK_HOME)) {
Command_MoveCursorsToSide(window, DIR_LEFT, SHIFT_PRESSED); Command_MoveCursorsToSide(view, DIR_LEFT, SHIFT_PRESSED);
} else if (Press(SDLK_HOME)) { } else if (Press(SDLK_HOME)) {
Command_MoveCursorsToSide(window, DIR_LEFT); Command_MoveCursorsToSide(view, DIR_LEFT);
} }
if (Shift(SDLK_END)) { if (Shift(SDLK_END)) {
Command_MoveCursorsToSide(window, DIR_RIGHT, SHIFT_PRESSED); Command_MoveCursorsToSide(view, DIR_RIGHT, SHIFT_PRESSED);
} else if (Press(SDLK_END)) { } else if (Press(SDLK_END)) {
Command_MoveCursorsToSide(window, DIR_RIGHT); Command_MoveCursorsToSide(view, DIR_RIGHT);
} }
bool search = false; bool search = false;
@@ -664,7 +692,7 @@ void WindowCommand(Event event, Window *window, View *view) {
} else if (window->id.id == SearchWindowID.id) { } else if (window->id.id == SearchWindowID.id) {
} else { } else {
if (Ctrl(SDLK_RETURN)) { if (Ctrl(SDLK_RETURN)) {
Command_MoveCursorsToSide(window, DIR_RIGHT); Command_MoveCursorsToSide(view, DIR_RIGHT);
Command_Replace(view, L"\n"); Command_Replace(view, L"\n");
} else if (Press(SDLK_RETURN)) { } else if (Press(SDLK_RETURN)) {
Command_Replace(view, L"\n"); Command_Replace(view, L"\n");

View File

@@ -2,11 +2,11 @@
- page up and down should also scroll and leave you in exactly same scroll - page up and down should also scroll and leave you in exactly same scroll
- I think the way sublime text and we display line highlights is confusing with multiple cursors (line highlight can be confused with selection) - I think the way sublime text and we display line highlights is confusing with multiple cursors (line highlight can be confused with selection)
- save location on open and allow for revert (buffer id? or buffer name? - buffer name can change, buffer id is harder to serialize, I guess if internal only then buffer id)
- delete till indent - delete till indent
- indent on enter - indent on enter
- maybe my mouse selection is wrong? seems like on double click lite and sublime start to enclosing words!! - maybe my mouse selection is wrong? seems like on double click lite and sublime start to enclosing words!!
- click 3 times to select line - click 3 times to select line
- save location on open and allow for revert
- we could rewrite kill lines with simpler commands - extend selection to encompass lines->replace - we could rewrite kill lines with simpler commands - extend selection to encompass lines->replace
- improve cursor movement, it's too clunky, too much stopping - improve cursor movement, it's too clunky, too much stopping
- should be able click on title bar of windows which disappear on losing focus - should be able click on title bar of windows which disappear on losing focus