Exemplo n.º 1
0
        public Receiver(Controller controller, ViMode viMode, bool alwaysInputMode)
        {
            this.controller      = controller;
            this.lines           = controller.Lines;
            this.alwaysInputMode = alwaysInputMode;

            context = new Context(this);
            ProcessSetViMode(viMode);
        }
Exemplo n.º 2
0
        public LineIterator(LineArray lines, int index, int count, int blockI)
        {
            this.lines = lines;
            this.index = index;
            current    = null;

            linesCount = lines.LinesCount;
            endIndex   = index + count;
            direct     = index <= endIndex;
            if (endIndex > linesCount || index < 0 || endIndex < -1 || index > linesCount - 1)
            {
                throw new IndexOutOfRangeException("index=" + index + ", count=" + count + " is out of [0, " + linesCount + ")");
            }
            this.blockI = blockI != -1 ? blockI : lines.GetBlockIndex(index);
        }
        public static string GetFromRegister(LineArray lines, char c)
        {
            string result = null;

            if (c == '*' || c == '-')
            {
                result = GetFromClipboard();
            }
            else if (c == '0' || c == '\0')
            {
                result = registers[27];
            }
            else if (c >= 'a' && c <= 'z')
            {
                result = registers[c - 'a'];
            }
            else if (c >= 'A' && c <= 'Z')
            {
                result = registers[c - 'A'];
            }
            else if (c == '/')
            {
                result = registers[26];
            }
            else if (c == ':')
            {
                result = viLastCommand;
            }
            else if (c == '.')
            {
                if (viLastInputChars != null)
                {
                    result = new string(viLastInputChars.ToArray());
                }
            }
            else if (c == '%')
            {
                result = lines.viFullPath;
            }
            return(result ?? "");
        }
Exemplo n.º 4
0
 public Scroller(LineArray lines)
 {
     this.lines = lines;
 }
 public WordWrapValidator(LineArray lines)
 {
     this.lines = lines;
 }
Exemplo n.º 6
0
 public Moves(LineArray lines, int position)
 {
     _lines    = lines;
     _iterator = lines.GetCharIterator(position);
 }
Exemplo n.º 7
0
 public CommandProcessor(Controller controller, LineArray lines, List <Selection> selections)
 {
     this.controller = controller;
     this.lines      = lines;
     this.selections = selections;
 }
Exemplo n.º 8
0
        public bool Parse(LineArray lines, int maxMilliseconds)
        {
#if HIGHLIGHTER_DEBUG
            if (_debugStopwatch == null)
            {
                _debugStopwatch = new System.Diagnostics.Stopwatch();
                _debugStopwatch.Start();
                Console.WriteLine("HIGHLIGHTER START");
            }
#endif
            DateTime startTime = DateTime.Now;
            int      changesBeforeTimeCheck = 0;
            bool     timeElapsed            = false;
            bool     changed = false;
            stack = new PredictableList <Rules.Context>(8);
            stack.Add(contexts[0]);
            Rules.Context[] state           = stack.ToArray();
            bool            needSetStack    = false;
            bool            lastLineChanged = false;
            for (int i = 0; i < lines.blocksCount; i++)
            {
                LineBlock block = lines.blocks[i];
                if (timeElapsed && lastLineChanged)
                {
                    while (block.count == 0)
                    {
                        i++;
                        if (i >= lines.blocksCount)
                        {
                            block = null;
                            break;
                        }
                        block = lines.blocks[i];
                    }
                    if (block != null)
                    {
                        block.valid &= ~LineBlock.ColorValid;
                        Line line = block.array[0];
                        line.startState = state;
                        line.endState   = null;
                    }
                    stack = null;
                    return(changed);
                }
                {
                    bool noChangesInBlock = (block.valid & LineBlock.ColorValid) != 0 && !lastLineChanged;
                    if (noChangesInBlock && block.count > 0)
                    {
                        Rules.Context[] nextState = block.array[block.count - 1].endState;
                        if (nextState == null)
                        {
                            noChangesInBlock = false;
                        }
                        else
                        {
                            state = nextState;
                        }
                    }
                    if (noChangesInBlock)
                    {
                        needSetStack = true;
                        continue;
                    }
                }
                block.valid |= LineBlock.ColorValid;
                for (int j = 0; j < block.count; j++)
                {
                    Line line = block.array[j];
                    if (AreEquals(line.startState, state) && line.endState != null)
                    {
                        state           = line.endState;
                        needSetStack    = true;
                        lastLineChanged = false;
                        continue;
                    }
                    if (needSetStack)
                    {
                        needSetStack = false;
                        stack.Resize(state.Length);
                        Array.Copy(state, stack.buffer, stack.count);
                    }
                    line.startState = state;
                    string text = line.Text;
                    Array.Clear(awakePositions, 0, awakePositions.Length);
                    int        position    = 0;
                    int        count       = line.charsCount;
                    Rules.Rule lastMatched = null;
                    while (position < count)
                    {
                        Rules.Context context = stack.count > 0 ? stack.Peek() : contexts[0];
                        lastMatched = null;
                        foreach (Rules.Rule rule in context.childs)
                        {
                            int nextPosition;
                            if ((rule.column == -1 || position == rule.column) && rule.Match(text, position, out nextPosition))
                            {
                                if (!rule.lookAhead)
                                {
                                    for (; position < nextPosition; position++)
                                    {
                                        line.chars[position].style = rule.attribute.index;
                                    }
                                }
                                if (rule.childs != null && position < count)
                                {
                                    foreach (Rules.Rule childRule in rule.childs)
                                    {
                                        int childNextPosition;
                                        if (childRule.Match(text, nextPosition, out childNextPosition))
                                        {
                                            for (; position < childNextPosition; position++)
                                            {
                                                line.chars[position].style = childRule.attribute.index;
                                            }
                                            Switch(rule.context);
                                        }
                                    }
                                }
                                Switch(rule.context);
                                lastMatched = rule;
                                break;
                            }
                        }
                        if (lastMatched == null)
                        {
                            if (context.fallthrough)
                            {
                                Switch(context.fallthroughContext);
                            }
                            else
                            {
                                line.chars[position].style = context.attribute.index;
                                position++;
                            }
                        }
                    }
                    if (lastMatched == null || !lastMatched.isLineContinue)
                    {
                        while (stack.count > 0)
                        {
                            Rules.Context contextI = stack.Peek();
                            if (contextI.lineEndContext.next == null && contextI.lineEndContext.pops == 0)
                            {
                                break;
                            }
                            Switch(contextI.lineEndContext);
                        }
                    }
                    if (AreEquals(stack, state))
                    {
                        line.endState = state;
                    }
                    else
                    {
                        state         = stack.ToArray();
                        line.endState = state;
                    }
                    changesBeforeTimeCheck++;
                    lastLineChanged = true;
                    changed         = true;
                }
                if (changesBeforeTimeCheck > 50)
                {
                    changesBeforeTimeCheck = 0;
                    DateTime nextTime = DateTime.Now;
                    timeElapsed = (nextTime - startTime).TotalMilliseconds > maxMilliseconds;
                    if (timeElapsed)
                    {
                        startTime = nextTime;
                    }
                }
            }
            stack = null;
            lastParsingChanged = changed;
            if (!changed && lines.ranges != null)
            {
                foreach (StyleRange range in lines.ranges)
                {
                    lines.SetStyleRange(range);
                }
            }
#if HIGHLIGHTER_DEBUG
            if (!changed)
            {
                _debugStopwatch.Stop();
                Console.WriteLine("HIGHLIGHTER TIME: " + (_debugStopwatch.Elapsed.TotalMilliseconds / 1000).ToString("0.00"));
            }
#endif
            return(changed);
        }
