diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/AutoComplete.cxx | 13 | ||||
| -rw-r--r-- | src/AutoComplete.h | 8 | ||||
| -rw-r--r-- | src/Document.cxx | 21 | ||||
| -rw-r--r-- | src/Editor.cxx | 12 | ||||
| -rw-r--r-- | src/Editor.h | 1 | ||||
| -rw-r--r-- | src/ScintillaBase.cxx | 36 | 
6 files changed, 55 insertions, 36 deletions
| diff --git a/src/AutoComplete.cxx b/src/AutoComplete.cxx index aa65810eb..82773f4db 100644 --- a/src/AutoComplete.cxx +++ b/src/AutoComplete.cxx @@ -10,6 +10,8 @@  #include <stdio.h>  #include <assert.h> +#include <string> +  #include "Platform.h"  #include "CharacterSet.h" @@ -101,6 +103,16 @@ void AutoComplete::SetList(const char *list) {  	lb->SetList(list, separator, typesep);  } +int AutoComplete::GetSelection() const { +	return lb->GetSelection(); +} + +std::string AutoComplete::GetValue(int item) const { +	char value[maxItemLen]; +	lb->GetValue(item, value, sizeof(value)); +	return std::string(value); +} +  void AutoComplete::Show(bool show) {  	lb->Show(show);  	if (show) @@ -130,7 +142,6 @@ void AutoComplete::Move(int delta) {  void AutoComplete::Select(const char *word) {  	size_t lenWord = strlen(word);  	int location = -1; -	const int maxItemLen=1000;  	int start = 0; // lower bound of the api array block to search  	int end = lb->Length() - 1; // upper bound of the api array block to search  	while ((start <= end) && (location == -1)) { // Binary searching loop diff --git a/src/AutoComplete.h b/src/AutoComplete.h index 19a1271ac..91e084857 100644 --- a/src/AutoComplete.h +++ b/src/AutoComplete.h @@ -20,8 +20,10 @@ class AutoComplete {  	char fillUpChars[256];  	char separator;  	char typesep; // Type seperator +	enum { maxItemLen=1000 };  public: +  	bool ignoreCase;  	bool chooseSingle;  	ListBox *lb; @@ -61,6 +63,12 @@ public:  	/// The list string contains a sequence of words separated by the separator character  	void SetList(const char *list); +	 +	/// Return the position of the currently selected list item +	int GetSelection() const; + +	/// Return the value of an item in the list +	std::string GetValue(int item) const;  	void Show(bool show);  	void Cancel(); diff --git a/src/Document.cxx b/src/Document.cxx index 88e45638b..72c931b95 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -1026,21 +1026,19 @@ static int NextTab(int pos, int tabSize) {  	return ((pos / tabSize) + 1) * tabSize;  } -static void CreateIndentation(char *linebuf, int length, int indent, int tabSize, bool insertSpaces) { -	length--;	// ensure space for \0 +static std::string CreateIndentation(int indent, int tabSize, bool insertSpaces) { +	std::string indentation;  	if (!insertSpaces) { -		while ((indent >= tabSize) && (length > 0)) { -			*linebuf++ = '\t'; +		while (indent >= tabSize) { +			indentation += '\t';  			indent -= tabSize; -			length--;  		}  	} -	while ((indent > 0) && (length > 0)) { -		*linebuf++ = ' '; +	while (indent > 0) { +		indentation += ' ';  		indent--; -		length--;  	} -	*linebuf = '\0'; +	return indentation;  }  int SCI_METHOD Document::GetLineIndentation(int line) { @@ -1066,13 +1064,12 @@ void Document::SetLineIndentation(int line, int indent) {  	if (indent < 0)  		indent = 0;  	if (indent != indentOfLine) { -		char linebuf[1000]; -		CreateIndentation(linebuf, sizeof(linebuf), indent, tabInChars, !useTabs); +		std::string linebuf = CreateIndentation(indent, tabInChars, !useTabs);  		int thisLineStart = LineStart(line);  		int indentPos = GetLineIndentPosition(line);  		UndoGroup ug(this);  		DeleteChars(thisLineStart, indentPos - thisLineStart); -		InsertCString(thisLineStart, linebuf); +		InsertCString(thisLineStart, linebuf.c_str());  	}  } diff --git a/src/Editor.cxx b/src/Editor.cxx index 2bc89ba1f..c424cd278 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -5845,6 +5845,18 @@ char *Editor::CopyRange(int start, int end) {  	return text;  } +std::string Editor::RangeText(int start, int end) const { +	if (start < end) { +		int len = end - start; +		std::string ret(len, '\0'); +		for (int i = 0; i < len; i++) { +			ret[i] = pdoc->CharAt(start + i); +		} +		return ret; +	} +	return std::string(); +} +  void Editor::CopySelectionRange(SelectionText *ss, bool allowLineCopy) {  	if (sel.Empty()) {  		if (allowLineCopy) { diff --git a/src/Editor.h b/src/Editor.h index f8ab19d9e..00e4ec3a6 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -480,6 +480,7 @@ protected:	// ScintillaBase subclass needs access to much of Editor  	virtual void CopyToClipboard(const SelectionText &selectedText) = 0;  	char *CopyRange(int start, int end); +	std::string RangeText(int start, int end) const;  	void CopySelectionRange(SelectionText *ss, bool allowLineCopy=false);  	void CopyRangeToClipboard(int start, int end);  	void CopyText(int length, const char *text); diff --git a/src/ScintillaBase.cxx b/src/ScintillaBase.cxx index d730457fd..cc3992f8f 100644 --- a/src/ScintillaBase.cxx +++ b/src/ScintillaBase.cxx @@ -294,13 +294,8 @@ void ScintillaBase::AutoCompleteMove(int delta) {  }  void ScintillaBase::AutoCompleteMoveToCurrentWord() { -	char wordCurrent[1000]; -	int i; -	int startWord = ac.posStart - ac.startLen; -	for (i = startWord; i < sel.MainCaret() && i - startWord < 1000; i++) -		wordCurrent[i - startWord] = pdoc->CharAt(i); -	wordCurrent[Platform::Minimum(i - startWord, 999)] = '\0'; -	ac.Select(wordCurrent); +	std::string wordCurrent = RangeText(ac.posStart - ac.startLen, sel.MainCaret()); +	ac.Select(wordCurrent.c_str());  }  void ScintillaBase::AutoCompleteCharacterAdded(char ch) { @@ -329,15 +324,12 @@ void ScintillaBase::AutoCompleteCharacterDeleted() {  }  void ScintillaBase::AutoCompleteCompleted() { -	int item = ac.lb->GetSelection(); -	char selected[1000]; -	selected[0] = '\0'; -	if (item != -1) { -		ac.lb->GetValue(item, selected, sizeof(selected)); -	} else { +	int item = ac.GetSelection(); +	if (item == -1) {  		AutoCompleteCancel();  		return;  	} +	const std::string selected = ac.GetValue(item);  	ac.Show(false); @@ -349,7 +341,7 @@ void ScintillaBase::AutoCompleteCompleted() {  	Position firstPos = ac.posStart - ac.startLen;  	scn.position = firstPos;  	scn.lParam = firstPos; -	scn.text = selected; +	scn.text = selected.c_str();  	NotifyParent(scn);  	if (!ac.Active()) @@ -370,8 +362,8 @@ void ScintillaBase::AutoCompleteCompleted() {  	}  	SetEmptySelection(ac.posStart);  	if (item != -1) { -		pdoc->InsertCString(firstPos, selected); -		SetEmptySelection(firstPos + static_cast<int>(strlen(selected))); +		pdoc->InsertCString(firstPos, selected.c_str()); +		SetEmptySelection(firstPos + static_cast<int>(selected.length()));  	}  	SetLastXChosen();  } @@ -379,19 +371,17 @@ void ScintillaBase::AutoCompleteCompleted() {  int ScintillaBase::AutoCompleteGetCurrent() {  	if (!ac.Active())  		return -1; -	return ac.lb->GetSelection(); +	return ac.GetSelection();  }  int ScintillaBase::AutoCompleteGetCurrentText(char *buffer) {  	if (ac.Active()) { -		int item = ac.lb->GetSelection(); -		char selected[1000]; -		selected[0] = '\0'; +		int item = ac.GetSelection();  		if (item != -1) { -			ac.lb->GetValue(item, selected, sizeof(selected)); +			const std::string selected = ac.GetValue(item);  			if (buffer != NULL) -				strcpy(buffer, selected); -			return static_cast<int>(strlen(selected)); +				strcpy(buffer, selected.c_str()); +			return static_cast<int>(selected.length());  		}  	}  	if (buffer != NULL) | 
