widget - CodeMirror - addWidget 的用途是什么以及如何使用它?

标签 widget codemirror

我想对 CodeMirror 进行一些扩展。 addWidget 方法似乎是一个很有前途的起点。该文件指出

addWidget(pos, node, scrollIntoView) Puts node, which should be an absolutely positioned DOM node, into the editor, positioned right below the given {line, ch} position. When scrollIntoView is true, the editor will ensure that the entire node is visible (if possible). To remove the widget again, simply use DOM methods (move it somewhere else, or call removeChild on its parent).



我真的不明白这意味着什么或我会用它做什么。我在 CodeMirror 代码库或谷歌的其他任何地方都找不到它的用法。

最佳答案

您需要传递一个 html 节点和一个位置以及一个 bool 值

// create a node
var htmlNode =document.createElement("h1");
var text =  document.createTextNode("Text or whatever");
htmlNode.appendChild(text)

// call this after you initialized the editor.
// the position must be like this {ch: YourCharecterNumber, line: YourLineNumber}
editor.addWidget({ch:30 , line: 1},htmlNode, true)

关于widget - CodeMirror - addWidget 的用途是什么以及如何使用它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14366604/

相关文章:

javascript - Dojo:如何创建包含布局小部件(边框容器)的小部件

c++ - Qt:小部件方法 addButtons() 不能按需要工作

charts - 如何删除 TradingView 小部件 JS 中的特定工具?

javascript - 在同一页面(HTML 和 CSS)上使用 Codemirror 两次导致仅应用一种突出显示模式

codemirror - 加载 codemirror 时是否可以突出显示搜索模式

android - Android布局中如何实现Button的自动宽度

dart - 如何添加 Flutter DropdownButtonFormField

javascript - 将整个 HTML 页面存储到 jQuery 变量中

javascript - codemirror 可以在多个文本区域上使用吗?

javascript - 在 CodeMirror Textarea 的插入符号处插入文本