1:         /// <summary>
  2:         /// 两边追加标志
  3:         /// </summary>
  4:         /// <param name="syntax"></param>
  5:         public void ToggleSymmetricalMarkdownFormatting(string syntax)
  6:         {
  7:             int selectionLength = this.textEditor.SelectionLength;
  8:             int selectionStart = this.textEditor.SelectionStart;
  9:             if (selectionLength == 0 && selectionStart + syntax.Length <= this.textEditor.Text.Length)
 10:             {
 11:                 string text = this.textEditor.Document.GetText(selectionStart, syntax.Length);
 12:                 if (text == syntax)
 13:                 {
 14:                     this.textEditor.SelectionStart += syntax.Length;
 15:                     return;
 16:                 }
 17:             }
 18:             char[] array = syntax.ToCharArray();
 19:             Array.Reverse(array);
 20:             string text2 = new string(array);
 21:             int num = this.textEditor.SelectionLength;
 22:             int num2 = this.textEditor.SelectionStart;
 23:             if (num2 >= syntax.Length)
 24:             {
 25:                 num2 -= syntax.Length;
 26:                 num += syntax.Length;
 27:             }
 28:             DocumentLine lineByOffset = this.textEditor.Document.GetLineByOffset(this.textEditor.CaretOffset);
 29:             if (num2 + num + syntax.Length <= lineByOffset.EndOffset)
 30:             {
 31:                 num += syntax.Length;
 32:             }
 33:             string text3 = "";
 34:             if (num > 0)
 35:             {
 36:                 text3 = this.textEditor.Document.GetText(num2, num);
 37:             }
 38:             Match match = Regex.Match(text3, string.Concat(new string[]
 39:           {
 40:             "^",
 41:             Regex.Escape(syntax),
 42:             "(.*)",
 43:             Regex.Escape(text2),
 44:             "$"
 45:           }), RegexOptions.Singleline);
 46:             bool success = match.Success;
 47:             if (success)
 48:             {
 49:                 text3 = match.Groups[1].Value;
 50:                 this.textEditor.SelectionStart = num2;
 51:                 this.textEditor.SelectionLength = num;
 52:                 this.textEditor.SelectedText = text3;
 53:                 return;
 54:             }
 55:             text3 = syntax + this.textEditor.SelectedText + text2;
 56:             this.textEditor.SelectedText = text3;
 57:             this.textEditor.SelectionLength -= syntax.Length * 2;
 58:             this.textEditor.SelectionStart += syntax.Length;
 59:         }
  1:         /// <summary>
  2:         /// 左边添加前缀
  3:         /// </summary>
  4:         /// <param name="markdownSyntaxToApply"></param>
  5:         public void ToggleAsymmetricMarkdownFormatting(string markdownSyntaxToApply)
  6:         {
  7:             bool flag = this.textEditor.SelectedText == this.textEditor.Document.GetText(this.CurrentLine);
  8:             bool flag2 = this.textEditor.SelectedText.Contains(Environment.NewLine);
  9:             bool flag3 = this.textEditor.CaretOffset == this.CurrentLine.Offset;
 10:             if ((!flag3 || !flag) && !flag2)
 11:             {
 12:                 this.textEditor.SelectedText = Environment.NewLine + this.textEditor.SelectedText;
 13:                 this.textEditor.SelectionLength -= Environment.NewLine.Length;
 14:                 this.textEditor.SelectionStart += Environment.NewLine.Length;
 15:             }
 16:             if (this.textEditor.SelectionLength > 0)
 17:             {
 18:                 string selectedText = this.textEditor.SelectedText;
 19:                 string selectedText2;
 20:                 if (selectedText.Contains(markdownSyntaxToApply))
 21:                 {
 22:                     selectedText2 = selectedText.Replace(markdownSyntaxToApply, "");
 23:                 }
 24:                 else
 25:                 {
 26:                     selectedText2 = markdownSyntaxToApply + selectedText.Replace(Environment.NewLine, Environment.NewLine + markdownSyntaxToApply);
 27:                 }
 28:                 this.textEditor.SelectedText = selectedText2;
 29:                 return;
 30:             }
 31:             DocumentLine lineByOffset = this.textEditor.Document.GetLineByOffset(this.textEditor.CaretOffset);
 32:             string text = string.Empty;
 33:             if (!(lineByOffset.Length == 0))
 34:             {
 35:                 text = Environment.NewLine;
 36:             }
 37:             this.textEditor.SelectedText = text + markdownSyntaxToApply;
 38:             this.textEditor.SelectionLength = 0;
 39:             this.textEditor.SelectionStart += markdownSyntaxToApply.Length + text.Length;
 40:         }
 41:         public DocumentLine CurrentLine
 42:         {
 43:             get
 44:             {
 45:                 return this.textEditor.Document.GetLineByOffset(this.textEditor.CaretOffset);
 46:             }
 47:         }
 48: 

