通常在ace编辑器中,如果按住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();
};
我在第15479和15528行之间的ace.js中发现了这个;
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行
答案 0 :(得分:1)
看起来就像改变这条线一样简单......
var alt = ev.altKey;
到此......
var alt = !ev.altKey;
答案 1 :(得分: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])