├── AvalonEditB ├── .gitignore ├── Search │ ├── next.png │ ├── prev.png │ ├── replaceall.png │ └── replacenext.png ├── themes │ ├── RightArrow.cur │ └── generic.xaml ├── Utils │ ├── Logging.cs │ ├── Constants.cs │ ├── Empty.cs │ ├── Boxes.cs │ ├── PropertyChangedWeakEventManager.cs │ ├── NullSafeCollection.cs │ └── DelayedEvents.cs ├── Highlighting │ ├── Resources │ │ ├── ASPX.xshd │ │ ├── Patch-Mode.xshd │ │ ├── MarkDown-Mode.xshd │ │ ├── CSS-Mode.xshd │ │ ├── XmlDoc.xshd │ │ ├── Json.xshd │ │ ├── XML-Mode.xshd │ │ └── MarkDownWithFontSize-Mode.xshd │ ├── IHighlightingDefinitionReferenceResolver.cs │ ├── Xshd │ │ ├── XshdImport.cs │ │ ├── XshdElement.cs │ │ ├── XshdProperty.cs │ │ ├── XshdRule.cs │ │ ├── IXshdVisitor.cs │ │ ├── XshdKeywords.cs │ │ ├── XshdSyntaxDefinition.cs │ │ └── XshdRuleSet.cs │ ├── HighlightedSection.cs │ ├── HighlightingRule.cs │ ├── IHighlightingRule.cs │ ├── HighlightingRuleSet.cs │ ├── RichTextColorizer.cs │ ├── RuleMatch.cs │ ├── IHighlightingDefinition.cs │ ├── HighlightingDefinitionInvalidException.cs │ └── HtmlOptions.cs ├── Properties │ └── CodeAnalysisDictionary.xml ├── AvalonEditB.sln ├── Rendering │ ├── IVisualLineTransformer.cs │ ├── ITextViewConnect.cs │ ├── IBackgroundRenderer.cs │ ├── VisualLineConstructionStartEventArgs.cs │ ├── Layer.cs │ ├── SimpleTextSource.cs │ ├── GlobalTextRunProperties.cs │ ├── VisualLineTextParagraphProperties.cs │ ├── HeightTreeLineNode.cs │ ├── VisualLinesInvalidException.cs │ ├── TextViewCachedElements.cs │ ├── VisualYPosition.cs │ ├── ITextRunConstructionContext.cs │ └── ColumnRulerRenderer.cs ├── Snippets │ ├── SnippetElement.cs │ ├── SnippetTextElement.cs │ ├── IActiveElement.cs │ ├── SnippetContainerElement.cs │ ├── SnippetSelectionElement.cs │ ├── SnippetEventArgs.cs │ ├── Snippet.cs │ └── SnippetCaretElement.cs ├── Document │ ├── IUndoableOperation.cs │ ├── UndoOperationGroup.cs │ └── DocumentChangeOperation.cs ├── Indentation │ ├── IIndentationStrategy.cs │ └── DefaultIndentationStrategy.cs ├── CodeCompletion │ ├── IOverloadProvider.cs │ ├── CompletionList.xaml │ └── OverloadInsightWindow.cs ├── Editing │ ├── CaretWeakEventHandler.cs │ ├── MouseSelectionMode.cs │ ├── IReadOnlySectionProvider.cs │ ├── DottedLineMargin.cs │ ├── DragDropException.cs │ └── NoReadOnlySections.cs ├── TextEditorComponent.cs ├── TextEditorWeakEventManager.cs └── Folding │ └── NewFolding.cs ├── AvalonEditB.Docs ├── logo.ico ├── logo.png ├── logo128.png ├── logo400.png ├── logo800.png ├── logo1280x640.png └── READMEnuget.md ├── Documentation ├── icons │ └── Help.png ├── Media │ ├── VisualTree.png │ ├── RenderingPipeline.png │ ├── WelcomeScreenshot.png │ └── NamespaceDependencies.png ├── ICSharpCode.AvalonEdit.content ├── License.html └── Architecture.aml ├── global.json ├── ICSharpCode.AvalonEdit.Sample ├── Images │ ├── Cut.png │ ├── Copy.png │ ├── Open.png │ ├── Paste.png │ ├── Redo.png │ ├── Save.png │ ├── Undo.png │ ├── Delete.png │ └── WordWrap.png ├── AvalonEdit │ ├── snoop.png │ ├── folding.png │ ├── screenshot.png │ ├── dependencies.png │ └── renderingPipeline.png ├── RenderingPipeline.pptx ├── app.config ├── App.xaml ├── Properties │ ├── AssemblyInfo.cs │ └── WPFAssemblyInfo.cs ├── CustomHighlighting.xshd ├── App.xaml.cs ├── ICSharpCode.AvalonEdit.Sample.csproj ├── MyCompletionData.cs └── ColorizeAvalonEdit.cs ├── ICSharpCode.AvalonEdit.Tests ├── ICSharpCode.AvalonEdit.Tests.PartCover.Settings ├── Highlighting │ ├── XmlHighlightingDefinitionTests.cs │ ├── HighlightingManagerTests.cs │ ├── DeserializationTests.cs │ ├── HtmlClipboardTests.cs │ └── RichTextTests.cs ├── ICSharpCode.AvalonEdit.Tests.csproj ├── Properties │ └── AssemblyInfo.cs └── Utils │ ├── ExtensionMethodsTests.cs │ └── IndentationStringTests.cs ├── BuildTools └── tidy.py ├── ThirdParty-Highlightings ├── README.md └── CLLE.xshd ├── LICENSE.txt ├── ICSharpCode.AvalonEdit.Documentation.sln ├── ICSharpCode.AvalonEdit.sln └── .gitattributes /AvalonEditB/.gitignore: -------------------------------------------------------------------------------- 1 | # /AvalonEditB.xml # not sure why this was to be ignored 2 | 3 | .fake -------------------------------------------------------------------------------- /AvalonEditB.Docs/logo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/goswinr/AvalonEditB/HEAD/AvalonEditB.Docs/logo.ico -------------------------------------------------------------------------------- /AvalonEditB.Docs/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/goswinr/AvalonEditB/HEAD/AvalonEditB.Docs/logo.png -------------------------------------------------------------------------------- /AvalonEditB.Docs/logo128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/goswinr/AvalonEditB/HEAD/AvalonEditB.Docs/logo128.png -------------------------------------------------------------------------------- /AvalonEditB.Docs/logo400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/goswinr/AvalonEditB/HEAD/AvalonEditB.Docs/logo400.png -------------------------------------------------------------------------------- /AvalonEditB.Docs/logo800.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/goswinr/AvalonEditB/HEAD/AvalonEditB.Docs/logo800.png -------------------------------------------------------------------------------- /AvalonEditB/Search/next.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/goswinr/AvalonEditB/HEAD/AvalonEditB/Search/next.png -------------------------------------------------------------------------------- /AvalonEditB/Search/prev.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/goswinr/AvalonEditB/HEAD/AvalonEditB/Search/prev.png -------------------------------------------------------------------------------- /Documentation/icons/Help.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/goswinr/AvalonEditB/HEAD/Documentation/icons/Help.png -------------------------------------------------------------------------------- /AvalonEditB.Docs/logo1280x640.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/goswinr/AvalonEditB/HEAD/AvalonEditB.Docs/logo1280x640.png -------------------------------------------------------------------------------- /AvalonEditB/Search/replaceall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/goswinr/AvalonEditB/HEAD/AvalonEditB/Search/replaceall.png -------------------------------------------------------------------------------- /AvalonEditB/Search/replacenext.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/goswinr/AvalonEditB/HEAD/AvalonEditB/Search/replacenext.png -------------------------------------------------------------------------------- /AvalonEditB/themes/RightArrow.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/goswinr/AvalonEditB/HEAD/AvalonEditB/themes/RightArrow.cur -------------------------------------------------------------------------------- /Documentation/Media/VisualTree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/goswinr/AvalonEditB/HEAD/Documentation/Media/VisualTree.png -------------------------------------------------------------------------------- /Documentation/Media/RenderingPipeline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/goswinr/AvalonEditB/HEAD/Documentation/Media/RenderingPipeline.png -------------------------------------------------------------------------------- /Documentation/Media/WelcomeScreenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/goswinr/AvalonEditB/HEAD/Documentation/Media/WelcomeScreenshot.png -------------------------------------------------------------------------------- /global.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdk": { 3 | "version": "8.0.100", 4 | "rollForward": "major", 5 | "allowPrerelease": true 6 | } 7 | } -------------------------------------------------------------------------------- /ICSharpCode.AvalonEdit.Sample/Images/Cut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/goswinr/AvalonEditB/HEAD/ICSharpCode.AvalonEdit.Sample/Images/Cut.png -------------------------------------------------------------------------------- /Documentation/Media/NamespaceDependencies.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/goswinr/AvalonEditB/HEAD/Documentation/Media/NamespaceDependencies.png -------------------------------------------------------------------------------- /ICSharpCode.AvalonEdit.Sample/Images/Copy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/goswinr/AvalonEditB/HEAD/ICSharpCode.AvalonEdit.Sample/Images/Copy.png -------------------------------------------------------------------------------- /ICSharpCode.AvalonEdit.Sample/Images/Open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/goswinr/AvalonEditB/HEAD/ICSharpCode.AvalonEdit.Sample/Images/Open.png -------------------------------------------------------------------------------- /ICSharpCode.AvalonEdit.Sample/Images/Paste.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/goswinr/AvalonEditB/HEAD/ICSharpCode.AvalonEdit.Sample/Images/Paste.png -------------------------------------------------------------------------------- /ICSharpCode.AvalonEdit.Sample/Images/Redo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/goswinr/AvalonEditB/HEAD/ICSharpCode.AvalonEdit.Sample/Images/Redo.png -------------------------------------------------------------------------------- /ICSharpCode.AvalonEdit.Sample/Images/Save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/goswinr/AvalonEditB/HEAD/ICSharpCode.AvalonEdit.Sample/Images/Save.png -------------------------------------------------------------------------------- /ICSharpCode.AvalonEdit.Sample/Images/Undo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/goswinr/AvalonEditB/HEAD/ICSharpCode.AvalonEdit.Sample/Images/Undo.png -------------------------------------------------------------------------------- /ICSharpCode.AvalonEdit.Sample/Images/Delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/goswinr/AvalonEditB/HEAD/ICSharpCode.AvalonEdit.Sample/Images/Delete.png -------------------------------------------------------------------------------- /ICSharpCode.AvalonEdit.Sample/Images/WordWrap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/goswinr/AvalonEditB/HEAD/ICSharpCode.AvalonEdit.Sample/Images/WordWrap.png -------------------------------------------------------------------------------- /ICSharpCode.AvalonEdit.Sample/AvalonEdit/snoop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/goswinr/AvalonEditB/HEAD/ICSharpCode.AvalonEdit.Sample/AvalonEdit/snoop.png -------------------------------------------------------------------------------- /ICSharpCode.AvalonEdit.Sample/AvalonEdit/folding.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/goswinr/AvalonEditB/HEAD/ICSharpCode.AvalonEdit.Sample/AvalonEdit/folding.png -------------------------------------------------------------------------------- /ICSharpCode.AvalonEdit.Sample/RenderingPipeline.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/goswinr/AvalonEditB/HEAD/ICSharpCode.AvalonEdit.Sample/RenderingPipeline.pptx -------------------------------------------------------------------------------- /ICSharpCode.AvalonEdit.Sample/AvalonEdit/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/goswinr/AvalonEditB/HEAD/ICSharpCode.AvalonEdit.Sample/AvalonEdit/screenshot.png -------------------------------------------------------------------------------- /ICSharpCode.AvalonEdit.Tests/ICSharpCode.AvalonEdit.Tests.PartCover.Settings: -------------------------------------------------------------------------------- 1 | 2 | +[ICSharpCode.AvalonEdit]* 3 | -------------------------------------------------------------------------------- /ICSharpCode.AvalonEdit.Sample/AvalonEdit/dependencies.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/goswinr/AvalonEditB/HEAD/ICSharpCode.AvalonEdit.Sample/AvalonEdit/dependencies.png -------------------------------------------------------------------------------- /ICSharpCode.AvalonEdit.Sample/AvalonEdit/renderingPipeline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/goswinr/AvalonEditB/HEAD/ICSharpCode.AvalonEdit.Sample/AvalonEdit/renderingPipeline.png -------------------------------------------------------------------------------- /ICSharpCode.AvalonEdit.Sample/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /ICSharpCode.AvalonEdit.Sample/App.xaml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ICSharpCode.AvalonEdit.Sample/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | #region Using directives 2 | 3 | using System; 4 | using System.Reflection; 5 | using System.Runtime.InteropServices; 6 | 7 | #endregion 8 | 9 | // This sets the default COM visibility of types in the assembly to invisible. 10 | // If you need to expose a type to COM, use [ComVisible(true)] on that type. 11 | [assembly: ComVisible(false)] 12 | -------------------------------------------------------------------------------- /AvalonEditB/Utils/Logging.cs: -------------------------------------------------------------------------------- 1 | 2 | // added by goswinr for using an external logging function during debugging 3 | using System; 4 | 5 | namespace AvalonEditB.Utils 6 | { 7 | /// 8 | /// A static class for logging ,intended for debuging 9 | /// 10 | public static class Logging 11 | { 12 | /// 13 | /// The logging action that can be set 14 | /// 15 | public static Action LogAction = new Action(message => { }); 16 | 17 | /// 18 | /// This function uses the logging Action 'logAction' of the same static class. 19 | /// 20 | public static void Log(string message) { LogAction.Invoke(message); } 21 | 22 | } 23 | 24 | } 25 | 26 | 27 | -------------------------------------------------------------------------------- /Documentation/ICSharpCode.AvalonEdit.content: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /AvalonEditB/Highlighting/Resources/ASPX.xshd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | <% 9 | %> 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /AvalonEditB/themes/generic.xaml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 15 | 16 | -------------------------------------------------------------------------------- /BuildTools/tidy.py: -------------------------------------------------------------------------------- 1 | import os, sys 2 | 3 | def check(filename): 4 | ok = True 5 | with open(filename, 'r') as f: 6 | for i, line in enumerate(f): 7 | if line.startswith(' '): 8 | print('{}:{}: Line starting with spaces. Use tabs for indentation instead!'.format(filename, i+1)) 9 | ok = False 10 | return ok 11 | 12 | def main(): 13 | dir = os.path.normpath(os.path.join(os.path.dirname(__file__), '..')) 14 | ok = True 15 | for root, dirs, files in os.walk(dir): 16 | if '\\obj\\' in root: 17 | continue 18 | for filename in files: 19 | if filename.lower().endswith('.cs') or filename.lower().endswith('.xaml'): 20 | if not check(os.path.join(root, filename)): 21 | ok = False 22 | print('Tidy check: {}'.format('successful' if ok else 'failed')) 23 | return 0 if ok else 1 24 | 25 | if __name__ == '__main__': 26 | sys.exit(main()) -------------------------------------------------------------------------------- /ThirdParty-Highlightings/README.md: -------------------------------------------------------------------------------- 1 | Third-Party Highlighting Definitions for AvalonEdit 2 | ================================================== 3 | 4 | These custom highlighting definitions have been provided by the community. 5 | We are sharing them here, because we cannot include every possible language in the AvalonEdit bundle. 6 | 7 | If you want your highlighting included, please open a pull request. 8 | 9 | * [RPG](https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_73/rbam6/rbam6clmain.htm) see RPGLE.xshd (provided by @worksofliam in #144) 10 | * [CLLE](https://www.ibm.com/developerworks/ibmi/library/i-ibmi-rpg-support/index.html) see CLLE.xshd (provided by @worksofliam in #144) 11 | 12 | Highlighting Definitions found in other locations 13 | ------------------------------------------------ 14 | 15 | * Assembler highlighting (shipping with ILSpy): https://github.com/icsharpcode/ILSpy/blob/master/ILSpy/TextView/Asm-Mode.xshd 16 | * MSIL highlighting (shipping with ILSpy): https://github.com/icsharpcode/ILSpy/blob/master/ILSpy/TextView/ILAsm-Mode.xshd 17 | -------------------------------------------------------------------------------- /AvalonEditB/Properties/CodeAnalysisDictionary.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Uncollapse 7 | Foldings 8 | Xshd 9 | Utils 10 | Deque 11 | Colorizer 12 | Renderer 13 | Renderers 14 | Deletable 15 | 16 | y 17 | 18 | 19 | 20 | Lineup 21 | 22 | 23 | 24 | Bestest 25 | 26 | 27 | 28 | 29 | 30 | WiX 31 | 32 | 33 | -------------------------------------------------------------------------------- /ICSharpCode.AvalonEdit.Sample/Properties/WPFAssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | #region Using directives 2 | 3 | using System.Resources; 4 | using System.Windows; 5 | 6 | #endregion 7 | 8 | 9 | 10 | //In order to begin building localizable applications, set 11 | //CultureYouAreCodingWith in your .csproj file 12 | //inside a . For example, if you are using US english 13 | //in your source files, set the to en-US. Then uncomment 14 | //the NeutralResourceLanguage attribute below. Update the "en-US" in 15 | //the line below to match the UICulture setting in the project file. 16 | 17 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] 18 | 19 | 20 | [assembly: ThemeInfo( 21 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 22 | //(used if a resource is not found in the page, 23 | // or application resource dictionaries) 24 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 25 | //(used if a resource is not found in the page, 26 | // app, or any theme specific resource dictionaries) 27 | )] 28 | -------------------------------------------------------------------------------- /AvalonEditB/AvalonEditB.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30804.86 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AvalonEditB", "AvalonEditB.csproj", "{553803FC-91CF-4F0F-8584-0CEC9531B6B1}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {553803FC-91CF-4F0F-8584-0CEC9531B6B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {553803FC-91CF-4F0F-8584-0CEC9531B6B1}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {553803FC-91CF-4F0F-8584-0CEC9531B6B1}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {553803FC-91CF-4F0F-8584-0CEC9531B6B1}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {3DD87063-B682-4867-9C1A-AC15FCF579C6} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | AvalonEditB Copyright (c) 2021 Goswin Rothenthal 4 | 5 | AvalonEdit Copyright (c) AvalonEdit Contributors 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | -------------------------------------------------------------------------------- /ThirdParty-Highlightings/CLLE.xshd: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | ' 12 | ' 13 | 14 | 15 | 16 | /\* 17 | \*/ 18 | 19 | 20 | 21 | 22 | \b0[xX][0-9a-fA-F]+ # hex number 23 | | \b 24 | ( \d+(\.[0-9]+)? #number with optional floating point 25 | | \.[0-9]+ #or just starting with floating point 26 | ) 27 | ([eE][+-]?[0-9]+)? # optional exponent 28 | 29 | 30 | 31 | (\w+) 32 | 33 | 34 | 35 | \B[\%\&]\w+ 36 | 37 | 38 | 39 | 40 | \B\*\w+ 41 | 42 | 43 | -------------------------------------------------------------------------------- /ICSharpCode.AvalonEdit.Tests/Highlighting/XmlHighlightingDefinitionTests.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | 3 | using ICSharpCode.AvalonEdit.Document; 4 | using ICSharpCode.AvalonEdit.Highlighting; 5 | using ICSharpCode.AvalonEdit.Highlighting.Xshd; 6 | 7 | using NUnit.Framework; 8 | 9 | namespace ICSharpCode.AvalonEdit.Tests.Highlighting 10 | { 11 | [TestFixture] 12 | public class XmlHighlightingDefinitionTests 13 | { 14 | [Test] 15 | public void LongerKeywordsArePreferred() 16 | { 17 | var color = new XshdColor { Name = "Result" }; 18 | var syntaxDefinition = new XshdSyntaxDefinition { 19 | Elements = { 20 | color, 21 | new XshdRuleSet { 22 | Elements = { new XshdKeywords { 23 | ColorReference = new XshdReference(null, color.Name), 24 | Words = { "foo", "foo.bar." } 25 | } 26 | } 27 | } 28 | } 29 | }; 30 | 31 | var document = new TextDocument("This is a foo.bar. keyword"); 32 | var highlighter = new DocumentHighlighter(document, new XmlHighlightingDefinition(syntaxDefinition, HighlightingManager.Instance)); 33 | var result = highlighter.HighlightLine(1); 34 | 35 | var highlightedText = document.GetText(result.Sections.Single()); 36 | Assert.That(highlightedText, Is.EqualTo("foo.bar.")); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /AvalonEditB/Highlighting/Resources/Patch-Mode.xshd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Index:\s 12 | 13 | 14 | == 15 | 16 | 17 | --- 18 | 19 | 20 | \+\+\+ 21 | 22 | 23 | @@ 24 | 25 | 26 | - 27 | 28 | 29 | \+ 30 | 31 | 32 | \s 33 | 34 | 35 | -------------------------------------------------------------------------------- /ICSharpCode.AvalonEdit.Sample/CustomHighlighting.xshd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | " 13 | " 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | if 22 | else 23 | 24 | 25 | 26 | 27 | AvalonEdit 28 | 29 | 30 | 31 | 32 | \b0[xX][0-9a-fA-F]+ # hex number 33 | | \b 34 | ( \d+(\.[0-9]+)? #number with optional floating point 35 | | \.[0-9]+ #or just starting with floating point 36 | ) 37 | ([eE][+-]?[0-9]+)? # optional exponent 38 | 39 | 40 | -------------------------------------------------------------------------------- /AvalonEditB/Utils/Constants.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | namespace AvalonEditB.Utils 20 | { 21 | static class Constants 22 | { 23 | /// 24 | /// Multiply with this constant to convert from points to device-independent pixels. 25 | /// 26 | public const double PixelPerPoint = 4 / 3.0; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Documentation/License.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | License 5 | 6 | 7 | 8 | 9 | 10 |

