public AutoCorrectionResult TryApply(AutoCorrectionInput input)
        {
            // add a new body Run if user hit enter after existing headline
            if (input.Trigger == AutoCorrectionTrigger.Return && input.Range.End.Parent is Headline)
            {
                var body = new Body(string.Empty, input.Range.End);
                return(new AutoCorrectionResult(true, body.ContentStart));
            }

            var result = new AutoCorrectionResult(false);

            foreach (var line in input.Context.GetLines())
            {
                if (line.Text.StartsWith("# "))
                {
                    result = InsertHeadline(line, 1);
                }
                else if (line.Text.StartsWith("## "))
                {
                    result = InsertHeadline(line, 2);
                }
                else if (line.Text.StartsWith("### "))
                {
                    result = InsertHeadline(line, 3);
                }
            }

            return(result);
        }
        internal AutoCorrectionResult Merge(AutoCorrectionResult other)
        {
            Contract.RequiresNotNull(other, "other");

            return(new AutoCorrectionResult(
                       Success || other.Success,
                       GetCaretPosition(CaretPosition, other.CaretPosition)
                       ));
        }
示例#3
0
        public AutoCorrectionResult Apply(AutoCorrectionInput input)
        {
            var result = new AutoCorrectionResult(false);

            foreach (var correction in Corrections)
            {
                // could be a paste operation so replacing multiple autocorrections makes sense!
                result = result.Merge(correction.TryApply(input));
            }

            return(result);
        }
        public AutoCorrectionResult TryApply(AutoCorrectionInput input)
        {
            var result = new AutoCorrectionResult(false);

            foreach (var line in input.Context.GetLines())
            {
                if (line.Text.StartsWith("- "))
                {
                    result = InsertBullet(input, line, 0);
                }
            }

            return(result);
        }