Highlight exec word
This commit is contained in:
@@ -295,6 +295,28 @@ Int GetLoadWordEnd(Buffer *buffer, Int pos) {
|
||||
return pos;
|
||||
}
|
||||
|
||||
Int GetExecWordStart(Buffer *buffer, Int pos) {
|
||||
pos = Clamp(pos, (Int)0, buffer->len);
|
||||
for (Int i = pos - 1; i >= 0; i -= 1) {
|
||||
if (IsWhitespace(buffer->str[i])) break;
|
||||
pos = i;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
Int GetExecWordEnd(Buffer *buffer, Int pos) {
|
||||
pos = Clamp(pos, (Int)0, buffer->len);
|
||||
for (Int i = pos;; i += 1) {
|
||||
pos = i;
|
||||
// this is because buffer end terminates the loop
|
||||
// too early and we cannot establish the proper range
|
||||
// semantics - proper max is one past last index
|
||||
if (!(i < buffer->len)) break;
|
||||
if (IsWhitespace(buffer->str[i])) break;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
Int GetNextWordEnd(Buffer *buffer, Int pos) {
|
||||
pos = Clamp(pos, (Int)0, buffer->len);
|
||||
wchar_t prev = 0;
|
||||
@@ -397,6 +419,11 @@ Range EncloseLoadWord(Buffer *buffer, Int pos) {
|
||||
return result;
|
||||
}
|
||||
|
||||
Range EncloseExecWord(Buffer *buffer, Int pos) {
|
||||
Range result = {GetExecWordStart(buffer, pos), GetExecWordEnd(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});
|
||||
|
||||
@@ -170,7 +170,24 @@ bool GlobalCommand(Event event) {
|
||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||
Int p = ScreenSpaceToBufferPosErrorOutOfBounds(window, view, buffer, mouse);
|
||||
if (p != -1) {
|
||||
view->underline_pos[view->underline_count++] = p;
|
||||
view->underline_pos[view->underline_count++] = EncloseLoadWord(buffer, p);
|
||||
Assert(view->underline_count <= 2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (event.alt) {
|
||||
Vec2I mouse = MouseVec2I();
|
||||
For(order) {
|
||||
Window *window = &Windows[it];
|
||||
if (!window->visible) continue;
|
||||
bool mouse_in_document = CheckCollisionPointRec(mouse, window->document_rect);
|
||||
if (mouse_in_document) {
|
||||
View *view = GetView(window->active_view);
|
||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||
Int p = ScreenSpaceToBufferPosErrorOutOfBounds(window, view, buffer, mouse);
|
||||
if (p != -1) {
|
||||
view->underline_pos[view->underline_count++] = EncloseExecWord(buffer, p);
|
||||
Assert(view->underline_count <= 2);
|
||||
}
|
||||
break;
|
||||
@@ -270,7 +287,8 @@ bool GlobalCommand(Event event) {
|
||||
// for now let's leave it because we are relaying on global state
|
||||
// - maybe just do the check if active window is matching the DocumentSelected window
|
||||
// - if scrollbar selected then don't invoke window command
|
||||
if (event.ctrl && Mouse(LEFT)) {
|
||||
if (event.alt && Mouse(LEFT)) {
|
||||
} else if (event.ctrl && Mouse(LEFT)) {
|
||||
Vec2I mouse = MouseVec2I();
|
||||
Window *window = GetActiveWindow();
|
||||
|
||||
|
||||
@@ -825,7 +825,13 @@ void WindowCommand(Event event, Window *window, View *view) {
|
||||
if (event.ctrl) {
|
||||
Caret caret = view->carets[0];
|
||||
if (GetSize(caret.range) == 0) {
|
||||
view->underline_pos[view->underline_count++] = caret.range.min;
|
||||
view->underline_pos[view->underline_count++] = EncloseLoadWord(buffer, caret.range.min);
|
||||
Assert(view->underline_count <= 2);
|
||||
}
|
||||
} else if (event.alt) {
|
||||
Caret caret = view->carets[0];
|
||||
if (GetSize(caret.range) == 0) {
|
||||
view->underline_pos[view->underline_count++] = EncloseExecWord(buffer, caret.range.min);
|
||||
Assert(view->underline_count <= 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,8 +50,8 @@ struct View {
|
||||
Caret main_caret_on_begin_frame;
|
||||
bool update_scroll;
|
||||
|
||||
int underline_count;
|
||||
Int underline_pos[2];
|
||||
int underline_count;
|
||||
Range underline_pos[2];
|
||||
|
||||
struct {
|
||||
bool fuzzy_search : 1;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
- I think the way sublime text and we display line highlights is confusing with multiple cursors (line highlight can be confused with selection)
|
||||
- ctrl + delete maybe should stop on new line but it keeps on going, sublime is much more careful with deleting
|
||||
|
||||
- mouse execute (control right click)
|
||||
- mouse execute
|
||||
- alt right click what to do ? (toggle console?)
|
||||
- experiment with using multiple cursors to select command and it's input
|
||||
- should be able click on title bar of windows which disappear on losing focus
|
||||
|
||||
@@ -168,7 +168,7 @@ void DrawWindow(Window *window) {
|
||||
}
|
||||
|
||||
for (int i = 0; i < view->underline_count; i += 1) {
|
||||
Range range = EncloseLoadWord(buffer, view->underline_pos[i]);
|
||||
Range range = view->underline_pos[i];
|
||||
|
||||
XY xy_min = PosToXY(*buffer, range.min);
|
||||
XY xy_max = PosToXY(*buffer, range.max);
|
||||
|
||||
Reference in New Issue
Block a user