diff --git a/assets/assets.qtpl.go b/assets/assets.qtpl.go
index 6ff02ce..5fddd1a 100644
--- a/assets/assets.qtpl.go
+++ b/assets/assets.qtpl.go
@@ -422,15 +422,84 @@ func StreamToolbarJS(qw422016 *qt422016.Writer) {
//line assets/assets.qtpl:14
qw422016.N().S(`const editTextarea = document.getElementsByClassName('edit-form__textarea')[0]
-function insertTextAtCursor(text, el = editTextarea) {
- const [start, end] = [el.selectionStart, el.selectionEnd];
- el.setRangeText(text, start, end, 'select');
+function placeCursor(position, el = editTextarea) {
+ el.selectionEnd = position
+ el.selectionStart = el.selectionEnd
+}
+
+function getSelectedText(el = editTextarea) {
+ const [start, end] = [el.selectionStart, el.selectionEnd]
+ const text = el.value
+ return text.substring(start, end)
+}
+
+function insertTextAtCursor(text, cursorPosition = null, el = editTextarea) {
+ const [start, end] = [el.selectionStart, el.selectionEnd]
+ el.setRangeText(text, start, end, 'select')
+ el.focus()
+ if (cursorPosition == null) {
+ placeCursor(end + text.length)
+ } else {
+ placeCursor(end + cursorPosition)
+ }
+}
+
+function wrapSelection(prefix, postfix = null, el = editTextarea) {
+ 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 + (prefix + postfix).length)
}
function insertDate() {
let date = new Date().toISOString().split('T')[0]
insertTextAtCursor(date)
}
+
+function wrapBold() {
+ wrapSelection('**')
+}
+
+function wrapItalic() {
+ wrapSelection('//')
+}
+
+function wrapMonospace() {
+ wrapSelection('`)
+//line assets/assets.qtpl:14
+ qw422016.N().S("`")
+//line assets/assets.qtpl:14
+ qw422016.N().S(`')
+}
+
+function wrapHighlighted() {
+ wrapSelection('!!')
+}
+
+function wrapLifted() {
+ wrapSelection('^')
+}
+
+function wrapLowered() {
+ wrapSelection(',,')
+}
+
+function wrapStroked() {
+ wrapSelection('~~')
+}
+
+function insertHorizontalBar() {
+ insertTextAtCursor('----\n')
+}
+
+function insertImgBlock() {
+ insertTextAtCursor('img {\n\t\n}\n', 7)
+}
`)
//line assets/assets.qtpl:14
qw422016.N().S(`
diff --git a/assets/toolbar.js b/assets/toolbar.js
index a528e73..7ea07aa 100644
--- a/assets/toolbar.js
+++ b/assets/toolbar.js
@@ -1,11 +1,76 @@
const editTextarea = document.getElementsByClassName('edit-form__textarea')[0]
-function insertTextAtCursor(text, el = editTextarea) {
- const [start, end] = [el.selectionStart, el.selectionEnd];
- el.setRangeText(text, start, end, 'select');
+function placeCursor(position, el = editTextarea) {
+ el.selectionEnd = position
+ el.selectionStart = el.selectionEnd
+}
+
+function getSelectedText(el = editTextarea) {
+ const [start, end] = [el.selectionStart, el.selectionEnd]
+ const text = el.value
+ return text.substring(start, end)
+}
+
+function insertTextAtCursor(text, cursorPosition = null, el = editTextarea) {
+ const [start, end] = [el.selectionStart, el.selectionEnd]
+ el.setRangeText(text, start, end, 'select')
+ el.focus()
+ if (cursorPosition == null) {
+ placeCursor(end + text.length)
+ } else {
+ placeCursor(end + cursorPosition)
+ }
+}
+
+function wrapSelection(prefix, postfix = null, el = editTextarea) {
+ 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 + (prefix + postfix).length)
}
function insertDate() {
let date = new Date().toISOString().split('T')[0]
insertTextAtCursor(date)
}
+
+function wrapBold() {
+ wrapSelection('**')
+}
+
+function wrapItalic() {
+ wrapSelection('//')
+}
+
+function wrapMonospace() {
+ wrapSelection('`')
+}
+
+function wrapHighlighted() {
+ wrapSelection('!!')
+}
+
+function wrapLifted() {
+ wrapSelection('^')
+}
+
+function wrapLowered() {
+ wrapSelection(',,')
+}
+
+function wrapStroked() {
+ wrapSelection('~~')
+}
+
+function insertHorizontalBar() {
+ insertTextAtCursor('----\n')
+}
+
+function insertImgBlock() {
+ insertTextAtCursor('img {\n\t\n}\n', 7)
+}
diff --git a/views/mutators.qtpl b/views/mutators.qtpl
index dfcc049..a32bd23 100644
--- a/views/mutators.qtpl
+++ b/views/mutators.qtpl
@@ -1,15 +1,29 @@
{% import "net/http" %}
{% import "github.com/bouncepaw/mycorrhiza/util" %}
+{% func Toolbar() %}
+
+
+{% endfunc %}
+
{% func EditHTML(rq *http.Request, hyphaName, textAreaFill, warning string) %}
{%s= NavHTML(rq, hyphaName, "edit") %}
Edit {%s util.BeautifulName(hyphaName) %}
{%s= warning %}
-
-
-
+{%s= Toolbar() %}
-
{% endfunc %}
{% func PreviewHTML(rq *http.Request, hyphaName, textAreaFill, warning string, renderedPage string) %}
@@ -31,7 +45,7 @@
{%s= warning %}