Skip to content

Commit

Permalink
Merge branch 'feat/limitEditorInput' into dev
Browse files Browse the repository at this point in the history
# Conflicts:
#	WebSocketClient/src/main.ts
  • Loading branch information
JannisDommer committed Dec 5, 2023
2 parents 422f425 + ca2c73b commit 26e9f51
Showing 1 changed file with 24 additions and 35 deletions.
59 changes: 24 additions & 35 deletions WebSocketClient/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ let fileID;
let model;
const connectionText = document.getElementById("connection");
let debounceGenGraph;
const MAX_LINES = 100;
const MAX_NUMBER_LINES = 100;

const createUrl = (hostname: string, port: number, path: string, searchParams: Record<string, any> = {}, secure: boolean): string => {
const protocol = secure ? 'wss' : 'ws';
Expand Down Expand Up @@ -144,12 +144,12 @@ const createLanguageClient = (transports: MessageTransports): MonacoLanguageClie
createDiagramFromDot(res as string);
});
}, 500);

const firstPane = document.getElementById("first");
const secondPane = document.getElementById("second");
if(firstPane && secondPane){
firstPane.style.width = "50%";
secondPane.style.width = "50%";
secondPane.style.width = "50%";
}

}else{
Expand All @@ -162,10 +162,10 @@ const createLanguageClient = (transports: MessageTransports): MonacoLanguageClie
const secondPane = document.getElementById("second");
if(firstPane && secondPane){
firstPane.style.width = "100%";
secondPane.style.width = "0%";
secondPane.style.width = "0%";
}
}

}
else {
next(command, args);
Expand All @@ -180,7 +180,7 @@ const createLanguageClient = (transports: MessageTransports): MonacoLanguageClie
}
}
});

return client;
};

Expand Down Expand Up @@ -254,19 +254,6 @@ export const startPythonClient = async () => {
// use the file create before
const modelRef = await createModelReference(monaco.Uri.file(`/workspace/${fileID}.uvl`));
model = modelRef.object;

const debouncedSave = lodash.debounce(saveFm, 1000);

modelRef.object.onDidChangeContent(() => {
debouncedSave();
if(debounceGenGraph !== undefined){
debounceGenGraph();
}
});




modelRef.object.setLanguageId(languageId);

// create monaco editor
Expand All @@ -275,23 +262,25 @@ export const startPythonClient = async () => {
automaticLayout: true
});

if(editor !== null){
editor.onDidChangeModelContent(() => {
const numberOfLines = editor.getModel()?.getLineCount();
if(numberOfLines && numberOfLines > MAX_LINES){
let lines = editor.getModel()?.getLinesContent();
lines?.splice(MAX_LINES);
const newContent = lines?.reduce((p, c) => {return p + "\n" + c});
if(newContent !== undefined){
const position = editor.getPosition();
editor.getModel()?.setValue(newContent);
if(position !== null){
editor.setPosition(position);
}
}
editor.onDidChangeModelContent(() => {
const model = editor.getModel();
const lineCount = model?.getLineCount();
if(lineCount && lineCount > MAX_NUMBER_LINES){
vscode.commands.executeCommand("undo");
if(connectionText){
connectionText.textContent = `The Editor only allows content up to ${MAX_NUMBER_LINES} Lines!`
setTimeout(() => {
connectionText.textContent = "";
}, 2000);
}
});
}
}
debouncedSave();
if(debounceGenGraph !== undefined){
debounceGenGraph();
}
})

const debouncedSave = lodash.debounce(saveFm, 1000);
};

function getInitialFm(){
Expand Down

0 comments on commit 26e9f51

Please sign in to comment.