35
35
namespace Mono.TextEditor.Vi
37
public class NewViEditMode : EditMode
39
protected ViEditor ViEditor { get ; private set ;}
41
public NewViEditMode ()
43
ViEditor = new ViEditor (this);
46
protected override void HandleKeypress (Gdk.Key key, uint unicodeKey, Gdk.ModifierType modifier)
48
ViEditor.ProcessKey (modifier, key, (char)unicodeKey);
51
public new TextEditor Editor { get { return base.Editor; } }
52
public new TextEditorData Data { get { return base.Data; } }
54
public override bool WantsToPreemptIM {
56
switch (ViEditor.Mode) {
57
case ViEditorMode.Insert:
58
case ViEditorMode.Replace:
60
case ViEditorMode.Normal:
61
case ViEditorMode.Visual:
62
case ViEditorMode.VisualLine:
69
protected override void OnAddedToEditor (TextEditorData data)
71
ViEditor.SetMode (ViEditorMode.Normal);
72
SetCaretMode (CaretMode.Block, data);
73
ViActions.RetreatFromLineEnd (data);
76
protected override void OnRemovedFromEditor (TextEditorData data)
78
SetCaretMode (CaretMode.Insert, data);
81
protected override void CaretPositionChanged ()
83
ViEditor.OnCaretPositionChanged ();
86
public void SetCaretMode (CaretMode mode)
88
SetCaretMode (mode, Data);
91
static void SetCaretMode (CaretMode mode, TextEditorData data)
93
if (data.Caret.Mode == mode)
95
data.Caret.Mode = mode;
96
data.Document.RequestUpdate (new SinglePositionUpdate (data.Caret.Line, data.Caret.Column));
97
data.Document.CommitDocumentUpdate ();
38
101
public class ViEditMode : EditMode
40
103
bool searchBackward;
45
108
StringBuilder commandBuffer = new StringBuilder ();
46
109
Dictionary<char,ViMark> marks = new Dictionary<char, ViMark>();
47
110
Dictionary<char,ViMacro> macros = new Dictionary<char, ViMacro>();
111
char macros_lastplayed = '@'; // start with the illegal macro character
48
112
string statusText = "";
79
143
if (int.TryParse (command.Substring (1), out line)) {
80
if (line < 0 || line > Data.Document.LineCount) {
144
if (line < DocumentLocation.MinLine || line > Data.Document.LineCount) {
81
145
return "Invalid line number.";
82
146
} else if (line == 0) {
83
147
RunAction (CaretMoveActions.ToDocumentStart);
194
258
data.ClearSelection ();
196
260
//Editor can be null during GUI-less tests
198
Editor.HighlightSearchPattern = false;
261
// Commenting this fixes bug: Bug 622618 - Inline search fails in vi mode
262
// if (Editor != null)
263
// Editor.HighlightSearchPattern = false;
200
265
if (CaretMode.Block != data.Caret.Mode) {
201
266
data.Caret.Mode = CaretMode.Block;
202
if (data.Caret.Column > 0)
267
if (data.Caret.Column > DocumentLocation.MinColumn)
203
268
data.Caret.Column--;
205
270
ViActions.RetreatFromLineEnd (data);
426
Caret.Line = System.Math.Max (0, Editor.VisualToDocumentLocation (0, Editor.LineHeight - 1).Line);
491
Caret.Line = System.Math.Max (DocumentLocation.MinLine, Editor.PointToLocation (0, Editor.LineHeight - 1).Line);
429
494
RunAction (ViActions.Join);
432
int line = Editor.VisualToDocumentLocation (0, Editor.Allocation.Height - Editor.LineHeight * 2 - 2).Line;
434
line = Document.LineCount - 1;
497
int line = Editor.PointToLocation (0, Editor.Allocation.Height - Editor.LineHeight * 2 - 2).Line;
498
if (line < DocumentLocation.MinLine)
499
line = Document.LineCount;
435
500
Caret.Line = line;
438
line = Editor.VisualToDocumentLocation (0, Editor.Allocation.Height/2).Line;
440
line = Document.LineCount - 1;
503
line = Editor.PointToLocation (0, Editor.Allocation.Height/2).Line;
504
if (line < DocumentLocation.MinLine)
505
line = Document.LineCount;
441
506
Caret.Line = line;
767
831
case State.PlayMacro: {
768
832
char k = (char) unicodeKey;
834
k = macros_lastplayed;
769
835
if (macros.ContainsKey(k)) {
837
macros_lastplayed = k; // FIXME play nice when playing macros from inside macros?
771
838
ViMacro macroToPlay = macros [k];
772
839
foreach (ViMacro.KeySet keySet in macroToPlay.KeysPressed) {
773
HandleKeypress(keySet.Key, keySet.UnicodeKey, keySet.Modifiers);
840
HandleKeypress(keySet.Key, keySet.UnicodeKey, keySet.Modifiers); // FIXME stop on errors? essential with multipliers and nowrapscan
775
842
/* Once all the keys have been played back, quickly exit. */
778
Reset ("Invalid Macro Name");
845
Reset ("Invalid Macro Name '" + k + "'");
957
1024
private void PasteAfter (bool linemode)
959
1026
TextEditorData data = Data;
1027
this.Document.BeginAtomicUndo();
961
1029
Gtk.Clipboard.Get (ClipboardActions.CopyOperation.CLIPBOARD_ATOM).RequestText
962
1030
(delegate (Gtk.Clipboard cb, string contents) {
1005
1074
TextEditorData data = Data;
1076
this.Document.BeginAtomicUndo();
1007
1077
Gtk.Clipboard.Get (ClipboardActions.CopyOperation.CLIPBOARD_ATOM).RequestText
1008
1078
(delegate (Gtk.Clipboard cb, string contents) {
1009
1079
if (contents == null)