javascript - 代码镜像。替换文本的简单方法?
问题描述
我使用CodeMirror (5.58.2)来编辑文本。
new_cm = CodeMirror.fromTextArea(textarea_obj, param);
但是在 textarea 中,我可以轻松地替换文本,只需这样做obj.value = obj.value.replace( /123/g, '3210');
我可以在 CodeMirror 中这样做吗?对用户没有任何接口请求。只是一个简单的“Make Replace”按钮和带有正则表达式模式的代码。
解决方案
这是一个例子......
// start the editor instance
const new_cm = CodeMirror.fromTextArea(textarea_obj, param);
// get the entire editor text from CodeMirror editor
let text = new_cm.getValue();
// edit the text, for example
text = text.replace(/abc/g, '');
// set the text back to the editor
new_cm.setValue(text);
推荐阅读
- node.js - 哪些内置 MongoDB 角色允许用户为所有数据库创建新数据库和用户?
- android - android中的按钮视图
- mysql - 过滤具有相同 PK 但不同值键的查询
- silverlight - 百度地图有Silverlight控件吗
- maven - MAVEN 对子模块中的插件有不同的执行
- php - 无法使用 libsodium 解密加密文件
- accessibility - 多个元素共享相同的正 tabindex 值?
- c++ - 使用分配器构造函数的 uninitialized_X 函数?
- r - 在 R 的 GoogleWay 库中使用 Places API 时出现 next_page_token 错误
- python - 我想单独访问我的列表列表(心脏网格)的元素并以正确的方式打印心脏