Exemple #1
0
        static void StartMultiplierBuilder(ViBuilderContext ctx, ViBuilder nextBuilder)
        {
            int factor     = 1;
            int multiplier = 0;

            ctx.Builder = (ViBuilderContext x) => {
                int c = (int)x.LastKey.Char;
                if (c >= (int)'0' && c <= (int)'9')
                {
                    //don't eat '0' if not preceded by non-zero digit
                    //pass on to interpret as goto line start
                    if (c == (int)'0' && factor == 1)
                    {
                        ctx.Multiplier *= multiplier;
                        ctx.Builder     = nextBuilder;
                        return(ctx.Builder(ctx));
                    }
                    int d = c - (int)'0';
                    multiplier = multiplier * factor + d;
                    factor    *= 10;
                    return(true);
                }
                else
                {
                    ctx.Multiplier *= multiplier;
                    ctx.Builder     = nextBuilder;
                    return(ctx.Builder(ctx));
                }
            };
            ctx.Builder(ctx);
        }
        static bool Replace(ViBuilderContext ctx)
        {
            ctx.RunAction((ViEditor e) => e.SetMode(ViEditorMode.Replace));
            ctx.SuppressCompleted();

            ctx.Builder = ViBuilders.InsertBuilder(insertActions);
            return(true);
        }
Exemple #3
0
 public static bool ReplaceChar(ViBuilderContext ctx)
 {
     if (ctx.LastKey.Char != '\0')
     {
         ctx.RunAction((ViEditor ed) => ed.Data.Replace(ed.Data.Caret.Offset, 1, ctx.LastKey.Char.ToString()));
     }
     else
     {
         ctx.SetError("Expecting a character");
     }
     return(true);
 }
Exemple #4
0
        public void Reset(string message)
        {
            Context = ViBuilderContext.Create(this);
            Message = message;

            if (Data.Caret.Mode != CaretMode.Block)
            {
                Data.Caret.Mode = CaretMode.Block;
                if (Data.Caret.Column > DocumentLocation.MinColumn)
                {
                    Data.Caret.Column--;
                }
            }
            ViActions.RetreatFromLineEnd(Data);
        }
Exemple #5
0
        public static bool GoToMark(ViBuilderContext ctx)
        {
            char c = ctx.LastKey.Char;
            if (!char.IsLetterOrDigit (c)) {
                ctx.SetError ("Invalid Mark");
                return true;
            }

            ctx.RunAction ((ViEditor ed) => {
                ViMark mark;
                if (ed.Marks.TryGetValue (c, out mark))
                    mark.LoadMark (ed.Data);
                else
                    ed.Reset ("Unknown Mark");
            });
            return true;
        }
Exemple #6
0
 static void StartRegisterBuilder(ViBuilderContext ctx, ViBuilder nextBuilder)
 {
     if (ctx.Register != '\0')
     {
         ctx.SetError("Register already set");
         return;
     }
     ctx.Builder = (ViBuilderContext x) => {
         char c = x.LastKey.Char;
         if (!ViEditor.IsValidRegister(c))
         {
             x.SetError("Invalid register");
             return(true);
         }
         x.Register = c;
         x.Builder  = nextBuilder;
         return(true);
     };
 }
Exemple #7
0
        public static bool Mark(ViBuilderContext ctx)
        {
            char c = ctx.LastKey.Char;

            if (!char.IsLetterOrDigit(c))
            {
                ctx.SetError("Invalid Mark");
                return(true);
            }

            ctx.RunAction((ViEditor ed) => {
                ViMark mark;
                if (!ed.Marks.TryGetValue(c, out mark))
                {
                    ed.Marks [c] = mark = new ViMark(c);
                }
                mark.SaveMark(ed.Data);
            });
            return(true);
        }
Exemple #8
0
        public static bool GoToMark(ViBuilderContext ctx)
        {
            char c = ctx.LastKey.Char;

            if (!char.IsLetterOrDigit(c))
            {
                ctx.SetError("Invalid Mark");
                return(true);
            }

            ctx.RunAction((ViEditor ed) => {
                ViMark mark;
                if (ed.Marks.TryGetValue(c, out mark))
                {
                    mark.LoadMark(ed.Data);
                }
                else
                {
                    ed.Reset("Unknown Mark");
                }
            });
            return(true);
        }
Exemple #9
0
        public bool Builder(ViBuilderContext ctx)
        {
            Action <ViEditor> a;

            if (actions.TryGetValue(ctx.LastKey, out a))
            {
                ctx.RunAction(a);
                return(true);
            }
            else
            {
                BuilderAction b;
                if (builders.TryGetValue(ctx.LastKey, out b))
                {
                    ctx.Builder = b.Builder;
                    if (b.RunInstantly)
                    {
                        ctx.Builder(ctx);
                    }
                    return(true);
                }
            }
            return(false);
        }
 static bool OpenAbove(ViBuilderContext ctx)
 {
     // FIXME: this doesn't work correctly on the first line
     ctx.RunAction((ViEditor e) => ViActions.Up(e.Data));
     return(Open(ctx));
 }
