admin管理员组文章数量:1316980
I have an Ace Editor embedded on my website in which I allow the users to type in it. Currently, the built in function automatically shows the line number for every line inserted like this:
Is there a way for me to set the content in the gutter manually and read the value in it later?
Eg: instead of setting it to 1,2,3... I would want it to look like
A abc
B def
And then later when I access the line containg "abc", I would want to read the value in the gutter of that line which is "A".
Update:
To customize the gutter for Ace Editor, you'll have to override the "update" function:
ace.require("ace/layer/my_gutter")
//...
define('ace/layer/my_gutter', ['require', 'exports', 'ace/lib/dom'], function(require, exports, module) {
var dom = require("ace/lib/dom");
require("ace/layer/gutter").Gutter.prototype.update = update =
function(config) {
//...
};
});
The function is pretty long and plicated for this small change that I need. So, I didn't go with it.
I found another editor, CodeMirror which provides an easier way to do this and have switched over to CodeMirror.
I have an Ace Editor embedded on my website in which I allow the users to type in it. Currently, the built in function automatically shows the line number for every line inserted like this:
Is there a way for me to set the content in the gutter manually and read the value in it later?
Eg: instead of setting it to 1,2,3... I would want it to look like
A abc
B def
And then later when I access the line containg "abc", I would want to read the value in the gutter of that line which is "A".
Update:
To customize the gutter for Ace Editor, you'll have to override the "update" function:
ace.require("ace/layer/my_gutter")
//...
define('ace/layer/my_gutter', ['require', 'exports', 'ace/lib/dom'], function(require, exports, module) {
var dom = require("ace/lib/dom");
require("ace/layer/gutter").Gutter.prototype.update = update =
function(config) {
//...
};
});
The function is pretty long and plicated for this small change that I need. So, I didn't go with it.
I found another editor, CodeMirror which provides an easier way to do this and have switched over to CodeMirror.
Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Feb 3, 2015 at 23:56 jianweichuahjianweichuah 1,4271 gold badge11 silver badges22 bronze badges1 Answer
Reset to default 11You can set a custom renderer for the gutter with
editor.session.gutterRenderer = {
getWidth: function(session, lastLineNumber, config) {
return lastLineNumber.toString().length * config.characterWidth;
},
getText: function(session, row) {
return String.fromCharCode(row + 65);
}
};
本文标签: javascriptModify the gutter of Ajaxorg Cloud9 Editor (Ace Editor)Stack Overflow
版权声明:本文标题:javascript - Modify the gutter of Ajax.org Cloud9 Editor (Ace Editor) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742016374a2413848.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论