AvalonEdit 对于选定的文本添加前缀和后缀的更多相关文章

  1. excel给一列数据添加前缀和后缀

    1.选中一列单元格后设置单元格格式,在自定义中输入-----“前缀”@(前缀为需要添加的内容) 输入----@“后缀” 2.字符串拼接:“前缀”&B1,B1&“后缀”

  2. Xcode常用技巧(2)-使Xcode在创建类时自动添加前缀

    在Xcode5之前的版本中,Xcode在新建项目时,会要求为一个类指定一个前缀,这样方便我们区分相同名字的类.而从Xcode6开始,由于Swift增加了命名空间的关系,Xcode在新建项目时,不会再要 ...

  3. 在Navicat 中给Mysql中的某字段添加前缀00

    第一次分享心得,希望大家多多关注. 我遇到的情况是这样的,在Navicat中某表的varchar字段内容长度不够5的在内容前面添加‘0’:如字段内容是 101 我就要改成00101: 其中有2个难点: ...

  4. css之为文本添加线性渐变和外描边

    css之为文本添加线性渐变和外描边  一.效果: 描边:描边+渐变: 二.描边: api:text-stroke 问题:text-stroke的描边是居中描边,无法直接设置外描边 解决:在before ...

  5. iOS: 在Xcode7系列中给类名自动添加前缀

    添加前缀原因: 我个人还是很喜欢 Class Prefix 的,因为: 1. 使用它几乎不增加什么成本, 2. 不使用它可能会造成安全隐患, 3. 它能够以直接的方式编码一些信息以供未来的回溯, 4. ...

  6. 用Emmet写CSS3属性会自动添加前缀

    CSS3的很多属性都包含浏览器厂商前缀,用Emmet写CSS3属性会自动添加前缀,比如输入trs 会展开为: -webkit-transition: prop time; -moz-transitio ...

  7. 我的Android进阶之旅------> Android为TextView组件中显示的文本添加背景色

    通过上一篇文章 我的Android进阶之旅------> Android在TextView中显示图片方法 (地址:http://blog.csdn.net/ouyang_peng/article ...

  8. webpack css文件编译、自动添加前缀、剥离

    1.css文件编译 webpack默认只能编译js文件,引入css需要loader支持 // css文件写入js中 npm i style-loader -D // css文件loader npm i ...

  9. Makefile中的$(addprefix),添加前缀,指定目标生成目录

    先给大家看段Makefile的代码吧: INCLUDE_DIR=usr/java/jdk1..0_25/include \ usr/java/jdk1..0_25/include/linux INCL ...

随机推荐

  1. 使用nice命令调整进程优先级

    Adjusting Process Priority with nice   When Linux processes are started, they are started with a spe ...

  2. Java多线程——线程同步

    在之前,已经学习到了线程的创建和状态控制,但是每个线程之间几乎都没有什么太大的联系.可是有的时候,可能存在多个线程多同一个数据进行操作,这样,可能就会引用各种奇怪的问题.现在就来学习多线程对数据访问的 ...

  3. 本篇文章主要是对jquery+ajax+C#实现无刷新操作数据库数据的简单实例进行了介绍,需要的朋友可以过来参考下,希望对大家有所帮助

    我们知道同步执行和异步执行的区别,为了更好的提高用户的体验,我们都会采用异步方式去处理一些问题,毕竟单线程的同步可能回造成卡死等现象,很不友好,所以可以使用ajax来完成用户的体验,现在我们就来说说如 ...

  4. 开源CMS建站项目DNN研究与心得

    DNN (Dotnetnuke) 首先是开源的,并且采用BSD开源协议,也就是说你可以任意修改源代码.传播.作为商品出售,仅有的要求就是保留源代码中的版权文字,这就解决了我多年来的心病:我知道动网新闻 ...

  5. 你好,C++(24)好大一个箱子!5.1.1 函数的声明和定义

    第5章 用函数封装程序功能 在完成功能强大的工资程序V1.0之后,我们信心倍增,开始向C++世界的更深远处探索. 现在,我们可以用各种数据类型定义变量来表达问题中所涉及的各种数据:用操作符连接这些变量 ...

  6. hadoop实现共同出现的单词(Word co-occurrence)

    共同出现的单词(Word co-occurrence)是指在一个句子中相邻的两个单词.每一个相邻的单词就是一个Co-Occurrence对. Sample Input: a b cc, c d d c ...

  7. spring boot了解

    spring4倾向于基于注解的配置,强化的注解的功能,对比与spring3还是有很多的区别:spring boot对spring的各个组件功能管理,基于默认配置即可简单构建一个spring4的项目,对 ...

  8. protocol buffer介绍(protobuf)

    一.理论概述0.参考资料入门资料:https://developers.google.com/protocol-buffers/docs/javatutorial更详细的资料:For more det ...

  9. oldboy第一天学习

    oldboy第一天学习 一.听Alex Li 吹牛逼! 1.老男孩附加的功能.每节课都有鸡汤.节省时间,投资自己.结识更多的朋友. 2.python的创始人为吉多·范罗苏姆(Guido van Ros ...

  10. DDMS中File Explorer无法查看data/data文件解决办法

    http://www.cnblogs.com/smyhvae/p/3881477.html  找了个连接 问题描述:最近在学习Android SQLite中的SQLiteOpenHelper,使用SQ ...