0
我正在使用王牌編輯器,我想僅適用於變量(JSON)的readyOnly。王牌編輯器 - 只准備變量
{ "number": 10, "text": "my text" }
我嘗試使用此代碼: 例如,在這種情況下,用戶無法編輯變量「數量」和「文字」,但他可以編輯值「10」和「我的文字」 :
var Range = window.ace.require('ace/range').Range
let range = new Range(1, 4, 4, 10);
const markerId = session.addMarker(range, "readonly-highlight");
editor.keyBinding.addKeyboardHandler( handleKeyboard : function(data, hash, keyString, keyCode, event) {
if (hash === -1 || (keyCode <= 40 && keyCode >= 37)) return false;
if (intersects(range)) {
return {command:"null", passEvent:false};
}
}
});
before(editor, 'onPaste', preventReadonly);
before(editor, 'onCut', preventReadonly);
range.start = session.doc.createAnchor(range.start);
range.end = session.doc.createAnchor(range.end);
range.end.$insertRight = true;
function before(obj, method, wrapper) {
var orig = obj[method];
obj[method] = function() {
var args = Array.prototype.slice.call(arguments);
return wrapper.call(this, function(){
return orig.apply(obj, args);
}, args);
}
return obj[method];
}
function intersects(range) {
return editor.getSelectionRange().intersects(range);
}
function preventReadonly(next, args) {
if (intersects(range)) return;
next();
}
但我無法選擇變量readyOnly。 請問有人可以幫我嗎?