New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Take into account wordboundaries for custom highlighting #1358
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if referencing module.exports here is okay. If not, let me know! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if doing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a great point, it probably does. I was wondering why > JSON.stringify({ foo: 'bar', test() { return 'foo'; }, regex: new RegExp("test") })
'{"foo":"bar","regex":{}}' Kinda sucks that we do @xPaw, what do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exporting under a separate object is probably the cleanest way of doing it. Or making a I have also found other unintentional variable that would be stored: https://github.com/thelounge/lounge/blob/0b85582744be6671c96c185866171798af4eead9/client/js/sorting.js#L33 |
||
} else { | ||
module.exports.highlightsRE = null; | ||
} | ||
} else if (name === "showSeconds") { | ||
chat.find(".msg > .time").each(function() { | ||
$(this).text(tz($(this).parent().data("time"))); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before we merge, gotta test if this actually only brings the relevant function, or half of lodash with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It adds nothing to the size because client/js/libs/handlebars/ircmessageparser/findChannels.js already has a reference to it.