1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-12 05:20:26 +00:00

Refactor the toolbar a little and move the cursor more

This commit is contained in:
bouncepaw 2021-04-05 22:38:44 +05:00
parent ded26881fd
commit 9070ef90e2
4 changed files with 176 additions and 144 deletions

View File

@ -461,37 +461,31 @@ function insertDate() {
insertTextAtCursor(date) insertTextAtCursor(date)
} }
function wrapBold() { function selectionWrapper(cursorPosition, prefix, postfix = null, el = editTextarea) {
wrapSelection('**') return function() {
const [start, end] = [el.selectionStart, el.selectionEnd]
if (postfix == null) {
postfix = prefix
}
text = getSelectedText(el)
result = prefix + text + postfix
el.setRangeText(result, start, end, 'select')
el.focus()
placeCursor(end + cursorPosition)
}
} }
function wrapItalic() { const wrapBold = selectionWrapper(2, '**'),
wrapSelection('//') wrapItalic = selectionWrapper(2, '//'),
} wrapMonospace = selectionWrapper(1, '`)
function wrapMonospace() {
wrapSelection('`)
//line assets/assets.qtpl:14 //line assets/assets.qtpl:14
qw422016.N().S("`") qw422016.N().S("`")
//line assets/assets.qtpl:14 //line assets/assets.qtpl:14
qw422016.N().S(`') qw422016.N().S(`'),
} wrapHighlighted = selectionWrapper(2, '!!'),
wrapLifted = selectionWrapper(1, '^'),
function wrapHighlighted() { wrapLowered = selectionWrapper(2, ',,'),
wrapSelection('!!') wrapStrikethrough = selectionWrapper(2, '~~')
}
function wrapLifted() {
wrapSelection('^')
}
function wrapLowered() {
wrapSelection(',,')
}
function wrapStroked() {
wrapSelection('~~')
}
function insertHorizontalBar() { function insertHorizontalBar() {
insertTextAtCursor('----\n') insertTextAtCursor('----\n')

View File

@ -39,33 +39,27 @@ function insertDate() {
insertTextAtCursor(date) insertTextAtCursor(date)
} }
function wrapBold() { function selectionWrapper(cursorPosition, prefix, postfix = null, el = editTextarea) {
wrapSelection('**') return function() {
const [start, end] = [el.selectionStart, el.selectionEnd]
if (postfix == null) {
postfix = prefix
}
text = getSelectedText(el)
result = prefix + text + postfix
el.setRangeText(result, start, end, 'select')
el.focus()
placeCursor(end + cursorPosition)
}
} }
function wrapItalic() { const wrapBold = selectionWrapper(2, '**'),
wrapSelection('//') wrapItalic = selectionWrapper(2, '//'),
} wrapMonospace = selectionWrapper(1, '`'),
wrapHighlighted = selectionWrapper(2, '!!'),
function wrapMonospace() { wrapLifted = selectionWrapper(1, '^'),
wrapSelection('`') wrapLowered = selectionWrapper(2, ',,'),
} wrapStrikethrough = selectionWrapper(2, '~~')
function wrapHighlighted() {
wrapSelection('!!')
}
function wrapLifted() {
wrapSelection('^')
}
function wrapLowered() {
wrapSelection(',,')
}
function wrapStroked() {
wrapSelection('~~')
}
function insertHorizontalBar() { function insertHorizontalBar() {
insertTextAtCursor('----\n') insertTextAtCursor('----\n')

View File

@ -4,16 +4,28 @@
{% func Toolbar() %} {% func Toolbar() %}
<aside class="edit-toolbar layout-card"> <aside class="edit-toolbar layout-card">
<h2 class="edit-toolbar__title layout-card__title">Actions</h2> <h2 class="edit-toolbar__title layout-card__title">Actions</h2>
<button class="edit-toolbar__bold" onclick="wrapBold()"><b>Bold</b></button> {% for _, el := range []struct{
<button class="edit-toolbar__italic" onclick="wrapItalic()"><i>Italic</i></button> class string
<button class="edit-toolbar__highlight" onclick="wrapHighlighted()"><mark>Highlight</mark></button> onclick string
<button class="edit-toolbar__monospace" onclick="wrapMonospace()"><code>Monospace</code></button> display string
<button class="edit-toolbar__lifted" onclick="wrapLifted()"><sup>Lifted</sup></button> }{
<button class="edit-toolbar__lowered" onclick="wrapLowered()"><sub>Lowered</sub></button> {"bold", "wrapBold()", "<b>**Bold**</b>"},
<button class="edit-toolbar__stroked" onclick="wrapStroked()"><s>Stroked</s></button> {"italic", "wrapItalic()", "<i>//Italic//</i>"},
<button class="edit-toolbar__date" onclick="insertDate()">Current Date</button> {"highlighted", "wrapHighlighted()", "<mark>!!Highlight!!</mark>"},
<button class="edit-toolbar__bar" onclick="insertHorizontalBar()">Horizontal Bar</button> {"monospace", "wrapMonospace()", "<code>`Monospace`</code>"},
<button class="edit-toolbar__img" onclick="insertImgBlock()">Image</button> {"lifted", "wrapLifted()", "<sup>^Lifted^</sup>"},
{"lowered", "wrapLowered()", "<sub>,,Lowered,,</sub>"},
{"strikethrough", "wrapStrikethrough()", "<strike>~~Strikethrough~~</strike>"},
{"img", "insertImgBlock()", "Image block <code>img {}</code>"},
{"hr", "insertHorizontalBar()", "Horizontal bar"},
{"date", "insertDate()", "Insert current date"},
} %}
<button
class="edit-toolbar__btn edit-toolbar__{%s el.class %}"
onclick="{%s el.onclick %}">
{%s= el.display %}
</button>
{% endfor %}
</aside> </aside>
<script src="/static/toolbar.js"></script> <script src="/static/toolbar.js"></script>
{% endfunc %} {% endfunc %}

View File

@ -29,206 +29,238 @@ func StreamToolbar(qw422016 *qt422016.Writer) {
qw422016.N().S(` qw422016.N().S(`
<aside class="edit-toolbar layout-card"> <aside class="edit-toolbar layout-card">
<h2 class="edit-toolbar__title layout-card__title">Actions</h2> <h2 class="edit-toolbar__title layout-card__title">Actions</h2>
<button class="edit-toolbar__bold" onclick="wrapBold()"><b>Bold</b></button> `)
<button class="edit-toolbar__italic" onclick="wrapItalic()"><i>Italic</i></button> //line views/mutators.qtpl:7
<button class="edit-toolbar__highlight" onclick="wrapHighlighted()"><mark>Highlight</mark></button> for _, el := range []struct {
<button class="edit-toolbar__monospace" onclick="wrapMonospace()"><code>Monospace</code></button> class string
<button class="edit-toolbar__lifted" onclick="wrapLifted()"><sup>Lifted</sup></button> onclick string
<button class="edit-toolbar__lowered" onclick="wrapLowered()"><sub>Lowered</sub></button> display string
<button class="edit-toolbar__stroked" onclick="wrapStroked()"><s>Stroked</s></button> }{
<button class="edit-toolbar__date" onclick="insertDate()">Current Date</button> {"bold", "wrapBold()", "<b>**Bold**</b>"},
<button class="edit-toolbar__bar" onclick="insertHorizontalBar()">Horizontal Bar</button> {"italic", "wrapItalic()", "<i>//Italic//</i>"},
<button class="edit-toolbar__img" onclick="insertImgBlock()">Image</button> {"highlighted", "wrapHighlighted()", "<mark>!!Highlight!!</mark>"},
{"monospace", "wrapMonospace()", "<code>`Monospace`</code>"},
{"lifted", "wrapLifted()", "<sup>^Lifted^</sup>"},
{"lowered", "wrapLowered()", "<sub>,,Lowered,,</sub>"},
{"strikethrough", "wrapStrikethrough()", "<strike>~~Strikethrough~~</strike>"},
{"img", "insertImgBlock()", "Image block <code>img {}</code>"},
{"hr", "insertHorizontalBar()", "Horizontal bar"},
{"date", "insertDate()", "Insert current date"},
} {
//line views/mutators.qtpl:22
qw422016.N().S(`
<button
class="edit-toolbar__btn edit-toolbar__`)
//line views/mutators.qtpl:24
qw422016.E().S(el.class)
//line views/mutators.qtpl:24
qw422016.N().S(`"
onclick="`)
//line views/mutators.qtpl:25
qw422016.E().S(el.onclick)
//line views/mutators.qtpl:25
qw422016.N().S(`">
`)
//line views/mutators.qtpl:26
qw422016.N().S(el.display)
//line views/mutators.qtpl:26
qw422016.N().S(`
</button>
`)
//line views/mutators.qtpl:28
}
//line views/mutators.qtpl:28
qw422016.N().S(`
</aside> </aside>
<script src="/static/toolbar.js"></script> <script src="/static/toolbar.js"></script>
`) `)
//line views/mutators.qtpl:19 //line views/mutators.qtpl:31
} }
//line views/mutators.qtpl:19 //line views/mutators.qtpl:31
func WriteToolbar(qq422016 qtio422016.Writer) { func WriteToolbar(qq422016 qtio422016.Writer) {
//line views/mutators.qtpl:19 //line views/mutators.qtpl:31
qw422016 := qt422016.AcquireWriter(qq422016) qw422016 := qt422016.AcquireWriter(qq422016)
//line views/mutators.qtpl:19 //line views/mutators.qtpl:31
StreamToolbar(qw422016) StreamToolbar(qw422016)
//line views/mutators.qtpl:19 //line views/mutators.qtpl:31
qt422016.ReleaseWriter(qw422016) qt422016.ReleaseWriter(qw422016)
//line views/mutators.qtpl:19 //line views/mutators.qtpl:31
} }
//line views/mutators.qtpl:19 //line views/mutators.qtpl:31
func Toolbar() string { func Toolbar() string {
//line views/mutators.qtpl:19 //line views/mutators.qtpl:31
qb422016 := qt422016.AcquireByteBuffer() qb422016 := qt422016.AcquireByteBuffer()
//line views/mutators.qtpl:19 //line views/mutators.qtpl:31
WriteToolbar(qb422016) WriteToolbar(qb422016)
//line views/mutators.qtpl:19 //line views/mutators.qtpl:31
qs422016 := string(qb422016.B) qs422016 := string(qb422016.B)
//line views/mutators.qtpl:19 //line views/mutators.qtpl:31
qt422016.ReleaseByteBuffer(qb422016) qt422016.ReleaseByteBuffer(qb422016)
//line views/mutators.qtpl:19 //line views/mutators.qtpl:31
return qs422016 return qs422016
//line views/mutators.qtpl:19 //line views/mutators.qtpl:31
} }
//line views/mutators.qtpl:21 //line views/mutators.qtpl:33
func StreamEditHTML(qw422016 *qt422016.Writer, rq *http.Request, hyphaName, textAreaFill, warning string) { func StreamEditHTML(qw422016 *qt422016.Writer, rq *http.Request, hyphaName, textAreaFill, warning string) {
//line views/mutators.qtpl:21 //line views/mutators.qtpl:33
qw422016.N().S(` qw422016.N().S(`
`) `)
//line views/mutators.qtpl:22 //line views/mutators.qtpl:34
qw422016.N().S(NavHTML(rq, hyphaName, "edit")) qw422016.N().S(NavHTML(rq, hyphaName, "edit"))
//line views/mutators.qtpl:22 //line views/mutators.qtpl:34
qw422016.N().S(` qw422016.N().S(`
<div class="layout"> <div class="layout">
<main class="main-width edit edit_no-preview"> <main class="main-width edit edit_no-preview">
<h1 class="edit__title">Edit `) <h1 class="edit__title">Edit `)
//line views/mutators.qtpl:25 //line views/mutators.qtpl:37
qw422016.E().S(util.BeautifulName(hyphaName)) qw422016.E().S(util.BeautifulName(hyphaName))
//line views/mutators.qtpl:25 //line views/mutators.qtpl:37
qw422016.N().S(`</h1> qw422016.N().S(`</h1>
`) `)
//line views/mutators.qtpl:26 //line views/mutators.qtpl:38
qw422016.N().S(warning) qw422016.N().S(warning)
//line views/mutators.qtpl:26 //line views/mutators.qtpl:38
qw422016.N().S(` qw422016.N().S(`
<form method="post" class="edit-form" <form method="post" class="edit-form"
action="/upload-text/`) action="/upload-text/`)
//line views/mutators.qtpl:28 //line views/mutators.qtpl:40
qw422016.E().S(hyphaName) qw422016.E().S(hyphaName)
//line views/mutators.qtpl:28 //line views/mutators.qtpl:40
qw422016.N().S(`"> qw422016.N().S(`">
<textarea name="text" class="edit-form__textarea">`) <textarea name="text" class="edit-form__textarea">`)
//line views/mutators.qtpl:29 //line views/mutators.qtpl:41
qw422016.E().S(textAreaFill) qw422016.E().S(textAreaFill)
//line views/mutators.qtpl:29 //line views/mutators.qtpl:41
qw422016.N().S(`</textarea> qw422016.N().S(`</textarea>
<br/> <br/>
<input type="submit" name="action" value="Save" class="edit-form__save"/> <input type="submit" name="action" value="Save" class="edit-form__save"/>
<input type="submit" name="action" value="Preview" class="edit-form__preview"> <input type="submit" name="action" value="Preview" class="edit-form__preview">
<a href="/page/`) <a href="/page/`)
//line views/mutators.qtpl:33 //line views/mutators.qtpl:45
qw422016.E().S(hyphaName) qw422016.E().S(hyphaName)
//line views/mutators.qtpl:33 //line views/mutators.qtpl:45
qw422016.N().S(`" class="edit-form__cancel">Cancel</a> qw422016.N().S(`" class="edit-form__cancel">Cancel</a>
</form> </form>
</main> </main>
`) `)
//line views/mutators.qtpl:36 //line views/mutators.qtpl:48
qw422016.N().S(Toolbar()) qw422016.N().S(Toolbar())
//line views/mutators.qtpl:36 //line views/mutators.qtpl:48
qw422016.N().S(` qw422016.N().S(`
</div> </div>
`) `)
//line views/mutators.qtpl:38 //line views/mutators.qtpl:50
} }
//line views/mutators.qtpl:38 //line views/mutators.qtpl:50
func WriteEditHTML(qq422016 qtio422016.Writer, rq *http.Request, hyphaName, textAreaFill, warning string) { func WriteEditHTML(qq422016 qtio422016.Writer, rq *http.Request, hyphaName, textAreaFill, warning string) {
//line views/mutators.qtpl:38 //line views/mutators.qtpl:50
qw422016 := qt422016.AcquireWriter(qq422016) qw422016 := qt422016.AcquireWriter(qq422016)
//line views/mutators.qtpl:38 //line views/mutators.qtpl:50
StreamEditHTML(qw422016, rq, hyphaName, textAreaFill, warning) StreamEditHTML(qw422016, rq, hyphaName, textAreaFill, warning)
//line views/mutators.qtpl:38 //line views/mutators.qtpl:50
qt422016.ReleaseWriter(qw422016) qt422016.ReleaseWriter(qw422016)
//line views/mutators.qtpl:38 //line views/mutators.qtpl:50
} }
//line views/mutators.qtpl:38 //line views/mutators.qtpl:50
func EditHTML(rq *http.Request, hyphaName, textAreaFill, warning string) string { func EditHTML(rq *http.Request, hyphaName, textAreaFill, warning string) string {
//line views/mutators.qtpl:38 //line views/mutators.qtpl:50
qb422016 := qt422016.AcquireByteBuffer() qb422016 := qt422016.AcquireByteBuffer()
//line views/mutators.qtpl:38 //line views/mutators.qtpl:50
WriteEditHTML(qb422016, rq, hyphaName, textAreaFill, warning) WriteEditHTML(qb422016, rq, hyphaName, textAreaFill, warning)
//line views/mutators.qtpl:38 //line views/mutators.qtpl:50
qs422016 := string(qb422016.B) qs422016 := string(qb422016.B)
//line views/mutators.qtpl:38 //line views/mutators.qtpl:50
qt422016.ReleaseByteBuffer(qb422016) qt422016.ReleaseByteBuffer(qb422016)
//line views/mutators.qtpl:38 //line views/mutators.qtpl:50
return qs422016 return qs422016
//line views/mutators.qtpl:38 //line views/mutators.qtpl:50
} }
//line views/mutators.qtpl:40 //line views/mutators.qtpl:52
func StreamPreviewHTML(qw422016 *qt422016.Writer, rq *http.Request, hyphaName, textAreaFill, warning string, renderedPage string) { func StreamPreviewHTML(qw422016 *qt422016.Writer, rq *http.Request, hyphaName, textAreaFill, warning string, renderedPage string) {
//line views/mutators.qtpl:40 //line views/mutators.qtpl:52
qw422016.N().S(` qw422016.N().S(`
`) `)
//line views/mutators.qtpl:41 //line views/mutators.qtpl:53
qw422016.N().S(NavHTML(rq, hyphaName, "edit")) qw422016.N().S(NavHTML(rq, hyphaName, "edit"))
//line views/mutators.qtpl:41 //line views/mutators.qtpl:53
qw422016.N().S(` qw422016.N().S(`
<div class="layout"> <div class="layout">
<main class="main-width edit edit_with-preview"> <main class="main-width edit edit_with-preview">
<h1>Edit `) <h1>Edit `)
//line views/mutators.qtpl:44 //line views/mutators.qtpl:56
qw422016.E().S(util.BeautifulName(hyphaName)) qw422016.E().S(util.BeautifulName(hyphaName))
//line views/mutators.qtpl:44 //line views/mutators.qtpl:56
qw422016.N().S(` (preview)</h1> qw422016.N().S(` (preview)</h1>
`) `)
//line views/mutators.qtpl:45 //line views/mutators.qtpl:57
qw422016.N().S(warning) qw422016.N().S(warning)
//line views/mutators.qtpl:45 //line views/mutators.qtpl:57
qw422016.N().S(` qw422016.N().S(`
<form method="post" class="edit-form" <form method="post" class="edit-form"
action="/upload-text/`) action="/upload-text/`)
//line views/mutators.qtpl:47 //line views/mutators.qtpl:59
qw422016.E().S(hyphaName) qw422016.E().S(hyphaName)
//line views/mutators.qtpl:47 //line views/mutators.qtpl:59
qw422016.N().S(`"> qw422016.N().S(`">
<textarea class="edit-form__textarea" name="text">`) <textarea class="edit-form__textarea" name="text">`)
//line views/mutators.qtpl:48 //line views/mutators.qtpl:60
qw422016.E().S(textAreaFill) qw422016.E().S(textAreaFill)
//line views/mutators.qtpl:48 //line views/mutators.qtpl:60
qw422016.N().S(`</textarea> qw422016.N().S(`</textarea>
<br/> <br/>
<input type="submit" name="action" value="Save" class="edit-form__save"/> <input type="submit" name="action" value="Save" class="edit-form__save"/>
<input type="submit" name="action" value="Preview" class="edit-form__preview"> <input type="submit" name="action" value="Preview" class="edit-form__preview">
<a href="/page/`) <a href="/page/`)
//line views/mutators.qtpl:52 //line views/mutators.qtpl:64
qw422016.E().S(hyphaName) qw422016.E().S(hyphaName)
//line views/mutators.qtpl:52 //line views/mutators.qtpl:64
qw422016.N().S(`" class="edit-form__cancel">Cancel</a> qw422016.N().S(`" class="edit-form__cancel">Cancel</a>
</form> </form>
<p class="warning">Note that the hypha is not saved yet. You can preview the changes </p> <p class="warning">Note that the hypha is not saved yet. You can preview the changes </p>
<article class="edit__preview">`) <article class="edit__preview">`)
//line views/mutators.qtpl:55 //line views/mutators.qtpl:67
qw422016.N().S(renderedPage) qw422016.N().S(renderedPage)
//line views/mutators.qtpl:55 //line views/mutators.qtpl:67
qw422016.N().S(`</article> qw422016.N().S(`</article>
</main> </main>
`) `)
//line views/mutators.qtpl:57 //line views/mutators.qtpl:69
qw422016.N().S(Toolbar()) qw422016.N().S(Toolbar())
//line views/mutators.qtpl:57 //line views/mutators.qtpl:69
qw422016.N().S(` qw422016.N().S(`
</div> </div>
`) `)
//line views/mutators.qtpl:59 //line views/mutators.qtpl:71
} }
//line views/mutators.qtpl:59 //line views/mutators.qtpl:71
func WritePreviewHTML(qq422016 qtio422016.Writer, rq *http.Request, hyphaName, textAreaFill, warning string, renderedPage string) { func WritePreviewHTML(qq422016 qtio422016.Writer, rq *http.Request, hyphaName, textAreaFill, warning string, renderedPage string) {
//line views/mutators.qtpl:59 //line views/mutators.qtpl:71
qw422016 := qt422016.AcquireWriter(qq422016) qw422016 := qt422016.AcquireWriter(qq422016)
//line views/mutators.qtpl:59 //line views/mutators.qtpl:71
StreamPreviewHTML(qw422016, rq, hyphaName, textAreaFill, warning, renderedPage) StreamPreviewHTML(qw422016, rq, hyphaName, textAreaFill, warning, renderedPage)
//line views/mutators.qtpl:59 //line views/mutators.qtpl:71
qt422016.ReleaseWriter(qw422016) qt422016.ReleaseWriter(qw422016)
//line views/mutators.qtpl:59 //line views/mutators.qtpl:71
} }
//line views/mutators.qtpl:59 //line views/mutators.qtpl:71
func PreviewHTML(rq *http.Request, hyphaName, textAreaFill, warning string, renderedPage string) string { func PreviewHTML(rq *http.Request, hyphaName, textAreaFill, warning string, renderedPage string) string {
//line views/mutators.qtpl:59 //line views/mutators.qtpl:71
qb422016 := qt422016.AcquireByteBuffer() qb422016 := qt422016.AcquireByteBuffer()
//line views/mutators.qtpl:59 //line views/mutators.qtpl:71
WritePreviewHTML(qb422016, rq, hyphaName, textAreaFill, warning, renderedPage) WritePreviewHTML(qb422016, rq, hyphaName, textAreaFill, warning, renderedPage)
//line views/mutators.qtpl:59 //line views/mutators.qtpl:71
qs422016 := string(qb422016.B) qs422016 := string(qb422016.B)
//line views/mutators.qtpl:59 //line views/mutators.qtpl:71
qt422016.ReleaseByteBuffer(qb422016) qt422016.ReleaseByteBuffer(qb422016)
//line views/mutators.qtpl:59 //line views/mutators.qtpl:71
return qs422016 return qs422016
//line views/mutators.qtpl:59 //line views/mutators.qtpl:71
} }