admin管理员组文章数量:1313054
As you can see in the following screenshot:
Ace editors have a 'gutter' on the left-hand side that contains the line numbers. I would like to detect a click on this gutter and insert a marker for a breakpoint, as in the following screenshot from chrome dev tools
I've had a look at the Ace editor API, but can't figure out how to do it, could someone tell me the best way to go about it?
Thanks
As you can see in the following screenshot:
Ace editors have a 'gutter' on the left-hand side that contains the line numbers. I would like to detect a click on this gutter and insert a marker for a breakpoint, as in the following screenshot from chrome dev tools
I've had a look at the Ace editor API, but can't figure out how to do it, could someone tell me the best way to go about it?
Thanks
Share Improve this question edited Feb 8, 2017 at 14:41 CommunityBot 11 silver badge asked May 31, 2013 at 19:10 horseyguyhorseyguy 29.9k20 gold badges109 silver badges148 bronze badges1 Answer
Reset to default 10See this thread https://groups.google./d/msg/ace-discuss/sfGv4tRWZdY/ca1LuolbLnAJ
you can use this functioneditor.on("guttermousedown", function(e) { var target = e.domEvent.target; if (target.className.indexOf("ace_gutter-cell") == -1) return; if (!editor.isFocused()) return; if (e.clientX > 25 + target.getBoundingClientRect().left) return; var row = e.getDocumentPosition().row; e.editor.session.setBreakpoint(row); e.stop(); })and don't forget to add some styling for breakpoints e.g.
.ace_gutter-cell.ace_breakpoint{ border-radius: 20px 0px 0px 20px; box-shadow: 0px 0px 1px 1px red inset; }
Breakpoints are often toggled. To achieve this behavior, use
...
var breakpoints = e.editor.session.getBreakpoints(row, 0);
var row = e.getDocumentPosition().row;
if(typeof breakpoints[row] === typeof undefined)
e.editor.session.setBreakpoint(row);
else
e.editor.session.clearBreakpoint(row);
...
Notice the strange use of EditSession.getBreakpoints()
, which doesn't return an array of row numbers as documentation suggests, but rather an array with indices corresponding to the row numbers.
本文标签: webHow to mark line numbers in javascript ace editorStack Overflow
版权声明:本文标题:web - How to mark line numbers in javascript ace editor? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741891582a2403332.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论