hor*_*guy 5 javascript editor breakpoints web ace-editor
正如您在以下屏幕截图中看到的:

王牌编辑在左侧有一个"排水沟",其中包含行号.我想检测一下这个装订线上的一个点击并为断点插入一个标记,如下面的chrome dev工具截图
我已经看过Ace编辑器API,但无法弄清楚如何去做,有人能告诉我最好的方法吗?
谢谢
a u*_*ser 10
请参阅此主题https://groups.google.com/d/msg/ace-discuss/sfGv4tRWZdY/ca1LuolbLnAJ
你可以使用这个功能editor.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(); })并且不要忘记为断点添加一些样式,例如
.ace_gutter-cell.ace_breakpoint{ border-radius: 20px 0px 0px 20px; box-shadow: 0px 0px 1px 1px red inset; }
断点经常被切换.要实现此行为,请使用
...
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);
...
Run Code Online (Sandbox Code Playgroud)
请注意奇怪的用法EditSession.getBreakpoints(),它不会返回文档建议的行号数组,而是一个索引对应于行号的数组.
| 归档时间: |
|
| 查看次数: |
2658 次 |
| 最近记录: |