Tweak highlighting for keywords
All checks were successful
timw4mail/scroll/pipeline/head This commit looks good

This commit is contained in:
Timothy Warren 2024-07-19 15:55:16 -04:00
parent 21d26ede6c
commit 6101132a15
2 changed files with 14 additions and 5 deletions

View File

@ -117,6 +117,9 @@ export class JavaScriptFile extends AbstractFileType {
'^', '^',
'~', '~',
'!', '!',
'.',
',',
';',
]; ];
public readonly hlOptions: HighlightingOptions = { public readonly hlOptions: HighlightingOptions = {
...defaultHighlightOptions, ...defaultHighlightOptions,

View File

@ -443,12 +443,18 @@ export class Row {
} }
for (const keyword of keywords) { for (const keyword of keywords) {
if (i + strlen(keyword) < this.rsize) { // Skip keywords that can't fit in the current line
if (i + strlen(keyword) >= this.rsize) {
continue;
}
// Check the character after the keyword
// if it is not a 'separator' character,
// we must be highlighting the middle of something else
const nextChar = this.rchars[i + strlen(keyword)]; const nextChar = this.rchars[i + strlen(keyword)];
if (!isSeparator(nextChar)) { if (!isSeparator(nextChar)) {
continue; continue;
} }
}
const maybeHighlight = this.highlightStr(i, keyword, hl_type); const maybeHighlight = this.highlightStr(i, keyword, hl_type);
if (maybeHighlight.isSome()) { if (maybeHighlight.isSome()) {