mirror of
https://github.com/odrling/Aegisub
synced 2025-04-11 22:56:02 +02:00
Several fixes to scintilla, regarding weird styling and spellchecker
Originally committed to SVN as r605.
This commit is contained in:
parent
1e1841fc86
commit
204b0332d6
@ -49,6 +49,8 @@ SubsTextEditCtrl::SubsTextEditCtrl(wxWindow* parent, wxWindowID id, const wxStri
|
|||||||
// Set properties
|
// Set properties
|
||||||
SetWrapMode(wxSCI_WRAP_WORD);
|
SetWrapMode(wxSCI_WRAP_WORD);
|
||||||
SetMarginWidth(1,0);
|
SetMarginWidth(1,0);
|
||||||
|
|
||||||
|
// Set hotkeys
|
||||||
CmdKeyClear(wxSCI_KEY_RETURN,wxSCI_SCMOD_CTRL);
|
CmdKeyClear(wxSCI_KEY_RETURN,wxSCI_SCMOD_CTRL);
|
||||||
CmdKeyClear(wxSCI_KEY_RETURN,wxSCI_SCMOD_NULL);
|
CmdKeyClear(wxSCI_KEY_RETURN,wxSCI_SCMOD_NULL);
|
||||||
CmdKeyClear(wxSCI_KEY_TAB,wxSCI_SCMOD_NULL);
|
CmdKeyClear(wxSCI_KEY_TAB,wxSCI_SCMOD_NULL);
|
||||||
@ -99,7 +101,7 @@ SubsTextEditCtrl::SubsTextEditCtrl(wxWindow* parent, wxWindowID id, const wxStri
|
|||||||
|
|
||||||
// Misspelling indicator
|
// Misspelling indicator
|
||||||
IndicatorSetStyle(0,wxSCI_INDIC_SQUIGGLE);
|
IndicatorSetStyle(0,wxSCI_INDIC_SQUIGGLE);
|
||||||
IndicatorSetForeground(0,wxColour(200,0,0));
|
IndicatorSetForeground(0,wxColour(255,0,0));
|
||||||
|
|
||||||
// Set spellchecker
|
// Set spellchecker
|
||||||
spellchecker = SpellChecker::GetSpellChecker();
|
spellchecker = SpellChecker::GetSpellChecker();
|
||||||
@ -126,10 +128,11 @@ void SubsTextEditCtrl::UpdateStyle(int start, int _length) {
|
|||||||
if (_length < 0) end = text.Length();
|
if (_length < 0) end = text.Length();
|
||||||
|
|
||||||
// Begin styling
|
// Begin styling
|
||||||
StartStyling(0,31);
|
StartStyling(0,255);
|
||||||
int ran = 0;
|
int ran = 0;
|
||||||
int depth = 0;
|
int depth = 0;
|
||||||
int curStyle = 0;
|
int curStyle = 0;
|
||||||
|
int curPos = 0;
|
||||||
wxChar curChar = 0;
|
wxChar curChar = 0;
|
||||||
wxChar prevChar = 0;
|
wxChar prevChar = 0;
|
||||||
|
|
||||||
@ -141,14 +144,16 @@ void SubsTextEditCtrl::UpdateStyle(int start, int _length) {
|
|||||||
|
|
||||||
// Erroneous
|
// Erroneous
|
||||||
if (depth < 0 || depth > 1) {
|
if (depth < 0 || depth > 1) {
|
||||||
SetStyling(ran,curStyle);
|
SetUnicodeStyling(curPos,ran,curStyle);
|
||||||
|
curPos += ran;
|
||||||
ran = 0;
|
ran = 0;
|
||||||
curStyle = 4;
|
curStyle = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start override block
|
// Start override block
|
||||||
if (curChar == _T('{') && depth >= 0) {
|
if (curChar == _T('{') && depth >= 0) {
|
||||||
SetStyling(ran,curStyle);
|
SetUnicodeStyling(curPos,ran,curStyle);
|
||||||
|
curPos += ran;
|
||||||
ran = 0;
|
ran = 0;
|
||||||
depth++;
|
depth++;
|
||||||
if (depth == 1) curStyle = 1;
|
if (depth == 1) curStyle = 1;
|
||||||
@ -157,7 +162,8 @@ void SubsTextEditCtrl::UpdateStyle(int start, int _length) {
|
|||||||
|
|
||||||
// End override block
|
// End override block
|
||||||
else if (curChar == _T('}') && depth <= 1) {
|
else if (curChar == _T('}') && depth <= 1) {
|
||||||
SetStyling(ran,curStyle);
|
SetUnicodeStyling(curPos,ran,curStyle);
|
||||||
|
curPos += ran;
|
||||||
ran = 0;
|
ran = 0;
|
||||||
depth--;
|
depth--;
|
||||||
if (depth == 0) curStyle = 1;
|
if (depth == 0) curStyle = 1;
|
||||||
@ -166,7 +172,8 @@ void SubsTextEditCtrl::UpdateStyle(int start, int _length) {
|
|||||||
|
|
||||||
// Outside
|
// Outside
|
||||||
else if (depth == 0 && curStyle != 0) {
|
else if (depth == 0 && curStyle != 0) {
|
||||||
SetStyling(ran,curStyle);
|
SetUnicodeStyling(curPos,ran,curStyle);
|
||||||
|
curPos += ran;
|
||||||
ran = 0;
|
ran = 0;
|
||||||
curStyle = 0;
|
curStyle = 0;
|
||||||
}
|
}
|
||||||
@ -176,7 +183,8 @@ void SubsTextEditCtrl::UpdateStyle(int start, int _length) {
|
|||||||
// Special character
|
// Special character
|
||||||
if (curChar == _T('\\') || curChar == _T('(') || curChar == _T(')') || curChar == _T(',')) {
|
if (curChar == _T('\\') || curChar == _T('(') || curChar == _T(')') || curChar == _T(',')) {
|
||||||
if (curStyle != 2) {
|
if (curStyle != 2) {
|
||||||
SetStyling(ran,curStyle);
|
SetUnicodeStyling(curPos,ran,curStyle);
|
||||||
|
curPos += ran;
|
||||||
ran = 0;
|
ran = 0;
|
||||||
curStyle = 2;
|
curStyle = 2;
|
||||||
}
|
}
|
||||||
@ -185,7 +193,8 @@ void SubsTextEditCtrl::UpdateStyle(int start, int _length) {
|
|||||||
// Number
|
// Number
|
||||||
else if ((curChar >= '0' && curChar <= '9') || curChar == '.' || curChar == '&' || curChar == '+' || curChar == '-' || (curChar == 'H' && prevChar == '&')) {
|
else if ((curChar >= '0' && curChar <= '9') || curChar == '.' || curChar == '&' || curChar == '+' || curChar == '-' || (curChar == 'H' && prevChar == '&')) {
|
||||||
if (curStyle != 5) {
|
if (curStyle != 5) {
|
||||||
SetStyling(ran,curStyle);
|
SetUnicodeStyling(curPos,ran,curStyle);
|
||||||
|
curPos += ran;
|
||||||
ran = 0;
|
ran = 0;
|
||||||
curStyle = 5;
|
curStyle = 5;
|
||||||
}
|
}
|
||||||
@ -193,7 +202,8 @@ void SubsTextEditCtrl::UpdateStyle(int start, int _length) {
|
|||||||
|
|
||||||
// Tag name
|
// Tag name
|
||||||
else if (curStyle != 3) {
|
else if (curStyle != 3) {
|
||||||
SetStyling(ran,curStyle);
|
SetUnicodeStyling(curPos,ran,curStyle);
|
||||||
|
curPos += ran;
|
||||||
ran = 0;
|
ran = 0;
|
||||||
curStyle = 3;
|
curStyle = 3;
|
||||||
}
|
}
|
||||||
@ -202,13 +212,27 @@ void SubsTextEditCtrl::UpdateStyle(int start, int _length) {
|
|||||||
// Increase ran length
|
// Increase ran length
|
||||||
ran++;
|
ran++;
|
||||||
}
|
}
|
||||||
SetStyling(ran,curStyle);
|
SetUnicodeStyling(curPos,ran,curStyle);
|
||||||
|
|
||||||
// Spell check
|
// Spell check
|
||||||
StyleSpellCheck(start,_length);
|
StyleSpellCheck(start,_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////
|
||||||
|
// Unicode-safe styling
|
||||||
|
void SubsTextEditCtrl::SetUnicodeStyling(int start,int length,int style) {
|
||||||
|
// Get the real length
|
||||||
|
wxString string = GetText().Mid(start,length);
|
||||||
|
wxCharBuffer buffer = string.mb_str(wxConvUTF8);
|
||||||
|
const char* utf8str = buffer;
|
||||||
|
int len = strlen(utf8str);
|
||||||
|
|
||||||
|
// Set styling
|
||||||
|
SetStyling(len,style);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////
|
///////////////
|
||||||
// Spell check
|
// Spell check
|
||||||
void SubsTextEditCtrl::StyleSpellCheck(int start, int len) {
|
void SubsTextEditCtrl::StyleSpellCheck(int start, int len) {
|
||||||
@ -231,10 +255,11 @@ void SubsTextEditCtrl::StyleSpellCheck(int start, int len) {
|
|||||||
bool isDelim;
|
bool isDelim;
|
||||||
|
|
||||||
// Scan
|
// Scan
|
||||||
for (int i=start;i<end;i++) {
|
for (int i=start;i<end+1;i++) {
|
||||||
// Current character
|
// Current character
|
||||||
curPos = i;
|
curPos = i;
|
||||||
cur = text[i];
|
if (i < end) cur = text[i];
|
||||||
|
else cur = '.';
|
||||||
isDelim = false;
|
isDelim = false;
|
||||||
|
|
||||||
// Increase depth
|
// Increase depth
|
||||||
@ -262,16 +287,14 @@ void SubsTextEditCtrl::StyleSpellCheck(int start, int len) {
|
|||||||
if (depth != 0) continue;
|
if (depth != 0) continue;
|
||||||
|
|
||||||
// Check if it is \n or \N
|
// Check if it is \n or \N
|
||||||
if (cur == '\\' && i != end-2 && (text[i+1] == 'N' || text[i+1] == 'n')) {
|
if (cur == '\\' && i < end-1 && (text[i+1] == 'N' || text[i+1] == 'n')) {
|
||||||
isDelim = true;
|
isDelim = true;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for standard delimiters
|
// Check for standard delimiters
|
||||||
if (delim.Find(cur) != wxNOT_FOUND) {
|
if (delim.Find(cur) != wxNOT_FOUND) {
|
||||||
//if (lastpos != i-1) {
|
|
||||||
isDelim = true;
|
isDelim = true;
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is delimiter?
|
// Is delimiter?
|
||||||
@ -292,8 +315,15 @@ void SubsTextEditCtrl::StyleSpellCheck(int start, int len) {
|
|||||||
|
|
||||||
// Check if it's valid
|
// Check if it's valid
|
||||||
if (!spellchecker->CheckWord(curWord)) {
|
if (!spellchecker->CheckWord(curWord)) {
|
||||||
StartStyling(startPos[i],32);
|
// Get length before it
|
||||||
SetStyling(endPos[i]-startPos[i],32);
|
wxString string = GetText().Left(startPos[i]);
|
||||||
|
wxCharBuffer buffer = string.mb_str(wxConvUTF8);
|
||||||
|
const char* utf8str = buffer;
|
||||||
|
int utf8len = strlen(utf8str);
|
||||||
|
|
||||||
|
// Set styling
|
||||||
|
StartStyling(utf8len,32);
|
||||||
|
SetUnicodeStyling(startPos[i],endPos[i]-startPos[i],32);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,6 +56,8 @@ private:
|
|||||||
SpellChecker *spellchecker;
|
SpellChecker *spellchecker;
|
||||||
void OnMouseEvent(wxMouseEvent &event);
|
void OnMouseEvent(wxMouseEvent &event);
|
||||||
|
|
||||||
|
void SetUnicodeStyling(int start,int length,int style);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SubsEditBox *control;
|
SubsEditBox *control;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user