You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2019/06/04 15:14:36 UTC
[allura] branch master updated (e415651 -> 067d20b)
This is an automated email from the ASF dual-hosted git repository.
brondsem pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git.
from e415651 [#8288] remove remaining genshi references
new d93e213 [#8282] Add autocomplete list support to markdown editor for user mentions
new b50bce5 [#8282] Update licensing information
new 49dbcb5 [#8282] Add comment lines and improve Regex for matching -
new e8f054a [#8282] Check key name instead of keyCode
new 3c0179f [#8282] Display autocompletion when there is only one item in the list
new aa8d4c1 [#8282] Make autocomplete item filtering case insensitive
new 067d20b [#8282] make keypress check work in Edge too
The 7 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
Allura/LICENSE | 7 +-
Allura/allura/lib/widgets/form_fields.py | 4 +
.../allura/lib/widgets/resources/css/show-hint.css | 41 ++
.../allura/lib/widgets/resources/js/sf_markitup.js | 10 +
.../allura/lib/widgets/resources/js/show-hint.js | 460 +++++++++++++++++++++
.../widgets/resources/js/usermentions-helper.js | 60 +++
LICENSE | 7 +-
rat-excludes.txt | 2 +
8 files changed, 589 insertions(+), 2 deletions(-)
create mode 100644 Allura/allura/lib/widgets/resources/css/show-hint.css
create mode 100644 Allura/allura/lib/widgets/resources/js/show-hint.js
create mode 100644 Allura/allura/lib/widgets/resources/js/usermentions-helper.js
[allura] 05/07: [#8282] Display autocompletion when there is only
one item in the list
Posted by br...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
brondsem pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git
commit 3c0179f7a3c8fe4f31569274829cf71ef859d168
Author: Shalitha Suranga <sh...@gmail.com>
AuthorDate: Mon Jun 3 21:29:36 2019 +0530
[#8282] Display autocompletion when there is only one item in the list
---
Allura/allura/lib/widgets/resources/js/sf_markitup.js | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/Allura/allura/lib/widgets/resources/js/sf_markitup.js b/Allura/allura/lib/widgets/resources/js/sf_markitup.js
index 75da620..65d37a2 100644
--- a/Allura/allura/lib/widgets/resources/js/sf_markitup.js
+++ b/Allura/allura/lib/widgets/resources/js/sf_markitup.js
@@ -83,7 +83,9 @@ $(window).load(function() {
// user mentions support
editor.codemirror.on("keyup", function (cm, event) {
if(event.key == "@")
- CodeMirror.showHint(cm, CodeMirror.hint.alluraUserMentions);
+ CodeMirror.showHint(cm, CodeMirror.hint.alluraUserMentions, {
+ completeSingle: false
+ });
});
editor.render();
[allura] 06/07: [#8282] Make autocomplete item filtering case
insensitive
Posted by br...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
brondsem pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git
commit aa8d4c19b8607c9177fcc09c10aff8d8a138421c
Author: Shalitha Suranga <sh...@gmail.com>
AuthorDate: Mon Jun 3 21:34:17 2019 +0530
[#8282] Make autocomplete item filtering case insensitive
---
Allura/allura/lib/widgets/resources/js/usermentions-helper.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Allura/allura/lib/widgets/resources/js/usermentions-helper.js b/Allura/allura/lib/widgets/resources/js/usermentions-helper.js
index 97c3895..f53ee1b 100644
--- a/Allura/allura/lib/widgets/resources/js/usermentions-helper.js
+++ b/Allura/allura/lib/widgets/resources/js/usermentions-helper.js
@@ -47,7 +47,7 @@ CodeMirror.registerHelper('hint', 'alluraUserMentions', function (editor) {
if(curWord) {
// If there is current word set, We can filter out users from the main list and display them
userMentionList.forEach(function(item) {
- if(item.displayText.indexOf(curWord) != -1)
+ if(item.displayText.toLowerCase().indexOf(curWord.toLowerCase()) != -1)
list.push(item);
});
}
[allura] 07/07: [#8282] make keypress check work in Edge too
Posted by br...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
brondsem pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git
commit 067d20baa200687eb7c04f0e06340b6e8b5938c1
Author: Dave Brondsema <db...@slashdotmedia.com>
AuthorDate: Tue Jun 4 15:11:29 2019 +0000
[#8282] make keypress check work in Edge too
---
Allura/allura/lib/widgets/resources/js/sf_markitup.js | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/Allura/allura/lib/widgets/resources/js/sf_markitup.js b/Allura/allura/lib/widgets/resources/js/sf_markitup.js
index 65d37a2..ae47044 100644
--- a/Allura/allura/lib/widgets/resources/js/sf_markitup.js
+++ b/Allura/allura/lib/widgets/resources/js/sf_markitup.js
@@ -82,10 +82,11 @@ $(window).load(function() {
// user mentions support
editor.codemirror.on("keyup", function (cm, event) {
- if(event.key == "@")
+ if(event.key === "@" || (event.shiftKey && event.keyCode === 50 /* "2" key */)) {
CodeMirror.showHint(cm, CodeMirror.hint.alluraUserMentions, {
completeSingle: false
});
+ }
});
editor.render();
[allura] 01/07: [#8282] Add autocomplete list support to markdown
editor for user mentions
Posted by br...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
brondsem pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git
commit d93e213dc2b683ed332164d3028cf994c02b2fbf
Author: Shalitha Suranga <sh...@gmail.com>
AuthorDate: Sat May 25 21:19:55 2019 +0530
[#8282] Add autocomplete list support to markdown editor for user mentions
---
Allura/allura/lib/widgets/form_fields.py | 4 +
.../allura/lib/widgets/resources/css/show-hint.css | 36 ++
.../allura/lib/widgets/resources/js/sf_markitup.js | 7 +
.../allura/lib/widgets/resources/js/show-hint.js | 460 +++++++++++++++++++++
.../widgets/resources/js/usermentions-helper.js | 56 +++
5 files changed, 563 insertions(+)
diff --git a/Allura/allura/lib/widgets/form_fields.py b/Allura/allura/lib/widgets/form_fields.py
index 93d373e..7a5110a 100644
--- a/Allura/allura/lib/widgets/form_fields.py
+++ b/Allura/allura/lib/widgets/form_fields.py
@@ -280,8 +280,12 @@ class MarkdownEdit(ew.TextArea):
yield ew.JSLink('js/jquery.lightbox_me.js')
yield ew.CSSLink('css/simplemde.min.css', compress=False)
yield ew.CSSLink('css/markitup_sf.css')
+ yield ew.CSSLink('css/show-hint.css')
yield ew.JSLink('js/simplemde.min.js')
yield ew.JSLink('js/sf_markitup.js')
+ yield ew.JSLink('js/show-hint.js')
+ yield ew.JSLink('js/usermentions-helper.js')
+ yield onready('getProjectUsers(\'%s/users\')' % c.project.url())
class PageList(ew_core.Widget):
template = 'jinja:allura:templates/widgets/page_list.html'
diff --git a/Allura/allura/lib/widgets/resources/css/show-hint.css b/Allura/allura/lib/widgets/resources/css/show-hint.css
new file mode 100644
index 0000000..5617ccc
--- /dev/null
+++ b/Allura/allura/lib/widgets/resources/css/show-hint.css
@@ -0,0 +1,36 @@
+.CodeMirror-hints {
+ position: absolute;
+ z-index: 10;
+ overflow: hidden;
+ list-style: none;
+
+ margin: 0;
+ padding: 2px;
+
+ -webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
+ -moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
+ box-shadow: 2px 3px 5px rgba(0,0,0,.2);
+ border-radius: 3px;
+ border: 1px solid silver;
+
+ background: white;
+ font-size: 90%;
+ font-family: monospace;
+
+ max-height: 20em;
+ overflow-y: auto;
+}
+
+.CodeMirror-hint {
+ margin: 0;
+ padding: 0 4px;
+ border-radius: 2px;
+ white-space: pre;
+ color: black;
+ cursor: pointer;
+}
+
+li.CodeMirror-hint-active {
+ background: #08f;
+ color: white;
+}
diff --git a/Allura/allura/lib/widgets/resources/js/sf_markitup.js b/Allura/allura/lib/widgets/resources/js/sf_markitup.js
index cfc7c3f..dff5b10 100644
--- a/Allura/allura/lib/widgets/resources/js/sf_markitup.js
+++ b/Allura/allura/lib/widgets/resources/js/sf_markitup.js
@@ -79,6 +79,13 @@ $(window).load(function() {
// can't use simplemde's shortcuts settings, since those only hook into bindings set up for each button
editor.codemirror.options.extraKeys.Home = "goLineLeft";
editor.codemirror.options.extraKeys.End = "goLineRight";
+
+ // user mentions support
+ editor.codemirror.on("keyup", function (cm, event) {
+ if(event.shiftKey && event.keyCode == 50)
+ CodeMirror.showHint(cm, CodeMirror.hint.alluraUserMentions);
+ });
+
editor.render();
// shared at https://github.com/codemirror/CodeMirror/issues/2143#issuecomment-140100969
diff --git a/Allura/allura/lib/widgets/resources/js/show-hint.js b/Allura/allura/lib/widgets/resources/js/show-hint.js
new file mode 100644
index 0000000..0172cc8
--- /dev/null
+++ b/Allura/allura/lib/widgets/resources/js/show-hint.js
@@ -0,0 +1,460 @@
+// 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 HINT_ELEMENT_CLASS = "CodeMirror-hint";
+ var ACTIVE_HINT_ELEMENT_CLASS = "CodeMirror-hint-active";
+
+ // This is the old interface, kept around for now to stay
+ // backwards-compatible.
+ CodeMirror.showHint = function(cm, getHints, options) {
+ if (!getHints) return cm.showHint(options);
+ if (options && options.async) getHints.async = true;
+ var newOpts = {hint: getHints};
+ if (options) for (var prop in options) newOpts[prop] = options[prop];
+ return cm.showHint(newOpts);
+ };
+
+ CodeMirror.defineExtension("showHint", function(options) {
+ options = parseOptions(this, this.getCursor("start"), options);
+ var selections = this.listSelections()
+ if (selections.length > 1) return;
+ // By default, don't allow completion when something is selected.
+ // A hint function can have a `supportsSelection` property to
+ // indicate that it can handle selections.
+ if (this.somethingSelected()) {
+ if (!options.hint.supportsSelection) return;
+ // Don't try with cross-line selections
+ for (var i = 0; i < selections.length; i++)
+ if (selections[i].head.line != selections[i].anchor.line) return;
+ }
+
+ if (this.state.completionActive) this.state.completionActive.close();
+ var completion = this.state.completionActive = new Completion(this, options);
+ if (!completion.options.hint) return;
+
+ CodeMirror.signal(this, "startCompletion", this);
+ completion.update(true);
+ });
+
+ CodeMirror.defineExtension("closeHint", function() {
+ if (this.state.completionActive) this.state.completionActive.close()
+ })
+
+ function Completion(cm, options) {
+ this.cm = cm;
+ this.options = options;
+ this.widget = null;
+ this.debounce = 0;
+ this.tick = 0;
+ this.startPos = this.cm.getCursor("start");
+ this.startLen = this.cm.getLine(this.startPos.line).length - this.cm.getSelection().length;
+
+ var self = this;
+ cm.on("cursorActivity", this.activityFunc = function() { self.cursorActivity(); });
+ }
+
+ var requestAnimationFrame = window.requestAnimationFrame || function(fn) {
+ return setTimeout(fn, 1000/60);
+ };
+ var cancelAnimationFrame = window.cancelAnimationFrame || clearTimeout;
+
+ Completion.prototype = {
+ close: function() {
+ if (!this.active()) return;
+ this.cm.state.completionActive = null;
+ this.tick = null;
+ this.cm.off("cursorActivity", this.activityFunc);
+
+ if (this.widget && this.data) CodeMirror.signal(this.data, "close");
+ if (this.widget) this.widget.close();
+ CodeMirror.signal(this.cm, "endCompletion", this.cm);
+ },
+
+ active: function() {
+ return this.cm.state.completionActive == this;
+ },
+
+ pick: function(data, i) {
+ var completion = data.list[i];
+ if (completion.hint) completion.hint(this.cm, data, completion);
+ else this.cm.replaceRange(getText(completion), completion.from || data.from,
+ completion.to || data.to, "complete");
+ CodeMirror.signal(data, "pick", completion);
+ this.close();
+ },
+
+ cursorActivity: function() {
+ if (this.debounce) {
+ cancelAnimationFrame(this.debounce);
+ this.debounce = 0;
+ }
+
+ var pos = this.cm.getCursor(), line = this.cm.getLine(pos.line);
+ if (pos.line != this.startPos.line || line.length - pos.ch != this.startLen - this.startPos.ch ||
+ pos.ch < this.startPos.ch || this.cm.somethingSelected() ||
+ (!pos.ch || this.options.closeCharacters.test(line.charAt(pos.ch - 1)))) {
+ this.close();
+ } else {
+ var self = this;
+ this.debounce = requestAnimationFrame(function() {self.update();});
+ if (this.widget) this.widget.disable();
+ }
+ },
+
+ update: function(first) {
+ if (this.tick == null) return
+ var self = this, myTick = ++this.tick
+ fetchHints(this.options.hint, this.cm, this.options, function(data) {
+ if (self.tick == myTick) self.finishUpdate(data, first)
+ })
+ },
+
+ finishUpdate: function(data, first) {
+ if (this.data) CodeMirror.signal(this.data, "update");
+
+ var picked = (this.widget && this.widget.picked) || (first && this.options.completeSingle);
+ if (this.widget) this.widget.close();
+
+ this.data = data;
+
+ if (data && data.list.length) {
+ if (picked && data.list.length == 1) {
+ this.pick(data, 0);
+ } else {
+ this.widget = new Widget(this, data);
+ CodeMirror.signal(data, "shown");
+ }
+ }
+ }
+ };
+
+ function parseOptions(cm, pos, options) {
+ var editor = cm.options.hintOptions;
+ var out = {};
+ for (var prop in defaultOptions) out[prop] = defaultOptions[prop];
+ if (editor) for (var prop in editor)
+ if (editor[prop] !== undefined) out[prop] = editor[prop];
+ if (options) for (var prop in options)
+ if (options[prop] !== undefined) out[prop] = options[prop];
+ if (out.hint.resolve) out.hint = out.hint.resolve(cm, pos)
+ return out;
+ }
+
+ function getText(completion) {
+ if (typeof completion == "string") return completion;
+ else return completion.text;
+ }
+
+ function buildKeyMap(completion, handle) {
+ var baseMap = {
+ Up: function() {handle.moveFocus(-1);},
+ Down: function() {handle.moveFocus(1);},
+ PageUp: function() {handle.moveFocus(-handle.menuSize() + 1, true);},
+ PageDown: function() {handle.moveFocus(handle.menuSize() - 1, true);},
+ Home: function() {handle.setFocus(0);},
+ End: function() {handle.setFocus(handle.length - 1);},
+ Enter: handle.pick,
+ Tab: handle.pick,
+ Esc: handle.close
+ };
+
+ var mac = /Mac/.test(navigator.platform);
+
+ if (mac) {
+ baseMap["Ctrl-P"] = function() {handle.moveFocus(-1);};
+ baseMap["Ctrl-N"] = function() {handle.moveFocus(1);};
+ }
+
+ var custom = completion.options.customKeys;
+ var ourMap = custom ? {} : baseMap;
+ function addBinding(key, val) {
+ var bound;
+ if (typeof val != "string")
+ bound = function(cm) { return val(cm, handle); };
+ // This mechanism is deprecated
+ else if (baseMap.hasOwnProperty(val))
+ bound = baseMap[val];
+ else
+ bound = val;
+ ourMap[key] = bound;
+ }
+ if (custom)
+ for (var key in custom) if (custom.hasOwnProperty(key))
+ addBinding(key, custom[key]);
+ var extra = completion.options.extraKeys;
+ if (extra)
+ for (var key in extra) if (extra.hasOwnProperty(key))
+ addBinding(key, extra[key]);
+ return ourMap;
+ }
+
+ function getHintElement(hintsElement, el) {
+ while (el && el != hintsElement) {
+ if (el.nodeName.toUpperCase() === "LI" && el.parentNode == hintsElement) return el;
+ el = el.parentNode;
+ }
+ }
+
+ function Widget(completion, data) {
+ this.completion = completion;
+ this.data = data;
+ this.picked = false;
+ var widget = this, cm = completion.cm;
+ var ownerDocument = cm.getInputField().ownerDocument;
+ var parentWindow = ownerDocument.defaultView || ownerDocument.parentWindow;
+
+ var hints = this.hints = ownerDocument.createElement("ul");
+ var theme = completion.cm.options.theme;
+ hints.className = "CodeMirror-hints " + theme;
+ this.selectedHint = data.selectedHint || 0;
+
+ var completions = data.list;
+ for (var i = 0; i < completions.length; ++i) {
+ var elt = hints.appendChild(ownerDocument.createElement("li")), cur = completions[i];
+ var className = HINT_ELEMENT_CLASS + (i != this.selectedHint ? "" : " " + ACTIVE_HINT_ELEMENT_CLASS);
+ if (cur.className != null) className = cur.className + " " + className;
+ elt.className = className;
+ if (cur.render) cur.render(elt, data, cur);
+ else elt.appendChild(ownerDocument.createTextNode(cur.displayText || getText(cur)));
+ elt.hintId = i;
+ }
+
+ var container = completion.options.container || ownerDocument.body;
+ var pos = cm.cursorCoords(completion.options.alignWithWord ? data.from : null);
+ var left = pos.left, top = pos.bottom, below = true;
+ var offsetLeft = 0, offsetTop = 0;
+ if (container !== ownerDocument.body) {
+ // We offset the cursor position because left and top are relative to the offsetParent's top left corner.
+ var isContainerPositioned = ['absolute', 'relative', 'fixed'].indexOf(parentWindow.getComputedStyle(container).position) !== -1;
+ var offsetParent = isContainerPositioned ? container : container.offsetParent;
+ var offsetParentPosition = offsetParent.getBoundingClientRect();
+ var bodyPosition = ownerDocument.body.getBoundingClientRect();
+ offsetLeft = (offsetParentPosition.left - bodyPosition.left);
+ offsetTop = (offsetParentPosition.top - bodyPosition.top);
+ }
+ hints.style.left = (left - offsetLeft) + "px";
+ hints.style.top = (top - offsetTop) + "px";
+
+ // If we're at the edge of the screen, then we want the menu to appear on the left of the cursor.
+ var winW = parentWindow.innerWidth || Math.max(ownerDocument.body.offsetWidth, ownerDocument.documentElement.offsetWidth);
+ var winH = parentWindow.innerHeight || Math.max(ownerDocument.body.offsetHeight, ownerDocument.documentElement.offsetHeight);
+ container.appendChild(hints);
+ var box = hints.getBoundingClientRect(), overlapY = box.bottom - winH;
+ var scrolls = hints.scrollHeight > hints.clientHeight + 1
+ var startScroll = cm.getScrollInfo();
+
+ if (overlapY > 0) {
+ var height = box.bottom - box.top, curTop = pos.top - (pos.bottom - box.top);
+ if (curTop - height > 0) { // Fits above cursor
+ hints.style.top = (top = pos.top - height - offsetTop) + "px";
+ below = false;
+ } else if (height > winH) {
+ hints.style.height = (winH - 5) + "px";
+ hints.style.top = (top = pos.bottom - box.top - offsetTop) + "px";
+ var cursor = cm.getCursor();
+ if (data.from.ch != cursor.ch) {
+ pos = cm.cursorCoords(cursor);
+ hints.style.left = (left = pos.left - offsetLeft) + "px";
+ box = hints.getBoundingClientRect();
+ }
+ }
+ }
+ var overlapX = box.right - winW;
+ if (overlapX > 0) {
+ if (box.right - box.left > winW) {
+ hints.style.width = (winW - 5) + "px";
+ overlapX -= (box.right - box.left) - winW;
+ }
+ hints.style.left = (left = pos.left - overlapX - offsetLeft) + "px";
+ }
+ if (scrolls) for (var node = hints.firstChild; node; node = node.nextSibling)
+ node.style.paddingRight = cm.display.nativeBarWidth + "px"
+
+ cm.addKeyMap(this.keyMap = buildKeyMap(completion, {
+ moveFocus: function(n, avoidWrap) { widget.changeActive(widget.selectedHint + n, avoidWrap); },
+ setFocus: function(n) { widget.changeActive(n); },
+ menuSize: function() { return widget.screenAmount(); },
+ length: completions.length,
+ close: function() { completion.close(); },
+ pick: function() { widget.pick(); },
+ data: data
+ }));
+
+ if (completion.options.closeOnUnfocus) {
+ var closingOnBlur;
+ cm.on("blur", this.onBlur = function() { closingOnBlur = setTimeout(function() { completion.close(); }, 100); });
+ cm.on("focus", this.onFocus = function() { clearTimeout(closingOnBlur); });
+ }
+
+ cm.on("scroll", this.onScroll = function() {
+ var curScroll = cm.getScrollInfo(), editor = cm.getWrapperElement().getBoundingClientRect();
+ var newTop = top + startScroll.top - curScroll.top;
+ var point = newTop - (parentWindow.pageYOffset || (ownerDocument.documentElement || ownerDocument.body).scrollTop);
+ if (!below) point += hints.offsetHeight;
+ if (point <= editor.top || point >= editor.bottom) return completion.close();
+ hints.style.top = newTop + "px";
+ hints.style.left = (left + startScroll.left - curScroll.left) + "px";
+ });
+
+ CodeMirror.on(hints, "dblclick", function(e) {
+ var t = getHintElement(hints, e.target || e.srcElement);
+ if (t && t.hintId != null) {widget.changeActive(t.hintId); widget.pick();}
+ });
+
+ CodeMirror.on(hints, "click", function(e) {
+ var t = getHintElement(hints, e.target || e.srcElement);
+ if (t && t.hintId != null) {
+ widget.changeActive(t.hintId);
+ if (completion.options.completeOnSingleClick) widget.pick();
+ }
+ });
+
+ CodeMirror.on(hints, "mousedown", function() {
+ setTimeout(function(){cm.focus();}, 20);
+ });
+
+ CodeMirror.signal(data, "select", completions[this.selectedHint], hints.childNodes[this.selectedHint]);
+ return true;
+ }
+
+ Widget.prototype = {
+ close: function() {
+ if (this.completion.widget != this) return;
+ this.completion.widget = null;
+ this.hints.parentNode.removeChild(this.hints);
+ this.completion.cm.removeKeyMap(this.keyMap);
+
+ var cm = this.completion.cm;
+ if (this.completion.options.closeOnUnfocus) {
+ cm.off("blur", this.onBlur);
+ cm.off("focus", this.onFocus);
+ }
+ cm.off("scroll", this.onScroll);
+ },
+
+ disable: function() {
+ this.completion.cm.removeKeyMap(this.keyMap);
+ var widget = this;
+ this.keyMap = {Enter: function() { widget.picked = true; }};
+ this.completion.cm.addKeyMap(this.keyMap);
+ },
+
+ pick: function() {
+ this.completion.pick(this.data, this.selectedHint);
+ },
+
+ changeActive: function(i, avoidWrap) {
+ if (i >= this.data.list.length)
+ i = avoidWrap ? this.data.list.length - 1 : 0;
+ else if (i < 0)
+ i = avoidWrap ? 0 : this.data.list.length - 1;
+ if (this.selectedHint == i) return;
+ var node = this.hints.childNodes[this.selectedHint];
+ if (node) node.className = node.className.replace(" " + ACTIVE_HINT_ELEMENT_CLASS, "");
+ node = this.hints.childNodes[this.selectedHint = i];
+ node.className += " " + ACTIVE_HINT_ELEMENT_CLASS;
+ if (node.offsetTop < this.hints.scrollTop)
+ this.hints.scrollTop = node.offsetTop - 3;
+ else if (node.offsetTop + node.offsetHeight > this.hints.scrollTop + this.hints.clientHeight)
+ this.hints.scrollTop = node.offsetTop + node.offsetHeight - this.hints.clientHeight + 3;
+ CodeMirror.signal(this.data, "select", this.data.list[this.selectedHint], node);
+ },
+
+ screenAmount: function() {
+ return Math.floor(this.hints.clientHeight / this.hints.firstChild.offsetHeight) || 1;
+ }
+ };
+
+ function applicableHelpers(cm, helpers) {
+ if (!cm.somethingSelected()) return helpers
+ var result = []
+ for (var i = 0; i < helpers.length; i++)
+ if (helpers[i].supportsSelection) result.push(helpers[i])
+ return result
+ }
+
+ function fetchHints(hint, cm, options, callback) {
+ if (hint.async) {
+ hint(cm, callback, options)
+ } else {
+ var result = hint(cm, options)
+ if (result && result.then) result.then(callback)
+ else callback(result)
+ }
+ }
+
+ function resolveAutoHints(cm, pos) {
+ var helpers = cm.getHelpers(pos, "hint"), words
+ if (helpers.length) {
+ var resolved = function(cm, callback, options) {
+ var app = applicableHelpers(cm, helpers);
+ function run(i) {
+ if (i == app.length) return callback(null)
+ fetchHints(app[i], cm, options, function(result) {
+ if (result && result.list.length > 0) callback(result)
+ else run(i + 1)
+ })
+ }
+ run(0)
+ }
+ resolved.async = true
+ resolved.supportsSelection = true
+ return resolved
+ } else if (words = cm.getHelper(cm.getCursor(), "hintWords")) {
+ return function(cm) { return CodeMirror.hint.fromList(cm, {words: words}) }
+ } else if (CodeMirror.hint.anyword) {
+ return function(cm, options) { return CodeMirror.hint.anyword(cm, options) }
+ } else {
+ return function() {}
+ }
+ }
+
+ CodeMirror.registerHelper("hint", "auto", {
+ resolve: resolveAutoHints
+ });
+
+ CodeMirror.registerHelper("hint", "fromList", function(cm, options) {
+ var cur = cm.getCursor(), token = cm.getTokenAt(cur)
+ var term, from = CodeMirror.Pos(cur.line, token.start), to = cur
+ if (token.start < cur.ch && /\w/.test(token.string.charAt(cur.ch - token.start - 1))) {
+ term = token.string.substr(0, cur.ch - token.start)
+ } else {
+ term = ""
+ from = cur
+ }
+ var found = [];
+ for (var i = 0; i < options.words.length; i++) {
+ var word = options.words[i];
+ if (word.slice(0, term.length) == term)
+ found.push(word);
+ }
+
+ if (found.length) return {list: found, from: from, to: to};
+ });
+
+ CodeMirror.commands.autocomplete = CodeMirror.showHint;
+
+ var defaultOptions = {
+ hint: CodeMirror.hint.auto,
+ completeSingle: true,
+ alignWithWord: true,
+ closeCharacters: /[\s()\[\]{};:>,]/,
+ closeOnUnfocus: true,
+ completeOnSingleClick: true,
+ container: null,
+ customKeys: null,
+ extraKeys: null
+ };
+
+ CodeMirror.defineOption("hintOptions", null);
+});
diff --git a/Allura/allura/lib/widgets/resources/js/usermentions-helper.js b/Allura/allura/lib/widgets/resources/js/usermentions-helper.js
new file mode 100644
index 0000000..e0724d2
--- /dev/null
+++ b/Allura/allura/lib/widgets/resources/js/usermentions-helper.js
@@ -0,0 +1,56 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+*/
+
+var userMentionList;
+
+var getProjectUsers = function(users_url) {
+ $.get(users_url, function(data) {
+ userMentionList = data.options.map(function(item) {
+ return {
+ text: item.value,
+ displayText: item.label
+ };
+ });
+ });
+}
+
+CodeMirror.registerHelper('hint', 'alluraUserMentions', function (editor) {
+ var word = /[\w$]+/;
+ var cur = editor.getCursor(), curLine = editor.getLine(cur.line);
+ var tokenType = editor.getTokenTypeAt(cur);
+
+ if(!!tokenType && tokenType.indexOf('comment') != -1) // Disable um inside code
+ return;
+
+ var end = cur.ch, start = end;
+ while (start && word.test(curLine.charAt(start - 1))) --start;
+ var curWord = start != end && curLine.slice(start, end);
+ var list = [];
+ if(curWord) {
+ userMentionList.forEach(function(item) {
+ if(item.displayText.indexOf(curWord) != -1)
+ list.push(item);
+ });
+ }
+ else {
+ list = userMentionList.slice();
+ }
+
+ return { list: list, from: CodeMirror.Pos(cur.line, start), to: CodeMirror.Pos(cur.line, end) };
+});
\ No newline at end of file
[allura] 03/07: [#8282] Add comment lines and improve Regex for
matching -
Posted by br...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
brondsem pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git
commit 49dbcb54240681e71e36c0f237be109c2a675541
Author: Shalitha Suranga <sh...@gmail.com>
AuthorDate: Sun Jun 2 19:57:47 2019 +0530
[#8282] Add comment lines and improve Regex for matching -
---
Allura/allura/lib/widgets/resources/js/usermentions-helper.js | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/Allura/allura/lib/widgets/resources/js/usermentions-helper.js b/Allura/allura/lib/widgets/resources/js/usermentions-helper.js
index e0724d2..97c3895 100644
--- a/Allura/allura/lib/widgets/resources/js/usermentions-helper.js
+++ b/Allura/allura/lib/widgets/resources/js/usermentions-helper.js
@@ -31,7 +31,7 @@ var getProjectUsers = function(users_url) {
}
CodeMirror.registerHelper('hint', 'alluraUserMentions', function (editor) {
- var word = /[\w$]+/;
+ var word = /[\w-]+/;
var cur = editor.getCursor(), curLine = editor.getLine(cur.line);
var tokenType = editor.getTokenTypeAt(cur);
@@ -39,16 +39,20 @@ CodeMirror.registerHelper('hint', 'alluraUserMentions', function (editor) {
return;
var end = cur.ch, start = end;
+ // Find the starting position of currently typed word and set it to 'start' var
while (start && word.test(curLine.charAt(start - 1))) --start;
+ // Extract the current word from the current line using 'start' / 'end' value pair
var curWord = start != end && curLine.slice(start, end);
var list = [];
if(curWord) {
+ // If there is current word set, We can filter out users from the main list and display them
userMentionList.forEach(function(item) {
if(item.displayText.indexOf(curWord) != -1)
list.push(item);
});
}
else {
+ // Otherwise, we display the entire list
list = userMentionList.slice();
}
[allura] 04/07: [#8282] Check key name instead of keyCode
Posted by br...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
brondsem pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git
commit e8f054a66ced505c343756ef4e98bb3341264b59
Author: Shalitha Suranga <sh...@gmail.com>
AuthorDate: Mon Jun 3 21:11:58 2019 +0530
[#8282] Check key name instead of keyCode
---
Allura/allura/lib/widgets/resources/js/sf_markitup.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Allura/allura/lib/widgets/resources/js/sf_markitup.js b/Allura/allura/lib/widgets/resources/js/sf_markitup.js
index dff5b10..75da620 100644
--- a/Allura/allura/lib/widgets/resources/js/sf_markitup.js
+++ b/Allura/allura/lib/widgets/resources/js/sf_markitup.js
@@ -82,7 +82,7 @@ $(window).load(function() {
// user mentions support
editor.codemirror.on("keyup", function (cm, event) {
- if(event.shiftKey && event.keyCode == 50)
+ if(event.key == "@")
CodeMirror.showHint(cm, CodeMirror.hint.alluraUserMentions);
});
[allura] 02/07: [#8282] Update licensing information
Posted by br...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
brondsem pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git
commit b50bce51d82ed4c3aabe8011dad0bd63ba1fc729
Author: Shalitha Suranga <sh...@gmail.com>
AuthorDate: Sun Jun 2 19:04:51 2019 +0530
[#8282] Update licensing information
---
Allura/LICENSE | 7 ++++++-
Allura/allura/lib/widgets/resources/css/show-hint.css | 5 +++++
LICENSE | 7 ++++++-
rat-excludes.txt | 2 ++
4 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/Allura/LICENSE b/Allura/LICENSE
index 5501aeb..2895714 100644
--- a/Allura/LICENSE
+++ b/Allura/LICENSE
@@ -286,4 +286,9 @@ Sortable, which is available under the MIT license (https://github.com/RubaXa/So
allura/public/nf/js/Sortable.min.js
Foundation, which is available under the MIT license
- Allura/allura/public/nf/js/foundation.min.js
\ No newline at end of file
+ Allura/allura/public/nf/js/foundation.min.js
+
+Show-hint addon for CodeMirror library (https://codemirror.net/addon/hint/) is available under the MIT
+license. For details, see:
+ Allura/allura/lib/widgets/resources/js/show-hint.js
+ Allura/allura/lib/widgets/resources/css/show-hint.css
\ No newline at end of file
diff --git a/Allura/allura/lib/widgets/resources/css/show-hint.css b/Allura/allura/lib/widgets/resources/css/show-hint.css
index 5617ccc..1952002 100644
--- a/Allura/allura/lib/widgets/resources/css/show-hint.css
+++ b/Allura/allura/lib/widgets/resources/css/show-hint.css
@@ -1,3 +1,8 @@
+/*
+ CodeMirror, copyright (c) by Marijn Haverbeke and others
+ Distributed under an MIT license: https://codemirror.net/LICENSE
+*/
+
.CodeMirror-hints {
position: absolute;
z-index: 10;
diff --git a/LICENSE b/LICENSE
index 38dab44..85596c7 100644
--- a/LICENSE
+++ b/LICENSE
@@ -302,4 +302,9 @@ Sortable, which is available under the MIT license (https://github.com/RubaXa/So
Allura/allura/public/nf/js/Sortable.min.js
Foundation, which is available under the MIT license
- Allura/allura/public/nf/js/foundation.min.js
\ No newline at end of file
+ Allura/allura/public/nf/js/foundation.min.js
+
+Show-hint addon for CodeMirror library (https://codemirror.net/addon/hint/) is available under the MIT
+license. For details, see:
+ Allura/allura/lib/widgets/resources/js/show-hint.js
+ Allura/allura/lib/widgets/resources/css/show-hint.css
\ No newline at end of file
diff --git a/rat-excludes.txt b/rat-excludes.txt
index cce8487..52bdca8 100644
--- a/rat-excludes.txt
+++ b/rat-excludes.txt
@@ -19,11 +19,13 @@ Allura/allura/lib/widgets/resources/css/autocomplete.css
Allura/allura/lib/widgets/resources/css/colorPicker.css
Allura/allura/lib/widgets/resources/css/jqfontselector.css
Allura/allura/lib/widgets/resources/css/jquery.tagsinput.css
+Allura/allura/lib/widgets/resources/css/show-hint.css
Allura/allura/lib/widgets/resources/css/simplemde.min.css
Allura/allura/lib/widgets/resources/js/jqfontselector.js
Allura/allura/lib/widgets/resources/js/jquery.autosize-min.js
Allura/allura/lib/widgets/resources/js/jquery.colorPicker.js
Allura/allura/lib/widgets/resources/js/jquery.tagsinput.js
+Allura/allura/lib/widgets/resources/js/show-hint.js
Allura/allura/lib/widgets/resources/js/simplemde.min.js
Allura/allura/nf/responsive/scss/_settings.scss
Allura/allura/public/nf/css/blueprint/