Skip to content

Commit

Permalink
LibWebView: Append remaining source after consuming all tokens
Browse files Browse the repository at this point in the history
Since "Character" tokens do not have an "end position", viewing source
drops the source contents following the final non-"Character" token.

By handling the EOF token and breaking out of the loop, we avoid this
issue.

(cherry picked from commit 7de669dc07956c402e0ddec76e3f214f622cf2c4)
  • Loading branch information
sgeisenh authored and nico committed Nov 1, 2024
1 parent 0515b10 commit 5067a04
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Userland/Libraries/LibWebView/SourceHighlighter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ String highlight_source(URL::URL const& url, StringView source)
previous_position = end_position;
};

for (auto token = tokenizer.next_token(); token.has_value() && !token->is_end_of_file(); token = tokenizer.next_token()) {
for (auto token = tokenizer.next_token(); token.has_value(); token = tokenizer.next_token()) {
if (token->is_comment()) {
append_source(token->start_position().byte_offset);
append_source(token->end_position().byte_offset, "comment"sv);
Expand All @@ -83,6 +83,8 @@ String highlight_source(URL::URL const& url, StringView source)
append_source(token->end_position().byte_offset);
} else {
append_source(token->end_position().byte_offset);
if (token->is_end_of_file())
break;
}
}

Expand Down

0 comments on commit 5067a04

Please sign in to comment.