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);
        }
        private AutoCorrectionResult InsertBullet(AutoCorrectionInput input, TextRange line, int level)
        {
            line.Text = line.Text.Trim().Substring(1).Trim();

            input.Editor.ToggleBulletsCommand.Execute(null);

            return(new AutoCorrectionResult(true));
        }
        private AutoCorrectionResult InsertNumbering(AutoCorrectionInput input, TextRange line, int level)
        {
            // remove "1."
            line.Text = line.Text.Trim().Substring(2).Trim();

            input.Editor.ToggleNumberingommand.Execute(null);

            return(new AutoCorrectionResult(true));
        }
Beispiel #4
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);
        }
Beispiel #6
0
        public AutoCorrectionResult TryApply(AutoCorrectionInput input)
        {
            bool success = false;

            foreach (var wordRange in input.Context.GetWords())
            {
                var symbol = Symbols.FirstOrDefault(x => x.Ascii == wordRange.TextOnly());
                if (symbol != null)
                {
                    wordRange.Text = symbol.UniCode;

                    success = true;
                }
            }

            return(new AutoCorrectionResult(success));
        }
        public AutoCorrectionResult TryApply(AutoCorrectionInput input)
        {
            bool success = false;

            foreach (var wordRange in input.Context.GetWords())
            {
                string wordText = wordRange.TextOnly();
                var    url      = TryCreateUrl(wordText);
                if (url != null && !IsInHyperlinkScope(wordRange.Start) && !IsInHyperlinkScope(wordRange.End))
                {
                    var hyperlink = new Hyperlink(wordRange.Start, wordRange.End);
                    hyperlink.NavigateUri = url;
                    WeakEventManager <Hyperlink, RequestNavigateEventArgs> .AddHandler(hyperlink, "RequestNavigate", OnHyperlinkRequestNavigate);

                    success = true;
                }
            }

            return(new AutoCorrectionResult(success));
        }