diff --git a/view/js/main.js b/view/js/main.js
index 7e84a08d8..47e7b968d 100644
--- a/view/js/main.js
+++ b/view/js/main.js
@@ -406,6 +406,61 @@ $(function() {
}
});
+/**
+ * Inserts a BBCode tag in the comment textarea identified by id
+ *
+ * @param {string} BBCode
+ * @param {int} id
+ * @returns {boolean}
+ */
+function insertFormatting(BBCode, id) {
+ let textarea = document.getElementById('comment-edit-text-' + id);
+
+ if (textarea.value === '') {
+ $(textarea)
+ .addClass("comment-edit-text-full")
+ .removeClass("comment-edit-text-empty");
+ closeMenu("comment-fake-form-" + id);
+ openMenu("item-comments-" + id);
+ }
+
+ insertBBCodeInTextarea(BBCode, textarea);
+
+ return true;
+}
+
+/**
+ * Inserts a BBCode tag in the provided textarea element, wrapping the currently selected text.
+ * For URL BBCode, it discriminates between link text and non-link text to determine where to insert the selected text.
+ *
+ * @param {string} BBCode
+ * @param {HTMLTextAreaElement} textarea
+ */
+function insertBBCodeInTextarea(BBCode, textarea) {
+ let selectionStart = textarea.selectionStart;
+ let selectionEnd = textarea.selectionEnd;
+ let selectedText = textarea.value.substring(selectionStart, selectionEnd);
+ let openingTag = '[' + BBCode + ']';
+ let closingTag = '[/' + BBCode + ']';
+ let cursorPosition = selectionStart + openingTag.length + selectedText.length;
+
+ if (BBCode === 'url') {
+ if (urlRegex.test(selectedText)) {
+ openingTag = '[' + BBCode + '=' + selectedText + ']';
+ selectedText = '';
+ cursorPosition = selectionStart + openingTag.length;
+ } else {
+ openingTag = '[' + BBCode + '=]';
+ cursorPosition = selectionStart + openingTag.length - 1;
+ }
+ }
+
+ textarea.value = textarea.value.substring(0, selectionStart) + openingTag + selectedText + closingTag + textarea.value.substring(selectionEnd, textarea.value.length);
+ textarea.setSelectionRange(cursorPosition, cursorPosition);
+ textarea.dispatchEvent(new Event('change'));
+ textarea.focus();
+}
+
function NavUpdate() {
if (!stopped) {
var pingCmd = 'ping?format=json' + ((localUser != 0) ? '&f=&uid=' + localUser : '');
diff --git a/view/theme/duepuntozero/theme.php b/view/theme/duepuntozero/theme.php
index 015e8090f..363f6dc48 100644
--- a/view/theme/duepuntozero/theme.php
+++ b/view/theme/duepuntozero/theme.php
@@ -28,28 +28,6 @@ Renderer::setActiveTemplateEngine('smarty3');
}
$a->page['htmlhead'] .= <<< EOT
diff --git a/view/theme/smoothly/theme.php b/view/theme/smoothly/theme.php
index 9dd958fff..e2289c87b 100644
--- a/view/theme/smoothly/theme.php
+++ b/view/theme/smoothly/theme.php
@@ -23,28 +23,6 @@ function smoothly_init(App $a) {
$a->page['htmlhead'] .= <<< EOT