More actions for EM page comments editor

This commit is contained in:
Kovid Goyal 2018-03-21 21:40:20 +05:30
parent c172e54223
commit 2645ef6209
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 30 additions and 5 deletions

5
imgsrc/srv/hr.svg Normal file
View File

@ -0,0 +1,5 @@
<svg viewBox="0 0 128 128" height="136.53334" width="136.53334">
<g transform="translate(0,-924.36216)">
<path d="m 127,990.98716 v -5.25 q 0,-1.1484 -0.73828,-1.8867 -0.73828,-0.7383 -1.88672,-0.7383 H 3.6250002 q -1.14844,0 -1.88672,0.7383 -0.7382799,0.7383 -0.7382799,1.8867 v 5.25 q 0,1.1484 0.7382799,1.8867 0.73828,0.7383 1.88672,0.7383 H 124.375 q 1.14844,0 1.88672,-0.7383 Q 127,992.13556 127,990.98716 Z" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 437 B

1
imgsrc/srv/subscript.svg Normal file
View File

@ -0,0 +1 @@
<svg width="1792" height="1792" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1025 1369v167h-248l-159-252-24-42q-8-9-11-21h-3l-9 21q-10 20-25 44l-155 250h-258v-167h128l197-291-185-272h-137v-168h276l139 228q2 4 23 42 8 9 11 21h3q3-9 11-21l25-42 140-228h257v168h-125l-184 267 204 296h109zm639 217v206h-514l-4-27q-3-45-3-46 0-64 26-117t65-86.5 84-65 84-54.5 65-54 26-64q0-38-29.5-62.5t-70.5-24.5q-51 0-97 39-14 11-36 38l-105-92q26-37 63-66 80-65 188-65 110 0 178 59.5t68 158.5q0 66-34.5 118.5t-84 86-99.5 62.5-87 63-41 73h232v-80h126z"/></svg>

After

Width:  |  Height:  |  Size: 563 B

View File

@ -0,0 +1 @@
<svg width="1792" height="1792" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1025 1369v167h-248l-159-252-24-42q-8-9-11-21h-3l-9 21q-10 20-25 44l-155 250h-258v-167h128l197-291-185-272h-137v-168h276l139 228q2 4 23 42 8 9 11 21h3q3-9 11-21l25-42 140-228h257v168h-125l-184 267 204 296h109zm637-679v206h-514l-3-27q-4-28-4-46 0-64 26-117t65-86.5 84-65 84-54.5 65-54 26-64q0-38-29.5-62.5t-70.5-24.5q-51 0-97 39-14 11-36 38l-105-92q26-37 63-66 83-65 188-65 110 0 178 59.5t68 158.5q0 56-24.5 103t-62 76.5-81.5 58.5-82 50.5-65.5 51.5-30.5 63h232v-80h126z"/></svg>

After

Width:  |  Height:  |  Size: 577 B

View File

@ -27,7 +27,7 @@ add_extra_css(def():
)
def all_editor_actions():
def all_editor_actions(): # {{{
if not all_editor_actions.ans:
all_editor_actions.ans = {
'select-all': {
@ -78,10 +78,27 @@ def all_editor_actions():
'execute': def (editor, activated):
editor.exec_command('strikeThrough')
},
'superscript': {
'icon': 'superscript',
'title': _('Superscript'),
'execute': def (editor, activated):
editor.exec_command('superscript')
},
'subscript': {
'icon': 'subscript',
'title': _('Subscript'),
'execute': def (editor, activated):
editor.exec_command('subscript')
},
'hr': {
'icon': 'hr',
'title': _('Insert separator'),
'execute': def (editor, activated):
editor.exec_command('insertHorizontalRule')
},
}
return all_editor_actions.ans
# }}}
class CommentsEditorBoss:
@ -100,6 +117,7 @@ class CommentsEditorBoss:
window.onerror = self.onerror
clear(document.body)
document.execCommand("defaultParagraphSeparator", False, "div")
document.execCommand("styleWithCSS", False, False)
document.body.style.margin = '0'
document.body.style.padding = '0'
document.documentElement.style.height = document.body.style.height = '100%'
@ -135,7 +153,7 @@ class CommentsEditorBoss:
self.update_state()
def update_state(self):
state = {name: document.queryCommandState(name) for name in 'bold italic underline'.split(' ')}
state = {name: document.queryCommandState(name) for name in 'bold italic underline superscript subscript'.split(' ')}
state.strikethrough = document.queryCommandState('strikeThrough')
self.comm.send_message('update_state', state=state)
@ -254,7 +272,7 @@ def create_comments_editor(container):
toolbar1 = E.div(class_=TOOLBAR_CLASS)
toolbars.appendChild(toolbar1)
acmap = all_editor_actions()
for ac_name in 'undo redo select-all remove-format | bold italic underline strikethrough |'.split(' '):
for ac_name in 'undo redo select-all remove-format | bold italic underline strikethrough | hr superscript subscript'.split(' '):
if acmap[ac_name]:
add_action(toolbar1, ac_name, acmap[ac_name], editor.id)
else: