我们在一个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
};
我还尝试使用ui-codemirror="{ onLoad : codemirrorLoaded }"
和以下代码来使用onload函数:
$scope.codemirrorLoaded = function(_editor) {
_editor.on("mouseDown", function(cm, event) {
cm.codemirrorIgnore = true;
//also tried return false
}
};
返回false什么也不做,并将codemirrorIgnore
设置为true会阻止左键单击做任何事情。
https://stackoverflow.com/questions/47599348
复制相似问题