mirror of
https://github.com/thelounge/thelounge
synced 2025-02-16 21:28:23 +00:00
Merge pull request #1358 from starquake/highlight-wordboundary
Take into account wordboundaries for custom highlighting
This commit is contained in:
commit
3b79a3df90
2 changed files with 15 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
|||
"use strict";
|
||||
|
||||
const $ = require("jquery");
|
||||
const escapeRegExp = require("lodash/escapeRegExp");
|
||||
const settings = $("#settings");
|
||||
const userStyles = $("#user-specified-css");
|
||||
const storage = require("./localStorage");
|
||||
|
@ -98,6 +99,15 @@ settings.on("change", "input, select, textarea", function() {
|
|||
// otherwise, users get notifications for everything
|
||||
return h !== "";
|
||||
});
|
||||
// Construct regex with wordboundary for every highlight item
|
||||
const highlightsTokens = options.highlights.map(function(h) {
|
||||
return escapeRegExp(h);
|
||||
});
|
||||
if (highlightsTokens && highlightsTokens.length) {
|
||||
module.exports.highlightsRE = new RegExp("\\b(?:" + highlightsTokens.join("|") + ")\\b", "i");
|
||||
} else {
|
||||
module.exports.highlightsRE = null;
|
||||
}
|
||||
} else if (name === "showSeconds") {
|
||||
chat.find(".msg > .time").each(function() {
|
||||
$(this).text(tz($(this).parent().data("time")));
|
||||
|
|
|
@ -73,9 +73,11 @@ function buildChatMessage(data) {
|
|||
const chan = chat.find(target);
|
||||
let template = "msg";
|
||||
|
||||
if (!data.msg.highlight && !data.msg.self && (type === "message" || type === "notice") && options.highlights.some(function(h) {
|
||||
return data.msg.text.toLocaleLowerCase().indexOf(h.toLocaleLowerCase()) > -1;
|
||||
})) {
|
||||
// See if any of the custom highlight regexes match
|
||||
if (!data.msg.highlight && !data.msg.self
|
||||
&& options.highlightsRE
|
||||
&& (type === "message" || type === "notice")
|
||||
&& options.highlightsRE.exec(data.msg.text)) {
|
||||
data.msg.highlight = true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue