ARCed.Scripting.ScriptEditorForm.Scintilla_CharAdded C# (CSharp) Method

Scintilla_CharAdded() private method

Registers characters added to the control for controlling auto-indentation and autocomplete
private Scintilla_CharAdded ( object sender, CharAddedEventArgs e ) : void
sender object
e CharAddedEventArgs
return void
		private void Scintilla_CharAdded(object sender, CharAddedEventArgs e)
		{
			// Update AutoIndent depending on words typed
			if (_settings.AutoIndent && e.Ch == '\n')
			{
				// Correct previous line indent
				string prevText = this._scintilla.Lines.Current.Previous.Text.Trim();
				int prevIndent = -1;
				if (prevText == "=begin" || prevText == "=end")
					this._scintilla.Lines.Current.Previous.Indentation = 0;
				else
					prevIndent = this.GetLineIndent(this._scintilla.Lines.Current.Previous);
				if (prevIndent != -1)
					this._scintilla.Lines.Current.Previous.Indentation = prevIndent * this._scintilla.Indentation.TabWidth;
				// Indent new line
				string indentStr = "";
				int indent = this.GetLineIndent(this._scintilla.Lines.Current);
				for (int i = 0; i < indent; i++)
					indentStr += "\t";
				this._scintilla.InsertText(indentStr);
			}
			// Update AutoComplete depending on the words typed
			if (_settings.AutoComplete)
			{
				int pos = this._scintilla.CurrentPos;
				// Prevents auto-complete for comments and strings
				int style = this._scintilla.Styles.GetStyleAt(pos - 2);
				if (style == 2 || style == 3 || style == 6 || style == 7 || style == 12 || style == 18)
					return;
				// Prevents certain characters from raising the auto-complete window
				string word = this._scintilla.GetWordFromPosition(pos).ToLower();
				if (_suppressedChars.Contains(e.Ch) || word.Length < _settings.AutoCompleteLength)
					return;
				// Select the matched words (we assume that Settings.AutoCompleteWords is already sorted)
				this._scintilla.AutoComplete.List = _settings.AutoCompleteWords.FindAll(
					listWord => (listWord.ToLower().Contains(word)));
				if (this._scintilla.AutoComplete.List.Count > 0)
					this._scintilla.AutoComplete.Show();
				else
					this._scintilla.AutoComplete.Cancel();
			}
		}