From 15f85645e0ba8ca0508f45b01e1359f3f0d9bb90 Mon Sep 17 00:00:00 2001 From: Alexopus Date: Sun, 14 Jun 2026 10:05:00 +0200 Subject: [PATCH] Option to highlight commented lines --- web/js/highlighting/highlighter.js | 8 ++++++++ web/js/highlighting/tokenizer.js | 3 +++ web/js/settings.js | 15 +++++++++++++++ web/js/textbox/state.js | 9 ++++++++- 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/web/js/highlighting/highlighter.js b/web/js/highlighting/highlighter.js index a48615f..d6e6197 100644 --- a/web/js/highlighting/highlighter.js +++ b/web/js/highlighting/highlighter.js @@ -54,6 +54,9 @@ export class SyntaxHighlighter { style: { backgroundColor: errorColor }, })}${escapeHtml(token.value[1])}`; + case TokenType.COMMENT_LINE: + return this.processCommentLine(token); + case TokenType.EMBEDDING: return this.processEmbedding(token); @@ -76,6 +79,11 @@ export class SyntaxHighlighter { } } + processCommentLine(token) { + if (!config.commentHighlight) return escapeHtml(token.value); + return html("span", token.value, { style: { backgroundColor: config.commentColor } }); + } + processEmbedding(token) { const { colors, errorColor, validEmbeddings } = config; const embeddingName = token.value.split(":")[1]; diff --git a/web/js/highlighting/tokenizer.js b/web/js/highlighting/tokenizer.js index 851a389..21142ff 100644 --- a/web/js/highlighting/tokenizer.js +++ b/web/js/highlighting/tokenizer.js @@ -9,11 +9,13 @@ export const TokenType = { INVALID_ESCAPE: "invalid_escape", WILDCARD_OPEN: "wildcard_open", WILDCARD_CLOSE: "wildcard_close", + COMMENT_LINE: "comment_line", }; export class SyntaxTokenizer { constructor() { this.patterns = [ + { type: TokenType.COMMENT_LINE, regex: /^\s*#[^\n]*/gm }, { type: TokenType.ESCAPE, regex: /\\[()]/g }, { type: TokenType.INVALID_ESCAPE, regex: /\/[()]/g }, { type: TokenType.EMBEDDING, regex: /embedding:[^,\s]+/gi }, @@ -47,6 +49,7 @@ export class SyntaxTokenizer { matches.sort((a, b) => { if (a.start !== b.start) return a.start - b.start; const priority = { + comment_line: -1, escape: 0, invalid_escape: 1, paren_open: 2, diff --git a/web/js/settings.js b/web/js/settings.js index 98b2877..e65a3b5 100644 --- a/web/js/settings.js +++ b/web/js/settings.js @@ -38,6 +38,21 @@ const settingsDefinitions = [ type: SettingsHelper.ST.COLORPICKER, onChange: () => SettingsHelper.PresetOnChange.reloadSettings(), }, + { + name: "Comment Highlighting", + category: ["Syntax Highlighting", "Textbox", "CommentHighlighting"], + defaultValue: true, + tooltip: "Highlight lines starting with '#' as comments (e.g. Impact Pack comment syntax). Suppresses all other highlighting on that line.", + type: SettingsHelper.ST.BOOLEAN, + onChange: () => SettingsHelper.PresetOnChange.reloadSettings(), + }, + { + name: "Comment Color", + category: ["Syntax Highlighting", "Textbox", "CommentColor"], + defaultValue: "#6a9955", + type: SettingsHelper.ST.COLORPICKER, + onChange: () => SettingsHelper.PresetOnChange.reloadSettings(), + }, { name: "Tag Tooltips", category: ["Syntax Highlighting", "Textbox", "TextboxTooltips"], diff --git a/web/js/textbox/state.js b/web/js/textbox/state.js index ad49287..2d28b66 100644 --- a/web/js/textbox/state.js +++ b/web/js/textbox/state.js @@ -7,6 +7,8 @@ export class TextHighlightConfig { colors = null; wildcardColor = null; wildcardHighlight = true; + commentColor = null; + commentHighlight = true; highlightType = "nesting"; errorColor = "var(--error-text)"; @@ -25,10 +27,12 @@ export class TextHighlightConfig { } async #updateTextColors() { - const [customTextboxColors, rawWildcardColor, wildcardHighlight] = await Promise.all([ + const [customTextboxColors, rawWildcardColor, wildcardHighlight, rawCommentColor, commentHighlight] = await Promise.all([ settingsHelper.getSetting("Textbox Colors"), settingsHelper.getSetting("Wildcard Color"), settingsHelper.getSetting("Wildcard Highlighting"), + settingsHelper.getSetting("Comment Color"), + settingsHelper.getSetting("Comment Highlighting"), ]); this.highlightType = await settingsHelper.getSetting("Textbox Highlight Type"); this.colors = customTextboxColors @@ -37,6 +41,9 @@ export class TextHighlightConfig { this.wildcardColor = rawWildcardColor.charAt(0) === "#" ? hexToRgb(rawWildcardColor) : rawWildcardColor; this.wildcardHighlight = wildcardHighlight; + this.commentColor = + rawCommentColor.charAt(0) === "#" ? hexToRgb(rawCommentColor) : rawCommentColor; + this.commentHighlight = commentHighlight; } }