에디팅 관련 수정
This commit is contained in:
@@ -100,8 +100,46 @@
|
||||
<script th:src="@{/plugins/vs/editor/editor.main.js}"></script>
|
||||
<script th:inline="javascript">
|
||||
var urlForSidebar = "/manage/findAllScriptInfos";
|
||||
let editor
|
||||
let editor;
|
||||
let constrainedInstance;
|
||||
|
||||
const isNew = [[${scriptInfo.id == null}]];
|
||||
|
||||
function findLineNumberByText(text){
|
||||
const linesContent = editor.getModel().getLinesContent();
|
||||
for (let i = 0; i < linesContent.length; i++) {
|
||||
const lineText = linesContent[i].trim();
|
||||
|
||||
if(lineText.startsWith(text)){
|
||||
return i + 1
|
||||
}
|
||||
}
|
||||
return 14;
|
||||
}
|
||||
|
||||
function setMainRestrictions(isNew){
|
||||
const model = editor.getModel();
|
||||
let editableLine = findLineNumberByText('public String postProcess') + 1;
|
||||
const linesContent = editor.getModel().getLinesContent();
|
||||
const editableLineTextLength = linesContent[editableLine - 1].length + 1;
|
||||
const mainRestrictions = [{
|
||||
// range : [ startLine, startColumn, endLine, endColumn ]
|
||||
range: [3, 1, 3, 26], // Range of Util Variable name
|
||||
label: 'import',
|
||||
allowMultiline: true
|
||||
}, {
|
||||
range: [editableLine, 1, editableLine, editableLineTextLength], // Range of Function definition
|
||||
allowMultiline: true,
|
||||
label: 'funcDefinition'
|
||||
}]
|
||||
|
||||
if(isNew){
|
||||
constrainedInstance.addRestrictionsTo(model, mainRestrictions);
|
||||
}else{
|
||||
model.updateRestrictions(mainRestrictions);
|
||||
}
|
||||
}
|
||||
|
||||
function setMonaco(elementId, initValue){
|
||||
var targetDivElement = document.getElementById(elementId);
|
||||
editor = monaco.editor.create(targetDivElement, {
|
||||
@@ -118,65 +156,13 @@
|
||||
automaticLayout: true
|
||||
});
|
||||
|
||||
const constrainedInstance = constrainedEditor(monaco);
|
||||
constrainedInstance = constrainedEditor(monaco);
|
||||
constrainedInstance.initializeIn(editor);
|
||||
const model = editor.getModel();
|
||||
let editableLine = 14
|
||||
|
||||
const linesContent = editor.getModel().getLinesContent();
|
||||
for (let i = 0; i < linesContent.length; i++) {
|
||||
const lineText = linesContent[i].trim();
|
||||
|
||||
if(lineText.startsWith('public String postProcess')){
|
||||
editableLine = i + 2
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
const editableLineTextLength = linesContent[editableLine - 1].length + 1;
|
||||
|
||||
constrainedInstance.addRestrictionsTo(model, [{
|
||||
// range : [ startLine, startColumn, endLine, endColumn ]
|
||||
range: [3, 1, 3, 26], // Range of Util Variable name
|
||||
label: 'import',
|
||||
allowMultiline: true
|
||||
}, {
|
||||
range: [editableLine, 1, editableLine, editableLineTextLength], // Range of Function definition
|
||||
allowMultiline: true,
|
||||
label: 'funcDefinition'
|
||||
}]);
|
||||
setMainRestrictions(true);
|
||||
model.toggleHighlightOfEditableAreas();
|
||||
|
||||
|
||||
|
||||
// const readonlyRange = new monaco.Range (1, 0, 7, 0)
|
||||
// editor.onKeyDown (e => {
|
||||
// const contains = editor.getSelections().findIndex (range => readonlyRange.intersectRanges (range))
|
||||
// let currentLineNumber = editor.getPosition().lineNumber
|
||||
// let lineCount = editor.getModel().getLineCount();
|
||||
// console.log(e.ctrlKey)
|
||||
// if(e.ctrlKey && e.keyCode == 33){
|
||||
// return
|
||||
// }
|
||||
// switch(e.keyCode){
|
||||
// case 13:
|
||||
// case 14:
|
||||
// case 15:
|
||||
// case 16:
|
||||
// case 17:
|
||||
// case 18:
|
||||
// case 63:
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// const matchTailPart = lineCount == currentLineNumber || lineCount - 1 == currentLineNumber;
|
||||
// if (contains !== -1 || matchTailPart) {
|
||||
// e.stopPropagation ()
|
||||
// e.preventDefault () // for Ctrl+C, Ctrl+V
|
||||
// return false;
|
||||
// }
|
||||
// });
|
||||
|
||||
$('#form').submit(function(eventObj) {
|
||||
$('#scriptName').prop( "disabled", false );
|
||||
$("<input />").attr("type", "hidden")
|
||||
@@ -192,10 +178,35 @@
|
||||
}
|
||||
$('#scriptName').on("change keyup paste", function(){
|
||||
const scriptName = $('#scriptName').val();
|
||||
const currentTextLength = editor.getModel().getLinesContent()[3].length + 1;
|
||||
const classLine = findLineNumberByText('public class')
|
||||
const model = editor.getModel();
|
||||
const linesContent = model.getLinesContent();
|
||||
const currentTextLength = linesContent[classLine - 1].length + 1;
|
||||
// model.toggleHighlightOfEditableAreas();
|
||||
model.updateRestrictions([
|
||||
{
|
||||
range: [classLine, 1, classLine, currentTextLength],
|
||||
label: "classLine"
|
||||
}
|
||||
]);
|
||||
|
||||
const newText = `public class ${scriptName} implements Script{`;
|
||||
editor.executeEdits("my-source",
|
||||
[{ range: new monaco.Range(4, 1, 4, currentTextLength), text: newText, forceMoveMarkers: true }]);
|
||||
editor.executeEdits("my-source", [{ range: new monaco.Range(classLine, 1, classLine, currentTextLength), text: newText, forceMoveMarkers: true }]);
|
||||
|
||||
setMainRestrictions(false);
|
||||
// model.toggleHighlightOfEditableAreas();
|
||||
|
||||
console.log(model.getCurrentEditableRanges());
|
||||
|
||||
|
||||
// constrainedInstance.addRestrictionsTo(model, [{
|
||||
// // range : [ startLine, startColumn, endLine, endColumn ]
|
||||
// range: [classLine, 1, classLine, currentTextLength], // Range of Util Variable name
|
||||
// label: 'className',
|
||||
// allowMultiline: false
|
||||
// }]);
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user