Example #1
0
        internal static Pos WordLeft(EditorControl ctx, Selection sel)
        {
            var caret = sel.Caret;
            var line  = ctx.Buffer.Document.Lines[caret.Line];

            if (caret.Col > 0)
            {
                var seps  = ctx.AffinityManager.GetAffinity(caret).GetNonWordSymbols(ctx);
                var c     = line.CharAt(caret.Col - 1);
                var strat = SelectWordCommand.GetStrategy(seps, c);
                var pos   = SelectWordCommand.FindBoundLeft(seps, line, caret.Col - 1, strat);

                if (pos < 0)
                {
                    return(LeftCommand.MoveLeft(ctx, sel));
                }

                if (Math.Abs(pos - caret.Col) > 1 && pos > 0)
                {
                    pos++;
                }

                return(new Pos(caret.Line, pos));
            }
            else
            {
                return(LeftCommand.MoveLeft(ctx, sel));
            }
        }
Example #2
0
        internal override ActionResults Execute(Selection sel, params object[] args)
        {
            var ln = Document.Lines[sel.Caret.Line];

            if (sel.Caret.Col == 0)
            {
                return(base.Execute(sel));
            }

            var aff  = Ed.AffinityManager.GetAffinity(sel.Caret);
            var seps = aff.NonWordSymbols ?? Ed.EditorSettings.NonWordSymbols;
            var st   = SelectWordCommand.GetStrategy(seps, ln.CharAt(sel.Caret.Col - 1));
            var col  = SelectWordCommand.FindBoundLeft(seps, ln, sel.Caret.Col - 1, st);

            sel.End = new Pos(sel.Caret.Line, col != 0 ? col + 1 : col);
            return(base.Execute(sel));
        }
Example #3
0
        internal override ActionResults Execute(Selection sel, params object[] args)
        {
            var ln = Document.Lines[sel.Caret.Line];

            if (sel.Caret.Col == ln.Length)
            {
                return(base.Execute(sel));
            }

            var aff    = Ed.AffinityManager.GetAffinity(sel.Caret);
            var seps   = aff.NonWordSymbols ?? Ed.EditorSettings.NonWordSymbols;
            var st     = SelectWordCommand.GetStrategy(seps, ln.CharAt(sel.Caret.Col));
            var col    = SelectWordCommand.FindBoundRight(seps, ln, sel.Caret.Col, st);
            var newSel = new Selection(sel.Caret, new Pos(sel.Caret.Line, col));

            redoSel = newSel;
            return(base.Execute(newSel));
        }
Example #4
0
        internal static Pos WordRight(EditorControl ctx, Selection sel)
        {
            var caret = sel.Caret;
            var line  = ctx.Buffer.Document.Lines[caret.Line];

            if (caret.Col < line.Length - 1)
            {
                var seps  = ctx.AffinityManager.GetAffinity(caret).GetNonWordSymbols(ctx);
                var c     = line.CharAt(caret.Col);
                var strat = SelectWordCommand.GetStrategy(seps, c);
                var pos   = SelectWordCommand.FindBoundRight(seps, line, caret.Col, strat);
                return(new Pos(caret.Line, pos));
            }
            else
            {
                return(RightCommand.MoveRight(ctx, sel));
            }
        }
Example #5
0
        internal override ActionResults Execute(Selection sel, params object[] args)
        {
            var newsel = default(Selection);
            var range  = default(Range);

            if (!sel.IsEmpty && (range = SelectWordCommand.SelectWord(Ed, Ed.Caret)) != null &&
                range.Start == sel.Start && range.End == sel.End)
            {
                newsel = new Selection(new Pos(sel.Caret.Line, 0),
                                       new Pos(sel.Caret.Line, Document.Lines[sel.Caret.Line].Length));
            }
            else
            {
                newsel = new Selection(Ed.Caret);
            }

            Buffer.Selections.Set(newsel);
            return(Clean);
        }