Exemple #11
0
 public static bool ReplaceChar(ViBuilderContext ctx)
 {
     if (ctx.LastKey.Char != '\0')
         ctx.RunAction ((ViEditor ed) => ed.Data.Replace (ed.Data.Caret.Offset, 1, ctx.LastKey.Char.ToString ()));
     else
         ctx.SetError ("Expecting a character");
     return true;
 }
Exemple #12
0
        static bool Replace(ViBuilderContext ctx)
        {
            ctx.RunAction ((ViEditor e) => e.SetMode (ViEditorMode.Replace));
            ctx.SuppressCompleted ();

            ctx.Builder = ViBuilders.InsertBuilder (insertActions);
            return true;
        }
Exemple #13
0
 static bool OpenAbove(ViBuilderContext ctx)
 {
     // FIXME: this doesn't work correctly on the first line
     ctx.RunAction ((ViEditor e) => ViActions.Up (e.Data));
     return Open (ctx);
 }
Exemple #14
0
 static bool Open(ViBuilderContext ctx)
 {
     ctx.RunAction ((ViEditor e) => MiscActions.InsertNewLineAtEnd (e.Data));
     return Insert (ctx);
 }
Exemple #15
0
 static bool GotoLine(ViBuilderContext ctx)
 {
     ctx.RunAction ((ViEditor e) => ViEditorActions.CaretToLineNumber (ctx.Multiplier, e));
       ctx.RunAction ((ViEditor e) => CaretMoveActions.LineFirstNonWhitespace (e.Data));
       return true;
 }
Exemple #16
0
 static void StartMultiplierBuilder(ViBuilderContext ctx, ViBuilder nextBuilder)
 {
     int factor = 1;
     int multiplier = 0;
     ctx.Builder = (ViBuilderContext x) => {
         int c = (int)x.LastKey.Char;
         if (c >= (int)'0' && c <= (int)'9') {
       //don't eat '0' if not preceded by non-zero digit
       //pass on to interpret as goto line start
       if (c == (int)'0' && factor == 1) {
     ctx.Multiplier *= multiplier;
     ctx.Builder = nextBuilder;
     return ctx.Builder (ctx);
       }
             int d = c - (int)'0';
             multiplier = multiplier * factor + d;
             factor *= 10;
             return true;
         } else {
             ctx.Multiplier *= multiplier;
             ctx.Builder = nextBuilder;
             return ctx.Builder (ctx);
         }
     };
     ctx.Builder (ctx);
 }
Exemple #17
0
        public static bool Mark(ViBuilderContext ctx)
        {
            char c = ctx.LastKey.Char;
            if (!char.IsLetterOrDigit (c)) {
                ctx.SetError ("Invalid Mark");
                return true;
            }

            ctx.RunAction ((ViEditor ed) => {
                ViMark mark;
                if (!ed.Marks.TryGetValue (c, out mark))
                    ed.Marks [c] = mark = new ViMark (c);
                mark.SaveMark (ed.Data);
            });
            return true;
        }
Exemple #18
0
 static void StartRegisterBuilder(ViBuilderContext ctx, ViBuilder nextBuilder)
 {
     if (ctx.Register != '\0') {
         ctx.SetError ("Register already set");
         return;
     }
     ctx.Builder = (ViBuilderContext x) => {
         char c = x.LastKey.Char;
         if (!ViEditor.IsValidRegister (c)) {
             x.SetError ("Invalid register");
             return true;
         }
         x.Register = c;
         x.Builder = nextBuilder;
         return true;
     };
 }
 static bool Open(ViBuilderContext ctx)
 {
     ctx.RunAction((ViEditor e) => MiscActions.InsertNewLineAtEnd(e.Data));
     return(Insert(ctx));
 }
 static bool GotoLine(ViBuilderContext ctx)
 {
     ctx.RunAction((ViEditor e) => ViEditorActions.CaretToLineNumber(ctx.Multiplier, e));
     ctx.RunAction((ViEditor e) => CaretMoveActions.LineFirstNonWhitespace(e.Data));
     return(true);
 }
Exemple #21
0
        public void Reset(string message)
        {
            Context = ViBuilderContext.Create (this);
            Message = message;

            if (Data.Caret.Mode != CaretMode.Block) {
                Data.Caret.Mode = CaretMode.Block;
                if (Data.Caret.Column > DocumentLocation.MinColumn)
                    Data.Caret.Column--;
            }
            ViActions.RetreatFromLineEnd (Data);
        }