forked from vsClojure/vsClojure
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputKeyHandler.cs
More file actions
62 lines (54 loc) · 2.46 KB
/
Copy pathInputKeyHandler.cs
File metadata and controls
62 lines (54 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System.Windows.Controls;
using System.Windows.Input;
using ClojureExtension.Utilities;
namespace ClojureExtension.Repl
{
public class InputKeyHandler
{
private readonly TextBox _interactiveTextBox;
private readonly KeyboardExaminer _keyboardExaminer;
private readonly Entity<ReplState> _replEntity;
private readonly ReplWriter _replWriter;
public InputKeyHandler(KeyboardExaminer keyboardExaminer, Entity<ReplState> replEntity, TextBox interactiveTextBox, ReplWriter replWriter)
{
_keyboardExaminer = keyboardExaminer;
_replEntity = replEntity;
_replWriter = replWriter;
_interactiveTextBox = interactiveTextBox;
}
public void PreviewTextInput(object sender, TextCompositionEventArgs e)
{
if (_interactiveTextBox.CaretIndex < _replEntity.CurrentState.PromptPosition) e.Handled = true;
}
public void PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter && !_keyboardExaminer.IsShiftDown() && _interactiveTextBox.CaretIndex >= _replEntity.CurrentState.PromptPosition)
{
string userInput = _interactiveTextBox.Text.Substring(_replEntity.CurrentState.PromptPosition);
_replWriter.WriteExpressionToRepl(userInput);
return;
}
if (_interactiveTextBox.CaretIndex > _replEntity.CurrentState.PromptPosition && e.Key == Key.Home && !_keyboardExaminer.IsShiftDown())
{
_interactiveTextBox.CaretIndex = _replEntity.CurrentState.PromptPosition;
e.Handled = true;
return;
}
if (_interactiveTextBox.CaretIndex > _replEntity.CurrentState.PromptPosition && e.Key == Key.Home && _keyboardExaminer.IsShiftDown())
{
_interactiveTextBox.Select(_replEntity.CurrentState.PromptPosition, _interactiveTextBox.CaretIndex - _replEntity.CurrentState.PromptPosition + _interactiveTextBox.SelectionLength);
e.Handled = true;
return;
}
if (_keyboardExaminer.IsArrowKey(e.Key)) return;
if (e.Key == Key.Home || e.Key == Key.End || e.Key == Key.PageUp || e.Key == Key.PageDown) return;
if (_interactiveTextBox.CaretIndex < _replEntity.CurrentState.PromptPosition) e.Handled = true;
if (_interactiveTextBox.CaretIndex == _replEntity.CurrentState.PromptPosition && e.Key == Key.Back)
{
_interactiveTextBox.Text = _interactiveTextBox.Text.Remove(_interactiveTextBox.SelectionStart, _interactiveTextBox.SelectionLength);
_interactiveTextBox.CaretIndex = _replEntity.CurrentState.PromptPosition;
e.Handled = true;
}
}
}
}