The MIT License (MIT)

11 | 12 |

13 | Permission is hereby granted, free of charge, to any person obtaining a copy 14 | of this software and associated documentation files (the "Software"), to deal 15 | in the Software without restriction, including without limitation the rights 16 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | copies of the Software, and to permit persons to whom the Software is 18 | furnished to do so, subject to the following conditions: 19 |

20 |

21 | The above copyright notice and this permission notice shall be included in 22 | all copies or substantial portions of the Software. 23 |

24 |

25 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 26 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 27 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 28 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 29 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 30 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 31 | THE SOFTWARE. 32 |

33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /AvalonEditB/Utils/Empty.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | namespace AvalonEditB.Utils 20 | { 21 | /// 22 | /// Provides immutable empty list instances. 23 | /// 24 | static class Empty 25 | { 26 | public static readonly T[] Array = new T[0]; 27 | //public static readonly ReadOnlyCollection ReadOnlyCollection = new ReadOnlyCollection(Array); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /ICSharpCode.AvalonEdit.Sample/App.xaml.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2009 Daniel Grunwald 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using System.Windows; 21 | using System.Data; 22 | using System.Xml; 23 | using System.Configuration; 24 | 25 | namespace ICSharpCode.AvalonEdit.Sample 26 | { 27 | /// 28 | /// Interaction logic for App.xaml 29 | /// 30 | public partial class App : Application 31 | { 32 | public App() 33 | { 34 | InitializeComponent(); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /AvalonEditB/Utils/Boxes.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | namespace AvalonEditB.Utils 20 | { 21 | /// 22 | /// Reuse the same instances for boxed booleans. 23 | /// 24 | static class Boxes 25 | { 26 | public static readonly object True = true; 27 | public static readonly object False = false; 28 | 29 | public static object Box(bool value) 30 | { 31 | return value ? True : False; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /ICSharpCode.AvalonEdit.Tests/Highlighting/HighlightingManagerTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using ICSharpCode.AvalonEdit.Highlighting; 4 | using ICSharpCode.AvalonEdit.Highlighting.Xshd; 5 | 6 | using NUnit.Framework; 7 | 8 | namespace ICSharpCode.AvalonEdit.Tests.Highlighting 9 | { 10 | [TestFixture] 11 | public class HighlightingManagerTests 12 | { 13 | [Test] 14 | public void OverwriteHighlightingDefinitionWithSameName() 15 | { 16 | var highlightingManager = new HighlightingManager(); 17 | 18 | var definitionA = CreateDefinition("TestDefinition"); 19 | var definitionB = CreateDefinition("TestDefinition"); 20 | var definitionC = CreateDefinition("DifferentName"); 21 | 22 | Assert.That(highlightingManager.HighlightingDefinitions, Is.Empty); 23 | 24 | highlightingManager.RegisterHighlighting(definitionA.Name, Array.Empty(), definitionA); 25 | Assert.That(highlightingManager.HighlightingDefinitions, Is.EqualTo(new[] { definitionA })); 26 | 27 | highlightingManager.RegisterHighlighting(definitionB.Name, Array.Empty(), definitionB); 28 | Assert.That(highlightingManager.HighlightingDefinitions, Is.EqualTo(new[] { definitionB })); 29 | 30 | highlightingManager.RegisterHighlighting(definitionC.Name, Array.Empty(), definitionC); 31 | Assert.That(highlightingManager.HighlightingDefinitions, Is.EqualTo(new[] { definitionB, definitionC })); 32 | 33 | XmlHighlightingDefinition CreateDefinition(string name) 34 | { 35 | return new XmlHighlightingDefinition(new XshdSyntaxDefinition { Name = name, Elements = { new XshdRuleSet() } }, highlightingManager); 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /AvalonEditB/Highlighting/IHighlightingDefinitionReferenceResolver.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | namespace AvalonEditB.Highlighting 20 | { 21 | /// 22 | /// Interface for resolvers that can solve cross-definition references. 23 | /// 24 | public interface IHighlightingDefinitionReferenceResolver 25 | { 26 | /// 27 | /// Gets the highlighting definition by name, or null if it is not found. 28 | /// 29 | IHighlightingDefinition GetDefinition(string name); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /AvalonEditB/Rendering/IVisualLineTransformer.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System.Collections.Generic; 20 | 21 | namespace AvalonEditB.Rendering 22 | { 23 | /// 24 | /// Allows transforming visual line elements. 25 | /// 26 | public interface IVisualLineTransformer 27 | { 28 | /// 29 | /// Applies the transformation to the specified list of visual line elements. 30 | /// 31 | void Transform(ITextRunConstructionContext context, IList elements); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /ICSharpCode.AvalonEdit.Tests/ICSharpCode.AvalonEdit.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | Library 4 | net6.0-windows;net8.0-windows;net462 5 | true 6 | true 7 | TRACE 8 | true 9 | ..\ICSharpCode.AvalonEdit\ICSharpCode.AvalonEdit.snk 10 | ic#code 11 | 2000-2025 AlphaSierraPapa for the SharpDevelop Team 12 | Tests for WPF-based extensible text editor 13 | false 14 | 15 | 16 | 17 | TRACE 18 | 19 | 20 | TRACE 21 | 22 | 23 | TRACE 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /ICSharpCode.AvalonEdit.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using System.Reflection; 21 | using System.Runtime.InteropServices; 22 | using System.Threading; 23 | using NUnit.Framework; 24 | 25 | // This sets the default COM visibility of types in the assembly to invisible. 26 | // If you need to expose a type to COM, use [ComVisible(true)] on that type. 27 | [assembly: ComVisible(false)] 28 | 29 | #if !NETCOREAPP 30 | // Run unit tests on STA thread. 31 | [assembly: Apartment(ApartmentState.STA)] 32 | #endif -------------------------------------------------------------------------------- /ICSharpCode.AvalonEdit.Tests/Highlighting/DeserializationTests.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Xml; 3 | 4 | using ICSharpCode.AvalonEdit.Document; 5 | using ICSharpCode.AvalonEdit.Highlighting; 6 | using ICSharpCode.AvalonEdit.Highlighting.Xshd; 7 | 8 | using Newtonsoft.Json; 9 | 10 | using NUnit.Framework; 11 | 12 | 13 | namespace ICSharpCode.AvalonEdit.Tests.Highlighting 14 | { 15 | [TestFixture] 16 | public class DeserializationTests 17 | { 18 | TextDocument document; 19 | DocumentHighlighter highlighter; 20 | 21 | [SetUp] 22 | public void SetUp() 23 | { 24 | document = new TextDocument("using System.Text;\n\tstring text = SomeMethod();"); 25 | highlighter = new DocumentHighlighter(document, HighlightingManager.Instance.GetDefinition("C#")); 26 | } 27 | 28 | [Test] 29 | public void TestRoundTripColor() 30 | { 31 | HighlightingColor color = highlighter.GetNamedColor("Comment"); 32 | string jsonString = JsonConvert.SerializeObject(color); 33 | 34 | HighlightingColor color2 = JsonConvert.DeserializeObject(jsonString); 35 | Assert.That(color2, Is.EqualTo(color)); 36 | } 37 | 38 | [TestCase("CSharp-Mode.xshd")] 39 | public void XshdSerializationDoesNotCrash(string resourceName) 40 | { 41 | XshdSyntaxDefinition xshd; 42 | using (Stream s = Resources.OpenStream(resourceName)) { 43 | using (XmlTextReader reader = new XmlTextReader(s)) { 44 | xshd = HighlightingLoader.LoadXshd(reader, false); 45 | } 46 | } 47 | Assert.That(xshd.Name, Is.EqualTo("C#")); 48 | Assert.That(xshd.Extensions, Is.Not.Empty); 49 | Assert.That(xshd.Extensions[0], Is.EqualTo(".cs")); 50 | 51 | Assert.DoesNotThrow(() => JsonConvert.SerializeObject(xshd)); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /AvalonEditB/Highlighting/Xshd/XshdImport.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | 21 | namespace AvalonEditB.Highlighting.Xshd 22 | { 23 | /// 24 | /// <Import> element. 25 | /// 26 | [Serializable] 27 | public class XshdImport : XshdElement 28 | { 29 | /// 30 | /// Gets/sets the referenced rule set. 31 | /// 32 | public XshdReference RuleSetReference { get; set; } 33 | 34 | /// 35 | public override object AcceptVisitor(IXshdVisitor visitor) 36 | { 37 | return visitor.VisitImport(this); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /ICSharpCode.AvalonEdit.Documentation.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.28714.193 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ICSharpCode.AvalonEdit", "ICSharpCode.AvalonEdit\ICSharpCode.AvalonEdit.csproj", "{417F2A81-E1C2-4366-B24B-C5DC8F958844}" 7 | EndProject 8 | Project("{7CF6DF6D-3B04-46F8-A40B-537D21BCA0B4}") = "ICSharpCode.AvalonEdit.Documentation", "Documentation\ICSharpCode.AvalonEdit.Documentation.shfbproj", "{850B6602-0A7F-413A-864A-E816B98D7407}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {417F2A81-E1C2-4366-B24B-C5DC8F958844}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {417F2A81-E1C2-4366-B24B-C5DC8F958844}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {417F2A81-E1C2-4366-B24B-C5DC8F958844}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {417F2A81-E1C2-4366-B24B-C5DC8F958844}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {850B6602-0A7F-413A-864A-E816B98D7407}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {850B6602-0A7F-413A-864A-E816B98D7407}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {850B6602-0A7F-413A-864A-E816B98D7407}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {850B6602-0A7F-413A-864A-E816B98D7407}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {919F9316-235F-49C8-868A-F0C8B9063F56} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /AvalonEditB/Snippets/SnippetElement.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using System.Windows.Documents; 21 | 22 | namespace AvalonEditB.Snippets 23 | { 24 | /// 25 | /// An element inside a snippet. 26 | /// 27 | [Serializable] 28 | public abstract class SnippetElement 29 | { 30 | /// 31 | /// Performs insertion of the snippet. 32 | /// 33 | public abstract void Insert(InsertionContext context); 34 | 35 | /// 36 | /// Converts the snippet to text, with replaceable fields in italic. 37 | /// 38 | public virtual Inline ToTextRun() 39 | { 40 | return null; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ICSharpCode.AvalonEdit.Sample/ICSharpCode.AvalonEdit.Sample.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | WinExe 4 | net6.0-windows;net8.0-windows;net472 5 | true 6 | true 7 | TRACE 8 | true 9 | ..\ICSharpCode.AvalonEdit\ICSharpCode.AvalonEdit.snk 10 | AvalonEdit.Sample 11 | ic#code 12 | 2000-2022 AlphaSierraPapa for the SharpDevelop Team 13 | Sample for WPF-based extensible text editor 14 | false 15 | 16 | 17 | 18 | TRACE 19 | 20 | 21 | TRACE 22 | 23 | 24 | TRACE 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /AvalonEditB/Document/IUndoableOperation.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | namespace AvalonEditB.Document 20 | { 21 | /// 22 | /// This Interface describes a the basic Undo/Redo operation 23 | /// all Undo Operations must implement this interface. 24 | /// 25 | public interface IUndoableOperation 26 | { 27 | /// 28 | /// Undo the last operation 29 | /// 30 | void Undo(); 31 | 32 | /// 33 | /// Redo the last operation 34 | /// 35 | void Redo(); 36 | } 37 | 38 | interface IUndoableOperationWithContext : IUndoableOperation 39 | { 40 | void Undo(UndoStack stack); 41 | void Redo(UndoStack stack); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /AvalonEditB/Rendering/ITextViewConnect.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | namespace AvalonEditB.Rendering 20 | { 21 | /// 22 | /// Allows s, s and 23 | /// s to be notified when they are added or removed from a text view. 24 | /// 25 | public interface ITextViewConnect 26 | { 27 | /// 28 | /// Called when added to a text view. 29 | /// 30 | void AddToTextView(TextView textView); 31 | 32 | /// 33 | /// Called when removed from a text view. 34 | /// 35 | void RemoveFromTextView(TextView textView); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /AvalonEditB/Highlighting/Xshd/XshdElement.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | 21 | namespace AvalonEditB.Highlighting.Xshd 22 | { 23 | /// 24 | /// An element in a XSHD rule set. 25 | /// 26 | [Serializable] 27 | public abstract class XshdElement 28 | { 29 | /// 30 | /// Gets the line number in the .xshd file. 31 | /// 32 | public int LineNumber { get; set; } 33 | 34 | /// 35 | /// Gets the column number in the .xshd file. 36 | /// 37 | public int ColumnNumber { get; set; } 38 | 39 | /// 40 | /// Applies the visitor to this element. 41 | /// 42 | public abstract object AcceptVisitor(IXshdVisitor visitor); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /AvalonEditB/Indentation/IIndentationStrategy.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using AvalonEditB.Document; 20 | 21 | namespace AvalonEditB.Indentation 22 | { 23 | /// 24 | /// Strategy how the text editor handles indentation when new lines are inserted. 25 | /// 26 | public interface IIndentationStrategy 27 | { 28 | /// 29 | /// Sets the indentation for the specified line. 30 | /// Usually this is constructed from the indentation of the previous line. 31 | /// 32 | void IndentLine(TextDocument document, DocumentLine line); 33 | 34 | /// 35 | /// Reindents a set of lines. 36 | /// 37 | void IndentLines(TextDocument document, int beginLine, int endLine); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /AvalonEditB/Utils/PropertyChangedWeakEventManager.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System.ComponentModel; 20 | 21 | namespace AvalonEditB.Utils 22 | { 23 | /// 24 | /// WeakEventManager for INotifyPropertyChanged.PropertyChanged. 25 | /// 26 | public sealed class PropertyChangedWeakEventManager : WeakEventManagerBase 27 | { 28 | /// 29 | protected override void StartListening(INotifyPropertyChanged source) 30 | { 31 | source.PropertyChanged += DeliverEvent; 32 | } 33 | 34 | /// 35 | protected override void StopListening(INotifyPropertyChanged source) 36 | { 37 | source.PropertyChanged -= DeliverEvent; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /AvalonEditB/Rendering/IBackgroundRenderer.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System.Windows.Media; 20 | 21 | namespace AvalonEditB.Rendering 22 | { 23 | /// 24 | /// Background renderers draw in the background of a known layer. 25 | /// You can use background renderers to draw non-interactive elements on the TextView 26 | /// without introducing new UIElements. 27 | /// 28 | public interface IBackgroundRenderer 29 | { 30 | /// 31 | /// Gets the layer on which this background renderer should draw. 32 | /// 33 | KnownLayer Layer { get; } 34 | 35 | /// 36 | /// Causes the background renderer to draw. 37 | /// 38 | void Draw(TextView textView, DrawingContext drawingContext); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /AvalonEditB/Highlighting/Resources/MarkDown-Mode.xshd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | ^\#.* 15 | 16 | 17 | \*\*.*\*\* 18 | 19 | 20 | __.*__ 21 | 22 | 23 | \*(?![ ]).*\* 24 | 25 | 26 | _.*_ 27 | 28 | 29 | `.*` 30 | 31 | 32 | ^\t 33 | ^(?!\t) 34 | 35 | 36 | ^[ ]{4} 37 | ^(?![ ]{4}) 38 | 39 | 40 | ^> 41 | ^(?!>) 42 | 43 | 44 | \!\[.*\]\[.*\] 45 | 46 | 47 | \[.*\]\(.*\) 48 | 49 | 50 | \[.*\]\[.*\] 51 | 52 | 53 | [ ]{2}$ 54 | 55 | 56 | -------------------------------------------------------------------------------- /AvalonEditB/Utils/NullSafeCollection.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using System.Collections.ObjectModel; 21 | 22 | namespace AvalonEditB.Utils 23 | { 24 | /// 25 | /// A collection that cannot contain null values. 26 | /// 27 | [Serializable] 28 | public class NullSafeCollection : Collection where T : class 29 | { 30 | /// 31 | protected override void InsertItem(int index, T item) 32 | { 33 | if (item == null) 34 | throw new ArgumentNullException("item"); 35 | base.InsertItem(index, item); 36 | } 37 | 38 | /// 39 | protected override void SetItem(int index, T item) 40 | { 41 | if (item == null) 42 | throw new ArgumentNullException("item"); 43 | base.SetItem(index, item); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /ICSharpCode.AvalonEdit.Tests/Utils/ExtensionMethodsTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using NUnit.Framework; 21 | 22 | namespace ICSharpCode.AvalonEdit.Utils 23 | { 24 | [TestFixture] 25 | public class ExtensionMethodsTests 26 | { 27 | [Test] 28 | public void ZeroIsNotCloseToOne() 29 | { 30 | Assert.That(0.0.IsClose(1), Is.False); 31 | } 32 | 33 | [Test] 34 | public void ZeroIsCloseToZero() 35 | { 36 | Assert.That(0.0.IsClose(0), Is.True); 37 | } 38 | 39 | [Test] 40 | public void InfinityIsCloseToInfinity() 41 | { 42 | Assert.That(double.PositiveInfinity.IsClose(double.PositiveInfinity), Is.True); 43 | } 44 | 45 | [Test] 46 | public void NaNIsNotCloseToNaN() 47 | { 48 | Assert.That(double.NaN.IsClose(double.NaN), Is.False); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /AvalonEditB/Snippets/SnippetTextElement.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using System.Windows.Documents; 21 | 22 | namespace AvalonEditB.Snippets 23 | { 24 | /// 25 | /// Represents a text element in a snippet. 26 | /// 27 | [Serializable] 28 | public class SnippetTextElement : SnippetElement 29 | { 30 | string text; 31 | 32 | /// 33 | /// The text to be inserted. 34 | /// 35 | public string Text { 36 | get { return text; } 37 | set { text = value; } 38 | } 39 | 40 | /// 41 | public override void Insert(InsertionContext context) 42 | { 43 | if (text != null) 44 | context.InsertText(text); 45 | } 46 | 47 | /// 48 | public override Inline ToTextRun() 49 | { 50 | return new Run(text ?? string.Empty); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /AvalonEditB/Highlighting/Xshd/XshdProperty.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | 21 | namespace AvalonEditB.Highlighting.Xshd 22 | { 23 | /// 24 | /// A property in an Xshd file. 25 | /// 26 | [Serializable] 27 | public class XshdProperty : XshdElement 28 | { 29 | /// 30 | /// Gets/sets the name. 31 | /// 32 | public string Name { get; set; } 33 | 34 | /// 35 | /// Gets/sets the value. 36 | /// 37 | public string Value { get; set; } 38 | 39 | /// 40 | /// Creates a new XshdColor instance. 41 | /// 42 | public XshdProperty() 43 | { 44 | } 45 | 46 | /// 47 | public override object AcceptVisitor(IXshdVisitor visitor) 48 | { 49 | return null; 50 | // return visitor.VisitProperty(this); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /AvalonEditB/Highlighting/Xshd/XshdRule.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | 21 | namespace AvalonEditB.Highlighting.Xshd 22 | { 23 | /// 24 | /// <Rule> element. 25 | /// 26 | [Serializable] 27 | public class XshdRule : XshdElement 28 | { 29 | /// 30 | /// Gets/sets the rule regex. 31 | /// 32 | public string Regex { get; set; } 33 | 34 | /// 35 | /// Gets/sets the rule regex type. 36 | /// 37 | public XshdRegexType RegexType { get; set; } 38 | 39 | /// 40 | /// Gets/sets the color reference. 41 | /// 42 | public XshdReference ColorReference { get; set; } 43 | 44 | /// 45 | public override object AcceptVisitor(IXshdVisitor visitor) 46 | { 47 | return visitor.VisitRule(this); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /AvalonEditB/Highlighting/Resources/CSS-Mode.xshd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | /\* 13 | \*/ 14 | 15 | 19 | \{ 20 | \} 21 | 22 | 23 | \# 24 | \s 25 | 26 | [\d\w] 27 | 28 | 29 | 30 | 31 | /\* 32 | \*/ 33 | 34 | 35 | \: 36 | \;|(?=\}) 37 | 38 | 39 | " 40 | " 41 | 42 | 43 | 44 | 45 | 46 | ' 47 | ' 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /Documentation/Architecture.aml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 14 | 15 | 16 | As you can see in this dependency graph, AvalonEdit consists of a few 17 | sub-namespaces that have cleanly separated jobs. 18 | Most of the namespaces have a kind of 'main' class. 19 | Here is the visual tree of the TextEditor control: 20 | 21 | It's important to understand that AvalonEdit is a composite control 22 | with the three layers: 23 | T:ICSharpCode.AvalonEdit.TextEditor (main control), 24 | T:ICSharpCode.AvalonEdit.Editing.TextArea (editing), 25 | T:ICSharpCode.AvalonEdit.Rendering.TextView (rendering). 26 | 27 | While the main control provides some convenience methods for common tasks, 28 | for most advanced features you have to work directly with the inner controls. 29 | You can access them using textEditor.TextArea or 30 | textEditor.TextArea.TextView. 31 | 32 | 33 | -------------------------------------------------------------------------------- /AvalonEditB/Highlighting/Xshd/IXshdVisitor.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | namespace AvalonEditB.Highlighting.Xshd 20 | { 21 | /// 22 | /// A visitor over the XSHD element tree. 23 | /// 24 | public interface IXshdVisitor 25 | { 26 | /// Visit method for XshdRuleSet 27 | object VisitRuleSet(XshdRuleSet ruleSet); 28 | 29 | /// Visit method for XshdColor 30 | object VisitColor(XshdColor color); 31 | 32 | /// Visit method for XshdKeywords 33 | object VisitKeywords(XshdKeywords keywords); 34 | 35 | /// Visit method for XshdSpan 36 | object VisitSpan(XshdSpan span); 37 | 38 | /// Visit method for XshdImport 39 | object VisitImport(XshdImport import); 40 | 41 | /// Visit method for XshdRule 42 | object VisitRule(XshdRule rule); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /AvalonEditB/Highlighting/Xshd/XshdKeywords.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using System.Collections.Generic; 21 | 22 | using AvalonEditB.Utils; 23 | 24 | namespace AvalonEditB.Highlighting.Xshd 25 | { 26 | /// 27 | /// A list of keywords. 28 | /// 29 | [Serializable] 30 | public class XshdKeywords : XshdElement 31 | { 32 | /// 33 | /// The color. 34 | /// 35 | public XshdReference ColorReference { get; set; } 36 | 37 | readonly NullSafeCollection words = new NullSafeCollection(); 38 | 39 | /// 40 | /// Gets the list of key words. 41 | /// 42 | public IList Words { 43 | get { return words; } 44 | } 45 | 46 | /// 47 | public override object AcceptVisitor(IXshdVisitor visitor) 48 | { 49 | return visitor.VisitKeywords(this); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /AvalonEditB/Highlighting/Resources/XmlDoc.xshd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | < 11 | > 12 | 13 | 14 | " 15 | " 16 | 17 | 18 | / 19 | | 20 | = 21 | 22 | 23 | c 24 | code 25 | example 26 | exception 27 | list 28 | para 29 | param 30 | paramref 31 | permission 32 | remarks 33 | returns 34 | see 35 | seealso 36 | summary 37 | value 38 | 39 | type 40 | name 41 | cref 42 | item 43 | term 44 | description 45 | listheader 46 | typeparam 47 | typeparamref 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /AvalonEditB/Rendering/VisualLineConstructionStartEventArgs.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | 21 | using AvalonEditB.Document; 22 | 23 | namespace AvalonEditB.Rendering 24 | { 25 | /// 26 | /// EventArgs for the event. 27 | /// 28 | public class VisualLineConstructionStartEventArgs : EventArgs 29 | { 30 | /// 31 | /// Gets/Sets the first line that is visible in the TextView. 32 | /// 33 | public DocumentLine FirstLineInView { get; private set; } 34 | 35 | /// 36 | /// Creates a new VisualLineConstructionStartEventArgs instance. 37 | /// 38 | public VisualLineConstructionStartEventArgs(DocumentLine firstLineInView) 39 | { 40 | if (firstLineInView == null) 41 | throw new ArgumentNullException("firstLineInView"); 42 | this.FirstLineInView = firstLineInView; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /AvalonEditB/CodeCompletion/IOverloadProvider.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System.ComponentModel; 20 | 21 | namespace AvalonEditB.CodeCompletion 22 | { 23 | /// 24 | /// Provides the items for the OverloadViewer. 25 | /// 26 | public interface IOverloadProvider : INotifyPropertyChanged 27 | { 28 | /// 29 | /// Gets/Sets the selected index. 30 | /// 31 | int SelectedIndex { get; set; } 32 | 33 | /// 34 | /// Gets the number of overloads. 35 | /// 36 | int Count { get; } 37 | 38 | /// 39 | /// Gets the text 'SelectedIndex of Count'. 40 | /// 41 | string CurrentIndexText { get; } 42 | 43 | /// 44 | /// Gets the current header. 45 | /// 46 | object CurrentHeader { get; } 47 | 48 | /// 49 | /// Gets the current content. 50 | /// 51 | object CurrentContent { get; } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /AvalonEditB/Editing/CaretWeakEventHandler.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using AvalonEditB.Utils; 20 | 21 | namespace AvalonEditB.Editing 22 | { 23 | /// 24 | /// Contains classes for handling weak events on the Caret class. 25 | /// 26 | public static class CaretWeakEventManager 27 | { 28 | /// 29 | /// Handles the Caret.PositionChanged event. 30 | /// 31 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")] 32 | public sealed class PositionChanged : WeakEventManagerBase 33 | { 34 | /// 35 | protected override void StartListening(Caret source) 36 | { 37 | source.PositionChanged += DeliverEvent; 38 | } 39 | 40 | /// 41 | protected override void StopListening(Caret source) 42 | { 43 | source.PositionChanged -= DeliverEvent; 44 | } 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /AvalonEditB/Snippets/IActiveElement.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using AvalonEditB.Document; 20 | 21 | namespace AvalonEditB.Snippets 22 | { 23 | /// 24 | /// Represents an active element that allows the snippet to stay interactive after insertion. 25 | /// 26 | public interface IActiveElement 27 | { 28 | /// 29 | /// Called when the all snippet elements have been inserted. 30 | /// 31 | void OnInsertionCompleted(); 32 | 33 | /// 34 | /// Called when the interactive mode is deactivated. 35 | /// 36 | void Deactivate(SnippetEventArgs e); 37 | 38 | /// 39 | /// Gets whether this element is editable (the user will be able to select it with Tab). 40 | /// 41 | bool IsEditable { get; } 42 | 43 | /// 44 | /// Gets the segment associated with this element. May be null. 45 | /// 46 | ISegment Segment { get; } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /AvalonEditB/Highlighting/HighlightedSection.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using AvalonEditB.Document; 20 | 21 | namespace AvalonEditB.Highlighting 22 | { 23 | /// 24 | /// A text section with syntax highlighting information. 25 | /// 26 | public class HighlightedSection : ISegment 27 | { 28 | /// 29 | /// Gets/sets the document offset of the section. 30 | /// 31 | public int Offset { get; set; } 32 | 33 | /// 34 | /// Gets/sets the length of the section. 35 | /// 36 | public int Length { get; set; } 37 | 38 | int ISegment.EndOffset { 39 | get { return this.Offset + this.Length; } 40 | } 41 | 42 | /// 43 | /// Gets the highlighting color associated with the highlighted section. 44 | /// 45 | public HighlightingColor Color { get; set; } 46 | 47 | /// 48 | public override string ToString() 49 | { 50 | return string.Format("[HighlightedSection ({0}-{1})={2}]", Offset, Offset + Length, Color); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /AvalonEditB/Editing/MouseSelectionMode.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | namespace AvalonEditB.Editing 20 | { 21 | /// 22 | /// Enumeration of possible states of mouse selection. 23 | /// 24 | public enum MouseSelectionMode 25 | { 26 | /// 27 | /// no selection (no mouse button down) 28 | /// 29 | None, 30 | /// 31 | /// left mouse button down on selection, might be normal click 32 | /// or might be drag'n'drop 33 | /// 34 | PossibleDragStart, 35 | /// 36 | /// dragging text 37 | /// 38 | Drag, 39 | /// 40 | /// normal selection (click+drag) 41 | /// 42 | Normal, 43 | /// 44 | /// whole-word selection (double click+drag or ctrl+click+drag) 45 | /// 46 | WholeWord, 47 | /// 48 | /// whole-line selection (triple click+drag) 49 | /// 50 | WholeLine, 51 | /// 52 | /// rectangular selection (alt+click+drag) 53 | /// 54 | Rectangular 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /AvalonEditB/Highlighting/HighlightingRule.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using System.Text.RegularExpressions; 21 | 22 | namespace AvalonEditB.Highlighting 23 | { 24 | /// 25 | /// A highlighting rule. 26 | /// 27 | [Serializable] 28 | public class HighlightingRule : IHighlightingRule 29 | { 30 | /// 31 | /// Gets/Sets the regular expression for the rule. 32 | /// 33 | public Regex Regex { get; set; } 34 | 35 | /// 36 | /// Gets/Sets the highlighting color. 37 | /// 38 | public HighlightingColor Color { get; set; } 39 | 40 | /// 41 | public string RuleInfo => $"Regex: {Regex}"; 42 | 43 | /// 44 | public RuleMatch GetMatch(string input, int beginning, int length, int lineNumber) 45 | { 46 | return RuleMatch.FromRegexMatch(Regex.Match(input, beginning, length)); 47 | } 48 | 49 | /// 50 | public override string ToString() 51 | { 52 | return "[" + GetType().Name + " " + Regex + "]"; 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /AvalonEditB/Utils/DelayedEvents.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using System.Collections.Generic; 21 | 22 | namespace AvalonEditB.Utils 23 | { 24 | /// 25 | /// Maintains a list of delayed events to raise. 26 | /// 27 | sealed class DelayedEvents 28 | { 29 | struct EventCall 30 | { 31 | EventHandler handler; 32 | object sender; 33 | EventArgs e; 34 | 35 | public EventCall(EventHandler handler, object sender, EventArgs e) 36 | { 37 | this.handler = handler; 38 | this.sender = sender; 39 | this.e = e; 40 | } 41 | 42 | public void Call() 43 | { 44 | handler(sender, e); 45 | } 46 | } 47 | 48 | Queue eventCalls = new Queue(); 49 | 50 | public void DelayedRaise(EventHandler handler, object sender, EventArgs e) 51 | { 52 | if (handler != null) { 53 | eventCalls.Enqueue(new EventCall(handler, sender, e)); 54 | } 55 | } 56 | 57 | public void RaiseEvents() 58 | { 59 | while (eventCalls.Count > 0) 60 | eventCalls.Dequeue().Call(); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /AvalonEditB/Rendering/Layer.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System.Diagnostics; 20 | using System.Windows; 21 | using System.Windows.Media; 22 | 23 | namespace AvalonEditB.Rendering 24 | { 25 | /// 26 | /// Base class for known layers. 27 | /// 28 | class Layer : UIElement 29 | { 30 | protected readonly TextView textView; 31 | protected readonly KnownLayer knownLayer; 32 | 33 | public Layer(TextView textView, KnownLayer knownLayer) 34 | { 35 | Debug.Assert(textView != null); 36 | this.textView = textView; 37 | this.knownLayer = knownLayer; 38 | this.Focusable = false; 39 | } 40 | 41 | protected override GeometryHitTestResult HitTestCore(GeometryHitTestParameters hitTestParameters) 42 | { 43 | return null; 44 | } 45 | 46 | protected override HitTestResult HitTestCore(PointHitTestParameters hitTestParameters) 47 | { 48 | return null; 49 | } 50 | 51 | protected override void OnRender(DrawingContext drawingContext) 52 | { 53 | base.OnRender(drawingContext); 54 | textView.RenderBackground(drawingContext, knownLayer); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /AvalonEditB/Editing/IReadOnlySectionProvider.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System.Collections.Generic; 20 | 21 | using AvalonEditB.Document; 22 | 23 | namespace AvalonEditB.Editing 24 | { 25 | /// 26 | /// Determines whether the document can be modified. 27 | /// 28 | public interface IReadOnlySectionProvider 29 | { 30 | /// 31 | /// Gets whether insertion is possible at the specified offset. 32 | /// 33 | bool CanInsert(int offset); 34 | 35 | /// 36 | /// Gets the deletable segments inside the given segment. 37 | /// 38 | /// 39 | /// All segments in the result must be within the given segment, and they must be returned in order 40 | /// (e.g. if two segments are returned, EndOffset of first segment must be less than StartOffset of second segment). 41 | /// 42 | /// For replacements, the last segment being returned will be replaced with the new text. If an empty list is returned, 43 | /// no replacement will be done. 44 | /// 45 | IEnumerable GetDeletableSegments(ISegment segment); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /AvalonEditB/Rendering/SimpleTextSource.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using System.Windows.Media.TextFormatting; 21 | 22 | namespace AvalonEditB.Rendering 23 | { 24 | sealed class SimpleTextSource : TextSource 25 | { 26 | readonly string text; 27 | readonly TextRunProperties properties; 28 | 29 | public SimpleTextSource(string text, TextRunProperties properties) 30 | { 31 | this.text = text; 32 | this.properties = properties; 33 | } 34 | 35 | public override TextRun GetTextRun(int textSourceCharacterIndex) 36 | { 37 | if (textSourceCharacterIndex < text.Length) 38 | return new TextCharacters(text, textSourceCharacterIndex, text.Length - textSourceCharacterIndex, properties); 39 | else 40 | return new TextEndOfParagraph(1); 41 | } 42 | 43 | public override int GetTextEffectCharacterIndexFromTextSourceCharacterIndex(int textSourceCharacterIndex) 44 | { 45 | throw new NotImplementedException(); 46 | } 47 | 48 | public override TextSpan GetPrecedingText(int textSourceCharacterIndexLimit) 49 | { 50 | throw new NotImplementedException(); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /ICSharpCode.AvalonEdit.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.28714.193 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ICSharpCode.AvalonEdit", "ICSharpCode.AvalonEdit\ICSharpCode.AvalonEdit.csproj", "{417F2A81-E1C2-4366-B24B-C5DC8F958844}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ICSharpCode.AvalonEdit.Sample", "ICSharpCode.AvalonEdit.Sample\ICSharpCode.AvalonEdit.Sample.csproj", "{E506196C-A5E8-4D24-B889-6BA401C0B2B9}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ICSharpCode.AvalonEdit.Tests", "ICSharpCode.AvalonEdit.Tests\ICSharpCode.AvalonEdit.Tests.csproj", "{37CAC89C-C38C-4126-A4A0-91A240A474D7}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {417F2A81-E1C2-4366-B24B-C5DC8F958844}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {417F2A81-E1C2-4366-B24B-C5DC8F958844}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {417F2A81-E1C2-4366-B24B-C5DC8F958844}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {417F2A81-E1C2-4366-B24B-C5DC8F958844}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {E506196C-A5E8-4D24-B889-6BA401C0B2B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {E506196C-A5E8-4D24-B889-6BA401C0B2B9}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {E506196C-A5E8-4D24-B889-6BA401C0B2B9}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {E506196C-A5E8-4D24-B889-6BA401C0B2B9}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {37CAC89C-C38C-4126-A4A0-91A240A474D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {37CAC89C-C38C-4126-A4A0-91A240A474D7}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {37CAC89C-C38C-4126-A4A0-91A240A474D7}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {37CAC89C-C38C-4126-A4A0-91A240A474D7}.Release|Any CPU.Build.0 = Release|Any CPU 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | GlobalSection(ExtensibilityGlobals) = postSolution 35 | SolutionGuid = {919F9316-235F-49C8-868A-F0C8B9063F56} 36 | EndGlobalSection 37 | EndGlobal 38 | -------------------------------------------------------------------------------- /AvalonEditB/Rendering/GlobalTextRunProperties.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System.Windows; 20 | using System.Windows.Media; 21 | using System.Windows.Media.TextFormatting; 22 | 23 | namespace AvalonEditB.Rendering 24 | { 25 | sealed class GlobalTextRunProperties : TextRunProperties 26 | { 27 | internal Typeface typeface; 28 | internal double fontRenderingEmSize; 29 | internal Brush foregroundBrush; 30 | internal Brush backgroundBrush; 31 | internal System.Globalization.CultureInfo cultureInfo; 32 | 33 | public override Typeface Typeface { get { return typeface; } } 34 | public override double FontRenderingEmSize { get { return fontRenderingEmSize; } } 35 | public override double FontHintingEmSize { get { return fontRenderingEmSize; } } 36 | public override TextDecorationCollection TextDecorations { get { return null; } } 37 | public override Brush ForegroundBrush { get { return foregroundBrush; } } 38 | public override Brush BackgroundBrush { get { return backgroundBrush; } } 39 | public override System.Globalization.CultureInfo CultureInfo { get { return cultureInfo; } } 40 | public override TextEffectCollection TextEffects { get { return null; } } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /AvalonEditB/Snippets/SnippetContainerElement.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using System.Collections.Generic; 21 | using System.Windows.Documents; 22 | 23 | using AvalonEditB.Utils; 24 | 25 | namespace AvalonEditB.Snippets 26 | { 27 | /// 28 | /// A snippet element that has sub-elements. 29 | /// 30 | [Serializable] 31 | public class SnippetContainerElement : SnippetElement 32 | { 33 | NullSafeCollection elements = new NullSafeCollection(); 34 | 35 | /// 36 | /// Gets the list of child elements. 37 | /// 38 | public IList Elements { 39 | get { return elements; } 40 | } 41 | 42 | /// 43 | public override void Insert(InsertionContext context) 44 | { 45 | foreach (SnippetElement e in this.Elements) { 46 | e.Insert(context); 47 | } 48 | } 49 | 50 | /// 51 | public override Inline ToTextRun() 52 | { 53 | Span span = new Span(); 54 | foreach (SnippetElement e in this.Elements) { 55 | Inline r = e.ToTextRun(); 56 | if (r != null) 57 | span.Inlines.Add(r); 58 | } 59 | return span; 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /AvalonEditB/Highlighting/IHighlightingRule.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | namespace AvalonEditB.Highlighting 20 | { 21 | /// 22 | /// Interface of a highlighting rule 23 | /// 24 | public interface IHighlightingRule 25 | { 26 | /// 27 | /// Gets the first match for the rule 28 | /// 29 | /// The string to search for a match. 30 | /// The zero-based character position in the input string that defines the leftmost 31 | /// position to be searched. 32 | /// The number of characters in the substring to include in the search. 33 | /// The line number of the string. 34 | /// An object that contains information about the match. 35 | RuleMatch GetMatch(string input, int beginning, int length, int lineNumber); 36 | 37 | /// 38 | /// Gets the highlighting color. 39 | /// 40 | HighlightingColor Color { get; } 41 | 42 | /// 43 | /// Info about rule. Used to help figure out why rule failed 44 | /// 45 | string RuleInfo { get; } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /AvalonEditB/TextEditorComponent.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using System.ComponentModel; 21 | 22 | using AvalonEditB.Document; 23 | using AvalonEditB.Editing; 24 | using AvalonEditB.Rendering; 25 | 26 | namespace AvalonEditB 27 | { 28 | /// 29 | /// Represents a text editor control (, 30 | /// or ). 31 | /// 32 | public interface ITextEditorComponent : IServiceProvider 33 | { 34 | /// 35 | /// Gets the document being edited. 36 | /// 37 | TextDocument Document { get; } 38 | 39 | /// 40 | /// Occurs when the Document property changes (when the text editor is connected to another 41 | /// document - not when the document content changes). 42 | /// 43 | event EventHandler DocumentChanged; 44 | 45 | /// 46 | /// Gets the options of the text editor. 47 | /// 48 | TextEditorOptions Options { get; } 49 | 50 | /// 51 | /// Occurs when the Options property changes, or when an option inside the current option list 52 | /// changes. 53 | /// 54 | event PropertyChangedEventHandler OptionChanged; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /AvalonEditB/Highlighting/Resources/Json.xshd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | " 19 | " 20 | 21 | 22 | ' 23 | ' 24 | 25 | 26 | : 27 | (?= [,}] ) 28 | 29 | 30 | , 31 | 32 | 33 | 34 | 35 | 36 | 37 | , 38 | 39 | 40 | 41 | 42 | 43 | true 44 | false 45 | 46 | 47 | null 48 | 49 | 50 | " 51 | " 52 | 53 | 54 | ' 55 | ' 56 | 57 | 58 | \{ 59 | \} 60 | 61 | 62 | \[ 63 | \] 64 | 65 | 66 | -? \b 67 | (?: 68 | 0[xX][0-9a-fA-F]+ 69 | | 70 | (?: 71 | 72 | [0-9]+ (?: \. [0-9]+ )? 73 | | 74 | \. [0-9]+ 75 | ) 76 | (?: [eE] [+-]? [0-9]+ )? 77 | ) 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /AvalonEditB/Snippets/SnippetSelectionElement.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using System.Text; 21 | 22 | namespace AvalonEditB.Snippets 23 | { 24 | /// 25 | /// Inserts the previously selected text at the selection marker. 26 | /// 27 | [Serializable] 28 | public class SnippetSelectionElement : SnippetElement 29 | { 30 | /// 31 | /// Gets/Sets the new indentation of the selected text. 32 | /// 33 | public int Indentation { get; set; } 34 | 35 | /// 36 | public override void Insert(InsertionContext context) 37 | { 38 | StringBuilder tabString = new StringBuilder(); 39 | 40 | for (int i = 0; i < Indentation; i++) { 41 | tabString.Append(context.Tab); 42 | } 43 | 44 | string indent = tabString.ToString(); 45 | 46 | string text = context.SelectedText.TrimStart(' ', '\t'); 47 | 48 | text = text.Replace(context.LineTerminator, 49 | context.LineTerminator + indent); 50 | 51 | context.Document.Insert(context.InsertionPosition, text); 52 | context.InsertionPosition += text.Length; 53 | 54 | if (string.IsNullOrEmpty(context.SelectedText)) 55 | SnippetCaretElement.SetCaret(context); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /ICSharpCode.AvalonEdit.Sample/MyCompletionData.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2009 Daniel Grunwald 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using ICSharpCode.AvalonEdit.CodeCompletion; 21 | using ICSharpCode.AvalonEdit.Document; 22 | using ICSharpCode.AvalonEdit.Editing; 23 | 24 | namespace ICSharpCode.AvalonEdit.Sample 25 | { 26 | /// 27 | /// Implements AvalonEdit ICompletionData interface to provide the entries in the completion drop down. 28 | /// 29 | public class MyCompletionData : ICompletionData 30 | { 31 | public MyCompletionData(string text) 32 | { 33 | this.Text = text; 34 | } 35 | 36 | public System.Windows.Media.ImageSource Image { 37 | get { return null; } 38 | } 39 | 40 | public string Text { get; private set; } 41 | 42 | // Use this property if you want to show a fancy UIElement in the drop down list. 43 | public object Content { 44 | get { return this.Text; } 45 | } 46 | 47 | public object Description { 48 | get { return "Description for " + this.Text; } 49 | } 50 | 51 | public double Priority { get { return 0; } } 52 | 53 | public void Complete(TextArea textArea, ISegment completionSegment, EventArgs insertionRequestEventArgs) 54 | { 55 | textArea.Document.Replace(completionSegment, this.Text); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /AvalonEditB/Highlighting/HighlightingRuleSet.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using System.Collections.Generic; 21 | 22 | using AvalonEditB.Utils; 23 | 24 | namespace AvalonEditB.Highlighting 25 | { 26 | /// 27 | /// A highlighting rule set describes a set of spans that are valid at a given code location. 28 | /// 29 | [Serializable] 30 | public class HighlightingRuleSet 31 | { 32 | /// 33 | /// Creates a new RuleSet instance. 34 | /// 35 | public HighlightingRuleSet() 36 | { 37 | this.Spans = new NullSafeCollection(); 38 | this.Rules = new NullSafeCollection(); 39 | } 40 | 41 | /// 42 | /// Gets/Sets the name of the rule set. 43 | /// 44 | public string Name { get; set; } 45 | 46 | /// 47 | /// Gets the list of spans. 48 | /// 49 | public IList Spans { get; private set; } 50 | 51 | /// 52 | /// Gets the list of rules. 53 | /// 54 | public IList Rules { get; private set; } 55 | 56 | /// 57 | public override string ToString() 58 | { 59 | return "[" + GetType().Name + " " + Name + "]"; 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /AvalonEditB/Editing/DottedLineMargin.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System.Windows; 20 | using System.Windows.Media; 21 | using System.Windows.Shapes; 22 | 23 | namespace AvalonEditB.Editing 24 | { 25 | /// 26 | /// Margin for use with the text area. 27 | /// A vertical dotted line to separate the line numbers from the text view. 28 | /// 29 | public static class DottedLineMargin 30 | { 31 | static readonly object tag = new object(); 32 | 33 | /// 34 | /// Creates a vertical dotted line to separate the line numbers from the text view. 35 | /// 36 | public static UIElement Create() 37 | { 38 | Line line = new Line { 39 | X1 = 0, 40 | Y1 = 0, 41 | X2 = 0, 42 | Y2 = 1, 43 | StrokeDashArray = { 0, 2 }, 44 | Stretch = Stretch.Fill, 45 | StrokeThickness = 1, 46 | StrokeDashCap = PenLineCap.Round, 47 | Margin = new Thickness(2, 0, 2, 0), 48 | Tag = tag 49 | }; 50 | 51 | return line; 52 | } 53 | 54 | /// 55 | /// Gets whether the specified UIElement is the result of a DottedLineMargin.Create call. 56 | /// 57 | public static bool IsDottedLineMargin(UIElement element) 58 | { 59 | Line l = element as Line; 60 | return l != null && l.Tag == tag; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /AvalonEditB/Editing/DragDropException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using System.Runtime.Serialization; 21 | 22 | namespace AvalonEditB.Editing 23 | { 24 | /// 25 | /// Wraps exceptions that occur during drag'n'drop. 26 | /// Exceptions during drag'n'drop might 27 | /// get swallowed by WPF/COM, so AvalonEdit catches them and re-throws them later 28 | /// wrapped in a DragDropException. 29 | /// 30 | [Serializable()] 31 | public class DragDropException : Exception 32 | { 33 | /// 34 | /// Creates a new DragDropException. 35 | /// 36 | public DragDropException() : base() 37 | { 38 | } 39 | 40 | /// 41 | /// Creates a new DragDropException. 42 | /// 43 | public DragDropException(string message) : base(message) 44 | { 45 | } 46 | 47 | /// 48 | /// Creates a new DragDropException. 49 | /// 50 | public DragDropException(string message, Exception innerException) : base(message, innerException) 51 | { 52 | } 53 | #if !NET6_0_OR_GREATER 54 | /// 55 | /// Deserializes a DragDropException. 56 | /// 57 | protected DragDropException(SerializationInfo info, StreamingContext context) : base(info, context) 58 | { 59 | } 60 | #endif 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /AvalonEditB/Rendering/VisualLineTextParagraphProperties.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System.Windows; 20 | using System.Windows.Media.TextFormatting; 21 | 22 | namespace AvalonEditB.Rendering 23 | { 24 | sealed class VisualLineTextParagraphProperties : TextParagraphProperties 25 | { 26 | internal TextRunProperties defaultTextRunProperties; 27 | internal TextWrapping textWrapping; 28 | internal double tabSize; 29 | internal double indent; 30 | internal bool firstLineInParagraph; 31 | internal FlowDirection flowDirection; 32 | public override double DefaultIncrementalTab { 33 | get { return tabSize; } 34 | } 35 | 36 | public override FlowDirection FlowDirection { get { return flowDirection; } } 37 | public override TextAlignment TextAlignment { get { return TextAlignment.Left; } } 38 | public override double LineHeight { get { return double.NaN; } } 39 | public override bool FirstLineInParagraph { get { return firstLineInParagraph; } } 40 | public override TextRunProperties DefaultTextRunProperties { get { return defaultTextRunProperties; } } 41 | public override TextWrapping TextWrapping { get { return textWrapping; } } 42 | public override TextMarkerProperties TextMarkerProperties { get { return null; } } 43 | public override double Indent { get { return indent; } } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /AvalonEditB/Highlighting/RichTextColorizer.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | 21 | using AvalonEditB.Document; 22 | using AvalonEditB.Rendering; 23 | 24 | namespace AvalonEditB.Highlighting 25 | { 26 | /// 27 | /// A colorizer that applies the highlighting from a to the editor. 28 | /// 29 | public class RichTextColorizer : DocumentColorizingTransformer 30 | { 31 | readonly RichTextModel richTextModel; 32 | 33 | /// 34 | /// Creates a new RichTextColorizer instance. 35 | /// 36 | public RichTextColorizer(RichTextModel richTextModel) 37 | { 38 | if (richTextModel == null) 39 | throw new ArgumentNullException("richTextModel"); 40 | this.richTextModel = richTextModel; 41 | } 42 | 43 | /// 44 | protected override void ColorizeLine(DocumentLine line) 45 | { 46 | var sections = richTextModel.GetHighlightedSections(line.Offset, line.Length); 47 | foreach (HighlightedSection section in sections) { 48 | if (HighlightingColorizer.IsEmptyColor(section.Color)) 49 | continue; 50 | ChangeLinePart(section.Offset, section.Offset + section.Length, 51 | visualLineElement => HighlightingColorizer.ApplyColorToElement(visualLineElement, section.Color, CurrentContext)); 52 | } 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /AvalonEditB/Rendering/HeightTreeLineNode.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System.Collections.Generic; 20 | using System.Diagnostics; 21 | 22 | namespace AvalonEditB.Rendering 23 | { 24 | struct HeightTreeLineNode 25 | { 26 | internal HeightTreeLineNode(double height) 27 | { 28 | this.collapsedSections = null; 29 | this.height = height; 30 | } 31 | 32 | internal double height; 33 | internal List collapsedSections; 34 | 35 | internal bool IsDirectlyCollapsed { 36 | get { return collapsedSections != null; } 37 | } 38 | 39 | internal void AddDirectlyCollapsed(CollapsedLineSection section) 40 | { 41 | if (collapsedSections == null) 42 | collapsedSections = new List(); 43 | collapsedSections.Add(section); 44 | } 45 | 46 | internal void RemoveDirectlyCollapsed(CollapsedLineSection section) 47 | { 48 | Debug.Assert(collapsedSections.Contains(section)); 49 | collapsedSections.Remove(section); 50 | if (collapsedSections.Count == 0) 51 | collapsedSections = null; 52 | } 53 | 54 | /// 55 | /// Returns 0 if the line is directly collapsed, otherwise, returns . 56 | /// 57 | internal double TotalHeight { 58 | get { 59 | return IsDirectlyCollapsed ? 0 : height; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /AvalonEditB/Highlighting/Xshd/XshdSyntaxDefinition.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using System.Collections.Generic; 21 | 22 | using AvalonEditB.Utils; 23 | 24 | namespace AvalonEditB.Highlighting.Xshd 25 | { 26 | /// 27 | /// A <SyntaxDefinition> element. 28 | /// 29 | [Serializable] 30 | public class XshdSyntaxDefinition 31 | { 32 | /// 33 | /// Creates a new XshdSyntaxDefinition object. 34 | /// 35 | public XshdSyntaxDefinition() 36 | { 37 | this.Elements = new NullSafeCollection(); 38 | this.Extensions = new NullSafeCollection(); 39 | } 40 | 41 | /// 42 | /// Gets/sets the definition name 43 | /// 44 | public string Name { get; set; } 45 | 46 | /// 47 | /// Gets the associated extensions. 48 | /// 49 | public IList Extensions { get; private set; } 50 | 51 | /// 52 | /// Gets the collection of elements. 53 | /// 54 | public IList Elements { get; private set; } 55 | 56 | /// 57 | /// Applies the visitor to all elements. 58 | /// 59 | public void AcceptElements(IXshdVisitor visitor) 60 | { 61 | foreach (XshdElement element in Elements) { 62 | element.AcceptVisitor(visitor); 63 | } 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /AvalonEditB/Highlighting/RuleMatch.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System.Text.RegularExpressions; 20 | 21 | namespace AvalonEditB.Highlighting 22 | { 23 | /// 24 | /// And object that contains information about a rule's match 25 | /// 26 | public class RuleMatch 27 | { 28 | /// 29 | /// Creates a new RuleMatch instance. 30 | /// 31 | public RuleMatch() { } 32 | 33 | /// 34 | /// Gets a value indicating whether the match was successful. 35 | /// 36 | public bool Success { get; set; } 37 | 38 | /// 39 | /// The position in the original string where the first character of captured substring was found. 40 | /// 41 | public int Index { get; set; } 42 | 43 | /// 44 | /// The length of the captured substring. 45 | /// 46 | public int Length { get; set; } 47 | 48 | /// 49 | /// Creates a new RuleMatch instance from a instance. 50 | /// 51 | /// Match to use 52 | /// RuleMatch instance built from match parameter 53 | public static RuleMatch FromRegexMatch(Match match) 54 | { 55 | return new RuleMatch() { 56 | Success = match.Success, 57 | Index = match.Index, 58 | Length = match.Length, 59 | }; 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /AvalonEditB/Highlighting/Xshd/XshdRuleSet.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using System.Collections.Generic; 21 | 22 | using AvalonEditB.Utils; 23 | 24 | namespace AvalonEditB.Highlighting.Xshd 25 | { 26 | /// 27 | /// A rule set in a XSHD file. 28 | /// 29 | [Serializable] 30 | public class XshdRuleSet : XshdElement 31 | { 32 | /// 33 | /// Gets/Sets the name of the rule set. 34 | /// 35 | public string Name { get; set; } 36 | 37 | /// 38 | /// Gets/sets whether the case is ignored in expressions inside this rule set. 39 | /// 40 | public bool? IgnoreCase { get; set; } 41 | 42 | readonly NullSafeCollection elements = new NullSafeCollection(); 43 | 44 | /// 45 | /// Gets the collection of elements. 46 | /// 47 | public IList Elements { 48 | get { return elements; } 49 | } 50 | 51 | /// 52 | /// Applies the visitor to all elements. 53 | /// 54 | public void AcceptElements(IXshdVisitor visitor) 55 | { 56 | foreach (XshdElement element in Elements) { 57 | element.AcceptVisitor(visitor); 58 | } 59 | } 60 | 61 | /// 62 | public override object AcceptVisitor(IXshdVisitor visitor) 63 | { 64 | return visitor.VisitRuleSet(this); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /AvalonEditB/CodeCompletion/CompletionList.xaml: -------------------------------------------------------------------------------- 1 | 4 | 34 | 35 | 56 | -------------------------------------------------------------------------------- /AvalonEditB/Rendering/VisualLinesInvalidException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using System.Runtime.Serialization; 21 | 22 | namespace AvalonEditB.Rendering 23 | { 24 | /// 25 | /// A VisualLinesInvalidException indicates that you accessed the property 26 | /// of the while the visual lines were invalid. 27 | /// 28 | [Serializable] 29 | public class VisualLinesInvalidException : Exception 30 | { 31 | /// 32 | /// Creates a new VisualLinesInvalidException instance. 33 | /// 34 | public VisualLinesInvalidException() : base() 35 | { 36 | } 37 | 38 | /// 39 | /// Creates a new VisualLinesInvalidException instance. 40 | /// 41 | public VisualLinesInvalidException(string message) : base(message) 42 | { 43 | } 44 | 45 | /// 46 | /// Creates a new VisualLinesInvalidException instance. 47 | /// 48 | public VisualLinesInvalidException(string message, Exception innerException) : base(message, innerException) 49 | { 50 | } 51 | #if !NET6_0_OR_GREATER 52 | /// 53 | /// Creates a new VisualLinesInvalidException instance. 54 | /// 55 | protected VisualLinesInvalidException(SerializationInfo info, StreamingContext context) : base(info, context) 56 | { 57 | } 58 | #endif 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /AvalonEditB/Highlighting/IHighlightingDefinition.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System.Collections.Generic; 20 | using System.ComponentModel; 21 | 22 | namespace AvalonEditB.Highlighting 23 | { 24 | /// 25 | /// A highlighting definition. 26 | /// 27 | [TypeConverter(typeof(HighlightingDefinitionTypeConverter))] 28 | public interface IHighlightingDefinition 29 | { 30 | /// 31 | /// Gets the name of the highlighting definition. 32 | /// 33 | string Name { get; } 34 | 35 | /// 36 | /// Gets the main rule set. 37 | /// 38 | HighlightingRuleSet MainRuleSet { get; } 39 | 40 | /// 41 | /// Gets a rule set by name. 42 | /// 43 | /// The rule set, or null if it is not found. 44 | HighlightingRuleSet GetNamedRuleSet(string name); 45 | 46 | /// 47 | /// Gets a named highlighting color. 48 | /// 49 | /// The highlighting color, or null if it is not found. 50 | HighlightingColor GetNamedColor(string name); 51 | 52 | /// 53 | /// Gets the list of named highlighting colors. 54 | /// 55 | IEnumerable NamedHighlightingColors { get; } 56 | 57 | /// 58 | /// Gets the list of properties. 59 | /// 60 | IDictionary Properties { get; } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /AvalonEditB/Highlighting/HighlightingDefinitionInvalidException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using System.Runtime.Serialization; 21 | 22 | namespace AvalonEditB.Highlighting 23 | { 24 | /// 25 | /// Indicates that the highlighting definition that was tried to load was invalid. 26 | /// 27 | [Serializable()] 28 | public class HighlightingDefinitionInvalidException : Exception 29 | { 30 | /// 31 | /// Creates a new HighlightingDefinitionInvalidException instance. 32 | /// 33 | public HighlightingDefinitionInvalidException() : base() 34 | { 35 | } 36 | 37 | /// 38 | /// Creates a new HighlightingDefinitionInvalidException instance. 39 | /// 40 | public HighlightingDefinitionInvalidException(string message) : base(message) 41 | { 42 | } 43 | 44 | /// 45 | /// Creates a new HighlightingDefinitionInvalidException instance. 46 | /// 47 | public HighlightingDefinitionInvalidException(string message, Exception innerException) : base(message, innerException) 48 | { 49 | } 50 | #if !NET6_0_OR_GREATER 51 | /// 52 | /// Creates a new HighlightingDefinitionInvalidException instance. 53 | /// 54 | protected HighlightingDefinitionInvalidException(SerializationInfo info, StreamingContext context) : base(info, context) 55 | { 56 | } 57 | #endif 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /ICSharpCode.AvalonEdit.Tests/Utils/IndentationStringTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using NUnit.Framework; 21 | 22 | namespace ICSharpCode.AvalonEdit.Utils 23 | { 24 | [TestFixture] 25 | public class IndentationStringTests 26 | { 27 | [Test] 28 | public void IndentWithSingleTab() 29 | { 30 | var options = new TextEditorOptions { IndentationSize = 4, ConvertTabsToSpaces = false }; 31 | Assert.That(options.IndentationString, Is.EqualTo("\t")); 32 | Assert.That(options.GetIndentationString(2), Is.EqualTo("\t")); 33 | Assert.That(options.GetIndentationString(3), Is.EqualTo("\t")); 34 | Assert.That(options.GetIndentationString(4), Is.EqualTo("\t")); 35 | Assert.That(options.GetIndentationString(5), Is.EqualTo("\t")); 36 | Assert.That(options.GetIndentationString(6), Is.EqualTo("\t")); 37 | } 38 | 39 | [Test] 40 | public void IndentWith4Spaces() 41 | { 42 | var options = new TextEditorOptions { IndentationSize = 4, ConvertTabsToSpaces = true }; 43 | Assert.That(options.IndentationString, Is.EqualTo(" ")); 44 | Assert.That(options.GetIndentationString(2), Is.EqualTo(" ")); 45 | Assert.That(options.GetIndentationString(3), Is.EqualTo(" ")); 46 | Assert.That(options.GetIndentationString(4), Is.EqualTo(" ")); 47 | Assert.That(options.GetIndentationString(5), Is.EqualTo(" ")); 48 | Assert.That(options.GetIndentationString(6), Is.EqualTo(" ")); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /ICSharpCode.AvalonEdit.Sample/ColorizeAvalonEdit.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2009 Daniel Grunwald 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using System.Windows; 21 | using System.Windows.Media; 22 | 23 | using ICSharpCode.AvalonEdit.Document; 24 | using ICSharpCode.AvalonEdit.Rendering; 25 | 26 | namespace AvalonEdit.Sample 27 | { 28 | /// 29 | /// Finds the word 'AvalonEdit' and makes it bold and italic. 30 | /// 31 | public class ColorizeAvalonEdit : DocumentColorizingTransformer 32 | { 33 | protected override void ColorizeLine(DocumentLine line) 34 | { 35 | int lineStartOffset = line.Offset; 36 | string text = CurrentContext.Document.GetText(line); 37 | int start = 0; 38 | int index; 39 | while ((index = text.IndexOf("AvalonEdit", start)) >= 0) { 40 | base.ChangeLinePart( 41 | lineStartOffset + index, // startOffset 42 | lineStartOffset + index + 10, // endOffset 43 | (VisualLineElement element) => { 44 | // This lambda gets called once for every VisualLineElement 45 | // between the specified offsets. 46 | Typeface tf = element.TextRunProperties.Typeface; 47 | // Replace the typeface with a modified version of 48 | // the same typeface 49 | element.TextRunProperties.SetTypeface(new Typeface( 50 | tf.FontFamily, 51 | FontStyles.Italic, 52 | FontWeights.Bold, 53 | tf.Stretch 54 | )); 55 | }); 56 | start = index + 1; // search for next occurrence 57 | } 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /AvalonEditB/Editing/NoReadOnlySections.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using System.Collections.Generic; 21 | using System.Linq; 22 | 23 | using AvalonEditB.Document; 24 | using AvalonEditB.Utils; 25 | 26 | namespace AvalonEditB.Editing 27 | { 28 | /// 29 | /// that has no read-only sections; all text is editable. 30 | /// 31 | sealed class NoReadOnlySections : IReadOnlySectionProvider 32 | { 33 | public static readonly NoReadOnlySections Instance = new NoReadOnlySections(); 34 | 35 | public bool CanInsert(int offset) 36 | { 37 | return true; 38 | } 39 | 40 | public IEnumerable GetDeletableSegments(ISegment segment) 41 | { 42 | if (segment == null) 43 | throw new ArgumentNullException("segment"); 44 | // the segment is always deletable 45 | return ExtensionMethods.Sequence(segment); 46 | } 47 | } 48 | 49 | /// 50 | /// that completely disables editing. 51 | /// 52 | sealed class ReadOnlySectionDocument : IReadOnlySectionProvider 53 | { 54 | public static readonly ReadOnlySectionDocument Instance = new ReadOnlySectionDocument(); 55 | 56 | public bool CanInsert(int offset) 57 | { 58 | return false; 59 | } 60 | 61 | public IEnumerable GetDeletableSegments(ISegment segment) 62 | { 63 | return Enumerable.Empty(); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /AvalonEditB/Rendering/TextViewCachedElements.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using System.Collections.Generic; 21 | using System.Windows.Media.TextFormatting; 22 | 23 | using AvalonEditB.Utils; 24 | 25 | namespace AvalonEditB.Rendering 26 | { 27 | sealed class TextViewCachedElements : IDisposable 28 | { 29 | TextFormatter formatter; 30 | Dictionary nonPrintableCharacterTexts; 31 | 32 | public TextLine GetTextForNonPrintableCharacter(string text, ITextRunConstructionContext context) 33 | { 34 | if (nonPrintableCharacterTexts == null) 35 | nonPrintableCharacterTexts = new Dictionary(); 36 | TextLine textLine; 37 | if (!nonPrintableCharacterTexts.TryGetValue(text, out textLine)) { 38 | var p = new VisualLineElementTextRunProperties(context.GlobalTextRunProperties); 39 | p.SetForegroundBrush(context.TextView.NonPrintableCharacterBrush); 40 | if (formatter == null) 41 | formatter = TextFormatterFactory.Create(context.TextView); 42 | textLine = FormattedTextElement.PrepareText(formatter, text, p); 43 | nonPrintableCharacterTexts[text] = textLine; 44 | } 45 | return textLine; 46 | } 47 | 48 | public void Dispose() 49 | { 50 | if (nonPrintableCharacterTexts != null) { 51 | foreach (TextLine line in nonPrintableCharacterTexts.Values) 52 | line.Dispose(); 53 | } 54 | if (formatter != null) 55 | formatter.Dispose(); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /AvalonEditB/Rendering/VisualYPosition.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | namespace AvalonEditB.Rendering 20 | { 21 | /// 22 | /// An enum that specifies the possible Y positions that can be returned by VisualLine.GetVisualPosition. 23 | /// 24 | public enum VisualYPosition 25 | { 26 | /// 27 | /// Returns the top of the TextLine. 28 | /// 29 | LineTop, 30 | /// 31 | /// Returns the top of the text. 32 | /// If the line contains inline UI elements larger than the text, TextTop may be below LineTop. 33 | /// For a line containing regular text (all in the editor's main font), this will be equal to LineTop. 34 | /// 35 | TextTop, 36 | /// 37 | /// Returns the bottom of the TextLine. 38 | /// 39 | LineBottom, 40 | /// 41 | /// The middle between LineTop and LineBottom. 42 | /// 43 | LineMiddle, 44 | /// 45 | /// Returns the bottom of the text. 46 | /// If the line contains inline UI elements larger than the text, TextBottom might be above LineBottom. 47 | /// For a line containing regular text (all in the editor's main font), this will be equal to LineBottom. 48 | /// 49 | TextBottom, 50 | /// 51 | /// The middle between TextTop and TextBottom. 52 | /// 53 | TextMiddle, 54 | /// 55 | /// Returns the baseline of the text. 56 | /// 57 | Baseline 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /AvalonEditB/Snippets/SnippetEventArgs.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | 21 | namespace AvalonEditB.Snippets 22 | { 23 | /// 24 | /// Provides information about the event that occurred during use of snippets. 25 | /// 26 | public class SnippetEventArgs : EventArgs 27 | { 28 | /// 29 | /// Gets the reason for deactivation. 30 | /// 31 | public DeactivateReason Reason { get; private set; } 32 | 33 | /// 34 | /// Creates a new SnippetEventArgs object, with a DeactivateReason. 35 | /// 36 | public SnippetEventArgs(DeactivateReason reason) 37 | { 38 | this.Reason = reason; 39 | } 40 | } 41 | 42 | /// 43 | /// Describes the reason for deactivation of a . 44 | /// 45 | public enum DeactivateReason 46 | { 47 | /// 48 | /// Unknown reason. 49 | /// 50 | Unknown, 51 | /// 52 | /// Snippet was deleted. 53 | /// 54 | Deleted, 55 | /// 56 | /// There are no active elements in the snippet. 57 | /// 58 | NoActiveElements, 59 | /// 60 | /// The SnippetInputHandler was detached. 61 | /// 62 | InputHandlerDetached, 63 | /// 64 | /// Return was pressed by the user. 65 | /// 66 | ReturnPressed, 67 | /// 68 | /// Escape was pressed by the user. 69 | /// 70 | EscapePressed 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /AvalonEditB/Snippets/Snippet.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | 21 | using AvalonEditB.Document; 22 | using AvalonEditB.Editing; 23 | 24 | namespace AvalonEditB.Snippets 25 | { 26 | /// 27 | /// A code snippet that can be inserted into the text editor. 28 | /// 29 | [Serializable] 30 | public class Snippet : SnippetContainerElement 31 | { 32 | /// 33 | /// Inserts the snippet into the text area. 34 | /// 35 | public void Insert(TextArea textArea) 36 | { 37 | if (textArea == null) 38 | throw new ArgumentNullException("textArea"); 39 | 40 | ISegment selection = textArea.Selection.SurroundingSegment; 41 | int insertionPosition = textArea.Caret.Offset; 42 | 43 | if (selection != null) // if something is selected 44 | // use selection start instead of caret position, 45 | // because caret could be at end of selection or anywhere inside. 46 | // Removal of the selected text causes the caret position to be invalid. 47 | insertionPosition = selection.Offset + TextUtilities.GetWhitespaceAfter(textArea.Document, selection.Offset).Length; 48 | 49 | InsertionContext context = new InsertionContext(textArea, insertionPosition); 50 | 51 | using (context.Document.RunUpdate()) { 52 | if (selection != null) 53 | textArea.Document.Remove(insertionPosition, selection.EndOffset - insertionPosition); 54 | Insert(context); 55 | context.RaiseInsertionCompleted(EventArgs.Empty); 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /AvalonEditB/Highlighting/Resources/XML-Mode.xshd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | <!-- 15 | --> 16 | 17 | 18 | <!\[CDATA\[ 19 | ]]> 20 | 21 | 22 | <!DOCTYPE 23 | > 24 | 25 | 26 | <\? 27 | \?> 28 | 29 | 30 | < 31 | > 32 | 33 | 35 | 36 | " 37 | "|(?=<) 38 | 39 | 40 | ' 41 | '|(?=<) 42 | 43 | [\d\w_\-\.]+(?=(\s*=)) 44 | = 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | & 53 | [\w\d\#]+ 54 | ; 55 | 56 | 57 | 58 | & 59 | [\w\d\#]* 60 | #missing ; 61 | 62 | 63 | -------------------------------------------------------------------------------- /AvalonEditB/CodeCompletion/OverloadInsightWindow.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System.Windows; 20 | using System.Windows.Input; 21 | 22 | using AvalonEditB.Editing; 23 | 24 | namespace AvalonEditB.CodeCompletion 25 | { 26 | /// 27 | /// Insight window that shows an OverloadViewer. 28 | /// 29 | public class OverloadInsightWindow : InsightWindow 30 | { 31 | OverloadViewer overloadViewer = new OverloadViewer(); 32 | 33 | /// 34 | /// Creates a new OverloadInsightWindow. 35 | /// 36 | public OverloadInsightWindow(TextArea textArea) : base(textArea) 37 | { 38 | overloadViewer.Margin = new Thickness(2, 0, 0, 0); 39 | this.Content = overloadViewer; 40 | } 41 | 42 | /// 43 | /// Gets/Sets the item provider. 44 | /// 45 | public IOverloadProvider Provider { 46 | get { return overloadViewer.Provider; } 47 | set { overloadViewer.Provider = value; } 48 | } 49 | 50 | /// 51 | protected override void OnKeyDown(KeyEventArgs e) 52 | { 53 | base.OnKeyDown(e); 54 | if (!e.Handled && this.Provider != null && this.Provider.Count > 1) { 55 | switch (e.Key) { 56 | case Key.Up: 57 | e.Handled = true; 58 | overloadViewer.ChangeIndex(-1); 59 | break; 60 | case Key.Down: 61 | e.Handled = true; 62 | overloadViewer.ChangeIndex(+1); 63 | break; 64 | } 65 | if (e.Handled) { 66 | UpdateLayout(); 67 | UpdatePosition(); 68 | } 69 | } 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /AvalonEditB/Document/UndoOperationGroup.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using System.Diagnostics; 21 | 22 | using AvalonEditB.Utils; 23 | 24 | namespace AvalonEditB.Document 25 | { 26 | /// 27 | /// This class stacks the last x operations from the undostack and makes 28 | /// one undo/redo operation from it. 29 | /// 30 | sealed class UndoOperationGroup : IUndoableOperationWithContext 31 | { 32 | IUndoableOperation[] undolist; 33 | 34 | public UndoOperationGroup(Deque stack, int numops) 35 | { 36 | if (stack == null) { 37 | throw new ArgumentNullException("stack"); 38 | } 39 | 40 | Debug.Assert(numops > 0, "UndoOperationGroup : numops should be > 0"); 41 | Debug.Assert(numops <= stack.Count); 42 | 43 | undolist = new IUndoableOperation[numops]; 44 | for (int i = 0; i < numops; ++i) { 45 | undolist[i] = stack.PopBack(); 46 | } 47 | } 48 | 49 | public void Undo() 50 | { 51 | for (int i = 0; i < undolist.Length; ++i) { 52 | undolist[i].Undo(); 53 | } 54 | } 55 | 56 | public void Undo(UndoStack stack) 57 | { 58 | for (int i = 0; i < undolist.Length; ++i) { 59 | stack.RunUndo(undolist[i]); 60 | } 61 | } 62 | 63 | public void Redo() 64 | { 65 | for (int i = undolist.Length - 1; i >= 0; --i) { 66 | undolist[i].Redo(); 67 | } 68 | } 69 | 70 | public void Redo(UndoStack stack) 71 | { 72 | for (int i = undolist.Length - 1; i >= 0; --i) { 73 | stack.RunRedo(undolist[i]); 74 | } 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /AvalonEditB/Document/DocumentChangeOperation.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System.Diagnostics; 20 | 21 | namespace AvalonEditB.Document 22 | { 23 | /// 24 | /// Describes a change to a TextDocument. 25 | /// 26 | sealed class DocumentChangeOperation : IUndoableOperationWithContext 27 | { 28 | TextDocument document; 29 | DocumentChangeEventArgs change; 30 | 31 | public DocumentChangeOperation(TextDocument document, DocumentChangeEventArgs change) 32 | { 33 | this.document = document; 34 | this.change = change; 35 | } 36 | 37 | public void Undo(UndoStack stack) 38 | { 39 | Debug.Assert(stack.state == UndoStack.StatePlayback); 40 | stack.RegisterAffectedDocument(document); 41 | stack.state = UndoStack.StatePlaybackModifyDocument; 42 | this.Undo(); 43 | stack.state = UndoStack.StatePlayback; 44 | } 45 | 46 | public void Redo(UndoStack stack) 47 | { 48 | Debug.Assert(stack.state == UndoStack.StatePlayback); 49 | stack.RegisterAffectedDocument(document); 50 | stack.state = UndoStack.StatePlaybackModifyDocument; 51 | this.Redo(); 52 | stack.state = UndoStack.StatePlayback; 53 | } 54 | 55 | public void Undo() 56 | { 57 | OffsetChangeMap map = change.OffsetChangeMapOrNull; 58 | document.Replace(change.Offset, change.InsertionLength, change.RemovedText, map != null ? map.Invert() : null); 59 | } 60 | 61 | public void Redo() 62 | { 63 | document.Replace(change.Offset, change.RemovalLength, change.InsertedText, change.OffsetChangeMapOrNull); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /AvalonEditB/Rendering/ITextRunConstructionContext.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System.Windows.Media.TextFormatting; 20 | 21 | using AvalonEditB.Document; 22 | using AvalonEditB.Utils; 23 | 24 | namespace AvalonEditB.Rendering 25 | { 26 | /// 27 | /// Contains information relevant for text run creation. 28 | /// 29 | public interface ITextRunConstructionContext 30 | { 31 | /// 32 | /// Gets the text document. 33 | /// 34 | TextDocument Document { get; } 35 | 36 | /// 37 | /// Gets the text view for which the construction runs. 38 | /// 39 | TextView TextView { get; } 40 | 41 | /// 42 | /// Gets the visual line that is currently being constructed. 43 | /// 44 | VisualLine VisualLine { get; } 45 | 46 | /// 47 | /// Gets the global text run properties. 48 | /// 49 | TextRunProperties GlobalTextRunProperties { get; } 50 | 51 | /// 52 | /// Gets a piece of text from the document. 53 | /// 54 | /// 55 | /// This method is allowed to return a larger string than requested. 56 | /// It does this by returning a that describes the requested segment within the returned string. 57 | /// This method should be the preferred text access method in the text transformation pipeline, as it can avoid repeatedly allocating string instances 58 | /// for text within the same line. 59 | /// 60 | StringSegment GetText(int offset, int length); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /AvalonEditB/Indentation/DefaultIndentationStrategy.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | 21 | using AvalonEditB.Document; 22 | 23 | namespace AvalonEditB.Indentation 24 | { 25 | /// 26 | /// Handles indentation by copying the indentation from the previous line. 27 | /// Does not support indenting multiple lines. 28 | /// 29 | public class DefaultIndentationStrategy : IIndentationStrategy 30 | { 31 | /// 32 | public virtual void IndentLine(TextDocument document, DocumentLine line) 33 | { 34 | if (document == null) 35 | throw new ArgumentNullException("document"); 36 | if (line == null) 37 | throw new ArgumentNullException("line"); 38 | DocumentLine previousLine = line.PreviousLine; 39 | if (previousLine != null) { 40 | ISegment indentationSegment = TextUtilities.GetWhitespaceAfter(document, previousLine.Offset); 41 | string indentation = document.GetText(indentationSegment); 42 | // copy indentation to line 43 | indentationSegment = TextUtilities.GetWhitespaceAfter(document, line.Offset); 44 | document.Replace(indentationSegment.Offset, indentationSegment.Length, indentation, 45 | OffsetChangeMappingType.RemoveAndInsert); 46 | // OffsetChangeMappingType.RemoveAndInsert guarantees the caret moves behind the new indentation. 47 | } 48 | } 49 | 50 | /// 51 | /// Does nothing: indenting multiple lines is useless without a smart indentation strategy. 52 | /// 53 | public virtual void IndentLines(TextDocument document, int beginLine, int endLine) 54 | { 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /ICSharpCode.AvalonEdit.Tests/Highlighting/HtmlClipboardTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using System.Windows; 21 | using ICSharpCode.AvalonEdit.Document; 22 | using NUnit.Framework; 23 | 24 | namespace ICSharpCode.AvalonEdit.Highlighting 25 | { 26 | [TestFixture] 27 | public class HtmlClipboardTests 28 | { 29 | TextDocument document; 30 | DocumentHighlighter highlighter; 31 | 32 | public HtmlClipboardTests() 33 | { 34 | document = new TextDocument("using System.Text;\n\tstring text = SomeMethod();"); 35 | highlighter = new DocumentHighlighter(document, HighlightingManager.Instance.GetDefinition("C#")); 36 | } 37 | 38 | [Test] 39 | public void FullDocumentTest() 40 | { 41 | var segment = new TextSegment { StartOffset = 0, Length = document.TextLength }; 42 | string html = HtmlClipboard.CreateHtmlFragment(document, highlighter, segment, new HtmlOptions()); 43 | Assert.That(html, Is.EqualTo("using System.Text;
" + Environment.NewLine + 44 | "    string " + 45 | "text = SomeMethod();")); 46 | } 47 | 48 | [Test] 49 | public void PartOfHighlightedWordTest() 50 | { 51 | var segment = new TextSegment { StartOffset = 1, Length = 3 }; 52 | string html = HtmlClipboard.CreateHtmlFragment(document, highlighter, segment, new HtmlOptions()); 53 | Assert.That(html, Is.EqualTo("sin")); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /ICSharpCode.AvalonEdit.Tests/Highlighting/RichTextTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System.Windows; 20 | using System.Windows.Media; 21 | 22 | using NUnit.Framework; 23 | 24 | namespace ICSharpCode.AvalonEdit.Highlighting 25 | { 26 | [TestFixture] 27 | public class RichTextTests 28 | { 29 | [Test] 30 | public void ConcatTest() 31 | { 32 | var textModel = new RichTextModel(); 33 | textModel.SetHighlighting(0, 5, new HighlightingColor { Name = "text1" }); 34 | var text1 = new RichText("text1", textModel); 35 | 36 | var textModel2 = new RichTextModel(); 37 | textModel2.SetHighlighting(0, 5, new HighlightingColor { Name = "text2" }); 38 | var text2 = new RichText("text2", textModel2); 39 | 40 | RichText text3 = RichText.Concat(text1, RichText.Empty, text2); 41 | Assert.That(text3.GetHighlightingAt(0), Is.EqualTo(text1.GetHighlightingAt(0))); 42 | Assert.That(text3.GetHighlightingAt(5), Is.Not.EqualTo(text1.GetHighlightingAt(0))); 43 | Assert.That(text3.GetHighlightingAt(5), Is.EqualTo(text2.GetHighlightingAt(0))); 44 | } 45 | 46 | [Test] 47 | public void ToHtmlTest() 48 | { 49 | var textModel = new RichTextModel(); 50 | textModel.SetBackground(5, 3, new SimpleHighlightingBrush(Colors.Yellow)); 51 | textModel.SetForeground(9, 6, new SimpleHighlightingBrush(Colors.Blue)); 52 | textModel.SetFontWeight(15, 1, FontWeights.Bold); 53 | var text = new RichText("This has spaces!", textModel); 54 | var html = text.ToHtml(new HtmlOptions()); 55 | Assert.That(html, Is.EqualTo("This has spaces!")); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /AvalonEditB.Docs/READMEnuget.md: -------------------------------------------------------------------------------- 1 | # AvalonEditB 2 | 3 | ![logo](https://raw.githubusercontent.com/goswinr/AvalonEditB/main/AvalonEditB.Docs/logo400.png) 4 | 5 | AvalonEditB is a fork of a [AvalonEdit](https://github.com/icsharpcode/AvalonEdit) 6 | with some small modifications like: 7 | * **Search-and-Replace** functionality taken and adapted from [PR 99](https://github.com/icsharpcode/AvalonEdit/pull/99). 8 | * **Block Selection** with middle mouse button (like in VS code). 9 | * Some private properties exposed as public. 10 | * Support for cursive fonts via xshd syntax highlighting. 11 | * Less redrawing of folding sections for better performance (controlled via FoldingManger.AutoRedrawFoldingSections). 12 | * Bugfixes in key handling when completion list is not showing. 13 | * styling of current line and its number. 14 | 15 | ### Documentation 16 | Check out the original [original documentation](http://avalonedit.net/documentation/) and the [samples and articles wiki page](https://github.com/icsharpcode/AvalonEdit/wiki/Samples-and-Articles). 17 | 18 | ### License 19 | AvalonEditB is also distributed under the [MIT License](https://github.com/goswinr/AvalonEditB/blob/main/LICENSE.txt). 20 | 21 | ### Changelog 22 | 23 | `2.4.0` 24 | - add CollapsedLinesAreInconsitent to TextView to check Folding bugs 25 | 26 | `2.3.0` 27 | - use IHighlightingRule to allow non regex highlighters 28 | - Fix rounding error when getting VisualLine 29 | - merge changes from AvalonEdit 30 | - TargetFrameworks: net472, net6.0-windows 31 | 32 | `2.2.0` 33 | - fix key handling when completion list box is invisible. 34 | - FoldingManger.AutoRedrawFoldingSections = true ( by default) 35 | - Disable email links 36 | 37 | `2.1.0` 38 | - improve current line highlighting 39 | - improve line number margin 40 | - improve search panel 41 | 42 | `2.0.0` 43 | - add FoldingManger.AutoRedrawFoldingSections = false; to not redraw full section 44 | 45 | `1.8.0` 46 | - Enable code folding in more than one TextViews. 47 | - Don't build visual lines from collapsed lines 48 | 49 | `1.7.1` 50 | - bring in changes from Avalonedit 6.3.0 51 | - support all FontWeights and stylistic set 1 in xshd syntax highlighting 52 | 53 | `1.6.0` 54 | - show count in search 55 | - fix typos 56 | 57 | `1.5.1` 58 | - net7.0 59 | - bring in changes from Avalonedit repro up till Dec 2022 60 | - fix typos 61 | 62 | `1.4.1` 63 | - bring in changes from Avalonedit repro up till July 2022 64 | 65 | `1.4.0` 66 | - bring in changes from Avalonedit 6.1.3 67 | 68 | `1.3.0` 69 | - target net6.0 and net472 70 | 71 | `1.2.0` 72 | - Revert to original sorting in completion list. 73 | - Improve Error messages of TextSegment. 74 | - All relevant commits up to release 6.1.2 of [AvalonEdit](https://github.com/icsharpcode/AvalonEdit) are included. 75 | 76 | `1.0.0` 77 | - All relevant commits up to release 6.1.1 of [AvalonEdit](https://github.com/icsharpcode/AvalonEdit) are included. -------------------------------------------------------------------------------- /AvalonEditB/TextEditorWeakEventManager.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using AvalonEditB.Utils; 20 | 21 | namespace AvalonEditB 22 | { 23 | /// 24 | /// Contains weak event managers for . 25 | /// 26 | public static class TextEditorWeakEventManager 27 | { 28 | /// 29 | /// Weak event manager for the event. 30 | /// 31 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")] 32 | public sealed class DocumentChanged : WeakEventManagerBase 33 | { 34 | /// 35 | protected override void StartListening(ITextEditorComponent source) 36 | { 37 | source.DocumentChanged += DeliverEvent; 38 | } 39 | 40 | /// 41 | protected override void StopListening(ITextEditorComponent source) 42 | { 43 | source.DocumentChanged -= DeliverEvent; 44 | } 45 | } 46 | 47 | /// 48 | /// Weak event manager for the event. 49 | /// 50 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")] 51 | public sealed class OptionChanged : WeakEventManagerBase 52 | { 53 | /// 54 | protected override void StartListening(ITextEditorComponent source) 55 | { 56 | source.OptionChanged += DeliverEvent; 57 | } 58 | 59 | /// 60 | protected override void StopListening(ITextEditorComponent source) 61 | { 62 | source.OptionChanged -= DeliverEvent; 63 | } 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /AvalonEditB/Highlighting/Resources/MarkDownWithFontSize-Mode.xshd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | ^[#]{1}[ ]{1}.* 20 | 21 | 22 | ^[#]{2}[ ]{1}.* 23 | 24 | 25 | ^[#]{3}[ ]{1}.* 26 | 27 | 28 | ^[#]{4}[ ]{1}.* 29 | 30 | 31 | ^[#]{5}[ ]{1}.* 32 | 33 | 34 | ^[#]{6}[ ]{1}.* 35 | 36 | 37 | \*\*.*\*\* 38 | 39 | 40 | __.*__ 41 | 42 | 43 | \*(?![ ]).*\* 44 | 45 | 46 | _.*_ 47 | 48 | 49 | `.*` 50 | 51 | 52 | ^\t 53 | ^(?!\t) 54 | 55 | 56 | ^[ ]{4} 57 | ^(?![ ]{4}) 58 | 59 | 60 | ^> 61 | ^(?!>) 62 | 63 | 64 | \!\[.*\]\[.*\] 65 | 66 | 67 | \[.*\]\(.*\) 68 | 69 | 70 | \[.*\]\[.*\] 71 | 72 | 73 | [ ]{2}$ 74 | 75 | 76 | -------------------------------------------------------------------------------- /AvalonEditB/Folding/NewFolding.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | 21 | using AvalonEditB.Document; 22 | 23 | namespace AvalonEditB.Folding 24 | { 25 | /// 26 | /// Helper class used for . 27 | /// 28 | public class NewFolding : ISegment 29 | { 30 | /// 31 | /// Gets/Sets the start offset. 32 | /// 33 | public int StartOffset { get; set; } 34 | 35 | /// 36 | /// Gets/Sets the end offset. 37 | /// 38 | public int EndOffset { get; set; } 39 | 40 | /// 41 | /// Gets/Sets the name displayed for the folding. 42 | /// 43 | public string Name { get; set; } 44 | 45 | /// 46 | /// Gets/Sets whether the folding is closed by default. 47 | /// 48 | public bool DefaultClosed { get; set; } 49 | 50 | /// 51 | /// Gets/Sets whether the folding is considered to be a definition. 52 | /// This has an effect on the 'Show Definitions only' command. 53 | /// 54 | public bool IsDefinition { get; set; } 55 | 56 | /// 57 | /// Creates a new NewFolding instance. 58 | /// 59 | public NewFolding() 60 | { 61 | } 62 | 63 | /// 64 | /// Creates a new NewFolding instance. 65 | /// 66 | public NewFolding(int start, int end) 67 | { 68 | if (!(start <= end)) 69 | throw new ArgumentException("'start' must be less than 'end'"); 70 | this.StartOffset = start; 71 | this.EndOffset = end; 72 | this.Name = null; 73 | this.DefaultClosed = false; 74 | } 75 | 76 | int ISegment.Offset { 77 | get { return this.StartOffset; } 78 | } 79 | 80 | int ISegment.Length { 81 | get { return this.EndOffset - this.StartOffset; } 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /AvalonEditB/Highlighting/HtmlOptions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using System.IO; 21 | using System.Net; 22 | 23 | namespace AvalonEditB.Highlighting 24 | { 25 | /// 26 | /// Holds options for converting text to HTML. 27 | /// 28 | public class HtmlOptions 29 | { 30 | /// 31 | /// Creates a default HtmlOptions instance. 32 | /// 33 | public HtmlOptions() 34 | { 35 | this.TabSize = 4; 36 | } 37 | 38 | /// 39 | /// Creates a new HtmlOptions instance that copies applicable options from the . 40 | /// 41 | public HtmlOptions(TextEditorOptions options) : this() 42 | { 43 | if (options == null) 44 | throw new ArgumentNullException("options"); 45 | this.TabSize = options.IndentationSize; 46 | } 47 | 48 | /// 49 | /// The amount of spaces a tab gets converted to. 50 | /// 51 | public int TabSize { get; set; } 52 | 53 | /// 54 | /// Writes the HTML attribute for the style to the text writer. 55 | /// 56 | public virtual void WriteStyleAttributeForColor(TextWriter writer, HighlightingColor color) 57 | { 58 | if (writer == null) 59 | throw new ArgumentNullException("writer"); 60 | if (color == null) 61 | throw new ArgumentNullException("color"); 62 | writer.Write(" style=\""); 63 | WebUtility.HtmlEncode(color.ToCss(), writer); 64 | writer.Write('"'); 65 | } 66 | 67 | /// 68 | /// Gets whether the color needs to be written out to HTML. 69 | /// 70 | public virtual bool ColorNeedsSpanForStyling(HighlightingColor color) 71 | { 72 | if (color == null) 73 | throw new ArgumentNullException("color"); 74 | return !string.IsNullOrEmpty(color.ToCss()); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /AvalonEditB/Snippets/SnippetCaretElement.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using System.Runtime.Serialization; 21 | 22 | using AvalonEditB.Document; 23 | 24 | namespace AvalonEditB.Snippets 25 | { 26 | /// 27 | /// Sets the caret position after interactive mode has finished. 28 | /// 29 | [Serializable] 30 | public class SnippetCaretElement : SnippetElement 31 | { 32 | [OptionalField] 33 | bool setCaretOnlyIfTextIsSelected; 34 | 35 | /// 36 | /// Creates a new SnippetCaretElement. 37 | /// 38 | public SnippetCaretElement() 39 | { 40 | } 41 | 42 | /// 43 | /// Creates a new SnippetCaretElement. 44 | /// 45 | /// 46 | /// If set to true, the caret is set only when some text was selected. 47 | /// This is useful when both SnippetCaretElement and SnippetSelectionElement are used in the same snippet. 48 | /// 49 | public SnippetCaretElement(bool setCaretOnlyIfTextIsSelected) 50 | { 51 | this.setCaretOnlyIfTextIsSelected = setCaretOnlyIfTextIsSelected; 52 | } 53 | 54 | /// 55 | public override void Insert(InsertionContext context) 56 | { 57 | if (!setCaretOnlyIfTextIsSelected || !string.IsNullOrEmpty(context.SelectedText)) 58 | SetCaret(context); 59 | } 60 | 61 | internal static void SetCaret(InsertionContext context) 62 | { 63 | TextAnchor pos = context.Document.CreateAnchor(context.InsertionPosition); 64 | pos.MovementType = AnchorMovementType.BeforeInsertion; 65 | pos.SurviveDeletion = true; 66 | context.Deactivated += (sender, e) => { 67 | if (e.Reason == DeactivateReason.ReturnPressed || e.Reason == DeactivateReason.NoActiveElements) { 68 | context.TextArea.Caret.Offset = pos.Offset; 69 | } 70 | }; 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /AvalonEditB/Rendering/ColumnRulerRenderer.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | // software and associated documentation files (the "Software"), to deal in the Software 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 7 | // to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or 10 | // substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 17 | // DEALINGS IN THE SOFTWARE. 18 | 19 | using System; 20 | using System.Windows; 21 | using System.Windows.Media; 22 | 23 | using AvalonEditB.Utils; 24 | 25 | namespace AvalonEditB.Rendering 26 | { 27 | /// 28 | /// Renders a ruler at a certain column. 29 | /// 30 | sealed class ColumnRulerRenderer : IBackgroundRenderer 31 | { 32 | Pen pen; 33 | int column; 34 | TextView textView; 35 | 36 | public static readonly Color DefaultForeground = Colors.LightGray; 37 | 38 | public ColumnRulerRenderer(TextView textView) 39 | { 40 | if (textView == null) 41 | throw new ArgumentNullException("textView"); 42 | 43 | this.pen = new Pen(new SolidColorBrush(DefaultForeground), 1); 44 | this.pen.Freeze(); 45 | this.textView = textView; 46 | this.textView.BackgroundRenderers.Add(this); 47 | } 48 | 49 | public KnownLayer Layer { 50 | get { return KnownLayer.Background; } 51 | } 52 | 53 | public void SetRuler(int column, Pen pen) 54 | { 55 | if (this.column != column) { 56 | this.column = column; 57 | textView.InvalidateLayer(this.Layer); 58 | } 59 | if (this.pen != pen) { 60 | this.pen = pen; 61 | textView.InvalidateLayer(this.Layer); 62 | } 63 | } 64 | 65 | public void Draw(TextView textView, System.Windows.Media.DrawingContext drawingContext) 66 | { 67 | if (column < 1) return; 68 | double offset = textView.WideSpaceWidth * column; 69 | Size pixelSize = PixelSnapHelpers.GetPixelSize(textView); 70 | double markerXPos = PixelSnapHelpers.PixelAlign(offset, pixelSize.Width); 71 | markerXPos -= textView.ScrollOffset.X; 72 | Point start = new Point(markerXPos, 0); 73 | Point end = new Point(markerXPos, Math.Max(textView.DocumentHeight, textView.ActualHeight)); 74 | 75 | drawingContext.DrawLine(pen, start, end); 76 | } 77 | } 78 | } 79 | --------------------------------------------------------------------------------