Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zziger committed Oct 29, 2021
1 parent deac2dd commit 42535ff
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
6 changes: 3 additions & 3 deletions frontend/src/components/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export class Editor extends React.Component<EditorProps, EditorState> {

componentDidUpdate(prevProps: Readonly<EditorProps>, prevState: Readonly<EditorState>, snapshot?: any) {
if (prevProps.theme != this.props.theme) this.monaco?.editor.setTheme(this.props.theme);
this.editor?.layout();
}

editorLoaded = async (_: IStandaloneCodeEditor, editor: typeof monaco) => {
Expand Down Expand Up @@ -209,9 +210,8 @@ export class Editor extends React.Component<EditorProps, EditorState> {
render() {
return this.state.loaded
? <MonacoEditor
options={{
automaticLayout: true
}}
width="100%"
height="100%"
editorDidMount={this.editorLoaded}
language="javascript"
theme={this.state.loaded ? this.props.theme : 'vs-dark'}
Expand Down
10 changes: 7 additions & 3 deletions frontend/src/components/ResizableWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface WindowSize extends Vector2 {
}

interface ResizableWindowProps {
children: (startMove: (e: React.MouseEvent) => void) => JSX.Element;
children: (startMove: (e: React.MouseEvent) => void, dragging: boolean) => JSX.Element;
name: string;
visible?: boolean;
bgColor?: string;
Expand All @@ -22,6 +22,7 @@ interface ResizableWindowProps {

interface ResizableWindowState {
windowSize: WindowSize;
dragging: boolean;
}

export class ResizableWindow extends React.Component<ResizableWindowProps, ResizableWindowState> {
Expand All @@ -32,7 +33,8 @@ export class ResizableWindow extends React.Component<ResizableWindowProps, Resiz
y: 0,
width: 500,
height: 500,
}
},
dragging: false
}

private startWindowSize?: WindowSize;
Expand Down Expand Up @@ -64,6 +66,7 @@ export class ResizableWindow extends React.Component<ResizableWindowProps, Resiz
this.lastWindowSize = this.state.windowSize;
document.addEventListener('mousemove', this.processResize);
document.addEventListener('mouseup', this.stopResize);
this.setState({ dragging: true });
}

stopResize = () => {
Expand All @@ -75,6 +78,7 @@ export class ResizableWindow extends React.Component<ResizableWindowProps, Resiz
document.removeEventListener('mousemove', this.processResize);
document.removeEventListener('mouseup', this.stopResize);
this.save();
this.setState({ dragging: false });
};

processResize = (e: MouseEvent) => {
Expand Down Expand Up @@ -183,7 +187,7 @@ export class ResizableWindow extends React.Component<ResizableWindowProps, Resiz
{this.props.children((e: React.MouseEvent) => e.target == e.currentTarget && this.startMove({
x: e.clientX,
y: e.clientY
}))}
}), this.state.dragging)}
</div>
<div className="edge vertical" onMouseDown={this.getResize(true, undefined)}/>
<div className="corner right" onMouseDown={this.getResize(false, true)}/>
Expand Down
7 changes: 2 additions & 5 deletions frontend/src/styles/App.sass
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
cursor: nwse-resize

.content
overflow: hidden

.header
width: 100%
height: 30px
Expand Down Expand Up @@ -63,9 +61,8 @@
height: 100%

.innerContent
height: calc(100% - 30px)
height: calc(100% - 30px - #{$frame})
width: 100%
max-height: calc(100% - 30px)
max-width: 100%
background: RGB(var(--bg))
overflow: hidden
background: RGB(var(--bg))
4 changes: 4 additions & 0 deletions frontend/src/styles/codeEditor.sass
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@
background: RGB(var(--bg))
flex: 1

&[data-dragging=true]
& > *
display: none

.result
background: RGB(var(--bg))
height: 30%
Expand Down
13 changes: 6 additions & 7 deletions frontend/src/windows/codeEditor/CodeEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class CodeEditor extends React.Component<CodeEditorProps, CodeEditorState> {

log = (id: number, data: string) => {
if (this.actionId !== id) return;
this.setState({ result: this.state.result + this.converter.toHtml(data) + '<br>' });
this.setState({result: this.state.result + this.converter.toHtml(data) + '<br>'});
}

execute = async () => {
Expand Down Expand Up @@ -315,13 +315,12 @@ class CodeEditor extends React.Component<CodeEditorProps, CodeEditorState> {
}

setSetting = (key: string, value: any) => {
this.setState({settings: {...this.state.settings, [key]: value}});
this.saveSettings();
this.setState({settings: {...this.state.settings, [key]: value}}, this.saveSettings);
};

saveSettings() {
saveSettings = () => {
ClientMethods.save('codeEditor:settings', this.state.settings);
}
};

onUpdate = Utils.debounce(this.saveFile, 3000);

Expand All @@ -341,7 +340,7 @@ class CodeEditor extends React.Component<CodeEditorProps, CodeEditorState> {
styleColors['--sep'] = this.state.settings.highlightSeparators === false ? styleColors['--bg'] : styleColors['--fg'];

return <ResizableWindow bgColor={colors.background} fgColor={colors.foreground} name="codeEditor" visible={this.props.active}>
{startMove => <>
{(startMove, dragging) => <>
<div className="header" onMouseDown={startMove}>
<div className="name">Code
editor{!!this.state.activeFile && ` - ${this.state.activeFile} [${this.files.find(f => f.name === this.state.activeFile)?.type === 0 ? 'client' : 'server'}]`}</div>
Expand Down Expand Up @@ -385,7 +384,7 @@ class CodeEditor extends React.Component<CodeEditorProps, CodeEditorState> {
</div>
</div>
<div className="mainBlock" ref={this._mainBlockRef}>
<div className="code" style={{
<div className="code" data-dragging={dragging} style={{
height: (100 - this.state.resultHeight) + '%'
}}>
<Editor theme={theme} ref={this._ref} onLoaded={this.onEditorLoad} onUpdate={this.onUpdate}/>
Expand Down

0 comments on commit 42535ff

Please sign in to comment.