Click multiple times to enclose load word or exec word

This commit is contained in:
Krzosa Karol
2024-08-05 15:31:38 +02:00
parent 956f2319b5
commit d81c403a5d
4 changed files with 20 additions and 11 deletions

View File

@@ -424,6 +424,11 @@ Range EncloseExecWord(Buffer *buffer, Int pos) {
return result;
}
Range EncloseLine(Buffer *buffer, Int pos) {
Range result = {GetLineStart(buffer, pos), GetLineEnd(buffer, pos)};
return result;
}
Int OffsetByLine(Buffer *buffer, Int pos, Int line_offset) {
XY xy = PosToXY(*buffer, pos);
Int result = XYToPosWithoutNL(*buffer, {xy.col, xy.line + line_offset});

View File

@@ -28,12 +28,12 @@ struct Event {
int16_t ymouse;
int16_t xwindow;
int16_t ywindow;
uint8_t clicks;
struct {
uint8_t shift : 1;
uint8_t ctrl : 1;
uint8_t alt : 1;
uint8_t super : 1;
uint8_t mouse_double_click : 1;
};
Vec2 wheel;
const char *text;
@@ -352,10 +352,12 @@ bool GlobalCommand(Event event) {
caret.range.max = p;
caret.ifront = 1;
}
} else if (event.mouse_double_click) {
} else if (event.clicks >= 2) {
view->carets.len = 1;
Range range = EncloseWord(buffer, p);
if (InBounds({caret.range.min - 1, caret.range.max + 1}, p)) {
Range range = EncloseWord(buffer, p);
if (event.clicks == 3) range = EncloseLoadWord(buffer, p);
if (event.clicks >= 4) range = EncloseExecWord(buffer, p);
caret = MakeCaret(range.max, range.min);
} else {
caret = MakeCaret(p);

View File

@@ -89,14 +89,16 @@ Event TranslateSDLEvent(SDL_Event *input_event) {
event.xmouse = (int16_t)b.x;
event.ymouse = (int16_t)b.y;
if (b.button == SDL_BUTTON_LEFT) {
event.kind = EVENT_MOUSE_LEFT;
if (b.clicks == 2) {
event.mouse_double_click = 1;
}
event.kind = EVENT_MOUSE_LEFT;
event.clicks = b.clicks;
} else if (b.button == SDL_BUTTON_RIGHT) {
event.kind = EVENT_MOUSE_RIGHT;
event.kind = EVENT_MOUSE_RIGHT;
event.clicks = b.clicks;
} else if (b.button == SDL_BUTTON_MIDDLE) {
event.kind = EVENT_MOUSE_MIDDLE;
event.kind = EVENT_MOUSE_MIDDLE;
event.clicks = b.clicks;
} else {
event.kind = EVENT_NONE;
}
} break;
@@ -110,6 +112,8 @@ Event TranslateSDLEvent(SDL_Event *input_event) {
event.kind = EVENT_MOUSE_RIGHT_UP;
} else if (b.button == SDL_BUTTON_MIDDLE) {
event.kind = EVENT_MOUSE_MIDDLE_UP;
} else {
event.kind = EVENT_NONE;
}
} break;

View File

@@ -3,14 +3,12 @@
- ctrl + delete maybe should stop on new line but it keeps on going, sublime is much more careful with deleting
BUG: there is a click hang when switching windows sometimes, you click after select and it doesn't switch active window
- mouse execute
- experiment with using multiple cursors to select command and it's input
- search as a command to execute which is going to be in the title bar
- each buffer needs a directory even the special ones: C:\a\b\c\+errors?
- open directories - resulting in buffer with dir listing and proper buffer name
- alt/ctrl + double click should select the exec or load word
- clean \r\n into \n on trim and load
- global config and local config