Commit f4d44034 authored by Michal Čihař's avatar Michal Čihař

Cleanup code for copying placeable

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 8bf43787
......@@ -92,6 +92,8 @@ While translating you can use following keyboard shortcuts:
Focus comment editor.
:kbd:`Alt+M`
Shows machine translation tab.
:kbd:`Alt+<NUMBER>`
Copies placeable of given number from source string.
:kbd:`Alt+M <NUMBER>`
Copy machine translation of given number to current translation.
:kbd:`Alt+I <NUMBER>`
......
......@@ -654,38 +654,37 @@ $(function () {
/* Copy from source text highlight check */
$('.hlcheck').click(function (e) {
var text = $(this).clone();
text.find(".nchk").remove();
text.find(".highlight-number").remove();
text=text.text();
$('.translation-editor').insertAtCaret($.trim(text)).trigger('autosize.resize');;
e.preventDefault();
});
/* and shortcuts */
var possibleShortcuts=['a','b','d','g','i','j','k','l','o','p','q','t','u','w','x','y'];
for (var icheck=0;icheck<possibleShortcuts.length;icheck++){
Mousetrap.bindGlobal("alt+"+possibleShortcuts[icheck], function(e) { });
for (var i = 1; i < 10; i++) {
Mousetrap.bindGlobal("alt+" + i, function(e) {});
}
if ($(".hlcheck").length>0) {
$('.hlcheck').each(function(idx){
var $this = $(this);
if (idx <possibleShortcuts.length) {
if ($this.find(".nchk").length > 0) {
$this.find(".nchk").html(
"<sup title='ALT+" + possibleShortcuts[idx] + "'>" + possibleShortcuts[idx] + "</sup>"
);
} else {
$this.prepend(
"<span class='nchk text-info' ><sup title='ALT+" + possibleShortcuts[idx] + "'>" + possibleShortcuts[idx] + "</sup></span>"
);
}
if (idx < 10) {
var key = getNumericKey(idx);
$(this).find('.highlight-number').html(
" <span class='badge kbd-badge' title='" +
interpolate(gettext('Alt+%s'), [key]) +
"'>" +
key +
"</span>"
);
Mousetrap.bindGlobal(
"alt+" + possibleShortcuts[idx],
function(e) { $this.click(); return false; }
"alt+" + key,
function(e) {
$this.click();
return false;
}
);
} else {
if ($this.find(".nchk")) {
$this.find(".nchk").html("");
}
$this.find(".highlight-number").html("");
}
});
}
......
......@@ -128,7 +128,7 @@ def format_translation(value, language, diff=None, search_match=None,
htext = escape(force_text(highlight[2]))
find_highlight = value.find(htext, start_search)
if find_highlight >= 0:
newpart = u'<span class="hlcheck">{0}</span>'.format(htext)
newpart = u'<span class="hlcheck">{0}<span class="highlight-number"></span></span>'.format(htext)
next_part = value[(find_highlight + len(htext)):]
value = value[:find_highlight] + newpart + next_part
start_search = find_highlight + len(newpart)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment