Skip to content

Commit

Permalink
problem_history_edit: add renum button
Browse files Browse the repository at this point in the history
  • Loading branch information
nblkblta committed Jun 22, 2021
1 parent 96a0b03 commit 5bd5e3c
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tt/lang/cn/problems.html.tt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
keyword => 'keyword',
input_format => 'input format',
output_format => 'output format',
formatting => 'formatting',
renum_tests => 'renum tests',
upload => 'upload',
want_to_delete_file => 'Do you really want to delete file ',
different_versions => 'Files on server and client did not match',
Expand Down
2 changes: 2 additions & 0 deletions tt/lang/en/problems.html.tt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
keyword => 'keyword',
input_format => 'input format',
output_format => 'output format',
formatting => 'formatting',
renum_tests => 'renum tests',
upload => 'upload',
want_to_delete_file => 'Do you really want to delete file ',
different_versions => 'Files on server and client did not match',
Expand Down
2 changes: 2 additions & 0 deletions tt/lang/ru/problems.html.tt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
keyword => 'ключевое слово',
input_format => 'формат ввода',
output_format => 'формат вывода',
formatting => 'форматирование',
renum_tests => 'перенумеровать тесты',
upload => 'загрузить',
want_to_delete_file => 'Вы действительно желаете удалить файл ',
different_versions => 'Файлы на сервере и клиенте не совпали',
Expand Down
60 changes: 60 additions & 0 deletions tt/problem_history_edit.html.tt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,58 @@ window.addEventListener('load', function () {
editor.renderer.scrollCursorIntoView(insert_position, 0.5);
}
}

function renum_tests_function(){
var editorLines = editor.selection.getAllRanges();
var start = editorLines[0].start.row;
var end = editorLines[0].end.row;
if (start == end){
return;
}
var text ="";
var new_line = editor.session.getLine(start);
text += new_line + "\n";
while (new_line==""){
start++
new_line = editor.session.getLine(start);
}
first_mark = new_line.indexOf('"');
second_mark = new_line.indexOf('"',first_mark+1);
num = new_line.slice(first_mark+1,second_mark);
if (num.indexOf('-')<0){
count = num.match(/(\d+)/)[0];
}else{
count = num.slice(num.indexOf('-')+1,num.length);
}
var prefix, suffix, first_mark, second_mark, add_num;
for (let i = start+1;i<=end;i++){
new_line = editor.session.getLine(i);
if (new_line==""){
continue;
}
count++;
first_mark = new_line.indexOf('"');
second_mark = new_line.indexOf('"',first_mark+1);
num = new_line.slice(first_mark+1,second_mark);
if (num.indexOf('-')<0){
num = count;
}else{
first_num = num.slice(0,num.indexOf('-'));
second_num = num.slice(num.indexOf('-')+1,num.length);
diff = second_num-first_num;
first_num = count;
second_num = first_num + diff;
num = first_num +"-"+ second_num;
count = second_num;
}
prefix = new_line.slice(0,first_mark+1);
suffix = new_line.slice(second_mark, new_line.length);
text+=prefix + num + suffix+"\n";
}
text = text.slice(0,text.length - 1);
//delete "\n" in the end of text
editor.session.replace(editor.selection.getRange(),text);
}

$('#keyword_button').click(add_button_function(true,
/<Keyword code=/, '<Keyword code="', '" />\n', /<Keyword code=/, /<ProblemStatement>/));
Expand All @@ -117,6 +169,8 @@ window.addEventListener('load', function () {
$('#output_button').click(add_button_function(false,
/<OutputFormat>/, '<OutputFormat>', '</OutputFormat>\n', /InputFormat>/, /<ProblemConstraints>/));

$('#renum_tests_button').click(renum_tests_function);

$('.problem_menu_trigger').click(function() { $(this).toggleClass('problem_menu_hovered'); });
$('.button_menu_trigger').click(function() { $(this).toggleClass('button_menu_hovered'); });

Expand Down Expand Up @@ -165,6 +219,12 @@ window.addEventListener('load', function () {
<button type="button" id="output_button" class="button toolbar_item">[% capt.output_format %]</button>
</div>
</a>
<a class="button_menu_trigger button toolbar_item ">[% capt.formatting %]
<div class="editor_menu">
<button type="button" id="renum_tests_button" class="button toolbar_item">[% capt.renum_tests %]</button>
</div>
</a>

<a class="problem_menu_trigger toolbar_item">&#x2261
[%- PROCESS includes/editor_menu.tti editor_id = 'ed_pe' _ pid _ '_' _ (edit_file ? file : hash) -%]
</a>
Expand Down

0 comments on commit 5bd5e3c

Please sign in to comment.