Skip to content

Commit

Permalink
website - add clickable-links to editor-code in report-warnings and r…
Browse files Browse the repository at this point in the history
…eport-functions (#368)

* Go to line warning

* Go to line: functions

* Removed old comment

* - website - add clickable-links to editor-code in report-warnings and report-functions

Co-authored-by: Kai Zhu <kaizhu256@gmail.com>
  • Loading branch information
unrealapex and kaizhu256 committed Oct 26, 2021
1 parent 12b67eb commit ad5be88
Show file tree
Hide file tree
Showing 5 changed files with 232 additions and 88 deletions.
4 changes: 2 additions & 2 deletions .ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ import moduleFs from "fs";
}, {
file: "index.html",
src: fileDict["index.html"].replace((
/\n<style\sclass="JSLINT_REPORT_STYLE">\n[\S\s]*?\n<\/style>\n/
/\n<style class="JSLINT_REPORT_STYLE">\n[\S\s]*?\n<\/style>\n/
), function () {
return fileDict["jslint.mjs"].match(
/\n<style\sclass="JSLINT_REPORT_STYLE">\n[\S\s]*?\n<\/style>\n/
/\n<style class="JSLINT_REPORT_STYLE">\n[\S\s]*?\n<\/style>\n/
)[0];
})
}, {
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
- jslint - try to improve parser to be able to parse jquery.js without stopping.
- jslint - unify analysis of variable-assignment/function-parameters into one function
- node - after node-v14 is deprecated, remove shell-code `export "NODE_OPTIONS=--unhandled-rejections=strict"`.
- perf - improve performance by hoisting inlined regexps out of loops and subfunctions

# v2021.11.1-beta
- ci - deprecate/remove jslint.cjs from ci
- website - add clickable-links to editor-code in report-warnings and report-functions

# v2021.10.20
- ci - add release-trigger to publish to `@jslint-org/jslint`
Expand Down
80 changes: 80 additions & 0 deletions asset_codemirror_rollup.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ shRawLibFetch
{
"url": "https://github.com/codemirror/CodeMirror/blob/5.62.0/addon/lint/lint.js"
},
{
"url": "https://github.com/codemirror/CodeMirror/blob/5.62.0/addon/selection/active-line.js"
},
{
"url": "https://github.com/codemirror/CodeMirror/blob/5.62.0/mode/javascript/javascript.js"
}
Expand Down Expand Up @@ -10360,6 +10363,83 @@ file https://github.com/codemirror/CodeMirror/blob/5.62.0/addon/lint/lint.js
});


/*
file https://github.com/codemirror/CodeMirror/blob/5.62.0/addon/selection/active-line.js
*/
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: https://codemirror.net/LICENSE

(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
var WRAP_CLASS = "CodeMirror-activeline";
var BACK_CLASS = "CodeMirror-activeline-background";
var GUTT_CLASS = "CodeMirror-activeline-gutter";

CodeMirror.defineOption("styleActiveLine", false, function(cm, val, old) {
var prev = old == CodeMirror.Init ? false : old;
if (val == prev) return
if (prev) {
cm.off("beforeSelectionChange", selectionChange);
clearActiveLines(cm);
delete cm.state.activeLines;
}
if (val) {
cm.state.activeLines = [];
updateActiveLines(cm, cm.listSelections());
cm.on("beforeSelectionChange", selectionChange);
}
});

function clearActiveLines(cm) {
for (var i = 0; i < cm.state.activeLines.length; i++) {
cm.removeLineClass(cm.state.activeLines[i], "wrap", WRAP_CLASS);
cm.removeLineClass(cm.state.activeLines[i], "background", BACK_CLASS);
cm.removeLineClass(cm.state.activeLines[i], "gutter", GUTT_CLASS);
}
}

function sameArray(a, b) {
if (a.length != b.length) return false;
for (var i = 0; i < a.length; i++)
if (a[i] != b[i]) return false;
return true;
}

function updateActiveLines(cm, ranges) {
var active = [];
for (var i = 0; i < ranges.length; i++) {
var range = ranges[i];
var option = cm.getOption("styleActiveLine");
if (typeof option == "object" && option.nonEmpty ? range.anchor.line != range.head.line : !range.empty())
continue
var line = cm.getLineHandleVisualStart(range.head.line);
if (active[active.length - 1] != line) active.push(line);
}
if (sameArray(cm.state.activeLines, active)) return;
cm.operation(function() {
clearActiveLines(cm);
for (var i = 0; i < active.length; i++) {
cm.addLineClass(active[i], "wrap", WRAP_CLASS);
cm.addLineClass(active[i], "background", BACK_CLASS);
cm.addLineClass(active[i], "gutter", GUTT_CLASS);
}
cm.state.activeLines = active;
});
}

function selectionChange(cm, sel) {
updateActiveLines(cm, sel.ranges);
}
});


/*
file https://github.com/codemirror/CodeMirror/blob/5.62.0/mode/javascript/javascript.js
*/
Expand Down
Loading

0 comments on commit ad5be88

Please sign in to comment.