The Unified and Autonomous Development Platform
Polish a little bit about source view styling.
robin shine4d51a2dd5799
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/CodeMirrorResourceReference.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/CodeMirrorResourceReference.javaindex cdeb71ad35..956f5c24e0 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/CodeMirrorResourceReference.java+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/CodeMirrorResourceReference.java@@ -43,10 +43,11 @@ public class CodeMirrorResourceReference extends WebjarsJavaScriptResourceRefereJavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/addon/search/searchcursor.js")),JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/addon/search/search.js")),JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/addon/search/matchesonscrollbar.js")),+ JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/addon/selection/active-line.js")),+ JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/addon/selection/mark-selection.js")),JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/addon/scroll/annotatescrollbar.js")),- JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/addon/scroll/simplescrollbars.js")),- JavaScriptHeaderItem.forReference(new JavaScriptResourceReference(CodeMirrorResourceReference.class, "match-highlighter.js")),+ JavaScriptHeaderItem.forReference(new JavaScriptResourceReference(CodeMirrorResourceReference.class, "identifier-highlighter.js")),CssHeaderItem.forReference(new WebjarsCssResourceReference("codemirror/current/lib/codemirror.css")),CssHeaderItem.forReference(new WebjarsCssResourceReference("codemirror/current/addon/dialog/dialog.css")),diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/codemirror.css b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/codemirror.cssindex 7009fec9ff..2b38d50539 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/codemirror.css+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/codemirror.css@@ -1,6 +1,5 @@-.CodeMirror-focused .cm-matchhighlight {background: #CCC;}-.CodeMirror-simplescroll-horizontal {height: 12px;}-.CodeMirror-simplescroll-vertical {width: 12px;}-.CodeMirror-simplescroll-horizontal div, .CodeMirror-simplescroll-vertical div {- background: none repeat scroll 0 0 #bbb; border: 1px solid #aaa;}-.cm-s-eclipse .CodeMirror-matchingbracket {outline: none; color: black !important; font-weight: bold;}\ No newline at end of file+.cm-identifierhighlight {background: #D4D4D4;}+.CodeMirror-selected {background-color: #3399FF !important;}+.CodeMirror-selectedtext {color: white !important;}+.cm-s-eclipse .CodeMirror-matchingbracket {outline: none; color: black !important; font-weight: bold;}+.cm-s-eclipse span.cm-meta {color: #888;}diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/identifier-highlighter.js b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/identifier-highlighter.jsnew file mode 100644index 0000000000..1569486b3e--- /dev/null+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/identifier-highlighter.js@@ -0,0 +1,108 @@+// CodeMirror, copyright (c) by Marijn Haverbeke and others+// Distributed under an MIT license: http://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 DEFAULT_TOKEN_STYLE = "identifierhighlight";+ var DEFAULT_DELAY = 100;++ function State(options) {+ if (typeof options == "object") {+ this.style = options.style;+ this.delay = options.delay;+ }+ if (this.style == null)+ this.style = DEFAULT_TOKEN_STYLE;+ if (this.delay == null)+ this.delay = DEFAULT_DELAY;+ this.overlay = this.timeout = null;+ }++ CodeMirror.defineOption("highlightIdentifiers", false, function(cm, val, old) {+ if (old && old != CodeMirror.Init) {+ var over = cm.state.identifierHighlighter.overlay;+ if (over)+ cm.removeOverlay(over);+ clearTimeout(cm.state.identifierHighlighter.timeout);+ cm.state.identifierHighlighter = null;+ cm.off("cursorActivity", cursorActivity);+ }+ if (val) {+ cm.state.identifierHighlighter = new State(val);+ highlightIdentifiers(cm);+ cm.on("cursorActivity", cursorActivity);+ }+ });++ function cursorActivity(cm) {+ var state = cm.state.identifierHighlighter;+ clearTimeout(state.timeout);+ state.timeout = setTimeout(function() {highlightIdentifiers(cm);}, state.delay);+ }++ function highlightIdentifiers(cm) {+ cm.operation(function() {+ var state = cm.state.identifierHighlighter;+ if (state.overlay) {+ cm.removeOverlay(state.overlay);+ state.overlay = null;+ }+ if (!cm.somethingSelected()) {+ clearScrollbarMatches(state);+ if (CodeMirror.commands.clearSearch)+ CodeMirror.commands.clearSearch(cm);+ var re = /[\w$]/;+ var cur = cm.getCursor(), line = cm.getLine(cur.line), start = cur.ch, end = start;+ while (start && re.test(line.charAt(start - 1))) --start;+ while (end < line.length && re.test(line.charAt(end))) ++end;+ if (start < end) {+ var tokenType = cm.getTokenTypeAt(new CodeMirror.Pos(cur.line, (start+end)/2));+ if (tokenType != null) {+ if (tokenType.indexOf("variable") > -1+ || tokenType.indexOf("property") > -1+ || tokenType.indexOf("def") > -1) {+ var query = line.slice(start, end);+ cm.addOverlay(state.overlay = makeOverlay(query, re, state.style));++ if (cm.showMatchesOnScrollbar) {+ clearScrollbarMatches(state);++ var queryRe = new RegExp("\\b" + query + "\\b");+ state.annotate = cm.showMatchesOnScrollbar(queryRe, false);+ }+ }+ }+ }+ }+ });+ }++ function clearScrollbarMatches(state) {+ if (state.annotate) {+ state.annotate.clear();+ state.annotate = null;+ }+ }++ function boundariesAround(stream, re) {+ return (!stream.start || !re.test(stream.string.charAt(stream.start - 1))) &&+ (stream.pos == stream.string.length || !re.test(stream.string.charAt(stream.pos)));+ }++ function makeOverlay(query, hasBoundary, style) {+ return {token: function(stream) {+ if (stream.match(query) && (!hasBoundary || boundariesAround(stream, hasBoundary)))+ return style;+ stream.next();+ stream.skipTo(query.charAt(0)) || stream.skipToEnd();+ }};+ }+});diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/match-highlighter.js b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/match-highlighter.jsdeleted file mode 100644index 75999f1106..0000000000--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/match-highlighter.js+++ /dev/null@@ -1,140 +0,0 @@-// CodeMirror, copyright (c) by Marijn Haverbeke and others-// Distributed under an MIT license: http://codemirror.net/LICENSE--// Highlighting text that matches the selection-//-// Defines an option highlightSelectionMatches, which, when enabled,-// will style strings that match the selection throughout the-// document.-//-// The option can be set to true to simply enable it, or to a-// {minChars, style, wordsOnly, showToken, delay} object to explicitly-// configure it. minChars is the minimum amount of characters that should be-// selected for the behavior to occur, and style is the token style to-// apply to the matches. This will be prefixed by "cm-" to create an-// actual CSS class name. If wordsOnly is enabled, the matches will be-// highlighted only if the selected text is a word. showToken, when enabled,-// will cause the current token to be highlighted when nothing is selected.-// delay is used to specify how much time to wait, in milliseconds, before-// highlighting the matches.--(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 DEFAULT_MIN_CHARS = 2;- var DEFAULT_TOKEN_STYLE = "matchhighlight";- var DEFAULT_DELAY = 100;- var DEFAULT_WORDS_ONLY = false;-- function State(options) {- if (typeof options == "object") {- this.minChars = options.minChars;- this.style = options.style;- this.showToken = options.showToken;- this.delay = options.delay;- this.wordsOnly = options.wordsOnly;- }- if (this.style == null)- this.style = DEFAULT_TOKEN_STYLE;- if (this.minChars == null)- this.minChars = DEFAULT_MIN_CHARS;- if (this.delay == null)- this.delay = DEFAULT_DELAY;- if (this.wordsOnly == null)- this.wordsOnly = DEFAULT_WORDS_ONLY;- this.overlay = this.timeout = null;- }-- CodeMirror.defineOption("highlightSelectionMatches", false, function(cm, val, old) {- if (old && old != CodeMirror.Init) {- var over = cm.state.matchHighlighter.overlay;- if (over)- cm.removeOverlay(over);- clearTimeout(cm.state.matchHighlighter.timeout);- cm.state.matchHighlighter = null;- cm.off("cursorActivity", cursorActivity);- }- if (val) {- cm.state.matchHighlighter = new State(val);- highlightMatches(cm);- cm.on("cursorActivity", cursorActivity);- }- });-- function cursorActivity(cm) {- var state = cm.state.matchHighlighter;- clearTimeout(state.timeout);- state.timeout = setTimeout(function() {highlightMatches(cm);}, state.delay);- }-- function highlightMatches(cm) {- cm.operation(function() {- var state = cm.state.matchHighlighter;- if (state.overlay) {- cm.removeOverlay(state.overlay);- state.overlay = null;- }- if (!cm.somethingSelected() && state.showToken) {- if (state.annotate) {- state.annotate.clear();- state.annotate = null;- }- if (CodeMirror.commands.clearSearch)- CodeMirror.commands.clearSearch(cm);- var re = state.showToken === true ? /[\w$]/ : state.showToken;- var cur = cm.getCursor(), line = cm.getLine(cur.line), start = cur.ch, end = start;- while (start && re.test(line.charAt(start - 1))) --start;- while (end < line.length && re.test(line.charAt(end))) ++end;- if (start < end) {- var query = line.slice(start, end);- cm.addOverlay(state.overlay = makeOverlay(query, re, state.style));-- if (cm.showMatchesOnScrollbar) {- if (state.annotate) { state.annotate.clear(); state.annotate = null; }- state.annotate = cm.showMatchesOnScrollbar(query, false);- }- }- }- });- }-- function isWord(cm, from, to) {- var str = cm.getRange(from, to);- if (str.match(/^\w+$/) !== null) {- if (from.ch > 0) {- var pos = {line: from.line, ch: from.ch - 1};- var chr = cm.getRange(pos, from);- if (chr.match(/\W/) === null) return false;- }- if (to.ch < cm.getLine(from.line).length) {- var pos = {line: to.line, ch: to.ch + 1};- var chr = cm.getRange(to, pos);- if (chr.match(/\W/) === null) return false;- }- return true;- } else {- return false;- }- }-- function boundariesAround(stream, re) {- return (!stream.start || !re.test(stream.string.charAt(stream.start - 1))) &&- (stream.pos == stream.string.length || !re.test(stream.string.charAt(stream.pos)));- }-- function makeOverlay(query, hasBoundary, style) {- return {token: function(stream) {- if (stream.match(query) && (!hasBoundary || boundariesAround(stream, hasBoundary)))- return style;- stream.next();- stream.skipTo(query.charAt(0)) || stream.skipToEnd();- }};- }-});diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceview/source-view.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceview/source-view.jsindex 58385c7037..41559ec427 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceview/source-view.js+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceview/source-view.js@@ -13,14 +13,15 @@ gitplex.sourceview = {var $code = $("#" + codeId);var options = {value: fileContent,- readOnly: true,+ readOnly: false,theme: "eclipse",lineNumbers: true,lineWrapping: true,+ styleActiveLine: true,+ styleSelectedText: true,foldGutter: true,matchBrackets: true,- scrollbarStyle: "simple",- highlightSelectionMatches: {showToken: /\w/, delay: 300},+ highlightIdentifiers: {delay: 300},gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"]};var editor = CodeMirror($code[0], options);