Don't mark things in drawing blocks as words in GetWordBoundaries

This disables spell checking in drawing blocks and potential weird
behavior when right-clicking on drawing blocks.

Originally committed to SVN as r6272.
This commit is contained in:
Thomas Goyne 2012-01-11 19:19:03 +00:00
parent 3f8b9b8213
commit 896a1ab902

View file

@ -190,25 +190,15 @@ int SmallestPowerOf2(int x) {
return x; return x;
} }
/// @brief Get word boundaries
/// @param text
/// @param results
/// @param start
/// @param end
///
void GetWordBoundaries(const wxString text, IntPairVector &results, int start, int end) { void GetWordBoundaries(const wxString text, IntPairVector &results, int start, int end) {
// Variables
wxChar cur;
int curPos;
int lastpos = -1;
int depth = 0; int depth = 0;
if (end < 0) end = text.Length(); bool in_draw_mode = false;
bool isDelim; if (end < 0) end = text.size();
// Delimiters // Delimiters
const wchar_t delim_chars[] = { static std::set<wxUniChar> delims;
if (delims.empty()) {
const wxUniChar delim_chars[] = {
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0028, 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0028,
0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, 0x003a, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, 0x003a,
0x003b, 0x003d, 0x003f, 0x0040, 0x005b, 0x005c, 0x005d, 0x005e, 0x003b, 0x003d, 0x003f, 0x0040, 0x005b, 0x005c, 0x005d, 0x005e,
@ -223,58 +213,52 @@ void GetWordBoundaries(const wxString text,IntPairVector &results,int start,int
0x3002, 0x3008, 0x3009, 0x300a, 0x300b, 0x300c, 0x300d, 0x300e, 0x3002, 0x3008, 0x3009, 0x300a, 0x300b, 0x300c, 0x300d, 0x300e,
0x300f, 0x3010, 0x3011, 0x3014, 0x3015, 0x3016, 0x3017, 0x3018, 0x300f, 0x3010, 0x3011, 0x3014, 0x3015, 0x3016, 0x3017, 0x3018,
0x3019, 0x301a, 0x301b, 0x301c, 0x3030, 0x303d, 0x30fb, 0xff0a, 0x3019, 0x301a, 0x301b, 0x301c, 0x3030, 0x303d, 0x30fb, 0xff0a,
0xff5b, 0xff5d, 0xff5e, 0 0xff5b, 0xff5d, 0xff5e
}; };
wxString delim(delim_chars); delims.insert(delim_chars, delim_chars + sizeof(delim_chars) / sizeof(delim_chars[0]));
}
// Scan for (int i = start; i < end + 1; ++i) {
for (int i=start;i<end+1;i++) {
// Current character // Current character
curPos = i; wxUniChar cur = i < end ? text[i] : '.';
if (i < end) cur = text[i];
else cur = '.';
isDelim = false;
// Increase depth // Increase depth
if (cur == '{') { if (cur == '{') {
depth++; depth++;
if (depth == 1) { if (depth == 1 && start != i && !in_draw_mode)
if (lastpos+1 != curPos) { results.push_back(std::make_pair(start, i));
results.push_back(std::pair<int,int>(lastpos+1,curPos));
} }
continue;
}
}
// Decrease depth // Decrease depth
if (cur == '}') { else if (cur == '}') {
depth--; depth--;
if (depth == 0) { start = i + 1;
lastpos = i; }
continue; else if (depth > 0) {
// Check for draw mode
if (cur == '\\' && i + 1 < end && text[i + 1] == 'p') {
i += 2;
// Eat leading zeros
while (i < end && text[i] == '0') ++i;
in_draw_mode = i < end && text[i] >= '0' && text[i] <= '9';
if (!in_draw_mode) --i;
} }
} }
else if (!in_draw_mode) {
// Wrong depth
if (depth != 0) continue;
// Check if it is \n or \N // Check if it is \n or \N
if (cur == '\\' && i < end-1 && (text[i+1] == 'N' || text[i+1] == 'n' || text[i+1] == 'h')) { if (cur == '\\' && i < end-1 && (text[i+1] == 'N' || text[i+1] == 'n' || text[i+1] == 'h')) {
isDelim = true; if (start != i)
results.push_back(std::make_pair(start, i));
start = i + 2;
i++; i++;
} }
// Check for standard delimiters // Check for standard delimiters
if (delim.Find(cur) != wxNOT_FOUND) { else if (delims.count(cur)) {
isDelim = true; if (start != i)
results.push_back(std::make_pair(start, i));
start = i + 1;
} }
// Is delimiter?
if (isDelim) {
if (lastpos+1 != curPos) {
results.push_back(std::pair<int,int>(lastpos+1,curPos));
}
lastpos = i;
} }
} }
} }