我们在 Angular Web 应用程序中使用 Code Mirror。当前,当用户突出显示一段文本并随后单击突出显示的部分时,Code Mirror 会将所选区域的副本放置到剪贴板中。这不是我们想要的行为。我们希望只是取消选择文本的正常行为。
我试图捕捉鼠标单击事件并返回 false 或将 codemirrorIgnore 设置为 true,但它不起作用。我还尝试重新定义“LeftDown”的键映射,但我找不到有关现有操作名称定义位置的信息。
任何人都可以帮忙吗?
这是我尝试更改 KeyMap 的代码:
$scope.editorOptions = {
lineWrapping: true,
lineNumbers: true,
smartIndent: true,
autoCloseTags: true,
cursorScrollMargin: 25,
styleActiveLine: true,
mode: "text/html",
theme: "default",
matchBrackets: true,
matchTags: {
bothTags: true
},
extraKeys: {
"F11": function (cm) {
cm.setOption("fullScreen", !cm.getOption("fullScreen"));
},
"Esc": function (cm) {
if (cm.getOption("fullScreen")) {
cm.setOption("fullScreen", false);
}
},
//Don't know where "autocomple", "findPersistent" are defined so I can see what is available
"LeftClick": "LeftClick",
"Ctrl-Space": "autocomplete",
"Alt-B": "findPersistent",
"Ctrl-J": "toMatchingTag"
},
viewportMargin: 10,
textWrapping: true
};
我还尝试使用 onload 函数使用ui-codemirror="{ onLoad : codemirrorLoaded }"
以下内容:
$scope.codemirrorLoaded = function(_editor) {
_editor.on("mouseDown", function(cm, event) {
cm.codemirrorIgnore = true;
//also tried return false
}
};
返回 false 什么也没做,设置codemirrorIgnore
为 true 会阻止左键单击做任何事情。