forked from jeff-zucker/solid-content-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
solid-ide-editor.js
98 lines (98 loc) · 3.14 KB
/
solid-ide-editor.js
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* VERSION 0.1.2
** 2018-11-27
*/
var SolidIdeEditor = function(elementID) {
this.name="zeditor"
this.ed = ace.edit(elementID,{
maxLines:24,
minLines:14,
});
this.getContents = function (){
return this.ed.getValue()
};
this.setContents = function (contents){
this.ed.setValue(contents)
};
this.setSize = function (lines){
this.ed.setOption("maxLines",lines)
this.ed.setOption("minLines",lines)
};
this.setReadOnly = function (trueOrFalse){
this.ed.setReadOnly(trueOrFalse)
};
this.setModeFromType = function (type){
if(type){
if(type==='folder') type = 'text/turtle'
if(type==='text/plain') type = 'text'
if(!type.match(/(unknown|image|video|audio)/)){
type = type.substring(type.lastIndexOf('/')+1);
this.setMode(type)
}
}
};
this.setMode = function (mode){
this.ed.getSession().setMode('ace/mode/'+mode);
};
this.setTheme = function (theme){
this.ed.setTheme('ace/theme/'+theme);
};
this.setKeys = function (key_style){
if(key_style==='zemacs'){
key_style='emacs';
if(!this.tweaksSet) { this.tweak_emacs()};
}
this.ed.setKeyboardHandler('ace/keyboard/'+key_style);
};
/* NOTHING BELOW HERE EXCEPTS EMACS TWEAKS
*/
this.tweak_emacs = function(){
this.tweaksSet=true;
this.ed.commands.addCommand({
name: "linedown",
bindKey: { win: "Down|Ctrl-Alt-N", mac: "Command-N" },
exec: function(editor, args) { editor.navigateDown(args.times); },
multiSelectAction: "forEach",
scrollIntoView: "cursor",
readOnly: true
});
this.ed.commands.addCommand({
name: "gotoend",
bindKey: {win:"Ctrl-Alt-K|Ctrl-End",mac:"Command-End|Command-Down"},
exec: function(editor) { editor.navigateFileEnd(); },
multiSelectAction: "forEach",
readOnly: true,
scrollIntoView: "animate",
aceCommandGroup: "fileJump"
});
this.ed.commands.addCommand({
name: "gotostart",
bindKey: {win:"Ctrl-Alt-J|Ctrl-Home",mac:"Command-Home|Command-Up"},
exec: function(editor) { editor.navigateFileStart(); },
multiSelectAction: "forEach",
readOnly: true,
scrollIntoView: "animate",
aceCommandGroup: "fileJump"
});
this.ed.commands.addCommand({
name: "lineup",
bindKey: { win: "Up|Ctrl-P|Ctrl-Alt-P", mac: "Command-P" },
exec: function(editor, args) { editor.navigateUp(args.times); },
multiSelectAction: "forEach",
scrollIntoView: "cursor",
readOnly: true
});
this.ed.commands.addCommand({
name: "gotoline",
bindKey: { win:"Ctrl-Alt-G", mac:"Command-G"},
exec: function(editor, line) {
if (typeof line !== "number")
line = parseInt(prompt("Enter line number:"), 10);
if (!isNaN(line)) {
editor.gotoLine(line);
}
},
readOnly: true
});
}/* function emacs_tweak */
return this
};/* Zeditor */