Beispiel #1
0
        private void OnEditboxKeyUp(EditboxKeyUpArgs argument)
        {
            var text = argument.Editbox.Text;

            text = text.Replace(":)", "😊");
            text = text.Replace(":p", "😛");

            if (text != argument.Editbox.Text)
            {
                var cursorPosition = argument.Editbox.SelectionStart;
                cursorPosition -= argument.Editbox.Text.Length - text.Length;

                argument.Editbox.Text           = text;
                argument.Editbox.SelectionStart = cursorPosition;
            }
        }
Beispiel #2
0
        private void OnEditboxKeyUp(EditboxKeyUpArgs argument)
        {
            //Check if this event was fired on twitch, or if the config says we should not adjust autocomplete
            if (!IsTwitchServer(argument.Window.Server) || !_settings.AutoComplete)
            {
                return;
            }

            //Early exit if its not a tab key
            if (argument.KeyEventArgs.KeyCode != Keys.Tab)
            {
                return;
            }

            //Check if we're operating in a channel window, otherwise exit.
            var channel = argument.Window as IChannel;

            if (channel == null)
            {
                return;
            }

            //Don't do work on an empty string
            if (string.IsNullOrWhiteSpace(argument.Editbox.Text))
            {
                return;
            }

            var editBoxCursor = argument.Editbox.SelectionStart;
            var text          = argument.Editbox.Text;


            //Search for the wordstart.
            var wordStartTuple = FindStringWordStartIndex(text, _host.EditboxOptions.TabCompleteSuffixFirstWord, editBoxCursor);

            if (wordStartTuple.Item2 == editBoxCursor)
            {
                //The FindStringWordStartIndex did not offset the initial word cursor
                //so it did not find a suffix. That means we can try and find the second suffix type.

                wordStartTuple = FindStringWordStartIndex(text, _host.EditboxOptions.TabCompleteSuffix, editBoxCursor);
            }

            var i = wordStartTuple.Item1;

            editBoxCursor = wordStartTuple.Item2;

            //Substring to get a word
            var word        = text.Substring(i, editBoxCursor - i);
            var isValidName = false;

            //See if the word is a valid nickname.
            foreach (IUser user in channel.GetUsers)
            {
                if (user.Nick == word)
                {
                    isValidName = true;
                    break;
                }
            }

            //Exit early if we don't need to edit the textbox.
            if (!isValidName)
            {
                return;
            }

            //Supress further actions on this Event
            argument.KeyEventArgs.SuppressKeyPress = true;

            //Remember old selectionstart, changing text resets it.
            var oldSelectionSTart = argument.Editbox.SelectionStart;

            //Insert @
            argument.Editbox.Text = text.Insert(i, "@");
            //Fix the cursor position.
            argument.Editbox.SelectionStart = oldSelectionSTart + 1;
        }