Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem_history_edit: Fix moving cursor and button menu style #373

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -605,3 +605,11 @@ table.edit_form td p.form_error { color: red; font-size: small; }
}

.keywords_cell a:hover { color: #e0e0e0; background-color: black; }

.button_menu_trigger {
display: inline-block;
padding-left: 5px;
padding-right: 5px;
}
.button_menu_trigger .editor_menu { display: none; }
.button_menu_trigger.button_menu_hovered .editor_menu { display: block; }
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
107 changes: 105 additions & 2 deletions tt/problem_history_edit.html.tt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ window.addEventListener('load', function () {
var search = function() { return editor.$search.findAll(editor.session); };
if (!is_repeat) {
editor.$search.setOptions({ needle: tag });
if (search().length)
var matches = search();
if (matches.length)
var match = matches[matches.length - 1].start;
var insert_position = { row: match.row, column: match.column };
editor.selection.moveTo(insert_position.row, prefix.length);
// 0.5 centers the line on screen
editor.renderer.scrollCursorIntoView(insert_position, 0.5);
return;
}
editor.$search.setOptions({ needle: prev });
Expand All @@ -103,14 +109,105 @@ window.addEventListener('load', function () {
editor.renderer.scrollCursorIntoView(insert_position, 0.5);
}
}

function renum_tests_function(){

var get_rank = function(new_line){
var first_mark = new_line.indexOf('rank="') + 5;
var second_mark = new_line.indexOf('"', first_mark + 1);
return new_line.slice(first_mark + 1, second_mark);
}

var is_valid = function(new_line){
if (new_line==null){
return false;
}
if (new_line.match(/<Test/) == null){
return false;
}
if (new_line.match(/rank=/) == null){
return false;
}
return true;
}

var find_min_rank = function(start, end){
var min_rank = 0;
for (var i = start; i <= end; i++) {
new_line = editor.session.getLine(i);
if (!is_valid(new_line)){
continue;
}
var rank = get_rank(new_line);
if (rank.indexOf('-') > 0) {
rank = rank.slice(0, rank.indexOf('-'));
}
if (!min_rank) {
min_rank = rank;
}
if (rank < min_rank) {
min_rank = rank;
}
}
return min_rank;
}

var editorLines = editor.selection.getAllRanges();
var start = editorLines[0].start.row;
var end = editorLines[0].end.row;
var text = "";
var new_line = editor.session.getLine(start);
while (!is_valid(new_line)) {
text += new_line + "\n";
start++;
new_line = editor.session.getLine(start);
}
var count = find_min_rank(start, end) - 1;
for (var i = start; i <= end; i++) {
new_line = editor.session.getLine(i);
if (!is_valid(new_line)) {
text += new_line + "\n";
continue;
}
count++;
var rank = get_rank(new_line);
var first_mark = new_line.indexOf('rank="') + 5;
var second_mark = new_line.indexOf('"', first_mark + 1);
prefix = new_line.slice(0,first_mark+1);
suffix = new_line.slice(second_mark, new_line.length);
if (rank.indexOf('-') < 0) {
rank = count;
} else {
var first_rank = rank.slice(0, rank.indexOf('-'));
var second_rank = rank.slice(rank.indexOf('-') + 1, rank.length);
var diff = second_rank - first_rank;
first_rank = count;
second_rank = first_rank + diff;
rank = first_rank +"-"+ second_rank;
count = second_rank;
}
text+=prefix + rank + suffix+"\n";
}
text = text.slice(0,text.length - 1);
//delete "\n" in the end of text
editorLines = editor.selection.getRange();
editorLines.start.column = 0;
editorLines.end.column = new_line.length;
editor.session.replace(editorLines, text);
}

$('#keyword_button').click(add_button_function(true,
/<Keyword code=/, '<Keyword code="', '" />\n', /<Keyword code=/, /<ProblemStatement>/));
$('#input_button').click(add_button_function(false,
/<InputFormat>/, '<InputFormat>', '</InputFormat>\n', /ProblemStatement>/, /<OutputFormat>/));
$('#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'); });

})</script>
[%- END %]
[% PROCESS includes/menu_begin.tti %]
Expand Down Expand Up @@ -149,13 +246,19 @@ window.addEventListener('load', function () {
<select id="de_id" class="toolbar_item">
[% FOREACH de IN de_list.des; editor_select_option(de.id, de.description, de.syntax, de.id == de_selected.id); END %]
</select>
<a class="problem_menu_trigger toolbar_item">[% capt.add %]
<a class="button_menu_trigger button toolbar_item ">[% capt.add %]
<div class="editor_menu">
<button type="button" id="keyword_button" class="button toolbar_item">[% capt.keyword %]</button>
<button type="button" id="input_button" class="button toolbar_item">[% capt.input_format %]</button>
<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