From 7e9608cf7a4abe3251175ba6ab6acf2ba352c49f Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Wed, 22 Feb 2012 22:36:45 +0000 Subject: [PATCH] Adjust syntax highlighting of template lines to match how karaoke templater parses the line Originally committed to SVN as r6503. --- aegisub/src/subs_edit_ctrl.cpp | 49 ++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/aegisub/src/subs_edit_ctrl.cpp b/aegisub/src/subs_edit_ctrl.cpp index 5e0bcc5d2..f7fda4aa2 100644 --- a/aegisub/src/subs_edit_ctrl.cpp +++ b/aegisub/src/subs_edit_ctrl.cpp @@ -284,6 +284,9 @@ void SubsTextEditCtrl::UpdateStyle() { // Check if it's a template line AssDialogue *diag = context->selectionController->GetActiveLine(); bool templateLine = diag && diag->Comment && diag->Effect.Lower().StartsWith("template"); + size_t last_template = 0; + if (templateLine) + last_template = text.rfind('!'); bool in_parens = false; bool in_unparened_arg = false; @@ -313,8 +316,30 @@ void SubsTextEditCtrl::UpdateStyle() { int new_style = style; + // Start karaoke template variable + if (templateLine && cur_char == '$') { + new_style = STYLE_KARAOKE_VARIABLE; + } + // Continue karaoke template variable + else if (style == STYLE_KARAOKE_VARIABLE && ((cur_char >= 'A' && cur_char <= 'Z') || (cur_char >= 'a' && cur_char <= 'z') || cur_char == '_')) { + // Do nothing and just continue the karaoke variable style + } + // Start karaoke template + else if (templateLine && !in_karaoke_template && cur_char == '!' && i < last_template) { + new_style = STYLE_KARAOKE_TEMPLATE; + in_karaoke_template = true; + } + // End karaoke template + else if (in_karaoke_template && cur_char == '!') { + new_style = STYLE_KARAOKE_TEMPLATE; + in_karaoke_template = false; + } + // Continue karaoke template + else if (in_karaoke_template) { + new_style = STYLE_KARAOKE_TEMPLATE; + } // Start override block - if (cur_char == '{') { + else if (cur_char == '{') { new_style = in_ovr ? STYLE_ERROR : STYLE_OVERRIDE; in_ovr = true; } @@ -323,31 +348,9 @@ void SubsTextEditCtrl::UpdateStyle() { new_style = in_ovr ? STYLE_OVERRIDE : STYLE_ERROR; in_ovr = false; - in_karaoke_template = false; in_parens = false; in_unparened_arg = false; } - // Start karaoke template - else if (templateLine && style != STYLE_KARAOKE_TEMPLATE && cur_char == '!') { - new_style = STYLE_KARAOKE_TEMPLATE; - in_karaoke_template = true; - } - // End karaoke template - else if (style == STYLE_KARAOKE_TEMPLATE && cur_char == '!') { - in_karaoke_template = false; - } - // Continue karaoke template - else if (in_karaoke_template) { - // Do nothing and just continue the karaoke template style - } - // Start karaoke template variable - else if (templateLine && style != STYLE_KARAOKE_TEMPLATE && cur_char == '$') { - new_style = STYLE_KARAOKE_VARIABLE; - } - // Continue karaoke template variable - else if (style == STYLE_KARAOKE_VARIABLE && ((cur_char >= 'A' && cur_char <= 'Z') || (cur_char >= 'a' && cur_char <= 'z') || cur_char == '_')) { - // Do nothing and just continue the karaoke variable style - } // Plain text else if (!in_ovr) { // Is \n, \N or \h?