private bool SelectPlaceholder(bool forward = true) { var selObj = ContentUtils.GetSelectionObject(); if (selObj != null) { selObj.collapse(!forward); if (selObj.findText("<++>", Flags: forward ? 0 : 1)) { selObj.select(); return(true); } } return(false); }
private void HandleKeyUp(HtmlKeyInfo info) { if (!Enabled) { return; } if (info.Key == Keys.None || info.Modifiers != KeyModifiers.None || info.Key == Keys.Escape) { return; } if ((info.Key == Keys.Up) || info.Key == Keys.Right || info.Key == Keys.Down || (info.Key == Keys.J && info.Modifiers == KeyModifiers.Ctrl) || (info.Key == Keys.K && info.Modifiers == KeyModifiers.Ctrl)) { LogTo.Debug("KeyUp: Ignoring because it was an arrow key."); return; } else if (info.Key == Keys.Escape) { LogTo.Debug("KeyUp: Escape pressed, closing popup"); CurrentPopup?.Hide(); return; } var selObj = ContentUtils.GetSelectionObject(); if (selObj == null || !string.IsNullOrEmpty(selObj.text)) { return; } var lastWord = ContentUtils.GetLastPartialWord(selObj); if (lastWord == null || string.IsNullOrEmpty(lastWord)) { CurrentPopup?.Hide(); return; } var matches = CurrentSuggestions.GetWords(lastWord); if (matches == null || !matches.Any()) { CurrentPopup?.Hide(); return; } if (matches.Count() == 1 && matches.First() == lastWord) { CurrentPopup?.Hide(); return; } if (CurrentPopup == null) { ShowNewAutocompleteWdw(matches, lastWord); } else { CurrentPopup?.Show(matches, lastWord); } }
public bool InsertSelectedItem() { try { string word = null; if (_popup == null) { return(false); } var selItem = GetSelectedItem(); if (selItem == null) { return(false); } var selObj = ContentUtils.GetSelectionObject(); if (selObj == null) { return(false); } // Replace the last partial word while (selObj.moveStart("character", -1) == -1) { if (string.IsNullOrEmpty(selObj.text)) { return(false); } char first = selObj.text.First(); if (char.IsWhiteSpace(first)) { selObj.moveStart("character", 1); break; } // Break if word contains punctuation else if (char.IsPunctuation(first)) { break; } } word = selItem.innerText; if (Svc <AutocompleterPlugin> .Plugin.Converter.ContainsKey(word)) { word = Svc <AutocompleterPlugin> .Plugin.Converter[word]; } Hide(); selObj.text = word; if (word.Contains("<++>")) { var sel = ContentUtils.GetSelectionObject(); sel.moveEnd("character", -word.Length); sel.select(); } return(true); } catch (RemotingException) { } catch (UnauthorizedAccessException) { } catch (COMException) { } return(false); }