Get title suggestion based on poll's description
This commit is contained in:
parent
91381ca77d
commit
8e1f15e88d
@ -61,6 +61,46 @@ define([
|
|||||||
editor.scrollTo(scroll.left, scroll.top);
|
editor.scrollTo(scroll.left, scroll.top);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.getHeadingText = function (editor) {
|
||||||
|
var lines = editor.getValue().split(/\n/);
|
||||||
|
|
||||||
|
var text = '';
|
||||||
|
lines.some(function (line) {
|
||||||
|
// lines including a c-style comment are also valuable
|
||||||
|
var clike = /^\s*(\/\*|\/\/)(.*)?(\*\/)*$/;
|
||||||
|
if (clike.test(line)) {
|
||||||
|
line.replace(clike, function (a, one, two) {
|
||||||
|
if (!(two && two.replace)) { return; }
|
||||||
|
text = two.replace(/\*\/\s*$/, '').trim();
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// lisps?
|
||||||
|
var lispy = /^\s*(;|#\|)+(.*?)$/;
|
||||||
|
if (lispy.test(line)) {
|
||||||
|
line.replace(lispy, function (a, one, two) {
|
||||||
|
text = two;
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// lines beginning with a hash are potentially valuable
|
||||||
|
// works for markdown, python, bash, etc.
|
||||||
|
var hash = /^#+(.*?)$/;
|
||||||
|
if (hash.test(line)) {
|
||||||
|
line.replace(hash, function (a, one) {
|
||||||
|
text = one;
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO make one more pass for multiline comments
|
||||||
|
});
|
||||||
|
|
||||||
|
return text.trim();
|
||||||
|
};
|
||||||
|
|
||||||
module.create = function (Common, defaultMode, CMeditor) {
|
module.create = function (Common, defaultMode, CMeditor) {
|
||||||
var exp = {};
|
var exp = {};
|
||||||
var Messages = Cryptpad.Messages;
|
var Messages = Cryptpad.Messages;
|
||||||
@ -151,43 +191,7 @@ define([
|
|||||||
}());
|
}());
|
||||||
|
|
||||||
exp.getHeadingText = function () {
|
exp.getHeadingText = function () {
|
||||||
var lines = editor.getValue().split(/\n/);
|
return module.getHeadingText(editor);
|
||||||
|
|
||||||
var text = '';
|
|
||||||
lines.some(function (line) {
|
|
||||||
// lines including a c-style comment are also valuable
|
|
||||||
var clike = /^\s*(\/\*|\/\/)(.*)?(\*\/)*$/;
|
|
||||||
if (clike.test(line)) {
|
|
||||||
line.replace(clike, function (a, one, two) {
|
|
||||||
if (!(two && two.replace)) { return; }
|
|
||||||
text = two.replace(/\*\/\s*$/, '').trim();
|
|
||||||
});
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// lisps?
|
|
||||||
var lispy = /^\s*(;|#\|)+(.*?)$/;
|
|
||||||
if (lispy.test(line)) {
|
|
||||||
line.replace(lispy, function (a, one, two) {
|
|
||||||
text = two;
|
|
||||||
});
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// lines beginning with a hash are potentially valuable
|
|
||||||
// works for markdown, python, bash, etc.
|
|
||||||
var hash = /^#+(.*?)$/;
|
|
||||||
if (hash.test(line)) {
|
|
||||||
line.replace(hash, function (a, one) {
|
|
||||||
text = one;
|
|
||||||
});
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO make one more pass for multiline comments
|
|
||||||
});
|
|
||||||
|
|
||||||
return text.trim();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
exp.configureLanguage = function (cb, onModeChanged) {
|
exp.configureLanguage = function (cb, onModeChanged) {
|
||||||
|
|||||||
@ -998,6 +998,11 @@ define([
|
|||||||
Cryptpad.findOKButton().click();
|
Cryptpad.findOKButton().click();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var getHeadingText = function () {
|
||||||
|
if (!APP.editor) { return; }
|
||||||
|
return SframeCM.getHeadingText(APP.editor);
|
||||||
|
};
|
||||||
|
|
||||||
var onCreate = function (info) {
|
var onCreate = function (info) {
|
||||||
APP.myID = info.myID;
|
APP.myID = info.myID;
|
||||||
|
|
||||||
@ -1011,7 +1016,8 @@ define([
|
|||||||
|
|
||||||
metadataMgr = common.getMetadataMgr();
|
metadataMgr = common.getMetadataMgr();
|
||||||
|
|
||||||
Title = common.createTitle();
|
var titleCfg = { getHeadingText: getHeadingText };
|
||||||
|
Title = common.createTitle(titleCfg);
|
||||||
|
|
||||||
var configTb = {
|
var configTb = {
|
||||||
displayed: ['title', 'useradmin', 'spinner', 'share', 'userlist', 'newpad', 'limit'],
|
displayed: ['title', 'useradmin', 'spinner', 'share', 'userlist', 'newpad', 'limit'],
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user