/// <summary> /// Called on key in *.ps1. /// </summary> static void OnKeyDownPSFile(object sender, KeyEventArgs e) { // editor; skip if selected IEditor editor = (IEditor)sender; switch (e.Key.VirtualKeyCode) { case KeyCode.F1: { if (e.Key.IsShift()) { // [ShiftF1] e.Ignore = true; Help.ShowHelpForContext(); } return; } case KeyCode.F5: { if (e.Key.Is()) { // [F5] e.Ignore = true; InvokeScriptBeingEdited(editor); } return; } case KeyCode.Tab: { if (e.Key.Is()) { // [Tab] if (!editor.SelectionExists && NeedsTabExpansion(editor)) { // TabExpansion e.Ignore = true; A.Psf.ExpandCode(editor.Line); editor.Redraw(); } } return; } } }
/// public void WorksKeyPressed(KeyEventArgs e) { if (KeyPressed != null) KeyPressed(this, e); }
void OnKeyDown(object sender, KeyEventArgs e) { // drop pipeline now, if any PowerShell = null; // skip if selected if (Editor.SelectionExists) return; // current line var currentLine = Editor.Line; switch (e.Key.VirtualKeyCode) { case KeyCode.Enter: { if (e.Key.Is()) { // invoke, copy, or pass e.Ignore = Invoke(); } else if (e.Key.IsShift()) { // similar to ISE e.Ignore = true; Editor.InsertLine(); Editor.Redraw(); } return; } case KeyCode.Tab: { if (e.Key.Is()) { if (GetCommandArea() != null && EditorKit.NeedsTabExpansion(Editor)) { e.Ignore = true; InitTabExpansion(); EditorKit.ExpandCode(currentLine, Runspace); Editor.Redraw(); } } return; } case KeyCode.Escape: { if (e.Key.Is()) { if (IsLastLineCurrent && currentLine.Length > 0) { e.Ignore = true; currentLine.Text = string.Empty; currentLine.Caret = 0; Editor.Redraw(); } } return; } case KeyCode.End: { if (e.Key.Is()) { if (!IsLastLineCurrent) return; if (currentLine.Caret != currentLine.Length) return; UI.CommandHistoryMenu m = new UI.CommandHistoryMenu(currentLine.Text); string code = m.Show(); if (code == null) return; e.Ignore = true; currentLine.Text = code; currentLine.Caret = -1; Editor.Redraw(); } return; } case KeyCode.UpArrow: goto case KeyCode.DownArrow; case KeyCode.DownArrow: { if (e.Key.Is()) { if (!IsLastLineCurrent) return; var command = History.GetNextCommand(e.Key.VirtualKeyCode == KeyCode.UpArrow, currentLine.Text); e.Ignore = true; currentLine.Text = command; currentLine.Caret = -1; Editor.Redraw(); } return; } case KeyCode.Delete: { if (e.Key.Is()) { if (!IsLastLineCurrent) return; if (currentLine.Length > 0) return; e.Ignore = true; Point pt = Editor.Caret; for (int i = pt.Y - 1; i >= 0; --i) { string text = Editor[i].Text; if (text == OutputMark1) { Editor.SelectText(0, i, -1, pt.Y, PlaceKind.Stream); Editor.DeleteText(); Editor.GoTo(0, i); Editor.InsertText(OutputMark3 + "\r"); Editor.GoToEnd(false); break; } if (text == OutputMark2 || text == OutputMark3) { pt = new Point(-1, i + 1); continue; } } Editor.Redraw(); } return; } case KeyCode.F1: { if (e.Key.IsShift()) { e.Ignore = true; Help.ShowHelpForContext(); } return; } default: { if (e.Key.Character != 0) History.Cache = null; return; } } }
/// public void WorksEscaping(KeyEventArgs e) { if (Escaping != null) Escaping(this, e); }