Skip to content

Commit

Permalink
LibWeb: Fix highlighting HTML comments
Browse files Browse the repository at this point in the history
Commit b193351 caused the HTML comments to flash when changing
the text cursor. Also, when double-clicking on a comment, the selection
started from the beginning of the file instead.

The following message was displaying when `TOKENIZER_TRACE_DEBUG`
was enabled:

    (Tokenizer::nth_last_position) Invalid position requested: 4th-last
    of 4. Returning (0-0).

Changing the `nth_last_position` to 3 fixes this. I'm guessing that's
because the parser is at that moment on the second hyphen of the `<!--`
string, so it has to go back only by three characters.
  • Loading branch information
krkk authored and alimpfard committed Feb 14, 2022
1 parent 704bb36 commit fb5e267
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Tests/LibWeb/TestHTMLTokenizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,5 +206,5 @@ TEST_CASE(regression)
auto file_contents = file.value()->read_all();
auto tokens = run_tokenizer(file_contents);
u32 hash = hash_tokens(tokens);
EXPECT_EQ(hash, 1280197787u);
EXPECT_EQ(hash, 3215459107u);
}
2 changes: 1 addition & 1 deletion Userland/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ Optional<HTMLToken> HTMLTokenizer::next_token()
DONT_CONSUME_NEXT_INPUT_CHARACTER;
if (consume_next_if_match("--")) {
create_new_token(HTMLToken::Type::Comment);
m_current_token.set_start_position({}, nth_last_position(4));
m_current_token.set_start_position({}, nth_last_position(3));
SWITCH_TO(CommentStart);
}
if (consume_next_if_match("DOCTYPE", CaseSensitivity::CaseInsensitive)) {
Expand Down

0 comments on commit fb5e267

Please sign in to comment.