- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在编写一个程序,该程序将使用 CodeMirror 实例,并有一个弹出的小元素,您可以在其中键入文本。该文本键入区域应该为一行高。我将在文本输入区域中执行许多与主 CodeMirror 实例相同的操作,因此我只想使用 CodeMirror 的另一个实例,但到目前为止我尝试过的所有操作都以失败告终太高了。
如何制作一个只有一行高并且可以水平滚动的 CodeMirror 实例?我想要没有行号,没有装订线等,只是要输入文本的区域。
我尝试了几件事,包括这里的代码(我全部和部分尝试过):codemirror for just one-line-textfield? 。该示例阻止用户在代码镜像实例中键入多行代码,但不会使其仅高一行。那里还有其他 CodeMirror 的东西,但我不确定那里有什么或者如何摆脱它。
编辑:回复:@rfornal 的请求,这是我引用的代码和解释(由 Tigran Saluev 编写):
Well, there is a way to make a single-line editor using rich capabilities of CodeMirror. First, you'll have to add a full-featured CodeMirror object (use a textarea).
Assume you've got var cm = CodeMirror(...). (Use value: ""). Then do
cm.setSize(200, cm.defaultTextHeight() + 2 * 4);
// 200 is the preferable width of text field in pixels,
// 4 is default CM padding (which depends on the theme you're using)
// now disallow adding newlines in the following simple way
cm.on("beforeChange", function(instance, change) {
var newtext = change.text.join("").replace(/\n/g, ""); // remove ALL \n !
change.update(change.from, change.to, [newtext]);
return true;
});
// and then hide ugly horizontal scrollbar
cm.on("change", function(instance, change) {
$(".CodeMirror-hscrollbar").css('display', 'none');
// (!) this code is using jQuery and the selector is quite imperfect if
// you're using more than one CodeMirror on your page. you're free to
// change it appealing to your page structure.
});
// the following line fixes a bug I've encountered in CodeMirror 3.1
$(".CodeMirror-scroll").css('overflow', 'hidden');
// jQuery again! be careful with selector or move this to .css fileThis works just fine for me.
到目前为止我所尝试的一切最终仍然比一行高。可能有一种方法可以做到这一点,我只是不明白如何做。
最佳答案
与往常一样,这是用户错误。我原以为 CodeMirror 的样式会覆盖我为容器创建的任何样式,但事实并非如此。我的样式感染了 CodeMirror 实例并导致了奇怪的情况。
具体:
- 设置position:relative于不应该在的地方(我不确定在哪里)
- 设置显示:内联 block 在不应该的地方(再次,不确定它具体影响了什么)
我很抱歉,我希望这对将来的其他人有帮助。
关于javascript - 1行高CodeMirror实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30472064/
使用代码镜像,我们可以折叠代码。 我想用花括号折叠所有代码。我发现了这种方法 我如何折叠整个代码,这是我的HTML脚本: window.onload = function() { var te =
我想将“Alt-Space”键映射添加到 codemirror,然后在按下键时执行特定功能。我无法使用 . cm.addKeyMap 我应该在哪里编写此函数,以便可以将键映射绑定(bind)到特定函数
我想重置 Codemirror 编辑器的所有内容。理想情况下,这应该清除 textarea,删除所有标记并清除历史记录。 实现这一目标的最佳方法是什么? 最佳答案 cm.setValue(""); c
我知道你用 editor.setValue(""); 设置一个值,但如何在 CodeMirror 中附加? IE: editor.appendText();? 最佳答案 使用 replaceRang
CodeMirrors 全屏模式的文档似乎有点稀疏。例如,我如何告诉它监听键以激活全屏?或者如何使用按钮切换全屏? 为了他人的利益,下面是我找到的解决方案。 最佳答案 这将获得选项值: editor
我需要在 CodeMirror 中当前行号旁边插入一个新行。 我查看了文档,但没有找到任何关于在行尾附加任何内容的信息。 请帮忙。 :( 最佳答案 从光标位置获取当前行,并对其进行操作。这应该这样做(
是否可以在 中显示隐藏字符(如回车符)? Codemirror 文本编辑器 ,但我没有在它的文档中找到任何关于它的配置引用。有可能这样做吗? 最佳答案 回车符由 CodeMirror 专门解释(当它自
CodeMirror 是实现单行表达式编辑器的好选择吗?我无法从手册(或我查看的问题)中弄清楚 CodeMirror 是否可以配置为执行以下操作: 不显示滚动条(如果太长,文本应该向左滑动) 忽略插入
来自 http://codemirror.net/doc/manual.html ,我只找到getRange() , undo()、redo() 等,我找不到 cut()、copy() 和 paste
我正在构建一个简单的代码编辑器来帮助 children 学习 HTML。我试图添加的一个功能是,当用户将鼠标悬停在他们呈现的代码上时(在 iframe 中),编辑器中相应的 HTML 代码会突出显示。
我正在构建一个简单的代码编辑器来帮助 children 学习 HTML。我试图添加的一个功能是,当用户将鼠标悬停在他们呈现的代码上时(在 iframe 中),编辑器中相应的 HTML 代码会突出显示。
我正在构建一个供个人使用的小型 extjs 5.1 应用程序,旨在保存我的 extjs 应用程序中使用的函数/方法的示例。 在 Navaneeth-Kesavan 和 Tarabass 的帮助下,我在
我正在使用CodeMirror 5.1。 This article显示 C# 语法突出显示,但显然解决了 CodeMirror 过时版本的问题。 问题:如何使用 CodeMirror 实现真正的 C#
我正在使用CodeMirror 5.1。 This article显示 C# 语法突出显示,但显然解决了 CodeMirror 过时版本的问题。 问题:如何使用 CodeMirror 实现真正的 C#
我正在写一些 cypress测试 Codemirror 编辑器。我用过 cypress在输入字段中输入。 我正在尝试实现 cy.type()在 CodeMirror 编辑器中。我在 codemirro
所以我检查规范化以将规范化库添加到 Codemirror 中。 我检查 jQuery,并在规范化后添加 jQuery 源: 但是如果我取消选中标准化,我希望它删除标准化链接,如果我再次选中它,我
https://github.com/angular-ui/ui-codemirror 我需要用 Angular 制作一个语法高亮器并将结果保存在数据库中。 我正在使用 ui-codemirror,但
有人为codemirror做了'htmlmixed' + 'Velocity'模式吗?或者任何人都可以建议如何实现这一目标? 最佳答案 我能够使用 overlay.js 插件轻松实现这一点: Code
我正在将 CodeMirror 实现到我的 Nuxtjs/Vuejs 应用程序中的文本区域之一。我想根据 XML 美化 textarea。 有时 CodeMirror 工作正常,但有时当我重新加载页面
我正在尝试在 React/Redux/TS 应用程序中启用 react-codemirror 组件的 linting 插件。正常的 codemirror 东西工作正常,语法突出显示,行号等。但是,启用
我是一名优秀的程序员,十分优秀!