private void BodyOnKeyDownNavigateSnippet(object sender, IControlHtmlEventArgs e) { try { var eventObj = e?.EventObj; if (eventObj.IsNull()) { return; } var span = e.spanElement; // Check keys bool ctrlPressed = eventObj.shiftKey; bool jPressed = eventObj.keyCode == 74; bool kPressed = eventObj.keyCode == 75; if (ctrlPressed && (jPressed || kPressed)) { var htmlDoc = ContentUtils.GetFocusedHTMLDocument(); if (htmlDoc.IsNull()) { return; } var selObj = htmlDoc.selection.createRange() as IHTMLTxtRange; var duplicate = selObj.duplicate(); // Check the event origin var src = selObj.parentElement(); var children = span.children as IHTMLElementCollection; // If either the event source == target // or some child of the event source == target... if (span.id == src.id || (!children.IsNull() && children.Cast <IHTMLElement>().Any(x => x == src))) { if (jPressed) { duplicate.moveToElementText(span); duplicate.setEndPoint("EndToEnd", selObj); if (duplicate.findText("_", -2000000000)) { duplicate.select(); } } else if (kPressed) { duplicate.moveToElementText(span); duplicate.setEndPoint("StartToStart", selObj); if (duplicate.findText("_")) { duplicate.select(); } } } } } catch (RemotingException) { } }
// TODO: pass span and body into the method instead private void OnKeyUp_RemoveNavigationEvent(object sender, IControlHtmlEventArgs e) { var span = e.spanElement; var body = e.bodyElement; // If there are no underscores left in the span, remove all of the events if (!span.IsNull() && !span.innerText.Contains("_")) { RemoveKeyDownEvent(body); RemoveKeyUpEvent(body); } }
private void KeydownEventHandler(object sender, IControlHtmlEventArgs e) { if (!Enabled) { return; } LogTo.Debug("Handling key down"); var ev = e?.EventObj; if (ev == null) { return; } if (CurrentPopup == null || !CurrentPopup.IsOpen()) { return; } var info = new HtmlKeyInfo(ev); if (info.Key == Keys.None) { return; } if (info.Key == Keys.Escape) { CurrentPopup?.Hide(); ev.returnValue = false; } else if ((info.Key == Keys.Up && info.Modifiers == KeyModifiers.None) || (info.Key == Keys.K && info.Modifiers == KeyModifiers.Ctrl)) { CurrentPopup?.SelectPreviousItem(); ev.returnValue = false; } else if ((info.Key == Keys.Down && info.Modifiers == KeyModifiers.None) || (info.Key == Keys.J && info.Modifiers == KeyModifiers.Ctrl)) { CurrentPopup?.SelectNextItem(); ev.returnValue = false; } else if ((info.Key == Keys.Right && info.Modifiers == KeyModifiers.None) || info.Key == Keys.Tab) { CurrentPopup?.InsertSelectedItem(); ev.returnValue = false; } }