AvalonEdit 对于选定的文本添加前缀和后缀

  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: 
时间: 2024-08-26 09:42:11

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

linux操作系统-给文本添加 &#39; -单引号,一般转成CSV格式时使用

[[email protected] ~]# cat 1.txt1ms2ms3ms4ms5ms [[email protected] ~]# cat 1.txt | awk '{print $1"\047"}'1ms'2ms'3ms'4ms'5ms' [[email protected] ~]# cat 1.txt | awk '{print $1"\047"}' > 2.txt[[email protected] ~]# cat 2.txt1ms'2ms'3

我的Android进阶之旅------&gt; Android为TextView组件中显示的文本添加背景色

通过上一篇文章 我的Android进阶之旅------> Android在TextView中显示图片方法 (地址:http://blog.csdn.net/ouyang_peng/article/details/46916963) 我们学会了在TextView中显示图片的方法,现在我们来学习如何为TextView组件中显示的文本添加背景色.要求完成的样子如图所示: 首先来学习使用BackgroundColorSpan对象设置文字背景色,代码如下: TextView textView=(TextV

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

第一次分享心得,希望大家多多关注. 我遇到的情况是这样的,在Navicat中某表的varchar字段内容长度不够5的在内容前面添加'0':如字段内容是 101 我就要改成00101: 其中有2个难点:1.判断字段内容的长度(我认知不够的原因) 2.给字段内容添加前缀: 之前的错误sql是 update base_sf set diy_code='00'+diy_code where pk in (select pk from base_sf where LENGTH(diy_code)=3) 这

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

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

pycharm在创建.py文件时自动添加前缀

有时候需要在创建py文件的时候需要自动添加前缀,他的具体操作是 打开pycharm的文件-->设置-->编辑器-->python script把你需要添加的前缀添加进去 #!/usr/bin/env python # -*- coding: utf-8 -*- # File  : ${NAME}.py # Author: HuXianyong # Date  : ${DATE} 原文地址:http://blog.51cto.com/853056088/2137381

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

css之为文本添加线性渐变和外描边  一.效果: 描边:描边+渐变: 二.描边: api:text-stroke 问题:text-stroke的描边是居中描边,无法直接设置外描边 解决:在before中添加文本,设置字体描边,绝对定位在文本下方 代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title<

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

1.css文件编译 webpack默认只能编译js文件,引入css需要loader支持 // css文件写入js中 npm i style-loader -D // css文件loader npm i css-loader -D webpack.config.js的rules中添加 { test: /\.css$/, use:['style-loader', 'css-loader'] } 2.css自动添加前缀 // postcss-loader 可以给css自动添加-webkit -ms前缀

关于为vue的图片添加前缀地址

今天在做项目的分页功能时,遇到了一个问题.在项目中,我抽离了微博组件,并利用 props,使其只需要传入一个微博数组便可将其转换成微博列表展示出来.对于其中的图片,我先前采用对数组 for 循环添加前缀,来使其找到对应的路径. 但是,当我使用分页时,因我在第一页已对数组中的图片添加了地址,当我加载第二页时,又对其第一页的图片添加了地址,于是图片地址便产生了错误. 在思考了一段时间后,我便尝试把 img 标签的 :src 从原先的微博.图片名修改成地址/微博.图片名,试了试,完美. 原代码 <di

将前缀和后缀相同的文件移动到同一个目录的算法设计及C代码实现

一.需求描述 在Linux系统的某几个目录下有一些前缀和后缀相同的文件,编写程序将它们移动到同一个目录下. 例如,有三个源目录FileDir1.FileDir2和FileDir3,里面分别存放有文件File_1.txt.File_2.txt和File_3.txt.由于它们有相同的前缀(File_)和后缀(txt),所以要将这三个文件移动到同一个结果目录(假设为GatherDir)中. 二.算法设计 基于需求,可以采用如图1所示的程序流程: 图1 程序总体流程 三.特殊流程考虑 在编写程序的过程中