-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathcreateEditor.js
More file actions
70 lines (67 loc) · 2.73 KB
/
createEditor.js
File metadata and controls
70 lines (67 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
ace.define('antlr4/index', function (require, exports, module) { module.exports = algorithm.antlr4; });
ace.config.setModuleUrl('ace/mode/my-mode', 'my-mode.js');
ace.config.setModuleUrl('ace/worker/my-worker', 'my-worker.js');
ace.mymodeFirstCreate = true;
ace.jsmodeFirstCreate = true;
window.createEditor = function (id, outId) {
var editor = ace.edit(id);
editor.getSession().setMode('ace/mode/my-mode');
editor.setTheme("ace/theme/crimson_editor");
editor.setOptions({
'showLineNumbers': false,
'fontSize': 14,
'wrapBehavioursEnabled': false,
'enableLiveAutocompletion': true,
'indentedSoftWrap': false,
'printMargin': false,
'showFoldWidgets': false,
'dragEnabled': false,
'indentedSoftWrap': false,
'highlightActiveLine': false,
'autoScrollEditorIntoView': true,
'enableBasicAutocompletion': true,
'maxLines': 100,
})
editor.setShowPrintMargin(false);
editor.renderer.setScrollMargin(5, 6, 5, 9);
var session = editor.getSession();
session.setUseWrapMode(false);
if (ace.mymodeFirstCreate) {
ace.mymodeFirstCreate = false;
var langTools = ace.require("ace/ext/language_tools");
var rhymeCompleter = {
getCompletions: function (editor, session, pos, prefix, callback) {
if (editor.getSession().getMode().$id != 'ace/mode/my-mode') { callback(null, []); return }
if (prefix.length === 0) { callback(null, []); return }
callback(null, ace_keywords.map(function (ea) { return { caption: ea.caption, pinyin: ea.pinyin, name: ea.text, value: ea.text, meta: ea.meta } }));
}
}
langTools.addCompleter(rhymeCompleter);
}
editor.setValue($("#" + outId).val());
editor.getSession().on('change', function (e) { $("#" + outId).val(editor.getValue()); });
editor.gotoLine(0);
}
var stringWidth = function (fontSize, content) {
var $span = $('<span></span>').hide().css('font-size', fontSize).text(content);
var w = $span.appendTo('body').width();
$span.remove();
return w;
};
window.jhcAutoWidth = function () {
$('.ace_autocomplete').each(function () {
if ($(this).is(":hidden")) return true;
var jige = $(this).find('.ace_line').length;
if (jige < 1) return '';
var maxText = '';
for (var i = 0; i < jige; i++) {
var nowText = $(this).find('.ace_line').eq(i).text();
if (nowText.length > maxText.length) maxText = nowText;
}
var jhcWidth = 200 + stringWidth('20', maxText);
if ($(this).width() < jhcWidth) {
$(this).css('width', jhcWidth + 'px');
}
})
}
setInterval("jhcAutoWidth()", "100");