Exemplo n.º 9
0
 public bool Parse(LineArray lines)
 {
     return(Parse(lines, 20));
 }
Exemplo n.º 10
0
 public void Init(Controller controller, Receiver.Context context)
 {
     this.controller = controller;
     this.lines      = controller.Lines;
     this.context    = context;
 }
Exemplo n.º 11
0
        public bool PrivateSelectAllFound(string text, bool isRegex, bool isIgnoreCase,
                                          List <SimpleRange> outRanges)
        {
            ResetOutput();

            bool   result   = true;
            string all      = controller.Lines.GetText();
            int    minIndex = 0;
            int    maxIndex = all.Length;

            Regex regex = null;

            if (isRegex)
            {
                string error;
                regex = ParseRegex(text, out error);
                if (regex == null || error != null)
                {
                    needShowError = error;
                    return(true);
                }
            }

            if (!controller.LastSelection.Empty && controller.SelectionsCount == 1)
            {
                string selectionText = all.Substring(controller.LastSelection.Left, controller.LastSelection.Count);
                bool   useArea       = false;
                if (isRegex)
                {
                    Match match = regex.Match(selectionText);
                    useArea = !match.Success || match.Length != selectionText.Length;
                }
                else
                {
                    useArea = text != selectionText;
                }
                if (useArea)
                {
                    result   = false;
                    minIndex = controller.LastSelection.Left;
                    maxIndex = controller.LastSelection.Right;
                }
            }

            LineArray        lines      = controller.Lines;
            List <Selection> selections = lines.selections;
            int  start = minIndex;
            bool found = false;
            bool first = true;

            while (true)
            {
                int index;
                int length;
                if (isRegex)
                {
                    Match match = regex.Match(all, start);
                    index  = -1;
                    length = text.Length;
                    if (match.Success)
                    {
                        index  = match.Index;
                        length = match.Length;
                    }
                }
                else
                {
                    length = text.Length;
                    CompareInfo ci = isIgnoreCase ? CultureInfo.InvariantCulture.CompareInfo : null;
                    index = ci != null?
                            ci.IndexOf(all, text, start, CompareOptions.IgnoreCase) :
                                all.IndexOf(text, start);
                }
                if (index == -1 || index + length > maxIndex)
                {
                    break;
                }
                if (outRanges == null)
                {
                    if (first)
                    {
                        first = false;
                        controller.ClearMinorSelections();
                    }
                    else
                    {
                        selections.Add(new Selection());
                    }
                    Selection selection = selections[selections.Count - 1];
                    selection.anchor = index;
                    selection.caret  = index + length;
                    lines.SetPreferredPos(selection, lines.PlaceOf(selection.caret));
                }
                else
                {
                    outRanges.Add(new SimpleRange(index, length));
                }
                start = index + length;
            }
            needMoveToCaret = found;
            return(result);
        }