From 65f7f90433cc2703f0e1eee6fc865efbb97dc0ca Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Tue, 11 Aug 2020 12:27:32 -0700 Subject: [PATCH] Correctly highlight =s in var assignments after the first We were not correctly offsetting the = in the token, it was always from the start of the string. --- src/fish_tests.cpp | 5 +++++ src/highlight.cpp | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index 5c97d09cf..c1fdadb25 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -4936,6 +4936,11 @@ static void test_highlighting() { {L"HOME", highlight_role_t::param}, {L"=", highlight_role_t::operat, ns}, {L".", highlight_role_t::param, ns}, + {L"VAR1", highlight_role_t::param}, + {L"=", highlight_role_t::operat, ns}, + {L"VAL1", highlight_role_t::param, ns}, + {L"VAR", highlight_role_t::param}, + {L"=", highlight_role_t::operat, ns}, {L"false", highlight_role_t::command}, {L"|&", highlight_role_t::error}, {L"true", highlight_role_t::command}, diff --git a/src/highlight.cpp b/src/highlight.cpp index 24e96e29d..31337e7f3 100644 --- a/src/highlight.cpp +++ b/src/highlight.cpp @@ -1034,8 +1034,10 @@ void highlighter_t::visit(const ast::argument_t &arg, bool cmd_is_cd) { void highlighter_t::visit(const ast::variable_assignment_t &varas) { color_as_argument(varas); + // Highlight the '=' in variable assignments as an operator. if (auto where = variable_assignment_equals_pos(varas.source(this->buff))) { - this->color_array.at(*where) = highlight_role_t::operat; + size_t equals_loc = varas.source_range().start + *where; + this->color_array.at(equals_loc) = highlight_role_t::operat; } }