Skip to content

Commit 31dc5b6

Browse files
committed
tabs 2, option to use codemirror, line numbers
1 parent 0d02b91 commit 31dc5b6

File tree

6 files changed

+25
-7
lines changed

6 files changed

+25
-7
lines changed

DEVELOPMENT.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,20 @@ Mine is configured only to respond to requests for domains I control.
7272

7373
Then, in one terminal
7474

75-
```
75+
```bash
7676
REACT_APP_OAUTH_HELPER_URL=<url-to-your-auth-helper> npm start
7777
```
7878

7979
and in another.
8080

81-
```
82-
ngron http --subdomain=somedomain 3000
81+
```bash
82+
ngrok http --subdomain=somedomain 3000
8383
```
8484

8585
Then go to `https://somedomain.ngrok.io`. Note that at the moment the preview won't
8686
work but you can test authenticating, etc...
87+
88+
# Switching editors
89+
90+
By default Monaco is used on desktop, CodeMirror on mobile.
91+
To test CodeMirror on desktop add `codeMirror=true` as a query parameter.

src/components/App.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,10 @@ hr {
702702
resize: vertical;
703703
overflow: auto;
704704
}
705+
.new-comment .new-comment-write {
706+
min-height: 10em;
707+
height: 10em;
708+
}
705709
.new-comment .new-comment-preview {
706710
min-height: 10em;
707711
padding: 0.5em;

src/components/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import ServiceContext from '../ServiceContext.js';
1818
import Settings from './Settings.js';
1919
import UserManager from '../libs/UserManager.js';
2020
import * as winMsgMgr from '../libs/WindowMessageManager';
21+
import query from '../libs/start-query.js';
2122

2223
import './App.css';
2324

@@ -90,7 +91,6 @@ class App extends React.Component {
9091
this.setState({dark: darkMatcher.matches});
9192
});
9293

93-
const query = Object.fromEntries(new URLSearchParams(window.location.search).entries());
9494
if (query.newGist) {
9595
window.history.pushState({}, '', `${window.location.origin}`);
9696
window.opener.postMessage({type: 'gimmeDaCodez'}, '*');

src/components/Code.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import React from 'react';
22
import CodeCodeMirror from './CodeCodeMirror';
33
import CodeMonaco from './CodeMonaco';
4+
import query from '../libs/start-query.js';
45

56
// TODO: Make Monaco lazy load
67

78
// This sucks but Monaco doesn't work on mobile
8-
const canMonaco = !(/webOS|iPhone|iPad|Android/.test(navigator.userAgent));
9+
const canMonaco = !query.codeMirror && !(/webOS|iPhone|iPad|Android/.test(navigator.userAgent));
910

1011
export default function Code(props) {
1112
return (

src/components/CodeMonaco.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ const darkMatcher = window.matchMedia
88

99
const noop = () => {};
1010

11+
function codeMirrorModeToLanguage(editor) {
12+
const language = (editor?.mode || 'javascript').split('/').pop();
13+
return language === 'gfm' ? 'markdown' : language;
14+
}
15+
1116
export default class CodeMonaco extends React.Component {
1217
constructor(props) {
1318
super(props);
@@ -22,6 +27,7 @@ export default class CodeMonaco extends React.Component {
2227
}
2328
handleEditorDidMount = (editor, monaco) => {
2429
this.editor = editor;
30+
editor.getModel().updateOptions({tabSize: 2});
2531
const {registerAPI} = this.props;
2632
if (registerAPI) {
2733
registerAPI({
@@ -50,7 +56,7 @@ export default class CodeMonaco extends React.Component {
5056
// https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.IEditorConstructionOptions.html
5157

5258
// we pass in mime-type (eg. 'text/css' but monaco wants just 'css')
53-
const language = (options.editor?.mode || 'javascript').split('/').pop();
59+
const language = codeMirrorModeToLanguage(options.editor).split('/').pop();
5460
return (
5561
<Editor
5662
theme={isDarkMode ? "vs-dark" : "light"}
@@ -60,7 +66,7 @@ export default class CodeMonaco extends React.Component {
6066
onMount={this.handleEditorDidMount}
6167
options={{
6268
minimap: {enabled: false},
63-
lineNumbers: "off",
69+
// lineNumbers: "off",
6470
glyphMargin: false,
6571
folding: false,
6672
}}

src/libs/start-query.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const query = Object.fromEntries(new URLSearchParams(window.location.search).entries());
2+
export default query;

0 commit comments

Comments
 (0)