0

通常在 ace-editor 中,如果您在进行选择时按住 alt 键,它将以块形式选择它,我认为这称为块选择。

我如何使它成为标准的块选择,然后按 alt 将其更改为正常选择。

我认为这与此有关

function onMouseDown(e) {
var ev = e.domEvent;
var alt = ev.altKey;
var shift = ev.shiftKey;
var ctrl = e.getAccelKey();
var button = e.getButton();

var editor = e.editor;
var selection = editor.selection;
var isMultiSelect = editor.inMultiSelectMode;
var pos = e.getDocumentPosition();
var cursor = selection.getCursor();
var inSelection = e.inSelection() || (selection.isEmpty() && isSamePoint(pos, cursor));


var mouseX = e.x, mouseY = e.y;
var onMouseSelection = function(e) {
    mouseX = e.clientX;
    mouseY = e.clientY;
};

var blockSelect = function() {
    var newCursor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY);
    var cursor = session.screenToDocumentPosition(newCursor.row, newCursor.column);

    if (isSamePoint(screenCursor, newCursor)
        && isSamePoint(cursor, selection.selectionLead))
        return;
    screenCursor = newCursor;

    editor.selection.moveCursorToPosition(cursor);
    editor.selection.clearSelection();
    editor.renderer.scrollCursorIntoView();

    editor.removeSelectionMarkers(rectSel);
    rectSel = selection.rectangularRangeBlock(screenCursor, screenAnchor);
    rectSel.forEach(editor.addSelectionMarker, editor);
    editor.updateSelectionMarkers();
};

我在 ace.js 中的第 15479 行和第 15528 行之间找到了这个;

 else if (alt && button == 0) {
    e.stop();

    if (isMultiSelect && !ctrl)
        selection.toSingleRange();
    else if (!isMultiSelect && ctrl)
        selection.addRange();

    var rectSel = [];
    if (shift) {
        screenAnchor = session.documentToScreenPosition(selection.lead);
        blockSelect();
    } else {
        selection.moveCursorToPosition(pos);
        selection.clearSelection();
    }

第 15561 和 15567 行

4

2 回答 2

1

它看起来就像改变这条线一样简单......

var alt = ev.altKey;

对这个...

var alt = !ev.altKey;
于 2013-10-01T08:41:06.930 回答
0

这可以在更改ace.js的情况下完成,方法是将存储在编辑器的_eventRegistry.mousedown[1]中的onMouseDown函数替换为一个包装器,该包装器调用具有反转值的ev.altKey的相同函数,如下所示。

editor._eventRegistry.mousedown[1] = (func => e => func({
  ...e, ...e.__proto__,
  getButton: () => e.getButton(),
  domEvent: { ...e.domEvent,
    altKey: !e.domEvent.altKey,
    shiftKey:e.domEvent.shiftKey,
    ctrlKey: e.domEvent.ctrlKey,
  },
}))(editor._eventRegistry.mousedown[1])
于 2018-07-31T06:22:22.077 回答