Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
add detailed comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bomsy committed Nov 3, 2016
1 parent 8e3a82a commit 947814e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions public/js/utils/source-search.js
Expand Up @@ -33,7 +33,19 @@ function getSearchCursor(cm, query, pos) {
typeof query == "string" && query == query.toLowerCase());
}

/**
* This returns a mode object used by CoeMirror's addOverlay function
* to parse and style tokens in the file.
* The mode object contains a tokenizer function (token) which takes
* a character stream as input, advances it past a token, and returns
* a style for that token. For more details see
* https://codemirror.net/doc/manual.html#modeapi
*
* @memberof utils/source-search
* @static
*/
function searchOverlay(query) {
// escape special characters
query = query.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
query = new RegExp(query === "" ? "(?!\s*.*)" : query, "g");
return {
Expand All @@ -52,6 +64,10 @@ function searchOverlay(query) {
};
}

/**
* @memberof utils/source-search
* @static
*/
function startSearch(cm, state, query) {
cm.removeOverlay(state.overlay);
state.overlay = searchOverlay(query);
Expand Down

0 comments on commit 947814e

Please sign in to comment.