Skip to content

Commit

Permalink
feat(client): limit number of lines
Browse files Browse the repository at this point in the history
  • Loading branch information
st-vi committed Dec 5, 2023
1 parent de448bc commit 4cbb37e
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion WebSocketClient/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ let fileID;
let model;
const connectionText = document.getElementById("connection");
let debounceGenGraph;
const MAX_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 @@ -263,14 +264,34 @@ export const startPythonClient = async () => {
}
});




modelRef.object.setLanguageId(languageId);

// create monaco editor
createConfiguredEditor(document.getElementById('container')!, {
const editor = createConfiguredEditor(document.getElementById('container')!, {
model: modelRef.object.textEditorModel,
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, i, a) => {return p + "\n" + c});
if(newContent !== undefined){
const position = editor.getPosition();
editor.getModel()?.setValue(newContent);
if(position !== null){
editor.setPosition(position);
}
}
}
});
}
};

function getInitialFm(){
Expand Down

0 comments on commit 4cbb37e

Please sign in to comment.