Fix underline bug and draw selection underline
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
BUG: when redo and ctrl pressed a bugged enclosure rect is shown - we probably want to pass the event to render and just do everything there!
|
||||
|
||||
- we should be able to execute selection using mouse and keyboard (for now only main cursor)
|
||||
- we should be able to execute a buffer (even scratch
|
||||
|
||||
@@ -93,6 +93,10 @@ void DrawUnderline(Window *window, View *view, Buffer *buffer, Range range) {
|
||||
XY xy_min = PosToXY(*buffer, range.min);
|
||||
XY xy_max = PosToXY(*buffer, range.max);
|
||||
|
||||
// @todo: maybe consider underlining multiple lines but then we would need to consider
|
||||
// optimizing and so on
|
||||
if (xy_min.line != xy_max.line) return;
|
||||
|
||||
Vec2I min = {xy_min.col * FontCharSpacing, (xy_min.line + 1) * FontLineSpacing - 1};
|
||||
Vec2I max = {xy_max.col * FontCharSpacing, (xy_max.line + 1) * FontLineSpacing};
|
||||
Rect2I rect = {min, max};
|
||||
@@ -183,6 +187,7 @@ void DrawWindow(Window *window, Event &event) {
|
||||
if (event.ctrl || event.alt) {
|
||||
auto enclose_proc = event.ctrl ? EncloseLoadWord : EncloseExecWord;
|
||||
|
||||
Caret caret = view->carets[0];
|
||||
Vec2I mouse = MouseVec2I();
|
||||
bool mouse_in_document = CheckCollisionPointRec(mouse, window->document_rect);
|
||||
if (mouse_in_document) {
|
||||
@@ -191,14 +196,18 @@ void DrawWindow(Window *window, Event &event) {
|
||||
Int p = ScreenSpaceToBufferPosErrorOutOfBounds(window, view, buffer, mouse);
|
||||
if (p != -1) {
|
||||
Range range = enclose_proc(buffer, p);
|
||||
if (InBounds(caret.range, p)) range = caret.range;
|
||||
DrawUnderline(window, view, buffer, range);
|
||||
}
|
||||
}
|
||||
|
||||
Caret caret = view->carets[0];
|
||||
if (GetSize(caret.range) == 0) {
|
||||
Range range = enclose_proc(buffer, caret.range.min);
|
||||
DrawUnderline(window, view, buffer, range);
|
||||
if (is_active) {
|
||||
if (GetSize(caret.range) == 0) {
|
||||
Range range = enclose_proc(buffer, caret.range.min);
|
||||
DrawUnderline(window, view, buffer, range);
|
||||
} else {
|
||||
DrawUnderline(window, view, buffer, caret.range);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user