prometheus: monaco editor: visual fixes (#41184)

* prometheus: monaco editor: visual fixes

* fixed typo in comment

Co-authored-by: Piotr Jamróz <pm.jamroz@gmail.com>

* more comments added

Co-authored-by: Piotr Jamróz <pm.jamroz@gmail.com>
This commit is contained in:
Gábor Farkas 2021-11-02 12:44:51 +01:00 committed by GitHub
parent c45c246646
commit c788e2f8e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,24 +15,38 @@ const options: monacoTypes.editor.IStandaloneEditorConstructionOptions = {
fixedOverflowWidgets: true,
folding: false,
fontSize: 14,
lineDecorationsWidth: 8,
lineDecorationsWidth: 8, // used as "padding-left"
lineNumbers: 'off',
minimap: { enabled: false },
overviewRulerBorder: false,
overviewRulerLanes: 0,
padding: {
// these numbers were picked so that visually this matches the previous version
// of the query-editor the best
top: 4,
bottom: 4,
bottom: 5,
},
renderLineHighlight: 'none',
scrollbar: {
vertical: 'hidden',
verticalScrollbarSize: 8, // used as "padding-right"
horizontal: 'hidden',
horizontalScrollbarSize: 0,
},
scrollBeyondLastLine: false,
suggestFontSize: 12,
wordWrap: 'off',
wordWrap: 'on',
};
// this number was chosen by testing various values. it might be necessary
// because of the width of the border, not sure.
//it needs to do 2 things:
// 1. when the editor is single-line, it should make the editor height be visually correct
// 2. when the editor is multi-line, the editor should not be "scrollable" (meaning,
// you do a scroll-movement in the editor, and it will scroll the content by a couple pixels
// up & down. this we want to avoid)
const EDITOR_HEIGHT_OFFSET = 2;
const PROMQL_LANG_ID = promLanguageDefinition.id;
// we must only run the promql-setup code once
@ -157,7 +171,7 @@ const MonacoQueryField = (props: Props) => {
const containerDiv = containerRef.current;
if (containerDiv !== null) {
const pixelHeight = editor.getContentHeight();
containerDiv.style.height = `${pixelHeight}px`;
containerDiv.style.height = `${pixelHeight + EDITOR_HEIGHT_OFFSET}px`;
containerDiv.style.width = '100%';
const pixelWidth = containerDiv.clientWidth;
editor.layout({ width: pixelWidth, height: pixelHeight });