Fix use of uninitialized variables in GetWordAtPosition when the position is not in a word

Originally committed to SVN as r6271.
This commit is contained in:
Thomas Goyne 2012-01-11 19:18:54 +00:00
parent 1293f86afe
commit 3f8b9b8213
2 changed files with 11 additions and 9 deletions

View file

@ -86,26 +86,28 @@ void ScintillaTextCtrl::SetUnicodeStyling(int start,int length,int style) {
/// @brief Get boundaries of word at position
void ScintillaTextCtrl::GetBoundsOfWordAtPosition(int pos,int &start,int &end) {
// Results
IntPairVector results;
GetWordBoundaries(GetText(), results);
// Get boundaries
int count = results.size();
for (int i = 0; i < count; i++) {
for (size_t i = 0; i < results.size(); i++) {
if (results[i].first <= pos && results[i].second >= pos) {
start = results[i].first;
end = results[i].second - 1;
end = results[i].second;
return;
}
}
// Word not found
start = 0;
end = 0;
}
/// @brief Get word at specified position
wxString ScintillaTextCtrl::GetWordAtPosition(int pos) {
int start,end;
GetBoundsOfWordAtPosition(pos,start,end);
return GetText().Mid(start, end - start + 1);
GetBoundsOfWordAtPosition(pos, start, end);
return GetText().Mid(start, end - start);
}
/// @brief Set selection, unicode-aware

View file

@ -869,11 +869,11 @@ void SubsTextEditCtrl::OnUseSuggestion(wxCommandEvent &event) {
}
// Get boundaries of text being replaced
int start,end;
GetBoundsOfWordAtPosition(currentWordPos,start,end);
int start, end;
GetBoundsOfWordAtPosition(currentWordPos, start, end);
wxString text = GetText();
SetText(text.Left(std::max(0,start)) + suggestion + text.Mid(end+1));
SetText(text.Left(std::max(0, start)) + suggestion + text.Mid(end));
// Set selection
SetSelectionU(start,start+suggestion.Length());