EncloseLoadWord
This commit is contained in:
@@ -374,7 +374,7 @@ void GenerateConfig() {
|
||||
|
||||
Array<Var> colors = {};
|
||||
colors.add({"Text", "GruvboxDark0Hard"});
|
||||
colors.add({"TextUnderline", "GruvboxDark0Hard"});
|
||||
colors.add({"LoadTextHighlight", "0x0000000F"});
|
||||
colors.add({"Background", "GruvboxLight0Hard"});
|
||||
colors.add({"InactiveWindow", "0x0000000F"});
|
||||
colors.add({"TextLineNumbers", "GruvboxDark4"});
|
||||
|
||||
@@ -24,8 +24,16 @@ bool IsNonWord(wchar_t w) {
|
||||
}
|
||||
|
||||
bool IsWord(wchar_t w) {
|
||||
bool result = IsSymbol(w) || IsWhitespace(w);
|
||||
return !result;
|
||||
bool result = !IsNonWord(w);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool IsLoadWord(wchar_t w) {
|
||||
bool result = w == '/' || w == '\\' || w == ':' || w == '*' || w == '_' || w == '.' || w == '-';
|
||||
if (!result) {
|
||||
result = !(IsSymbol(w) || IsWhitespace(w));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool IsAlphabetic(wchar_t a) {
|
||||
|
||||
@@ -220,7 +220,7 @@ Int XYToPosWithoutNL(Buffer &buffer, XY xy) {
|
||||
Int GetWordStart(Buffer *buffer, Int pos) {
|
||||
pos = Clamp(pos, (Int)0, buffer->len);
|
||||
for (Int i = pos - 1; i >= 0; i -= 1) {
|
||||
if (IsNonWord(buffer->str[i])) break;
|
||||
if (!IsWord(buffer->str[i])) break;
|
||||
pos = i;
|
||||
}
|
||||
return pos;
|
||||
@@ -230,7 +230,25 @@ Int GetWordEnd(Buffer *buffer, Int pos) {
|
||||
pos = Clamp(pos, (Int)0, buffer->len);
|
||||
for (Int i = pos; i < buffer->len; i += 1) {
|
||||
pos = i;
|
||||
if (IsNonWord(buffer->str[i])) break;
|
||||
if (!IsWord(buffer->str[i])) break;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
Int GetLoadWordStart(Buffer *buffer, Int pos) {
|
||||
pos = Clamp(pos, (Int)0, buffer->len);
|
||||
for (Int i = pos - 1; i >= 0; i -= 1) {
|
||||
if (!IsLoadWord(buffer->str[i])) break;
|
||||
pos = i;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
Int GetLoadWordEnd(Buffer *buffer, Int pos) {
|
||||
pos = Clamp(pos, (Int)0, buffer->len);
|
||||
for (Int i = pos; i < buffer->len; i += 1) {
|
||||
pos = i;
|
||||
if (!IsLoadWord(buffer->str[i])) break;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
@@ -321,4 +339,14 @@ Int GetPrevEmptyLineStart(Buffer *buffer, Int pos) {
|
||||
if (whitespace_line) break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Range EncloseWord(Buffer *buffer, Int pos) {
|
||||
Range result = {GetWordStart(buffer, pos), GetWordEnd(buffer, pos)};
|
||||
return result;
|
||||
}
|
||||
|
||||
Range EncloseLoadWord(Buffer *buffer, Int pos) {
|
||||
Range result = {GetLoadWordStart(buffer, pos), GetLoadWordEnd(buffer, pos)};
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -94,13 +94,6 @@ Int MovePos(Buffer &buffer, Int pos, int direction, bool ctrl_pressed = false) {
|
||||
}
|
||||
}
|
||||
|
||||
Range EncloseWord(Buffer &buffer, Int pos) {
|
||||
Range result = {};
|
||||
result.min = MoveOnWhitespaceBoundary(buffer, pos, DIR_LEFT);
|
||||
result.max = MoveOnWhitespaceBoundary(buffer, pos, DIR_RIGHT);
|
||||
return result;
|
||||
}
|
||||
|
||||
Caret FindInBuffer(Buffer *buffer, String16 needle, Caret caret, bool find_next = false) {
|
||||
Int pos = caret.range.min;
|
||||
String16 medium = GetString(*buffer, {pos, INT64_MAX});
|
||||
|
||||
@@ -702,7 +702,7 @@ void WindowCommand(Event event, Window *window, View *view) {
|
||||
} else if (mouse_in_document && Mouse(LEFT) && event.mouse_double_click) {
|
||||
Caret *c = &view->carets[0];
|
||||
if (InBounds({c->range.min - 1, c->range.max + 1}, p)) {
|
||||
c->range = EncloseWord(*buffer, p);
|
||||
c->range = EncloseWord(buffer, p);
|
||||
view->selection_anchor = c->range;
|
||||
} else {
|
||||
view->selection_anchor = Rng(p);
|
||||
|
||||
@@ -38,7 +38,7 @@ local GruvboxFadedAqua = 0x427b58ff
|
||||
local GruvboxFadedOrange = 0xaf3a03ff
|
||||
Color = {}
|
||||
Color.Text = GruvboxDark0Hard
|
||||
Color.TextUnderline = GruvboxDark0Hard
|
||||
Color.LoadTextHighlight = 0x0000000F
|
||||
Color.Background = GruvboxLight0Hard
|
||||
Color.InactiveWindow = 0x0000000F
|
||||
Color.TextLineNumbers = GruvboxDark4
|
||||
@@ -199,7 +199,7 @@ end
|
||||
)==";
|
||||
void ReloadStyle() {
|
||||
ColorText = GetColor("Text", ColorText);
|
||||
ColorTextUnderline = GetColor("TextUnderline", ColorTextUnderline);
|
||||
ColorLoadTextHighlight = GetColor("LoadTextHighlight", ColorLoadTextHighlight);
|
||||
ColorBackground = GetColor("Background", ColorBackground);
|
||||
ColorInactiveWindow = GetColor("InactiveWindow", ColorInactiveWindow);
|
||||
ColorTextLineNumbers = GetColor("TextLineNumbers", ColorTextLineNumbers);
|
||||
|
||||
@@ -36,7 +36,7 @@ Color GruvboxFadedPurple = {0x8f, 0x3f, 0x71, 0xff};
|
||||
Color GruvboxFadedAqua = {0x42, 0x7b, 0x58, 0xff};
|
||||
Color GruvboxFadedOrange = {0xaf, 0x3a, 0x03, 0xff};
|
||||
Color ColorText = GruvboxDark0Hard;
|
||||
Color ColorTextUnderline = GruvboxDark0Hard;
|
||||
Color ColorLoadTextHighlight = {0x00, 0x00, 0x00, 0x0F};
|
||||
Color ColorBackground = GruvboxLight0Hard;
|
||||
Color ColorInactiveWindow = {0x00, 0x00, 0x00, 0x0F};
|
||||
Color ColorTextLineNumbers = GruvboxDark4;
|
||||
|
||||
@@ -167,22 +167,22 @@ void DrawWindow(Window *window) {
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
if (is_active) {
|
||||
Caret caret = view->carets[0];
|
||||
if (GetSize(caret.range) == 0) {
|
||||
Int pos = caret.range.min;
|
||||
if (pos < buffer->len && !IsWhitespace(buffer->str[pos])) {
|
||||
Range range = EncloseWord(*buffer, pos);
|
||||
if (pos < buffer->len) {
|
||||
Range range = EncloseLoadWord(buffer, pos);
|
||||
|
||||
XY xy_min = PosToXY(*buffer, range.min);
|
||||
XY xy_max = PosToXY(*buffer, range.max);
|
||||
|
||||
Vec2I min = {xy_min.col * FontCharSpacing, (xy_min.line + 1) * FontLineSpacing - 2};
|
||||
Vec2I min = {xy_min.col * FontCharSpacing, (xy_min.line) * FontLineSpacing};
|
||||
Vec2I max = {xy_max.col * FontCharSpacing, (xy_max.line + 1) * FontLineSpacing};
|
||||
Rect2I rect = {min, max};
|
||||
rect -= view->scroll;
|
||||
rect += window->document_rect.min;
|
||||
DrawRect(rect, ColorTextUnderline);
|
||||
DrawRect(rect, ColorLoadTextHighlight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user