diff --git a/assets/css/index.css b/assets/css/index.css index 91edc09..334834f 100644 --- a/assets/css/index.css +++ b/assets/css/index.css @@ -593,6 +593,7 @@ u { .blockquote { display: flex; + display: -webkit-box; } .blockquote blockquote { @@ -647,7 +648,7 @@ u { white-space: pre-wrap; } -.markup pre, .markup blockquote { +.markup pre, .markup > blockquote { max-width: 90%; } diff --git a/assets/js/index.js b/assets/js/index.js index 56c0bc5..817fdd4 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -76,7 +76,6 @@ window.onload = () => { gui = guiParent.querySelector('.gui:first-of-type'); window.editor = CodeMirror(elt => editorHolder.parentNode.replaceChild(elt, editorHolder), { value: JSON.stringify(json, null, 4), - extraKeys: { Tab: cm => cm.replaceSelection(" ", "end") }, gutters: ["CodeMirror-foldgutter", "CodeMirror-lint-markers"], scrollbarStyle: "overlay", mode: "application/json", @@ -84,6 +83,22 @@ window.onload = () => { matchBrackets: true, foldGutter: true, lint: true, + extraKeys: { + // Make tabs four spaces long instead of the default two. + Tab: cm => cm.replaceSelection(" ", "end"), + // Fill in indent spaces on a new line when enter (return) key is pressed. + Enter: _ => { + let cur = editor.getCursor(), end = editor.getLine(cur.line), + leadingSpaces = end.replace(/\S($|.)+/g, '') || ' \n', nextLine = editor.getLine(cur.line + 1); + if ((nextLine === undefined || !nextLine.trim()) && !end.substr(cur.ch).trim()) + editor.replaceRange('\n', { line: cur.line, ch: cur.ch }); + else + editor.replaceRange(`\n${end.endsWith('{') ? leadingSpaces + ' ' : leadingSpaces}`, { + line: cur.line, + ch: cur.ch + }); + }, + } }); editor.focus(); @@ -156,8 +171,7 @@ window.onload = () => { if (data) el.innerHTML = data; el.style.display = displayType || "unset"; }, hide = el => el.style.removeProperty('display'), - imgSrc = (elm, src, remove) => remove ? elm.style.removeProperty('content') : elm.style.content = `url(${src})`, - toObj = jsonString => JSON.parse(jsonString.replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g, (x, y) => y ? "" : x)); + imgSrc = (elm, src, remove) => remove ? elm.style.removeProperty('content') : elm.style.content = `url(${src})`; buildGui = (object, opts) => { gui.innerHTML = `
Message content