Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/464.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单击“防止代码镜像复制”_Javascript_Angular_Codemirror_Ui Codemirror - Fatal编程技术网

Javascript 单击“防止代码镜像复制”

Javascript 单击“防止代码镜像复制”,javascript,angular,codemirror,ui-codemirror,Javascript,Angular,Codemirror,Ui Codemirror,我们在angular web应用程序中使用代码镜像。当前,当用户高亮显示一段文本并随后单击高亮显示的部分时,“代码镜像”会将选定区域的副本放入剪贴板。这不是我们想要的行为。我们想要的只是取消选择文本的正常行为 我尝试捕捉鼠标点击事件并返回false或将codemirrorIgnore设置为true,但没有成功。我还尝试为“LeftDown”重新定义键映射,但我找不到有关现有操作名称定义位置的信息 有人能帮忙吗 以下是我尝试更改密钥映射的代码: $scope.editorOptions = {

我们在angular web应用程序中使用代码镜像。当前,当用户高亮显示一段文本并随后单击高亮显示的部分时,“代码镜像”会将选定区域的副本放入剪贴板。这不是我们想要的行为。我们想要的只是取消选择文本的正常行为

我尝试捕捉鼠标点击事件并返回false或将codemirrorIgnore设置为true,但没有成功。我还尝试为“LeftDown”重新定义键映射,但我找不到有关现有操作名称定义位置的信息

有人能帮忙吗

以下是我尝试更改密钥映射的代码:

$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-codemirr=“{onload:codemirrorload}”
和以下内容:

$scope.codemirrorLoaded = function(_editor) {
    _editor.on("mouseDown", function(cm, event) {
        cm.codemirrorIgnore = true;
        //also tried return false
    }
};

返回false nothing并将
codemirrorIgnore
设置为true,完全阻止了左键单击操作。

我发现这是代码镜像的错误。以下是镜像代码的第一位代码:

if (cm.options.dragDrop && dragAndDrop && !cm.isReadOnly() &&
    type == "single" && (contained = sel.contains(start)) > -1 &&
    (cmp((contained = sel.ranges[contained]).from(), start) < 0 || start.xRel > 0) &&
    (cmp(contained.to(), start) > 0 || start.xRel < 0))
  leftButtonStartDrag(cm, e, start, modifier);
else
  leftButtonSelect(cm, e, start, type, modifier);
如果没有拖动,则将单击视为单击。我没有仔细查看代码,看看是否可以修复它,但由于拖动使用剪贴板,剪贴板已经被删除并替换为选定的文本


因此,为了避免这种情况发生,您需要禁用拖放功能。

提供您已有的代码以及您试图解决手头问题的代码会更有帮助。好的。我得等到星期一。谢谢。@GhassenLouhaichi添加了我尝试的代码示例。
// Start a text drag. When it ends, see if any dragging actually
// happen, and treat as a click if it didn't.
function leftButtonStartDrag(cm, e, start, modifier) {