Implement double click
This commit is contained in:
@@ -614,4 +614,11 @@ int64_t MoveUp(Buffer &buffer, int64_t pos) {
|
|||||||
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 - 1, info.column);
|
||||||
return new_pos;
|
return new_pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
Range EncloseWord(Buffer &buffer, int64_t pos) {
|
||||||
|
Range result = {};
|
||||||
|
result.min = Seek(buffer, pos, ITERATE_BACKWARD);
|
||||||
|
result.max = Seek(buffer, pos, ITERATE_FORWARD);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
@@ -31,6 +31,7 @@ struct Window {
|
|||||||
float font_spacing;
|
float font_spacing;
|
||||||
Rect2 rect;
|
Rect2 rect;
|
||||||
|
|
||||||
|
Range selection_anchor_point;
|
||||||
bool mouse_selecting;
|
bool mouse_selecting;
|
||||||
Vec2 scroll; // window_world_to_window_units
|
Vec2 scroll; // window_world_to_window_units
|
||||||
Cursor main_cursor_begin_frame;
|
Cursor main_cursor_begin_frame;
|
||||||
|
|||||||
@@ -6,6 +6,9 @@
|
|||||||
// @todo: add clipboard history?
|
// @todo: add clipboard history?
|
||||||
// @todo: mouse double click
|
// @todo: mouse double click
|
||||||
// @todo: context menu
|
// @todo: context menu
|
||||||
|
// @todo: scrollbars
|
||||||
|
// @todo: line numbers
|
||||||
|
// @todo: line wrapping
|
||||||
// @todo: toy around with acme ideas
|
// @todo: toy around with acme ideas
|
||||||
#include "rect2.cpp"
|
#include "rect2.cpp"
|
||||||
#include "buffer.cpp"
|
#include "buffer.cpp"
|
||||||
@@ -41,6 +44,23 @@ void Dbg_Draw() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsDoubleClick() {
|
||||||
|
static double last_click_time;
|
||||||
|
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
|
||||||
|
double time = GetTime();
|
||||||
|
double diff = time - last_click_time;
|
||||||
|
last_click_time = time;
|
||||||
|
// @todo: don't do this manually, use windows
|
||||||
|
if (diff >= 0.15 && diff <= 0.5) {
|
||||||
|
last_click_time = 0;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
|
||||||
|
last_click_time = 0;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
InitScratch();
|
InitScratch();
|
||||||
InitWindow(800, 600, "Hello");
|
InitWindow(800, 600, "Hello");
|
||||||
@@ -389,7 +409,6 @@ int main() {
|
|||||||
For(focused_window->cursors) AddEdit(&edits, it.range, string);
|
For(focused_window->cursors) AddEdit(&edits, it.range, string);
|
||||||
ApplyEdits(focused_window, edits);
|
ApplyEdits(focused_window, edits);
|
||||||
AfterEdit(focused_window, edits);
|
AfterEdit(focused_window, edits);
|
||||||
// For(focused_window->cursors) it.range.min = it.range.max = MoveRight(focused_window->buffer, it.range.min);
|
|
||||||
}
|
}
|
||||||
EventRecording_SimulateGetCharPressed(focused_window);
|
EventRecording_SimulateGetCharPressed(focused_window);
|
||||||
}
|
}
|
||||||
@@ -442,8 +461,16 @@ int main() {
|
|||||||
if (!IsKeyDown(KEY_LEFT_CONTROL)) {
|
if (!IsKeyDown(KEY_LEFT_CONTROL)) {
|
||||||
window.cursors.clear();
|
window.cursors.clear();
|
||||||
}
|
}
|
||||||
window.cursors.add({col->pos, col->pos});
|
window.cursors.add(MakeCursor(col->pos, col->pos));
|
||||||
|
window.selection_anchor_point = window.cursors.last()->range;
|
||||||
|
if (IsDoubleClick()) {
|
||||||
|
Cursor *c = window.cursors.last();
|
||||||
|
c->range = EncloseWord(window.buffer, col->pos);
|
||||||
|
window.selection_anchor_point = c->range;
|
||||||
|
}
|
||||||
|
|
||||||
MergeCursors(&window);
|
MergeCursors(&window);
|
||||||
|
} else if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
|
||||||
window.mouse_selecting = true;
|
window.mouse_selecting = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -453,7 +480,13 @@ int main() {
|
|||||||
window.mouse_selecting = false;
|
window.mouse_selecting = false;
|
||||||
}
|
}
|
||||||
Cursor *cursor = window.cursors.last();
|
Cursor *cursor = window.cursors.last();
|
||||||
cursor[0] = ChangeFront(*cursor, col->pos);
|
if (window.selection_anchor_point.min > col->pos) {
|
||||||
|
cursor[0] = MakeCursor(col->pos, window.selection_anchor_point.max);
|
||||||
|
} else if (window.selection_anchor_point.max < col->pos) {
|
||||||
|
cursor[0] = MakeCursor(col->pos, window.selection_anchor_point.min);
|
||||||
|
} else {
|
||||||
|
cursor[0] = MakeCursor(window.selection_anchor_point.max, window.selection_anchor_point.min);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
10
src/text_editor/multi_cursor_text_editor_behaviors.txt
Normal file
10
src/text_editor/multi_cursor_text_editor_behaviors.txt
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
- select word on double click - use selected word as the unselectable anchor point
|
||||||
|
- ctrl + mouse click to add and control a new cursor
|
||||||
|
- ctrl + alt + mouse click to do a rectangle select with multiple cursors @todo
|
||||||
|
- mouse wheel to scroll
|
||||||
|
- right click to open context menu with cut copy paste @todo
|
||||||
|
- shift + alt + up arrow to create a new cursor on line above
|
||||||
|
- ctrl + alt + up arrow to duplicate line, put it above and put cursor on it
|
||||||
|
- alt + up arrow to move line above @todo
|
||||||
|
- arrow to move cursor vertically or horizontally
|
||||||
|
- shift + arrow to move and select
|
||||||
Reference in New Issue
Block a user