forked from mia/Aegisub
When the cursor is in a comment block, insert override tags at the beginning of the block rather than inside the comment
Originally committed to SVN as r5757.
This commit is contained in:
parent
4009d24e73
commit
035445e93a
2 changed files with 40 additions and 24 deletions
|
@ -662,14 +662,14 @@ void SubsEditBox::OnCommentChange(wxCommandEvent &event) {
|
||||||
SetSelectedRows(&AssDialogue::Comment, CommentBox->GetValue(), _("comment change"), AssFile::COMMIT_DIAG_META);
|
SetSelectedRows(&AssDialogue::Comment, CommentBox->GetValue(), _("comment change"), AssFile::COMMIT_DIAG_META);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SubsEditBox::BlockAtPos(int pos) const {
|
int SubsEditBox::BlockAtPos(wxString const& text, int pos) const {
|
||||||
int n=0;
|
int n = 0;
|
||||||
wxString text = TextEdit->GetText();;
|
int max = text.size() - 1;
|
||||||
int max = text.Length()-1;
|
for (int i = 0; i <= pos && i <= max; ++i) {
|
||||||
|
if (i > 0 && text[i] == '{')
|
||||||
for (int i=0;i<=pos && i<=max;i++) {
|
n++;
|
||||||
if (i > 0 && text[i] == '{') n++;
|
if (text[i] == '}' && i != max && i != pos && i != pos -1 && (i+1 == max || text[i+1] != '{'))
|
||||||
if (text[i] == '}' && i != max && i != pos && i != pos -1 && (i+1 == max || text[i+1] != '{')) n++;
|
n++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
|
@ -684,27 +684,43 @@ void SubsEditBox::SetTag(wxString tag, wxString value, bool atEnd) {
|
||||||
int selstart, selend;
|
int selstart, selend;
|
||||||
get_selection(TextEdit, selstart, selend);
|
get_selection(TextEdit, selstart, selend);
|
||||||
int start = atEnd ? selend : selstart;
|
int start = atEnd ? selend : selstart;
|
||||||
int blockn = BlockAtPos(start);
|
int blockn = BlockAtPos(line->Text, start);
|
||||||
|
|
||||||
AssDialogueBlock *block = line->Blocks[blockn];
|
AssDialogueBlockPlain *plain;
|
||||||
AssDialogueBlockPlain *plain = dynamic_cast<AssDialogueBlockPlain*>(block);
|
AssDialogueBlockOverride *ovr;
|
||||||
AssDialogueBlockOverride *ovr = dynamic_cast<AssDialogueBlockOverride*>(block);
|
while (blockn >= 0) {
|
||||||
|
AssDialogueBlock *block = line->Blocks[blockn];
|
||||||
// Drawings should always be preceded by an override block (with the \pX)
|
if (dynamic_cast<AssDialogueBlockDrawing*>(block))
|
||||||
if (dynamic_cast<AssDialogueBlockDrawing*>(block)) {
|
--blockn;
|
||||||
assert(blockn > 0);
|
else if (plain = dynamic_cast<AssDialogueBlockPlain*>(block)) {
|
||||||
ovr = dynamic_cast<AssDialogueBlockOverride*>(line->Blocks[blockn - 1]);
|
// Cursor is in a comment block, so try the previous block instead
|
||||||
assert(ovr);
|
if (plain->GetText().StartsWith("{")) {
|
||||||
|
--blockn;
|
||||||
|
start = line->Text.rfind('{', start);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ovr = dynamic_cast<AssDialogueBlockOverride*>(block);
|
||||||
|
assert(ovr);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we didn't hit a suitable block for inserting the override just put
|
||||||
|
// it at the beginning of the line
|
||||||
|
if (blockn < 0)
|
||||||
|
start = 0;
|
||||||
|
|
||||||
wxString insert = tag + value;
|
wxString insert = tag + value;
|
||||||
int shift = insert.size();
|
int shift = insert.size();
|
||||||
if (plain) {
|
if (plain || blockn < 0) {
|
||||||
line->Text = line->Text.Left(start) + "{" + insert + "}" + line->Text.Mid(start);
|
line->Text = line->Text.Left(start) + "{" + insert + "}" + line->Text.Mid(start);
|
||||||
shift += 2;
|
shift += 2;
|
||||||
line->ParseASSTags();
|
line->ParseASSTags();
|
||||||
}
|
}
|
||||||
else if (ovr) {
|
else {
|
||||||
wxString alt;
|
wxString alt;
|
||||||
if (tag == "\\c") alt = "\\1c";
|
if (tag == "\\c") alt = "\\1c";
|
||||||
// Remove old of same
|
// Remove old of same
|
||||||
|
@ -772,7 +788,7 @@ void SubsEditBox::OnFlagButton(wxCommandEvent &evt) {
|
||||||
line->ParseASSTags();
|
line->ParseASSTags();
|
||||||
int selstart, selend;
|
int selstart, selend;
|
||||||
get_selection(TextEdit, selstart, selend);
|
get_selection(TextEdit, selstart, selend);
|
||||||
int blockn = BlockAtPos(selstart);
|
int blockn = BlockAtPos(line->Text, selstart);
|
||||||
|
|
||||||
state = get_value(*line, blockn, state, tagname);
|
state = get_value(*line, blockn, state, tagname);
|
||||||
|
|
||||||
|
@ -790,7 +806,7 @@ void SubsEditBox::OnFontButton(wxCommandEvent &) {
|
||||||
get_selection(TextEdit, selstart, selend);
|
get_selection(TextEdit, selstart, selend);
|
||||||
|
|
||||||
line->ParseASSTags();
|
line->ParseASSTags();
|
||||||
int blockn = BlockAtPos(selstart);
|
int blockn = BlockAtPos(line->Text, selstart);
|
||||||
|
|
||||||
wxFont startfont;
|
wxFont startfont;
|
||||||
AssStyle *style = c->ass->GetStyle(line->Style);
|
AssStyle *style = c->ass->GetStyle(line->Style);
|
||||||
|
@ -863,7 +879,7 @@ void SubsEditBox::OnColorButton(wxCommandEvent &evt) {
|
||||||
line->ParseASSTags();
|
line->ParseASSTags();
|
||||||
int selstart, selend;
|
int selstart, selend;
|
||||||
get_selection(TextEdit, selstart, selend);
|
get_selection(TextEdit, selstart, selend);
|
||||||
int blockn = BlockAtPos(selstart);
|
int blockn = BlockAtPos(line->Text, selstart);
|
||||||
|
|
||||||
color = get_value(*line, blockn, color, colorTag, alt);
|
color = get_value(*line, blockn, color, colorTag, alt);
|
||||||
wxString initialText = line->Text;
|
wxString initialText = line->Text;
|
||||||
|
|
|
@ -122,7 +122,7 @@ class SubsEditBox : public wxPanel, protected SelectionListener<AssDialogue> {
|
||||||
void CommitText(wxString desc);
|
void CommitText(wxString desc);
|
||||||
|
|
||||||
/// Get block number at text position
|
/// Get block number at text position
|
||||||
int BlockAtPos(int pos) const;
|
int BlockAtPos(wxString const& text, int pos) const;
|
||||||
|
|
||||||
/// @brief Move to the next line, creating it if needed
|
/// @brief Move to the next line, creating it if needed
|
||||||
void NextLine();
|
void NextLine();
|
||||||
|
|
Loading…
Reference in a new issue