Search is not available for this dataset
id
stringlengths 1
8
| text
stringlengths 72
9.81M
| addition_count
int64 0
10k
| commit_subject
stringlengths 0
3.7k
| deletion_count
int64 0
8.43k
| file_extension
stringlengths 0
32
| lang
stringlengths 1
94
| license
stringclasses 10
values | repo_name
stringlengths 9
59
|
---|---|---|---|---|---|---|---|---|
10066850 | <NME> EditingCommandHandler.cs
<BEF> // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Avalonia;
using AvaloniaEdit.Document;
using Avalonia.Input;
using AvaloniaEdit.Utils;
using System.Threading.Tasks;
namespace AvaloniaEdit.Editing
{
/// <summary>
/// We re-use the CommandBinding and InputBinding instances between multiple text areas,
/// so this class is static.
/// </summary>
internal class EditingCommandHandler
{
/// <summary>
/// Creates a new <see cref="TextAreaInputHandler"/> for the text area.
/// </summary>
public static TextAreaInputHandler Create(TextArea textArea)
{
var handler = new TextAreaInputHandler(textArea);
handler.CommandBindings.AddRange(CommandBindings);
handler.KeyBindings.AddRange(KeyBindings);
return handler;
}
private static readonly List<RoutedCommandBinding> CommandBindings = new List<RoutedCommandBinding>();
private static readonly List<KeyBinding> KeyBindings = new List<KeyBinding>();
private static void AddBinding(RoutedCommand command, KeyModifiers modifiers, Key key,
EventHandler<ExecutedRoutedEventArgs> handler)
{
CommandBindings.Add(new RoutedCommandBinding(command, handler));
KeyBindings.Add(TextAreaDefaultInputHandler.CreateKeyBinding(command, modifiers, key));
}
private static void AddBinding(RoutedCommand command, EventHandler<ExecutedRoutedEventArgs> handler, EventHandler<CanExecuteRoutedEventArgs> canExecuteHandler = null)
{
CommandBindings.Add(new RoutedCommandBinding(command, handler, canExecuteHandler));
}
static EditingCommandHandler()
{
AddBinding(EditingCommands.Delete, KeyModifiers.None, Key.Delete, OnDelete(CaretMovementType.CharRight));
AddBinding(EditingCommands.DeleteNextWord, KeyModifiers.Control, Key.Delete,
OnDelete(CaretMovementType.WordRight));
AddBinding(EditingCommands.Backspace, KeyModifiers.None, Key.Back, OnDelete(CaretMovementType.Backspace));
KeyBindings.Add(
TextAreaDefaultInputHandler.CreateKeyBinding(EditingCommands.Backspace, KeyModifiers.Shift,
Key.Back)); // make Shift-Backspace do the same as plain backspace
AddBinding(EditingCommands.DeletePreviousWord, KeyModifiers.Control, Key.Back,
OnDelete(CaretMovementType.WordLeft));
AddBinding(EditingCommands.EnterParagraphBreak, KeyModifiers.None, Key.Enter, OnEnter);
AddBinding(EditingCommands.EnterLineBreak, KeyModifiers.Shift, Key.Enter, OnEnter);
AddBinding(EditingCommands.TabForward, KeyModifiers.None, Key.Tab, OnTab);
AddBinding(EditingCommands.TabBackward, KeyModifiers.Shift, Key.Tab, OnShiftTab);
AddBinding(ApplicationCommands.Delete, OnDelete(CaretMovementType.None), CanDelete);
AddBinding(ApplicationCommands.Copy, OnCopy, CanCopy);
AddBinding(ApplicationCommands.Cut, OnCut, CanCut);
AddBinding(ApplicationCommands.Paste, OnPaste, CanPaste);
AddBinding(AvaloniaEditCommands.ToggleOverstrike, OnToggleOverstrike);
AddBinding(AvaloniaEditCommands.DeleteLine, OnDeleteLine);
AddBinding(AvaloniaEditCommands.RemoveLeadingWhitespace, OnRemoveLeadingWhitespace);
AddBinding(AvaloniaEditCommands.RemoveTrailingWhitespace, OnRemoveTrailingWhitespace);
AddBinding(AvaloniaEditCommands.ConvertToUppercase, OnConvertToUpperCase);
AddBinding(AvaloniaEditCommands.ConvertToLowercase, OnConvertToLowerCase);
AddBinding(AvaloniaEditCommands.ConvertToTitleCase, OnConvertToTitleCase);
AddBinding(AvaloniaEditCommands.InvertCase, OnInvertCase);
AddBinding(AvaloniaEditCommands.ConvertTabsToSpaces, OnConvertTabsToSpaces);
AddBinding(AvaloniaEditCommands.ConvertSpacesToTabs, OnConvertSpacesToTabs);
AddBinding(AvaloniaEditCommands.ConvertLeadingTabsToSpaces, OnConvertLeadingTabsToSpaces);
AddBinding(AvaloniaEditCommands.ConvertLeadingSpacesToTabs, OnConvertLeadingSpacesToTabs);
AddBinding(AvaloniaEditCommands.IndentSelection, OnIndentSelection);
}
private static TextArea GetTextArea(object target)
{
return target as TextArea;
}
#region Text Transformation Helpers
private enum DefaultSegmentType
{
WholeDocument,
CurrentLine
}
/// <summary>
/// Calls transformLine on all lines in the selected range.
/// transformLine needs to handle read-only segments!
/// </summary>
private static void TransformSelectedLines(Action<TextArea, DocumentLine> transformLine, object target,
ExecutedRoutedEventArgs args, DefaultSegmentType defaultSegmentType)
{
var textArea = GetTextArea(target);
if (textArea?.Document != null)
{
using (textArea.Document.RunUpdate())
{
DocumentLine start, end;
if (textArea.Selection.IsEmpty)
{
if (defaultSegmentType == DefaultSegmentType.CurrentLine)
{
start = end = textArea.Document.GetLineByNumber(textArea.Caret.Line);
}
else if (defaultSegmentType == DefaultSegmentType.WholeDocument)
{
start = textArea.Document.Lines.First();
end = textArea.Document.Lines.Last();
}
else
{
start = end = null;
}
}
else
{
var segment = textArea.Selection.SurroundingSegment;
start = textArea.Document.GetLineByOffset(segment.Offset);
end = textArea.Document.GetLineByOffset(segment.EndOffset);
// don't include the last line if no characters on it are selected
if (start != end && end.Offset == segment.EndOffset)
end = end.PreviousLine;
}
if (start != null)
{
transformLine(textArea, start);
while (start != end)
{
start = start.NextLine;
transformLine(textArea, start);
}
}
}
textArea.Caret.BringCaretToView();
args.Handled = true;
}
}
/// <summary>
/// Calls transformLine on all writable segment in the selected range.
/// </summary>
private static void TransformSelectedSegments(Action<TextArea, ISegment> transformSegment, object target,
ExecutedRoutedEventArgs args, DefaultSegmentType defaultSegmentType)
{
var textArea = GetTextArea(target);
if (textArea?.Document != null)
{
using (textArea.Document.RunUpdate())
{
IEnumerable<ISegment> segments;
if (textArea.Selection.IsEmpty)
{
if (defaultSegmentType == DefaultSegmentType.CurrentLine)
{
segments = new ISegment[] { textArea.Document.GetLineByNumber(textArea.Caret.Line) };
}
else if (defaultSegmentType == DefaultSegmentType.WholeDocument)
{
segments = textArea.Document.Lines;
}
else
{
segments = null;
}
}
else
{
segments = textArea.Selection.Segments;
}
if (segments != null)
{
foreach (var segment in segments.Reverse())
{
foreach (var writableSegment in textArea.GetDeletableSegments(segment).Reverse())
{
transformSegment(textArea, writableSegment);
}
}
}
}
textArea.Caret.BringCaretToView();
args.Handled = true;
}
}
#endregion
#region EnterLineBreak
private static void OnEnter(object target, ExecutedRoutedEventArgs args)
{
var textArea = GetTextArea(target);
if (textArea != null && textArea.IsFocused)
{
textArea.PerformTextInput("\n");
args.Handled = true;
}
}
#endregion
#region Tab
private static void OnTab(object target, ExecutedRoutedEventArgs args)
{
var textArea = GetTextArea(target);
if (textArea?.Document != null)
{
using (textArea.Document.RunUpdate())
{
if (textArea.Selection.IsMultiline)
{
var segment = textArea.Selection.SurroundingSegment;
var start = textArea.Document.GetLineByOffset(segment.Offset);
var end = textArea.Document.GetLineByOffset(segment.EndOffset);
// don't include the last line if no characters on it are selected
if (start != end && end.Offset == segment.EndOffset)
end = end.PreviousLine;
var current = start;
while (true)
{
var offset = current.Offset;
if (textArea.ReadOnlySectionProvider.CanInsert(offset))
textArea.Document.Replace(offset, 0, textArea.Options.IndentationString,
OffsetChangeMappingType.KeepAnchorBeforeInsertion);
if (current == end)
break;
current = current.NextLine;
}
}
else
{
var indentationString = textArea.Options.GetIndentationString(textArea.Caret.Column);
textArea.ReplaceSelectionWithText(indentationString);
}
}
textArea.Caret.BringCaretToView();
args.Handled = true;
}
}
private static void OnShiftTab(object target, ExecutedRoutedEventArgs args)
{
TransformSelectedLines(
delegate (TextArea textArea, DocumentLine line)
{
var offset = line.Offset;
var s = TextUtilities.GetSingleIndentationSegment(textArea.Document, offset,
textArea.Options.IndentationSize);
if (s.Length > 0)
{
s = textArea.GetDeletableSegments(s).FirstOrDefault();
if (s != null && s.Length > 0)
{
textArea.Document.Remove(s.Offset, s.Length);
}
}
}, target, args, DefaultSegmentType.CurrentLine);
}
#endregion
#region Delete
private static EventHandler<ExecutedRoutedEventArgs> OnDelete(CaretMovementType caretMovement)
{
return (target, args) =>
{
var textArea = GetTextArea(target);
if (textArea?.Document != null)
{
if (textArea.Selection.IsEmpty)
{
var startPos = textArea.Caret.Position;
var enableVirtualSpace = textArea.Options.EnableVirtualSpace;
// When pressing delete; don't move the caret further into virtual space - instead delete the newline
if (caretMovement == CaretMovementType.CharRight)
enableVirtualSpace = false;
var desiredXPos = textArea.Caret.DesiredXPos;
var endPos = CaretNavigationCommandHandler.GetNewCaretPosition(
textArea.TextView, startPos, caretMovement, enableVirtualSpace, ref desiredXPos);
// GetNewCaretPosition may return (0,0) as new position,
// thus we need to validate endPos before using it in the selection.
if (endPos.Line < 1 || endPos.Column < 1)
endPos = new TextViewPosition(Math.Max(endPos.Line, 1), Math.Max(endPos.Column, 1));
// Don't do anything if the number of lines of a rectangular selection would be changed by the deletion.
if (textArea.Selection is RectangleSelection && startPos.Line != endPos.Line)
return;
// Don't select the text to be deleted; just reuse the ReplaceSelectionWithText logic
// Reuse the existing selection, so that we continue using the same logic
textArea.Selection.StartSelectionOrSetEndpoint(startPos, endPos)
.ReplaceSelectionWithText(string.Empty);
}
else
{
textArea.RemoveSelectedText();
}
textArea.Caret.BringCaretToView();
args.Handled = true;
}
};
}
private static void CanDelete(object target, CanExecuteRoutedEventArgs args)
{
var textArea = GetTextArea(target);
if (textArea?.Document != null)
{
args.CanExecute = true;
args.Handled = true;
}
}
#endregion
#region Clipboard commands
private static void CanCut(object target, CanExecuteRoutedEventArgs args)
{
// HasSomethingSelected for copy and cut commands
var textArea = GetTextArea(target);
if (textArea?.Document != null)
{
args.CanExecute = (textArea.Options.CutCopyWholeLine || !textArea.Selection.IsEmpty) && !textArea.IsReadOnly;
args.Handled = true;
}
}
private static void CanCopy(object target, CanExecuteRoutedEventArgs args)
{
// HasSomethingSelected for copy and cut commands
var textArea = GetTextArea(target);
if (textArea?.Document != null)
{
args.CanExecute = textArea.Options.CutCopyWholeLine || !textArea.Selection.IsEmpty;
args.Handled = true;
}
}
private static void OnCopy(object target, ExecutedRoutedEventArgs args)
{
var textArea = GetTextArea(target);
if (textArea?.Document != null)
{
if (textArea.Selection.IsEmpty && textArea.Options.CutCopyWholeLine)
{
var currentLine = textArea.Document.GetLineByNumber(textArea.Caret.Line);
CopyWholeLine(textArea, currentLine);
}
else
{
CopySelectedText(textArea);
}
args.Handled = true;
}
}
private static void OnCut(object target, ExecutedRoutedEventArgs args)
{
var textArea = GetTextArea(target);
if (textArea?.Document != null)
{
if (textArea.Selection.IsEmpty && textArea.Options.CutCopyWholeLine)
{
var currentLine = textArea.Document.GetLineByNumber(textArea.Caret.Line);
if (CopyWholeLine(textArea, currentLine))
{
var segmentsToDelete =
textArea.GetDeletableSegments(
new SimpleSegment(currentLine.Offset, currentLine.TotalLength));
for (var i = segmentsToDelete.Length - 1; i >= 0; i--)
{
textArea.Document.Remove(segmentsToDelete[i]);
}
}
}
else
{
if (CopySelectedText(textArea))
textArea.RemoveSelectedText();
}
textArea.Caret.BringCaretToView();
args.Handled = true;
}
}
private static bool CopySelectedText(TextArea textArea)
{
var text = textArea.Selection.GetText();
text = TextUtilities.NormalizeNewLines(text, Environment.NewLine);
SetClipboardText(text);
textArea.OnTextCopied(new TextEventArgs(text));
return true;
}
private static void SetClipboardText(string text)
{
try
{
Application.Current.Clipboard.SetTextAsync(text).GetAwaiter().GetResult();
}
catch (Exception)
{
// Apparently this exception sometimes happens randomly.
// The MS controls just ignore it, so we'll do the same.
}
}
private static bool CopyWholeLine(TextArea textArea, DocumentLine line)
{
ISegment wholeLine = new SimpleSegment(line.Offset, line.TotalLength);
var text = textArea.Document.GetText(wholeLine);
// Ignore empty line copy
if(string.IsNullOrEmpty(text)) return false;
// Ensure we use the appropriate newline sequence for the OS
text = TextUtilities.NormalizeNewLines(text, Environment.NewLine);
// TODO: formats
//DataObject data = new DataObject();
//if (ConfirmDataFormat(textArea, data, DataFormats.UnicodeText))
// data.SetText(text);
//// Also copy text in HTML format to clipboard - good for pasting text into Word
//// or to the SharpDevelop forums.
//if (ConfirmDataFormat(textArea, data, DataFormats.Html))
//{
// IHighlighter highlighter = textArea.GetService(typeof(IHighlighter)) as IHighlighter;
// HtmlClipboard.SetHtml(data,
// HtmlClipboard.CreateHtmlFragment(textArea.Document, highlighter, wholeLine,
// new HtmlOptions(textArea.Options)));
//}
//if (ConfirmDataFormat(textArea, data, LineSelectedType))
//{
// var lineSelected = new MemoryStream(1);
// lineSelected.WriteByte(1);
// data.SetData(LineSelectedType, lineSelected, false);
//}
//var copyingEventArgs = new DataObjectCopyingEventArgs(data, false);
//textArea.RaiseEvent(copyingEventArgs);
//if (copyingEventArgs.CommandCancelled)
// return false;
SetClipboardText(text);
textArea.OnTextCopied(new TextEventArgs(text));
return true;
}
private static void CanPaste(object target, CanExecuteRoutedEventArgs args)
{
var textArea = GetTextArea(target);
if (textArea?.Document != null)
{
args.CanExecute = textArea.ReadOnlySectionProvider.CanInsert(textArea.Caret.Offset);
args.Handled = true;
}
}
private static async void OnPaste(object target, ExecutedRoutedEventArgs args)
{
var textArea = GetTextArea(target);
if (textArea?.Document != null)
{
textArea.Document.BeginUpdate();
string text = null;
try
{
text = await Application.Current.Clipboard.GetTextAsync();
}
catch (Exception)
{
textArea.Document.EndUpdate();
return;
}
if (text == null)
return;
text = GetTextToPaste(text, textArea);
if (!string.IsNullOrEmpty(text))
{
textArea.ReplaceSelectionWithText(text);
}
textArea.Caret.BringCaretToView();
args.Handled = true;
textArea.Document.EndUpdate();
}
}
internal static string GetTextToPaste(string text, TextArea textArea)
{
try
{
// Try retrieving the text as one of:
// - the FormatToApply
// - UnicodeText
// - Text
// (but don't try the same format twice)
//if (pastingEventArgs.FormatToApply != null && dataObject.GetDataPresent(pastingEventArgs.FormatToApply))
// text = (string)dataObject.GetData(pastingEventArgs.FormatToApply);
//else if (pastingEventArgs.FormatToApply != DataFormats.UnicodeText &&
// dataObject.GetDataPresent(DataFormats.UnicodeText))
// text = (string)dataObject.GetData(DataFormats.UnicodeText);
//else if (pastingEventArgs.FormatToApply != DataFormats.Text &&
// dataObject.GetDataPresent(DataFormats.Text))
// text = (string)dataObject.GetData(DataFormats.Text);
//else
// return null; // no text data format
// convert text back to correct newlines for this document
var newLine = TextUtilities.GetNewLineFromDocument(textArea.Document, textArea.Caret.Line);
text = TextUtilities.NormalizeNewLines(text, newLine);
text = textArea.Options.ConvertTabsToSpaces
? text.Replace("\t", new String(' ', textArea.Options.IndentationSize))
: text;
return text;
}
catch (OutOfMemoryException)
{
// may happen when trying to paste a huge string
return null;
}
}
#endregion
#region Toggle Overstrike
private static void OnToggleOverstrike(object target, ExecutedRoutedEventArgs args)
{
var textArea = GetTextArea(target);
if (textArea != null && textArea.Options.AllowToggleOverstrikeMode)
textArea.OverstrikeMode = !textArea.OverstrikeMode;
}
#endregion
#region DeleteLine
private static void OnDeleteLine(object target, ExecutedRoutedEventArgs args)
{
var textArea = GetTextArea(target);
if (textArea?.Document != null)
{
int firstLineIndex, lastLineIndex;
if (textArea.Selection.Length == 0)
{
// There is no selection, simply delete current line
firstLineIndex = lastLineIndex = textArea.Caret.Line;
}
else
{
// There is a selection, remove all lines affected by it (use Min/Max to be independent from selection direction)
firstLineIndex = Math.Min(textArea.Selection.StartPosition.Line,
textArea.Selection.EndPosition.Line);
lastLineIndex = Math.Max(textArea.Selection.StartPosition.Line,
textArea.Selection.EndPosition.Line);
}
var startLine = textArea.Document.GetLineByNumber(firstLineIndex);
var endLine = textArea.Document.GetLineByNumber(lastLineIndex);
textArea.Selection = Selection.Create(textArea, startLine.Offset,
endLine.Offset + endLine.TotalLength);
textArea.RemoveSelectedText();
args.Handled = true;
}
}
#endregion
#region Remove..Whitespace / Convert Tabs-Spaces
private static void OnRemoveLeadingWhitespace(object target, ExecutedRoutedEventArgs args)
{
TransformSelectedLines(
delegate (TextArea textArea, DocumentLine line)
{
textArea.Document.Remove(TextUtilities.GetLeadingWhitespace(textArea.Document, line));
}, target, args, DefaultSegmentType.WholeDocument);
}
private static void OnRemoveTrailingWhitespace(object target, ExecutedRoutedEventArgs args)
{
TransformSelectedLines(
delegate (TextArea textArea, DocumentLine line)
{
textArea.Document.Remove(TextUtilities.GetTrailingWhitespace(textArea.Document, line));
}, target, args, DefaultSegmentType.WholeDocument);
}
private static void OnConvertTabsToSpaces(object target, ExecutedRoutedEventArgs args)
{
TransformSelectedSegments(ConvertTabsToSpaces, target, args, DefaultSegmentType.WholeDocument);
}
private static void OnConvertLeadingTabsToSpaces(object target, ExecutedRoutedEventArgs args)
{
TransformSelectedLines(
delegate (TextArea textArea, DocumentLine line)
{
ConvertTabsToSpaces(textArea, TextUtilities.GetLeadingWhitespace(textArea.Document, line));
}, target, args, DefaultSegmentType.WholeDocument);
}
private static void ConvertTabsToSpaces(TextArea textArea, ISegment segment)
{
var document = textArea.Document;
var endOffset = segment.EndOffset;
var indentationString = new string(' ', textArea.Options.IndentationSize);
for (var offset = segment.Offset; offset < endOffset; offset++)
{
if (document.GetCharAt(offset) == '\t')
{
document.Replace(offset, 1, indentationString, OffsetChangeMappingType.CharacterReplace);
endOffset += indentationString.Length - 1;
}
}
}
private static void OnConvertSpacesToTabs(object target, ExecutedRoutedEventArgs args)
{
TransformSelectedSegments(ConvertSpacesToTabs, target, args, DefaultSegmentType.WholeDocument);
}
private static void OnConvertLeadingSpacesToTabs(object target, ExecutedRoutedEventArgs args)
{
TransformSelectedLines(
delegate (TextArea textArea, DocumentLine line)
{
ConvertSpacesToTabs(textArea, TextUtilities.GetLeadingWhitespace(textArea.Document, line));
}, target, args, DefaultSegmentType.WholeDocument);
}
private static void ConvertSpacesToTabs(TextArea textArea, ISegment segment)
{
var document = textArea.Document;
var endOffset = segment.EndOffset;
var indentationSize = textArea.Options.IndentationSize;
var spacesCount = 0;
for (var offset = segment.Offset; offset < endOffset; offset++)
{
if (document.GetCharAt(offset) == ' ')
{
spacesCount++;
if (spacesCount == indentationSize)
{
document.Replace(offset - (indentationSize - 1), indentationSize, "\t",
OffsetChangeMappingType.CharacterReplace);
spacesCount = 0;
offset -= indentationSize - 1;
endOffset -= indentationSize - 1;
}
}
else
{
spacesCount = 0;
}
}
}
#endregion
#region Convert...Case
private static void ConvertCase(Func<string, string> transformText, object target, ExecutedRoutedEventArgs args)
{
TransformSelectedSegments(
delegate (TextArea textArea, ISegment segment)
{
var oldText = textArea.Document.GetText(segment);
var newText = transformText(oldText);
textArea.Document.Replace(segment.Offset, segment.Length, newText,
OffsetChangeMappingType.CharacterReplace);
}, target, args, DefaultSegmentType.WholeDocument);
}
private static void OnConvertToUpperCase(object target, ExecutedRoutedEventArgs args)
{
ConvertCase(CultureInfo.CurrentCulture.TextInfo.ToUpper, target, args);
}
private static void OnConvertToLowerCase(object target, ExecutedRoutedEventArgs args)
{
ConvertCase(CultureInfo.CurrentCulture.TextInfo.ToLower, target, args);
}
private static void OnConvertToTitleCase(object target, ExecutedRoutedEventArgs args)
{
throw new NotSupportedException();
//ConvertCase(CultureInfo.CurrentCulture.TextInfo.ToTitleCase, target, args);
}
private static void OnInvertCase(object target, ExecutedRoutedEventArgs args)
{
private static void OnIndentSelection(object target, ExecutedRoutedEventArgs args)
{
var textArea = GetTextArea(target);
if (textArea?.Document != null)
{
using (textArea.Document.RunUpdate())
{
var buffer = text.ToCharArray();
for (var i = 0; i < buffer.Length; ++i)
{
var c = buffer[i];
buffer[i] = char.IsUpper(c) ? char.ToLower(c) : char.ToUpper(c);
}
return new string(buffer);
}
#endregion
private static void OnIndentSelection(object target, ExecutedRoutedEventArgs args)
{
var textArea = GetTextArea(target);
if (textArea?.Document != null && textArea.IndentationStrategy != null)
{
using (textArea.Document.RunUpdate())
{
int start, end;
if (textArea.Selection.IsEmpty)
{
start = 1;
end = textArea.Document.LineCount;
}
else
{
start = textArea.Document.GetLineByOffset(textArea.Selection.SurroundingSegment.Offset)
.LineNumber;
end = textArea.Document.GetLineByOffset(textArea.Selection.SurroundingSegment.EndOffset)
.LineNumber;
}
textArea.IndentationStrategy.IndentLines(textArea.Document, start, end);
}
textArea.Caret.BringCaretToView();
args.Handled = true;
}
}
}
}
<MSG> Add null check in OnIndentSelection() #122
https://github.com/icsharpcode/AvalonEdit/pull/122
<DFF> @@ -729,7 +729,7 @@ namespace AvaloniaEdit.Editing
private static void OnIndentSelection(object target, ExecutedRoutedEventArgs args)
{
var textArea = GetTextArea(target);
- if (textArea?.Document != null)
+ if (textArea?.Document != null && textArea.IndentationStrategy != null)
{
using (textArea.Document.RunUpdate())
{
| 1 | Add null check in OnIndentSelection() #122 | 1 | .cs | cs | mit | AvaloniaUI/AvaloniaEdit |
10066851 | <NME> index.js
<BEF>
/*jshint browser:true, node:true*/
'use strict';
/**
* Module Dependencies
*/
var util = require('utils');
var events = require('./events');
var extend = require('extend');
var mixin = util.mixin;
/**
* Exports
*/
module.exports = function(fm) {
// Alias prototype for optimum
// compression via uglifyjs
var proto = Module.prototype;
/**
* Module constructor
*
* Options:
*
* - `id {String}` a unique id to query by
* - `model {Object|Model}` the data with which to associate this module
* - `tag {String}` tagName to use for the root element
* - `classes {Array}` list of classes to add to the root element
* - `template {Function}` a template to use for rendering
* - `helpers {Array}`a list of helper function to use on this module
* - `children {Object|Array}` list of child modules
*
* @constructor
* @param {Object} options
* @api public
*/
function Module(options) {
// Shallow clone the options
options = mixin({}, options);
// Various config steps
this._configure(options);
this._add(options.children);
// Fire before initialize event hook
this.fireStatic('before initialize', options);
// Run initialize hooks
if (this.initialize) this.initialize(options);
// Fire initialize event hook
this.fireStatic('initialize', options);
}
/**
* Configures the new Module
* with the options passed
* to the constructor.
*
* @param {Object} options
* @api private
*/
proto._configure = function(options) {
// Setup static properties
this._id = options.id || util.uniqueId();
this._fmid = options.fmid || util.uniqueId('fmid');
this.tag = options.tag || this.tag || 'div';
this.classes = options.classes || this.classes || [];
this.helpers = options.helpers || this.helpers || [];
this.template = this._setTemplate(options.template || this.template);
this.slot = options.slot;
// Create id and module
// lookup objects
this.children = [];
this._ids = {};
this._modules = {};
this.slots = {};
// Use the model passed in,
// or create a model from
// the data passed in.
var model = options.model || options.data || {};
this.model = util.isPlainObject(model)
? new this.Model(model)
: model;
// Attach helpers
// TODO: Fix this for non-ES5 environments
this.helpers.forEach(this.attachHelper, this);
// We fire and 'inflation' event here
// so that helpers can make some changes
// to the view before instantiation.
if (options.fmid) {
fm.fire('inflation', this, options);
this.fireStatic('inflation', options);
}
};
/**
* A private add method
* that accepts a list of
* children.
*
* @param {Object|Array} children
* @api private
*/
proto._add = function(children) {
if (!children) return;
var isArray = util.isArray(children);
var child;
for (var key in children) {
child = children[key];
if (!isArray) child.slot = key;
this.add(child);
}
},
/**
* Instantiates the given
* helper on the Module.
*
* @param {Function} helper
* @return {Module}
* @api private
*/
proto.attachHelper = function(helper) {
if (helper) helper(this);
},
/**
* Returns the template function
* for the view.
*
* For template object like Hogan
* templates with a `render` method
* we need to bind the context
* so they can be called without
* a reciever.
*
* @return {Function}
* @api private
*/
proto._setTemplate = function(fn) {
return fn && fn.render
? util.bind(fn.render, fn)
: fn;
};
/**
* Adds a child view(s) to another Module.
*
* Options:
*
* - `at` The child index at which to insert
* - `inject` Injects the child's view element into the parent's
* - `slot` The slot at which to insert the child
*
* @param {Module|Object} children
* @param {Object|String|Number} options|slot
*/
proto.add = function(child, options) {
if (!child) return this;
// Options
var at = options && options.at;
var inject = options && options.inject;
var slot = ('object' === typeof options)
? options.slot
: options;
// Remove this view first if it already has a parent
if (child.parent) child.remove({ fromDOM: false });
// Assign a slot (prefering defined option)
slot = child.slot = slot || child.slot;
// Remove any module that already occupies this slot
var resident = this.slots[slot];
if (resident) resident.remove({ fromDOM: false });
// If it's not a Module, make it one.
if (!(child instanceof Module)) child = fm(child);
util.insert(child, this.children, at);
this._addLookup(child);
// We append the child to the parent view if there is a view
// element and the users hasn't flagged `append` false.
if (inject) this._injectEl(child.el, options);
// Allow chaining
return this;
};
/**
* Removes a child view from
* its current Module contexts
* and also from the DOM unless
* otherwise stated.
*
* Options:
*
* - `fromDOM` Whether the element should be removed from the DOM (default `true`)
*
* Example:
*
* // The following are equal
* // apple is removed from the
* // the view structure and DOM
* layout.remove(apple);
* apple.remove();
*
* // Apple is removed from the
* // view structure, but not the DOM
* layout.remove(apple, { el: false });
* apple.remove({ el: false });
*
* @return {FruitMachine}
* @api public
*/
proto.remove = function(param1, param2) {
// Don't do anything if the first arg is undefined
if (arguments.length === 1 && !param1) return this;
// Allow view.remove(child[, options])
// and view.remove([options]);
if (param1 instanceof Module) {
param1.remove(param2 || {});
return this;
}
// Options and aliases
var options = param1 || {};
var fromDOM = options.fromDOM !== false;
var parent = this.parent;
var el = this.el;
var parentNode = el && el.parentNode;
var index;
// Unless stated otherwise,
// remove the view element
// from its parent node.
if (fromDOM && parentNode) {
parentNode.removeChild(el);
this._unmount();
}
if (parent) {
// Remove reference from views array
index = parent.children.indexOf(this);
parent.children.splice(index, 1);
// Remove references from the lookup
parent._removeLookup(this);
}
return this;
};
/**
* Creates a lookup reference for
* the child view passed.
*
* @param {Module} child
* @api private
*/
proto._addLookup = function(child) {
var module = child.module();
// Add a lookup for module
(this._modules[module] = this._modules[module] || []).push(child);
// Add a lookup for id
this._ids[child.id()] = child;
// Store a reference by slot
if (child.slot) this.slots[child.slot] = child;
child.parent = this;
};
/**
* Removes the lookup for the
* the child view passed.
*
* @param {Module} child
* @api private
*/
proto._removeLookup = function(child) {
var module = child.module();
// Remove the module lookup
var index = this._modules[module].indexOf(child);
this._modules[module].splice(index, 1);
// Remove the id and slot lookup
delete this._ids[child._id];
delete this.slots[child.slot];
delete child.parent;
};
/**
* Injects an element into the
* Module's root element.
*
* By default the element is appended.
*
* Options:
*
* - `at` The index at which to insert.
*
* @param {Element} el
* @param {Object} options
* @api private
*/
proto._injectEl = function(el, options) {
var at = options && options.at;
var parent = this.el;
if (!el || !parent) return;
if (typeof at !== 'undefined') {
parent.insertBefore(el, parent.children[at]);
} else {
parent.appendChild(el);
}
};
/**
* Returns a decendent module
* by id, or if called with no
* arguments, returns this view's id.
*
* Example:
*
* myModule.id();
* //=> 'my_view_id'
*
* myModule.id('my_other_views_id');
* //=> Module
*
* @param {String|undefined} id
* @return {Module|String}
* @api public
*/
proto.id = function(id) {
if (!arguments.length) return this._id;
var child = this._ids[id];
if (child) return child;
return this.each(function(view) {
return view.id(id);
});
};
/**
* Returns the first descendent
* Module with the passed module type.
* If called with no arguments the
* Module's own module type is returned.
*
* Example:
*
* // Assuming 'myModule' has 3 descendent
* // views with the module type 'apple'
*
* myModule.modules('apple');
* //=> Module
*
* @param {String} key
* @return {Module}
*/
proto.module = function(key) {
if (!arguments.length) return this._module || this.name;
var view = this._modules[key];
if (view && view.length) return view[0];
return this.each(function(view) {
return view.module(key);
});
};
/**
* Returns a list of descendent
* Modules that match the module
* type given (Similar to
* Element.querySelectorAll();).
*
* Example:
*
* // Assuming 'myModule' has 3 descendent
* // views with the module type 'apple'
*
* myModule.modules('apple');
* //=> [ Module, Module, Module ]
*
* @param {String} key
* @return {Array}
* @api public
*/
proto.modules = function(key) {
var list = this._modules[key] || [];
// Then loop each child and run the
// same opperation, appending the result
// onto the list.
this.each(function(view) {
list = list.concat(view.modules(key));
});
return list;
};
/**
* Calls the passed function
* for each of the view's
* children.
*
* Example:
*
* myModule.each(function(child) {
* // Do stuff with each child view...
* });
*
* @param {Function} fn
* @return {[type]}
*/
proto.each = function(fn) {
var l = this.children.length;
var result;
for (var i = 0; i < l; i++) {
result = fn(this.children[i]);
if (result) return result;
}
};
/**
* Templates the view, including
* any descendent views returning
* an html string. All data in the
* views model is made accessible
* to the template.
*
* Child views are printed into the
* parent template by `id`. Alternatively
* children can be iterated over a a list
* and printed with `{{{child}}}}`.
*
* Example:
*
* <div class="slot-1">{{{<slot>}}}</div>
* <div class="slot-2">{{{<slot>}}}</div>
*
* // or
*
* {{#children}}
* @api public
*/
proto.toHTML = function() {
this.fireStatic('before tohtml');
var data = {};
var html;
proto._innerHTML = function() {
this.fireStatic('before tohtml');
var data = {};
var html;
var tmp;
// Create an array for view
// children data needed in template.
data[fm.config.templateIterator] = [];
// Loop each child
this.each(function(child) {
if (!child.model) {
var err = new Error("Child without a model");
err.context = child;
throw err;
// passing children data (for looping
// or child views) mixed with the
// view's model data.
html = this.template
? this.template(mixin(data, this.model.toJSON()))
: '';
// Wrap the html in a FruitMachine
// generated root element and return.
return this._wrapHTML(html);
};
/**
// passing children data (for looping
// or child views) mixed with the
// view's model data.
return this.template
? this.template(mixin(data, this.model.toJSON()))
: '';
};
/**
* Wraps the module html in
* a root element.
*
* @param {String} html
* @return {String}
* @api private
*/
proto._wrapHTML = function(html) {
return '<' + this.tag + ' class="' + this._classes().join(' ') + '" id="' + this._fmid + '">' + html + '</' + this.tag + '>';
};
/**
* Gets a space separated list
* of all a view's classes
*
* @return {String}
* @api private
*/
proto._classes = function() {
return [this.module()].concat(this.classes);
};
*/
proto.render = function() {
this.fireStatic('before render');
var html = this.toHTML();
var el = util.toNode(html);
// If possible recycle outer element but
// build from scratch if there is no
// existing element or if tag changed
if (this.el && this.el.tagName === this.tag.toUpperCase()) {
this.el.innerHTML = el.innerHTML;
this.el.className = this._classes();
} else {
// Sets a new element as a view's
// root element (purging descendent
// element caches).
this._setEl(el);
}
// Fetch all child module elements
el.innerHTML = this._innerHTML();
this._unmountChildren();
classes = el.className.split(/\s+/);
this._classes().forEach(function(add) {
if (!~classes.indexOf(add)) el.className = el.className + ' ' + add;
});
// Sets a new element as a view's
// root element (purging descendent
// element caches).
} else {
this._setEl(util.toNode(this.toHTML()));
}
// Fetch all child module elements
this._fetchEls(this.el);
// Handy hook
this.fireStatic('render');
return this;
};
/**
* Sets up a view and all descendent
* views.
*
* Setup will be aborted if no `view.el`
* is found. If a view is already setup,
* teardown is run first to prevent a
* view being setup twice.
*
* Your custom `setup()` method is called
*
* Options:
*
* - `shallow` Does not recurse when `true` (default `false`)
*
* @param {Object} options
* @return {Module}
*/
proto.setup = function(options) {
var shallow = options && options.shallow;
// Attempt to fetch the view's
// root element. Don't continue
// if no route element is found.
if (!this._getEl()) return this;
// If this is already setup, call
// `teardown` first so that we don't
// duplicate event bindings and shizzle.
if (this.isSetup) this.teardown({ shallow: true });
// Fire the `setup` event hook
this.fireStatic('before setup');
if (this._setup) this._setup();
this.fireStatic('setup');
// Flag view as 'setup'
this.isSetup = true;
// Call 'setup' on all subviews
// first (top down recursion)
if (!shallow) {
this.each(function(child) {
child.setup();
});
}
// For chaining
return this;
};
/**
* Tearsdown a view and all descendent
* views that have been setup.
*
* Your custom `teardown` method is
* called and a `teardown` event is fired.
*
* Options:
*
* - `shallow` Does not recurse when `true` (default `false`)
*
* @param {Object} options
* @return {Module}
*/
proto.teardown = function(options) {
var shallow = options && options.shallow;
// Call 'setup' on all subviews
// first (bottom up recursion).
if (!shallow) {
this.each(function(child) {
child.teardown();
});
}
// Only teardown if this view
// has been setup. Teardown
// is supposed to undo all the
// work setup does, and therefore
// will likely run into undefined
// variables if setup hasn't run.
if (this.isSetup) {
this.fireStatic('before teardown');
if (this._teardown) this._teardown();
this.fireStatic('teardown');
this.isSetup = false;
}
// For chaining
return this;
};
/**
* Completely destroys a view. This means
* a view is torn down, removed from it's
* current layout context and removed
* from the DOM.
*
* Your custom `destroy` method is
* called and a `destroy` event is fired.
*
* NOTE: `.remove()` is only run on the view
* that `.destroy()` is directly called on.
*
* Options:
*
* - `fromDOM` Whether the view should be removed from DOM (default `true`)
*
* @api public
*/
proto.destroy = function(options) {
options = options || {};
var remove = options.remove !== false;
var l = this.children.length;
// Destroy each child view.
// We don't waste time removing
// the child elements as they will
// get removed when the parent
// element is removed.
//
// We can't use the standard Module#each()
// as the array length gets altered
// with each iteration, hense the
// reverse while loop.
while (l--) {
this.children[l].destroy({ remove: false });
}
// Don't continue if this view
// has already been destroyed.
if (this.destroyed) return this;
// .remove() is only run on the view that
// destroy() was called on.
//
// It is a waste of time to remove the
// descendent views as well, as any
// references to them will get wiped
// within destroy and they will get
// removed from the DOM with the main view.
if (remove) this.remove(options);
// Run teardown
this.teardown({ shallow: true });
// Fire an event hook before the
// custom destroy logic is run
this.fireStatic('before destroy');
// If custom destroy logic has been
// defined on the prototype then run it.
if (this._destroy) this._destroy();
// Trigger a `destroy` event
// for custom Modules to bind to.
this.fireStatic('destroy');
// Unbind any old event listeners
this.off();
// Set a flag to say this view
// has been destroyed. This is
// useful to check for after a
// slow ajax call that might come
// back after a view has been detroyed.
this.destroyed = true;
// Clear references
this.el = this.model = this.parent = this._modules = this._ids = this._id = null;
};
/**
* Destroys all children.
*
* Is this needed?
*
* @return {Module}
* @api public
*/
proto.empty = function() {
var l = this.children.length;
while (l--) this.children[l].destroy();
return this;
};
/**
* Fetches all descendant elements
* from the given root element.
*
* @param {Element} root
* @return {undefined}
* @api private
*/
proto._fetchEls = function(root) {
if (!root) return;
this.each(function(child) {
child.mount(util.byId(child._fmid, root));
child._fetchEls(child.el || root);
});
};
/**
* Associate the view with an element.
* Provide events and lifecycle methods
* to fire when the element is newly
* associated.
*
* @param {Element} el
* @return {Element}
*/
proto.mount = function(el) {
if(this.el !== el) {
this.fireStatic('before mount');
this.el = el;
if(this._mount) this._mount();
this.fireStatic('mount');
}
return this.el;
};
/**
* Recursively fire unmount events on
* children. To be called when a view's
* children are implicitly removed from
* the DOM (e.g. setting innerHTML)
*
* @api private
*/
proto._unmountChildren = function() {
this.each(function(child) {
child._unmount();
});
};
/*_setEl * Recursively fire unmount events on
* a view and its children. To be
* called when a view'is implicitly
* removed from the DOM (e.g. _setEl)
*
* @api private
*/
proto._unmount = function() {
this._unmountChildren();
this.fireStatic('unmount');
}
/**
* Returns the Module's root element.
*
* If a cache is present it is used,
* else we search the DOM, else we
* find the closest element and
* perform a querySelector using
* the view._fmid.
*
* @return {Element|undefined}
* @api private
*/
proto._getEl = function() {
if (!util.hasDom()) return;
return this.mount(this.el || document.getElementById(this._fmid) || undefined);
};
/**
* Sets a root element on a view.
* If the view already has a root
* element, it is replaced.
*
* IMPORTANT: All descendent root
* element caches are purged so that
* the new correct elements are retrieved
* next time Module#getElement is called.
*
* @param {Element} el
* @return {Module}
* @api private
*/
proto._setEl = function(el) {
var existing = this.el;
var parentNode = existing && existing.parentNode;
// If the existing element has a context, replace it
if (parentNode) {
parentNode.replaceChild(el, existing);
this._unmount();
}
// Update cache
this.mount(el);
return this;
};
/**
* Empties the destination element
* and appends the view into it.
*
* @param {Element} dest
* @return {Module}
* @api public
*/
proto.inject = function(dest) {
if (dest) {
dest.innerHTML = '';
this.insertBefore(dest, null);
this.fireStatic('inject');
}
return this;
};
/**
* Appends the view element into
* the destination element.
*
* @param {Element} dest
* @return {Module}
* @api public
*/
proto.appendTo = function(dest) {
return this.insertBefore(dest, null);
};
/**
* Inserts the view element before the
* given child of the destination element.
*
* @param {Element} dest
* @param {Element} beforeEl
* @return {Module}
* @api public
*/
proto.insertBefore = function(dest, beforeEl) {
if (this.el && dest && dest.insertBefore) {
dest.insertBefore(this.el, beforeEl);
// This badly-named event is for legacy reasons; perhaps 'insert' would be better here?
this.fireStatic('appendto');
}
return this;
};
/**
* Returns a JSON represention of
* a FruitMachine Module. This can
* be generated serverside and
* passed into new FruitMachine(json)
* to inflate serverside rendered
* views.
*
* @return {Object}
* @api public
*/
proto.toJSON = function() {
var json = {};
json.children = [];
// Recurse
this.each(function(child) {
json.children.push(child.toJSON());
});
json.id = this.id();
json.fmid = this._fmid;
json.module = this.module();
json.model = this.model.toJSON();
json.slot = this.slot;
// Fire a hook to allow third
// parties to alter the json output
this.fireStatic('tojson', json);
return json;
};
// Events
proto.on = events.on;
proto.off = events.off;
proto.fire = events.fire;
proto.fireStatic = events.fireStatic;
// Allow Modules to be extended
Module.extend = extend(util.keys(proto));
// Adding proto.Model after
// Module.extend means this
// key can be overwritten.
proto.Model = fm.Model;
return Module;
};
<MSG> Don't unnecessarily wrap view html in DOM elements when able to recycle nodes
<DFF> @@ -472,6 +472,19 @@ module.exports = function(fm) {
* @api public
*/
proto.toHTML = function() {
+ var html = this._innerHTML();
+
+ // Wrap the html in a FruitMachine
+ // generated root element and return.
+ return this._wrapHTML(html);
+ };
+
+ /**
+ * Get the view's innerHTML
+ *
+ * @return {String}
+ */
+ proto._innerHTML = function() {
this.fireStatic('before tohtml');
var data = {};
var html;
@@ -494,13 +507,9 @@ module.exports = function(fm) {
// passing children data (for looping
// or child views) mixed with the
// view's model data.
- html = this.template
+ return this.template
? this.template(mixin(data, this.model.toJSON()))
: '';
-
- // Wrap the html in a FruitMachine
- // generated root element and return.
- return this._wrapHTML(html);
};
/**
@@ -537,21 +546,19 @@ module.exports = function(fm) {
*/
proto.render = function() {
this.fireStatic('before render');
- var html = this.toHTML();
- var el = util.toNode(html);
// If possible recycle outer element but
// build from scratch if there is no
// existing element or if tag changed
if (this.el && this.el.tagName === this.tag.toUpperCase()) {
- this.el.innerHTML = el.innerHTML;
+ this.el.innerHTML = this._innerHTML();
this.el.className = this._classes();
} else {
// Sets a new element as a view's
// root element (purging descendent
// element caches).
- this._setEl(el);
+ this._setEl(util.toNode(this.toHTML()));
}
// Fetch all child module elements
| 16 | Don't unnecessarily wrap view html in DOM elements when able to recycle nodes | 9 | .js | js | mit | ftlabs/fruitmachine |
10066852 | <NME> SearchPanel.cs
<BEF> // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.VisualTree;
using AvaloniaEdit.Document;
using AvaloniaEdit.Editing;
using AvaloniaEdit.Rendering;
namespace AvaloniaEdit.Search
{
/// <summary>
/// Provides search functionality for AvalonEdit. It is displayed in the top-right corner of the TextArea.
/// </summary>
public class SearchPanel : TemplatedControl, IRoutedCommandBindable
{
private TextArea _textArea;
private SearchInputHandler _handler;
private TextDocument _currentDocument;
private SearchResultBackgroundRenderer _renderer;
private TextBox _searchTextBox;
private TextEditor _textEditor { get; set; }
private Border _border;
#region DependencyProperties
/// <summary>
/// Dependency property for <see cref="UseRegex"/>.
/// </summary>
public static readonly StyledProperty<bool> UseRegexProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(UseRegex));
/// <summary>
/// Gets/sets whether the search pattern should be interpreted as regular expression.
/// </summary>
public bool UseRegex
{
get => GetValue(UseRegexProperty);
set => SetValue(UseRegexProperty, value);
}
/// <summary>
/// Dependency property for <see cref="MatchCase"/>.
/// </summary>
public static readonly StyledProperty<bool> MatchCaseProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(MatchCase));
/// <summary>
/// Gets/sets whether the search pattern should be interpreted case-sensitive.
/// </summary>
public bool MatchCase
{
get => GetValue(MatchCaseProperty);
set => SetValue(MatchCaseProperty, value);
}
/// <summary>
/// Dependency property for <see cref="WholeWords"/>.
/// </summary>
public static readonly StyledProperty<bool> WholeWordsProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(WholeWords));
/// <summary>
/// Gets/sets whether the search pattern should only match whole words.
/// </summary>
public bool WholeWords
{
get => GetValue(WholeWordsProperty);
set => SetValue(WholeWordsProperty, value);
}
/// <summary>
/// Dependency property for <see cref="SearchPattern"/>.
/// </summary>
public static readonly StyledProperty<string> SearchPatternProperty =
AvaloniaProperty.Register<SearchPanel, string>(nameof(SearchPattern), "");
/// <summary>
/// Gets/sets the search pattern.
/// </summary>
public string SearchPattern
{
get => GetValue(SearchPatternProperty);
set => SetValue(SearchPatternProperty, value);
}
public static readonly StyledProperty<bool> IsReplaceModeProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(IsReplaceMode));
/// <summary>
/// Checks if replacemode is allowed
/// </summary>
/// <returns>False if editor is not null and readonly</returns>
private static bool ValidateReplaceMode(SearchPanel panel, bool v1)
{
if (panel._textEditor == null || !v1) return v1;
return !panel._textEditor.IsReadOnly;
}
public bool IsReplaceMode
{
get => GetValue(IsReplaceModeProperty);
set => SetValue(IsReplaceModeProperty, _textEditor?.IsReadOnly ?? false ? false : value);
}
public static readonly StyledProperty<string> ReplacePatternProperty =
AvaloniaProperty.Register<SearchPanel, string>(nameof(ReplacePattern));
public string ReplacePattern
{
get => GetValue(ReplacePatternProperty);
set => SetValue(ReplacePatternProperty, value);
}
/// <summary>
/// Dependency property for <see cref="MarkerBrush"/>.
/// </summary>
public static readonly StyledProperty<IBrush> MarkerBrushProperty =
AvaloniaProperty.Register<SearchPanel, IBrush>(nameof(MarkerBrush), Brushes.LightGreen);
/// <summary>
/// Gets/sets the Brush used for marking search results in the TextView.
/// </summary>
public IBrush MarkerBrush
{
get => GetValue(MarkerBrushProperty);
set => SetValue(MarkerBrushProperty, value);
}
#endregion
private static void MarkerBrushChangedCallback(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is SearchPanel panel)
{
panel._renderer.MarkerBrush = (IBrush)e.NewValue;
}
}
private ISearchStrategy _strategy;
private static void SearchPatternChangedCallback(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is SearchPanel panel)
{
panel.ValidateSearchText();
panel.UpdateSearch();
}
}
private void UpdateSearch()
{
// only reset as long as there are results
// if no results are found, the "no matches found" message should not flicker.
// if results are found by the next run, the message will be hidden inside DoSearch ...
if (_renderer.CurrentResults.Any())
_messageView.IsOpen = false;
_strategy = SearchStrategyFactory.Create(SearchPattern ?? "", !MatchCase, WholeWords, UseRegex ? SearchMode.RegEx : SearchMode.Normal);
OnSearchOptionsChanged(new SearchOptionsChangedEventArgs(SearchPattern, MatchCase, UseRegex, WholeWords));
DoSearch(true);
}
static SearchPanel()
{
UseRegexProperty.Changed.Subscribe(SearchPatternChangedCallback);
MatchCaseProperty.Changed.Subscribe(SearchPatternChangedCallback);
WholeWordsProperty.Changed.Subscribe(SearchPatternChangedCallback);
SearchPatternProperty.Changed.Subscribe(SearchPatternChangedCallback);
MarkerBrushProperty.Changed.Subscribe(MarkerBrushChangedCallback);
}
/// <summary>
/// Creates a new SearchPanel.
/// </summary>
private SearchPanel()
{
}
/// <summary>
/// Creates a SearchPanel and installs it to the TextEditor's TextArea.
/// </summary>
/// <remarks>This is a convenience wrapper.</remarks>
public static SearchPanel Install(TextEditor editor)
{
if (editor == null) throw new ArgumentNullException(nameof(editor));
SearchPanel searchPanel = Install(editor.TextArea);
searchPanel._textEditor = editor;
return searchPanel;
}
/// <summary>
/// Creates a SearchPanel and installs it to the TextArea.
/// </summary>
public static SearchPanel Install(TextArea textArea)
{
if (textArea == null) throw new ArgumentNullException(nameof(textArea));
var panel = new SearchPanel();
panel.AttachInternal(textArea);
panel._handler = new SearchInputHandler(textArea, panel);
textArea.DefaultInputHandler.NestedInputHandlers.Add(panel._handler);
((ISetLogicalParent)panel).SetParent(textArea);
return panel;
}
/// <summary>
/// Adds the commands used by SearchPanel to the given CommandBindingCollection.
/// </summary>
public void RegisterCommands(ICollection<RoutedCommandBinding> commandBindings)
{
_handler.RegisterGlobalCommands(commandBindings);
}
/// <summary>
/// Removes the SearchPanel from the TextArea.
/// </summary>
public void Uninstall()
{
Close();
_textArea.DocumentChanged -= TextArea_DocumentChanged;
if (_currentDocument != null)
_currentDocument.TextChanged -= TextArea_Document_TextChanged;
_textArea.DefaultInputHandler.NestedInputHandlers.Remove(_handler);
}
private void AttachInternal(TextArea textArea)
{
_textArea = textArea;
_renderer = new SearchResultBackgroundRenderer();
_currentDocument = textArea.Document;
if (_currentDocument != null)
_currentDocument.TextChanged += TextArea_Document_TextChanged;
textArea.DocumentChanged += TextArea_DocumentChanged;
KeyDown += SearchLayerKeyDown;
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.FindNext, (sender, e) => FindNext()));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.FindPrevious, (sender, e) => FindPrevious()));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.CloseSearchPanel, (sender, e) => Close()));
CommandBindings.Add(new RoutedCommandBinding(ApplicationCommands.Find, (sender, e) =>
{
IsReplaceMode = false;
Reactivate();
}));
CommandBindings.Add(new RoutedCommandBinding(ApplicationCommands.Replace, (sender, e) => IsReplaceMode = true));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.ReplaceNext, (sender, e) => ReplaceNext(), (sender, e) => e.CanExecute = IsReplaceMode));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.ReplaceAll, (sender, e) => ReplaceAll(), (sender, e) => e.CanExecute = IsReplaceMode));
IsClosed = true;
}
private void TextArea_DocumentChanged(object sender, EventArgs e)
{
if (_currentDocument != null)
_currentDocument.TextChanged -= TextArea_Document_TextChanged;
_currentDocument = _textArea.Document;
if (_currentDocument != null)
{
_currentDocument.TextChanged += TextArea_Document_TextChanged;
DoSearch(false);
}
}
private void TextArea_Document_TextChanged(object sender, EventArgs e)
{
DoSearch(false);
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
_border = e.NameScope.Find<Border>("PART_Border");
_searchTextBox = e.NameScope.Find<TextBox>("PART_searchTextBox");
_messageView = e.NameScope.Find<Popup>("PART_MessageView");
_messageViewContent = e.NameScope.Find<ContentPresenter>("PART_MessageContent");
}
private void ValidateSearchText()
{
if (_searchTextBox == null)
return;
try
{
UpdateSearch();
_validationError = null;
}
catch (SearchPatternException ex)
{
_validationError = ex.Message;
}
}
/// <summary>
/// Reactivates the SearchPanel by setting the focus on the search box and selecting all text.
/// </summary>
public void Reactivate()
{
if (_searchTextBox == null)
return;
_searchTextBox.Focus();
_searchTextBox.SelectionStart = 0;
_searchTextBox.SelectionEnd = _searchTextBox.Text?.Length ?? 0;
}
/// <summary>
/// Moves to the next occurrence in the file.
/// </summary>
public void FindNext()
{
var result = _renderer.CurrentResults.FindFirstSegmentWithStartAfter(_textArea.Caret.Offset + 1) ??
_renderer.CurrentResults.FirstSegment;
if (result != null)
{
SelectResult(result);
}
}
/// <summary>
/// Moves to the previous occurrence in the file.
/// </summary>
public void FindPrevious()
{
var result = _renderer.CurrentResults.FindFirstSegmentWithStartAfter(_textArea.Caret.Offset);
if (result != null)
result = _renderer.CurrentResults.GetPreviousSegment(result);
if (result == null)
result = _renderer.CurrentResults.LastSegment;
if (result != null)
{
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
}
public void ReplaceAll()
FindNext();
if (!_textArea.Selection.IsEmpty)
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
UpdateSearch();
}
public void ReplaceAll()
{
if (!IsReplaceMode) return;
var replacement = ReplacePattern ?? string.Empty;
var document = _textArea.Document;
using (document.RunUpdate())
{
var segments = _renderer.CurrentResults.OrderByDescending(x => x.EndOffset).ToArray();
foreach (var textSegment in segments)
{
document.Replace(textSegment.StartOffset, textSegment.Length,
new StringTextSource(replacement));
}
}
}
private Popup _messageView;
private ContentPresenter _messageViewContent;
private string _validationError;
private void DoSearch(bool changeSelection)
{
if (IsClosed)
return;
_renderer.CurrentResults.Clear();
if (!string.IsNullOrEmpty(SearchPattern))
{
var offset = _textArea.Caret.Offset;
if (changeSelection)
{
_textArea.ClearSelection();
}
// We cast from ISearchResult to SearchResult; this is safe because we always use the built-in strategy
foreach (var result in _strategy.FindAll(_textArea.Document, 0, _textArea.Document.TextLength).Cast<SearchResult>())
{
if (changeSelection && result.StartOffset >= offset)
{
SelectResult(result);
changeSelection = false;
}
_renderer.CurrentResults.Add(result);
}
}
if (_messageView != null)
{
if (!_renderer.CurrentResults.Any())
{
_messageViewContent.Content = SR.SearchNoMatchesFoundText;
_messageView.PlacementTarget = _searchTextBox;
_messageView.IsOpen = true;
}
else
_messageView.IsOpen = false;
}
_textArea.TextView.InvalidateLayer(KnownLayer.Selection);
}
private void SelectResult(TextSegment result)
{
_textArea.Caret.Offset = result.StartOffset;
_textArea.Selection = Selection.Create(_textArea, result.StartOffset, result.EndOffset);
double distanceToViewBorder = _border == null ?
Caret.MinimumDistanceToViewBorder :
_border.Bounds.Height + _textArea.TextView.DefaultLineHeight;
_textArea.Caret.BringCaretToView(distanceToViewBorder);
// show caret even if the editor does not have the Keyboard Focus
_textArea.Caret.Show();
}
private void SearchLayerKeyDown(object sender, KeyEventArgs e)
{
switch (e.Key)
{
case Key.Enter:
e.Handled = true;
if (e.KeyModifiers.HasFlag(KeyModifiers.Shift))
{
FindPrevious();
}
else
{
FindNext();
}
if (_searchTextBox != null)
{
if (_validationError != null)
{
_messageViewContent.Content = SR.SearchErrorText + " " + _validationError;
_messageView.PlacementTarget = _searchTextBox;
_messageView.IsOpen = true;
}
}
break;
case Key.Escape:
e.Handled = true;
Close();
break;
}
}
/// <summary>
/// Gets whether the Panel is already closed.
/// </summary>
public bool IsClosed { get; private set; }
/// <summary>
/// Gets whether the Panel is currently opened.
/// </summary>
public bool IsOpened => !IsClosed;
/// <summary>
/// Closes the SearchPanel.
/// </summary>
public void Close()
{
_textArea.RemoveChild(this);
_messageView.IsOpen = false;
_textArea.TextView.BackgroundRenderers.Remove(_renderer);
IsClosed = true;
// Clear existing search results so that the segments don't have to be maintained
_renderer.CurrentResults.Clear();
_textArea.Focus();
}
/// <summary>
/// Opens the an existing search panel.
/// </summary>
public void Open()
{
if (!IsClosed) return;
_textArea.AddChild(this);
_textArea.TextView.BackgroundRenderers.Add(_renderer);
IsClosed = false;
DoSearch(false);
}
protected override void OnPointerPressed(PointerPressedEventArgs e)
{
e.Handled = true;
base.OnPointerPressed(e);
}
protected override void OnPointerMoved(PointerEventArgs e)
{
Cursor = Cursor.Default;
base.OnPointerMoved(e);
}
protected override void OnGotFocus(GotFocusEventArgs e)
{
e.Handled = true;
base.OnGotFocus(e);
}
/// <summary>
/// Fired when SearchOptions are changed inside the SearchPanel.
/// </summary>
public event EventHandler<SearchOptionsChangedEventArgs> SearchOptionsChanged;
/// <summary>
/// Raises the <see cref="SearchOptionsChanged" /> event.
/// </summary>
protected virtual void OnSearchOptionsChanged(SearchOptionsChangedEventArgs e)
{
SearchOptionsChanged?.Invoke(this, e);
}
public IList<RoutedCommandBinding> CommandBindings { get; } = new List<RoutedCommandBinding>();
}
/// <summary>
/// EventArgs for <see cref="SearchPanel.SearchOptionsChanged"/> event.
/// </summary>
public class SearchOptionsChangedEventArgs : EventArgs
{
/// <summary>
/// Gets the search pattern.
/// </summary>
public string SearchPattern { get; }
/// <summary>
/// Gets whether the search pattern should be interpreted case-sensitive.
/// </summary>
public bool MatchCase { get; }
/// <summary>
/// Gets whether the search pattern should be interpreted as regular expression.
/// </summary>
public bool UseRegex { get; }
/// <summary>
/// Gets whether the search pattern should only match whole words.
/// </summary>
public bool WholeWords { get; }
/// <summary>
/// Creates a new SearchOptionsChangedEventArgs instance.
/// </summary>
public SearchOptionsChangedEventArgs(string searchPattern, bool matchCase, bool useRegex, bool wholeWords)
{
SearchPattern = searchPattern;
MatchCase = matchCase;
UseRegex = useRegex;
WholeWords = wholeWords;
}
}
}
<MSG> update search after replace
<DFF> @@ -357,6 +357,8 @@ namespace AvaloniaEdit.Search
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
+
+ UpdateSearch();
}
public void ReplaceAll()
| 2 | update search after replace | 0 | .cs | cs | mit | AvaloniaUI/AvaloniaEdit |
10066853 | <NME> SearchPanel.cs
<BEF> // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.VisualTree;
using AvaloniaEdit.Document;
using AvaloniaEdit.Editing;
using AvaloniaEdit.Rendering;
namespace AvaloniaEdit.Search
{
/// <summary>
/// Provides search functionality for AvalonEdit. It is displayed in the top-right corner of the TextArea.
/// </summary>
public class SearchPanel : TemplatedControl, IRoutedCommandBindable
{
private TextArea _textArea;
private SearchInputHandler _handler;
private TextDocument _currentDocument;
private SearchResultBackgroundRenderer _renderer;
private TextBox _searchTextBox;
private TextEditor _textEditor { get; set; }
private Border _border;
#region DependencyProperties
/// <summary>
/// Dependency property for <see cref="UseRegex"/>.
/// </summary>
public static readonly StyledProperty<bool> UseRegexProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(UseRegex));
/// <summary>
/// Gets/sets whether the search pattern should be interpreted as regular expression.
/// </summary>
public bool UseRegex
{
get => GetValue(UseRegexProperty);
set => SetValue(UseRegexProperty, value);
}
/// <summary>
/// Dependency property for <see cref="MatchCase"/>.
/// </summary>
public static readonly StyledProperty<bool> MatchCaseProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(MatchCase));
/// <summary>
/// Gets/sets whether the search pattern should be interpreted case-sensitive.
/// </summary>
public bool MatchCase
{
get => GetValue(MatchCaseProperty);
set => SetValue(MatchCaseProperty, value);
}
/// <summary>
/// Dependency property for <see cref="WholeWords"/>.
/// </summary>
public static readonly StyledProperty<bool> WholeWordsProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(WholeWords));
/// <summary>
/// Gets/sets whether the search pattern should only match whole words.
/// </summary>
public bool WholeWords
{
get => GetValue(WholeWordsProperty);
set => SetValue(WholeWordsProperty, value);
}
/// <summary>
/// Dependency property for <see cref="SearchPattern"/>.
/// </summary>
public static readonly StyledProperty<string> SearchPatternProperty =
AvaloniaProperty.Register<SearchPanel, string>(nameof(SearchPattern), "");
/// <summary>
/// Gets/sets the search pattern.
/// </summary>
public string SearchPattern
{
get => GetValue(SearchPatternProperty);
set => SetValue(SearchPatternProperty, value);
}
public static readonly StyledProperty<bool> IsReplaceModeProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(IsReplaceMode));
/// <summary>
/// Checks if replacemode is allowed
/// </summary>
/// <returns>False if editor is not null and readonly</returns>
private static bool ValidateReplaceMode(SearchPanel panel, bool v1)
{
if (panel._textEditor == null || !v1) return v1;
return !panel._textEditor.IsReadOnly;
}
public bool IsReplaceMode
{
get => GetValue(IsReplaceModeProperty);
set => SetValue(IsReplaceModeProperty, _textEditor?.IsReadOnly ?? false ? false : value);
}
public static readonly StyledProperty<string> ReplacePatternProperty =
AvaloniaProperty.Register<SearchPanel, string>(nameof(ReplacePattern));
public string ReplacePattern
{
get => GetValue(ReplacePatternProperty);
set => SetValue(ReplacePatternProperty, value);
}
/// <summary>
/// Dependency property for <see cref="MarkerBrush"/>.
/// </summary>
public static readonly StyledProperty<IBrush> MarkerBrushProperty =
AvaloniaProperty.Register<SearchPanel, IBrush>(nameof(MarkerBrush), Brushes.LightGreen);
/// <summary>
/// Gets/sets the Brush used for marking search results in the TextView.
/// </summary>
public IBrush MarkerBrush
{
get => GetValue(MarkerBrushProperty);
set => SetValue(MarkerBrushProperty, value);
}
#endregion
private static void MarkerBrushChangedCallback(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is SearchPanel panel)
{
panel._renderer.MarkerBrush = (IBrush)e.NewValue;
}
}
private ISearchStrategy _strategy;
private static void SearchPatternChangedCallback(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is SearchPanel panel)
{
panel.ValidateSearchText();
panel.UpdateSearch();
}
}
private void UpdateSearch()
{
// only reset as long as there are results
// if no results are found, the "no matches found" message should not flicker.
// if results are found by the next run, the message will be hidden inside DoSearch ...
if (_renderer.CurrentResults.Any())
_messageView.IsOpen = false;
_strategy = SearchStrategyFactory.Create(SearchPattern ?? "", !MatchCase, WholeWords, UseRegex ? SearchMode.RegEx : SearchMode.Normal);
OnSearchOptionsChanged(new SearchOptionsChangedEventArgs(SearchPattern, MatchCase, UseRegex, WholeWords));
DoSearch(true);
}
static SearchPanel()
{
UseRegexProperty.Changed.Subscribe(SearchPatternChangedCallback);
MatchCaseProperty.Changed.Subscribe(SearchPatternChangedCallback);
WholeWordsProperty.Changed.Subscribe(SearchPatternChangedCallback);
SearchPatternProperty.Changed.Subscribe(SearchPatternChangedCallback);
MarkerBrushProperty.Changed.Subscribe(MarkerBrushChangedCallback);
}
/// <summary>
/// Creates a new SearchPanel.
/// </summary>
private SearchPanel()
{
}
/// <summary>
/// Creates a SearchPanel and installs it to the TextEditor's TextArea.
/// </summary>
/// <remarks>This is a convenience wrapper.</remarks>
public static SearchPanel Install(TextEditor editor)
{
if (editor == null) throw new ArgumentNullException(nameof(editor));
SearchPanel searchPanel = Install(editor.TextArea);
searchPanel._textEditor = editor;
return searchPanel;
}
/// <summary>
/// Creates a SearchPanel and installs it to the TextArea.
/// </summary>
public static SearchPanel Install(TextArea textArea)
{
if (textArea == null) throw new ArgumentNullException(nameof(textArea));
var panel = new SearchPanel();
panel.AttachInternal(textArea);
panel._handler = new SearchInputHandler(textArea, panel);
textArea.DefaultInputHandler.NestedInputHandlers.Add(panel._handler);
((ISetLogicalParent)panel).SetParent(textArea);
return panel;
}
/// <summary>
/// Adds the commands used by SearchPanel to the given CommandBindingCollection.
/// </summary>
public void RegisterCommands(ICollection<RoutedCommandBinding> commandBindings)
{
_handler.RegisterGlobalCommands(commandBindings);
}
/// <summary>
/// Removes the SearchPanel from the TextArea.
/// </summary>
public void Uninstall()
{
Close();
_textArea.DocumentChanged -= TextArea_DocumentChanged;
if (_currentDocument != null)
_currentDocument.TextChanged -= TextArea_Document_TextChanged;
_textArea.DefaultInputHandler.NestedInputHandlers.Remove(_handler);
}
private void AttachInternal(TextArea textArea)
{
_textArea = textArea;
_renderer = new SearchResultBackgroundRenderer();
_currentDocument = textArea.Document;
if (_currentDocument != null)
_currentDocument.TextChanged += TextArea_Document_TextChanged;
textArea.DocumentChanged += TextArea_DocumentChanged;
KeyDown += SearchLayerKeyDown;
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.FindNext, (sender, e) => FindNext()));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.FindPrevious, (sender, e) => FindPrevious()));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.CloseSearchPanel, (sender, e) => Close()));
CommandBindings.Add(new RoutedCommandBinding(ApplicationCommands.Find, (sender, e) =>
{
IsReplaceMode = false;
Reactivate();
}));
CommandBindings.Add(new RoutedCommandBinding(ApplicationCommands.Replace, (sender, e) => IsReplaceMode = true));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.ReplaceNext, (sender, e) => ReplaceNext(), (sender, e) => e.CanExecute = IsReplaceMode));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.ReplaceAll, (sender, e) => ReplaceAll(), (sender, e) => e.CanExecute = IsReplaceMode));
IsClosed = true;
}
private void TextArea_DocumentChanged(object sender, EventArgs e)
{
if (_currentDocument != null)
_currentDocument.TextChanged -= TextArea_Document_TextChanged;
_currentDocument = _textArea.Document;
if (_currentDocument != null)
{
_currentDocument.TextChanged += TextArea_Document_TextChanged;
DoSearch(false);
}
}
private void TextArea_Document_TextChanged(object sender, EventArgs e)
{
DoSearch(false);
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
_border = e.NameScope.Find<Border>("PART_Border");
_searchTextBox = e.NameScope.Find<TextBox>("PART_searchTextBox");
_messageView = e.NameScope.Find<Popup>("PART_MessageView");
_messageViewContent = e.NameScope.Find<ContentPresenter>("PART_MessageContent");
}
private void ValidateSearchText()
{
if (_searchTextBox == null)
return;
try
{
UpdateSearch();
_validationError = null;
}
catch (SearchPatternException ex)
{
_validationError = ex.Message;
}
}
/// <summary>
/// Reactivates the SearchPanel by setting the focus on the search box and selecting all text.
/// </summary>
public void Reactivate()
{
if (_searchTextBox == null)
return;
_searchTextBox.Focus();
_searchTextBox.SelectionStart = 0;
_searchTextBox.SelectionEnd = _searchTextBox.Text?.Length ?? 0;
}
/// <summary>
/// Moves to the next occurrence in the file.
/// </summary>
public void FindNext()
{
var result = _renderer.CurrentResults.FindFirstSegmentWithStartAfter(_textArea.Caret.Offset + 1) ??
_renderer.CurrentResults.FirstSegment;
if (result != null)
{
SelectResult(result);
}
}
/// <summary>
/// Moves to the previous occurrence in the file.
/// </summary>
public void FindPrevious()
{
var result = _renderer.CurrentResults.FindFirstSegmentWithStartAfter(_textArea.Caret.Offset);
if (result != null)
result = _renderer.CurrentResults.GetPreviousSegment(result);
if (result == null)
result = _renderer.CurrentResults.LastSegment;
if (result != null)
{
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
}
public void ReplaceAll()
FindNext();
if (!_textArea.Selection.IsEmpty)
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
UpdateSearch();
}
public void ReplaceAll()
{
if (!IsReplaceMode) return;
var replacement = ReplacePattern ?? string.Empty;
var document = _textArea.Document;
using (document.RunUpdate())
{
var segments = _renderer.CurrentResults.OrderByDescending(x => x.EndOffset).ToArray();
foreach (var textSegment in segments)
{
document.Replace(textSegment.StartOffset, textSegment.Length,
new StringTextSource(replacement));
}
}
}
private Popup _messageView;
private ContentPresenter _messageViewContent;
private string _validationError;
private void DoSearch(bool changeSelection)
{
if (IsClosed)
return;
_renderer.CurrentResults.Clear();
if (!string.IsNullOrEmpty(SearchPattern))
{
var offset = _textArea.Caret.Offset;
if (changeSelection)
{
_textArea.ClearSelection();
}
// We cast from ISearchResult to SearchResult; this is safe because we always use the built-in strategy
foreach (var result in _strategy.FindAll(_textArea.Document, 0, _textArea.Document.TextLength).Cast<SearchResult>())
{
if (changeSelection && result.StartOffset >= offset)
{
SelectResult(result);
changeSelection = false;
}
_renderer.CurrentResults.Add(result);
}
}
if (_messageView != null)
{
if (!_renderer.CurrentResults.Any())
{
_messageViewContent.Content = SR.SearchNoMatchesFoundText;
_messageView.PlacementTarget = _searchTextBox;
_messageView.IsOpen = true;
}
else
_messageView.IsOpen = false;
}
_textArea.TextView.InvalidateLayer(KnownLayer.Selection);
}
private void SelectResult(TextSegment result)
{
_textArea.Caret.Offset = result.StartOffset;
_textArea.Selection = Selection.Create(_textArea, result.StartOffset, result.EndOffset);
double distanceToViewBorder = _border == null ?
Caret.MinimumDistanceToViewBorder :
_border.Bounds.Height + _textArea.TextView.DefaultLineHeight;
_textArea.Caret.BringCaretToView(distanceToViewBorder);
// show caret even if the editor does not have the Keyboard Focus
_textArea.Caret.Show();
}
private void SearchLayerKeyDown(object sender, KeyEventArgs e)
{
switch (e.Key)
{
case Key.Enter:
e.Handled = true;
if (e.KeyModifiers.HasFlag(KeyModifiers.Shift))
{
FindPrevious();
}
else
{
FindNext();
}
if (_searchTextBox != null)
{
if (_validationError != null)
{
_messageViewContent.Content = SR.SearchErrorText + " " + _validationError;
_messageView.PlacementTarget = _searchTextBox;
_messageView.IsOpen = true;
}
}
break;
case Key.Escape:
e.Handled = true;
Close();
break;
}
}
/// <summary>
/// Gets whether the Panel is already closed.
/// </summary>
public bool IsClosed { get; private set; }
/// <summary>
/// Gets whether the Panel is currently opened.
/// </summary>
public bool IsOpened => !IsClosed;
/// <summary>
/// Closes the SearchPanel.
/// </summary>
public void Close()
{
_textArea.RemoveChild(this);
_messageView.IsOpen = false;
_textArea.TextView.BackgroundRenderers.Remove(_renderer);
IsClosed = true;
// Clear existing search results so that the segments don't have to be maintained
_renderer.CurrentResults.Clear();
_textArea.Focus();
}
/// <summary>
/// Opens the an existing search panel.
/// </summary>
public void Open()
{
if (!IsClosed) return;
_textArea.AddChild(this);
_textArea.TextView.BackgroundRenderers.Add(_renderer);
IsClosed = false;
DoSearch(false);
}
protected override void OnPointerPressed(PointerPressedEventArgs e)
{
e.Handled = true;
base.OnPointerPressed(e);
}
protected override void OnPointerMoved(PointerEventArgs e)
{
Cursor = Cursor.Default;
base.OnPointerMoved(e);
}
protected override void OnGotFocus(GotFocusEventArgs e)
{
e.Handled = true;
base.OnGotFocus(e);
}
/// <summary>
/// Fired when SearchOptions are changed inside the SearchPanel.
/// </summary>
public event EventHandler<SearchOptionsChangedEventArgs> SearchOptionsChanged;
/// <summary>
/// Raises the <see cref="SearchOptionsChanged" /> event.
/// </summary>
protected virtual void OnSearchOptionsChanged(SearchOptionsChangedEventArgs e)
{
SearchOptionsChanged?.Invoke(this, e);
}
public IList<RoutedCommandBinding> CommandBindings { get; } = new List<RoutedCommandBinding>();
}
/// <summary>
/// EventArgs for <see cref="SearchPanel.SearchOptionsChanged"/> event.
/// </summary>
public class SearchOptionsChangedEventArgs : EventArgs
{
/// <summary>
/// Gets the search pattern.
/// </summary>
public string SearchPattern { get; }
/// <summary>
/// Gets whether the search pattern should be interpreted case-sensitive.
/// </summary>
public bool MatchCase { get; }
/// <summary>
/// Gets whether the search pattern should be interpreted as regular expression.
/// </summary>
public bool UseRegex { get; }
/// <summary>
/// Gets whether the search pattern should only match whole words.
/// </summary>
public bool WholeWords { get; }
/// <summary>
/// Creates a new SearchOptionsChangedEventArgs instance.
/// </summary>
public SearchOptionsChangedEventArgs(string searchPattern, bool matchCase, bool useRegex, bool wholeWords)
{
SearchPattern = searchPattern;
MatchCase = matchCase;
UseRegex = useRegex;
WholeWords = wholeWords;
}
}
}
<MSG> update search after replace
<DFF> @@ -357,6 +357,8 @@ namespace AvaloniaEdit.Search
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
+
+ UpdateSearch();
}
public void ReplaceAll()
| 2 | update search after replace | 0 | .cs | cs | mit | AvaloniaUI/AvaloniaEdit |
10066854 | <NME> SearchPanel.cs
<BEF> // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.VisualTree;
using AvaloniaEdit.Document;
using AvaloniaEdit.Editing;
using AvaloniaEdit.Rendering;
namespace AvaloniaEdit.Search
{
/// <summary>
/// Provides search functionality for AvalonEdit. It is displayed in the top-right corner of the TextArea.
/// </summary>
public class SearchPanel : TemplatedControl, IRoutedCommandBindable
{
private TextArea _textArea;
private SearchInputHandler _handler;
private TextDocument _currentDocument;
private SearchResultBackgroundRenderer _renderer;
private TextBox _searchTextBox;
private TextEditor _textEditor { get; set; }
private Border _border;
#region DependencyProperties
/// <summary>
/// Dependency property for <see cref="UseRegex"/>.
/// </summary>
public static readonly StyledProperty<bool> UseRegexProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(UseRegex));
/// <summary>
/// Gets/sets whether the search pattern should be interpreted as regular expression.
/// </summary>
public bool UseRegex
{
get => GetValue(UseRegexProperty);
set => SetValue(UseRegexProperty, value);
}
/// <summary>
/// Dependency property for <see cref="MatchCase"/>.
/// </summary>
public static readonly StyledProperty<bool> MatchCaseProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(MatchCase));
/// <summary>
/// Gets/sets whether the search pattern should be interpreted case-sensitive.
/// </summary>
public bool MatchCase
{
get => GetValue(MatchCaseProperty);
set => SetValue(MatchCaseProperty, value);
}
/// <summary>
/// Dependency property for <see cref="WholeWords"/>.
/// </summary>
public static readonly StyledProperty<bool> WholeWordsProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(WholeWords));
/// <summary>
/// Gets/sets whether the search pattern should only match whole words.
/// </summary>
public bool WholeWords
{
get => GetValue(WholeWordsProperty);
set => SetValue(WholeWordsProperty, value);
}
/// <summary>
/// Dependency property for <see cref="SearchPattern"/>.
/// </summary>
public static readonly StyledProperty<string> SearchPatternProperty =
AvaloniaProperty.Register<SearchPanel, string>(nameof(SearchPattern), "");
/// <summary>
/// Gets/sets the search pattern.
/// </summary>
public string SearchPattern
{
get => GetValue(SearchPatternProperty);
set => SetValue(SearchPatternProperty, value);
}
public static readonly StyledProperty<bool> IsReplaceModeProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(IsReplaceMode));
/// <summary>
/// Checks if replacemode is allowed
/// </summary>
/// <returns>False if editor is not null and readonly</returns>
private static bool ValidateReplaceMode(SearchPanel panel, bool v1)
{
if (panel._textEditor == null || !v1) return v1;
return !panel._textEditor.IsReadOnly;
}
public bool IsReplaceMode
{
get => GetValue(IsReplaceModeProperty);
set => SetValue(IsReplaceModeProperty, _textEditor?.IsReadOnly ?? false ? false : value);
}
public static readonly StyledProperty<string> ReplacePatternProperty =
AvaloniaProperty.Register<SearchPanel, string>(nameof(ReplacePattern));
public string ReplacePattern
{
get => GetValue(ReplacePatternProperty);
set => SetValue(ReplacePatternProperty, value);
}
/// <summary>
/// Dependency property for <see cref="MarkerBrush"/>.
/// </summary>
public static readonly StyledProperty<IBrush> MarkerBrushProperty =
AvaloniaProperty.Register<SearchPanel, IBrush>(nameof(MarkerBrush), Brushes.LightGreen);
/// <summary>
/// Gets/sets the Brush used for marking search results in the TextView.
/// </summary>
public IBrush MarkerBrush
{
get => GetValue(MarkerBrushProperty);
set => SetValue(MarkerBrushProperty, value);
}
#endregion
private static void MarkerBrushChangedCallback(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is SearchPanel panel)
{
panel._renderer.MarkerBrush = (IBrush)e.NewValue;
}
}
private ISearchStrategy _strategy;
private static void SearchPatternChangedCallback(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is SearchPanel panel)
{
panel.ValidateSearchText();
panel.UpdateSearch();
}
}
private void UpdateSearch()
{
// only reset as long as there are results
// if no results are found, the "no matches found" message should not flicker.
// if results are found by the next run, the message will be hidden inside DoSearch ...
if (_renderer.CurrentResults.Any())
_messageView.IsOpen = false;
_strategy = SearchStrategyFactory.Create(SearchPattern ?? "", !MatchCase, WholeWords, UseRegex ? SearchMode.RegEx : SearchMode.Normal);
OnSearchOptionsChanged(new SearchOptionsChangedEventArgs(SearchPattern, MatchCase, UseRegex, WholeWords));
DoSearch(true);
}
static SearchPanel()
{
UseRegexProperty.Changed.Subscribe(SearchPatternChangedCallback);
MatchCaseProperty.Changed.Subscribe(SearchPatternChangedCallback);
WholeWordsProperty.Changed.Subscribe(SearchPatternChangedCallback);
SearchPatternProperty.Changed.Subscribe(SearchPatternChangedCallback);
MarkerBrushProperty.Changed.Subscribe(MarkerBrushChangedCallback);
}
/// <summary>
/// Creates a new SearchPanel.
/// </summary>
private SearchPanel()
{
}
/// <summary>
/// Creates a SearchPanel and installs it to the TextEditor's TextArea.
/// </summary>
/// <remarks>This is a convenience wrapper.</remarks>
public static SearchPanel Install(TextEditor editor)
{
if (editor == null) throw new ArgumentNullException(nameof(editor));
SearchPanel searchPanel = Install(editor.TextArea);
searchPanel._textEditor = editor;
return searchPanel;
}
/// <summary>
/// Creates a SearchPanel and installs it to the TextArea.
/// </summary>
public static SearchPanel Install(TextArea textArea)
{
if (textArea == null) throw new ArgumentNullException(nameof(textArea));
var panel = new SearchPanel();
panel.AttachInternal(textArea);
panel._handler = new SearchInputHandler(textArea, panel);
textArea.DefaultInputHandler.NestedInputHandlers.Add(panel._handler);
((ISetLogicalParent)panel).SetParent(textArea);
return panel;
}
/// <summary>
/// Adds the commands used by SearchPanel to the given CommandBindingCollection.
/// </summary>
public void RegisterCommands(ICollection<RoutedCommandBinding> commandBindings)
{
_handler.RegisterGlobalCommands(commandBindings);
}
/// <summary>
/// Removes the SearchPanel from the TextArea.
/// </summary>
public void Uninstall()
{
Close();
_textArea.DocumentChanged -= TextArea_DocumentChanged;
if (_currentDocument != null)
_currentDocument.TextChanged -= TextArea_Document_TextChanged;
_textArea.DefaultInputHandler.NestedInputHandlers.Remove(_handler);
}
private void AttachInternal(TextArea textArea)
{
_textArea = textArea;
_renderer = new SearchResultBackgroundRenderer();
_currentDocument = textArea.Document;
if (_currentDocument != null)
_currentDocument.TextChanged += TextArea_Document_TextChanged;
textArea.DocumentChanged += TextArea_DocumentChanged;
KeyDown += SearchLayerKeyDown;
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.FindNext, (sender, e) => FindNext()));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.FindPrevious, (sender, e) => FindPrevious()));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.CloseSearchPanel, (sender, e) => Close()));
CommandBindings.Add(new RoutedCommandBinding(ApplicationCommands.Find, (sender, e) =>
{
IsReplaceMode = false;
Reactivate();
}));
CommandBindings.Add(new RoutedCommandBinding(ApplicationCommands.Replace, (sender, e) => IsReplaceMode = true));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.ReplaceNext, (sender, e) => ReplaceNext(), (sender, e) => e.CanExecute = IsReplaceMode));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.ReplaceAll, (sender, e) => ReplaceAll(), (sender, e) => e.CanExecute = IsReplaceMode));
IsClosed = true;
}
private void TextArea_DocumentChanged(object sender, EventArgs e)
{
if (_currentDocument != null)
_currentDocument.TextChanged -= TextArea_Document_TextChanged;
_currentDocument = _textArea.Document;
if (_currentDocument != null)
{
_currentDocument.TextChanged += TextArea_Document_TextChanged;
DoSearch(false);
}
}
private void TextArea_Document_TextChanged(object sender, EventArgs e)
{
DoSearch(false);
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
_border = e.NameScope.Find<Border>("PART_Border");
_searchTextBox = e.NameScope.Find<TextBox>("PART_searchTextBox");
_messageView = e.NameScope.Find<Popup>("PART_MessageView");
_messageViewContent = e.NameScope.Find<ContentPresenter>("PART_MessageContent");
}
private void ValidateSearchText()
{
if (_searchTextBox == null)
return;
try
{
UpdateSearch();
_validationError = null;
}
catch (SearchPatternException ex)
{
_validationError = ex.Message;
}
}
/// <summary>
/// Reactivates the SearchPanel by setting the focus on the search box and selecting all text.
/// </summary>
public void Reactivate()
{
if (_searchTextBox == null)
return;
_searchTextBox.Focus();
_searchTextBox.SelectionStart = 0;
_searchTextBox.SelectionEnd = _searchTextBox.Text?.Length ?? 0;
}
/// <summary>
/// Moves to the next occurrence in the file.
/// </summary>
public void FindNext()
{
var result = _renderer.CurrentResults.FindFirstSegmentWithStartAfter(_textArea.Caret.Offset + 1) ??
_renderer.CurrentResults.FirstSegment;
if (result != null)
{
SelectResult(result);
}
}
/// <summary>
/// Moves to the previous occurrence in the file.
/// </summary>
public void FindPrevious()
{
var result = _renderer.CurrentResults.FindFirstSegmentWithStartAfter(_textArea.Caret.Offset);
if (result != null)
result = _renderer.CurrentResults.GetPreviousSegment(result);
if (result == null)
result = _renderer.CurrentResults.LastSegment;
if (result != null)
{
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
}
public void ReplaceAll()
FindNext();
if (!_textArea.Selection.IsEmpty)
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
UpdateSearch();
}
public void ReplaceAll()
{
if (!IsReplaceMode) return;
var replacement = ReplacePattern ?? string.Empty;
var document = _textArea.Document;
using (document.RunUpdate())
{
var segments = _renderer.CurrentResults.OrderByDescending(x => x.EndOffset).ToArray();
foreach (var textSegment in segments)
{
document.Replace(textSegment.StartOffset, textSegment.Length,
new StringTextSource(replacement));
}
}
}
private Popup _messageView;
private ContentPresenter _messageViewContent;
private string _validationError;
private void DoSearch(bool changeSelection)
{
if (IsClosed)
return;
_renderer.CurrentResults.Clear();
if (!string.IsNullOrEmpty(SearchPattern))
{
var offset = _textArea.Caret.Offset;
if (changeSelection)
{
_textArea.ClearSelection();
}
// We cast from ISearchResult to SearchResult; this is safe because we always use the built-in strategy
foreach (var result in _strategy.FindAll(_textArea.Document, 0, _textArea.Document.TextLength).Cast<SearchResult>())
{
if (changeSelection && result.StartOffset >= offset)
{
SelectResult(result);
changeSelection = false;
}
_renderer.CurrentResults.Add(result);
}
}
if (_messageView != null)
{
if (!_renderer.CurrentResults.Any())
{
_messageViewContent.Content = SR.SearchNoMatchesFoundText;
_messageView.PlacementTarget = _searchTextBox;
_messageView.IsOpen = true;
}
else
_messageView.IsOpen = false;
}
_textArea.TextView.InvalidateLayer(KnownLayer.Selection);
}
private void SelectResult(TextSegment result)
{
_textArea.Caret.Offset = result.StartOffset;
_textArea.Selection = Selection.Create(_textArea, result.StartOffset, result.EndOffset);
double distanceToViewBorder = _border == null ?
Caret.MinimumDistanceToViewBorder :
_border.Bounds.Height + _textArea.TextView.DefaultLineHeight;
_textArea.Caret.BringCaretToView(distanceToViewBorder);
// show caret even if the editor does not have the Keyboard Focus
_textArea.Caret.Show();
}
private void SearchLayerKeyDown(object sender, KeyEventArgs e)
{
switch (e.Key)
{
case Key.Enter:
e.Handled = true;
if (e.KeyModifiers.HasFlag(KeyModifiers.Shift))
{
FindPrevious();
}
else
{
FindNext();
}
if (_searchTextBox != null)
{
if (_validationError != null)
{
_messageViewContent.Content = SR.SearchErrorText + " " + _validationError;
_messageView.PlacementTarget = _searchTextBox;
_messageView.IsOpen = true;
}
}
break;
case Key.Escape:
e.Handled = true;
Close();
break;
}
}
/// <summary>
/// Gets whether the Panel is already closed.
/// </summary>
public bool IsClosed { get; private set; }
/// <summary>
/// Gets whether the Panel is currently opened.
/// </summary>
public bool IsOpened => !IsClosed;
/// <summary>
/// Closes the SearchPanel.
/// </summary>
public void Close()
{
_textArea.RemoveChild(this);
_messageView.IsOpen = false;
_textArea.TextView.BackgroundRenderers.Remove(_renderer);
IsClosed = true;
// Clear existing search results so that the segments don't have to be maintained
_renderer.CurrentResults.Clear();
_textArea.Focus();
}
/// <summary>
/// Opens the an existing search panel.
/// </summary>
public void Open()
{
if (!IsClosed) return;
_textArea.AddChild(this);
_textArea.TextView.BackgroundRenderers.Add(_renderer);
IsClosed = false;
DoSearch(false);
}
protected override void OnPointerPressed(PointerPressedEventArgs e)
{
e.Handled = true;
base.OnPointerPressed(e);
}
protected override void OnPointerMoved(PointerEventArgs e)
{
Cursor = Cursor.Default;
base.OnPointerMoved(e);
}
protected override void OnGotFocus(GotFocusEventArgs e)
{
e.Handled = true;
base.OnGotFocus(e);
}
/// <summary>
/// Fired when SearchOptions are changed inside the SearchPanel.
/// </summary>
public event EventHandler<SearchOptionsChangedEventArgs> SearchOptionsChanged;
/// <summary>
/// Raises the <see cref="SearchOptionsChanged" /> event.
/// </summary>
protected virtual void OnSearchOptionsChanged(SearchOptionsChangedEventArgs e)
{
SearchOptionsChanged?.Invoke(this, e);
}
public IList<RoutedCommandBinding> CommandBindings { get; } = new List<RoutedCommandBinding>();
}
/// <summary>
/// EventArgs for <see cref="SearchPanel.SearchOptionsChanged"/> event.
/// </summary>
public class SearchOptionsChangedEventArgs : EventArgs
{
/// <summary>
/// Gets the search pattern.
/// </summary>
public string SearchPattern { get; }
/// <summary>
/// Gets whether the search pattern should be interpreted case-sensitive.
/// </summary>
public bool MatchCase { get; }
/// <summary>
/// Gets whether the search pattern should be interpreted as regular expression.
/// </summary>
public bool UseRegex { get; }
/// <summary>
/// Gets whether the search pattern should only match whole words.
/// </summary>
public bool WholeWords { get; }
/// <summary>
/// Creates a new SearchOptionsChangedEventArgs instance.
/// </summary>
public SearchOptionsChangedEventArgs(string searchPattern, bool matchCase, bool useRegex, bool wholeWords)
{
SearchPattern = searchPattern;
MatchCase = matchCase;
UseRegex = useRegex;
WholeWords = wholeWords;
}
}
}
<MSG> update search after replace
<DFF> @@ -357,6 +357,8 @@ namespace AvaloniaEdit.Search
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
+
+ UpdateSearch();
}
public void ReplaceAll()
| 2 | update search after replace | 0 | .cs | cs | mit | AvaloniaUI/AvaloniaEdit |
10066855 | <NME> SearchPanel.cs
<BEF> // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.VisualTree;
using AvaloniaEdit.Document;
using AvaloniaEdit.Editing;
using AvaloniaEdit.Rendering;
namespace AvaloniaEdit.Search
{
/// <summary>
/// Provides search functionality for AvalonEdit. It is displayed in the top-right corner of the TextArea.
/// </summary>
public class SearchPanel : TemplatedControl, IRoutedCommandBindable
{
private TextArea _textArea;
private SearchInputHandler _handler;
private TextDocument _currentDocument;
private SearchResultBackgroundRenderer _renderer;
private TextBox _searchTextBox;
private TextEditor _textEditor { get; set; }
private Border _border;
#region DependencyProperties
/// <summary>
/// Dependency property for <see cref="UseRegex"/>.
/// </summary>
public static readonly StyledProperty<bool> UseRegexProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(UseRegex));
/// <summary>
/// Gets/sets whether the search pattern should be interpreted as regular expression.
/// </summary>
public bool UseRegex
{
get => GetValue(UseRegexProperty);
set => SetValue(UseRegexProperty, value);
}
/// <summary>
/// Dependency property for <see cref="MatchCase"/>.
/// </summary>
public static readonly StyledProperty<bool> MatchCaseProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(MatchCase));
/// <summary>
/// Gets/sets whether the search pattern should be interpreted case-sensitive.
/// </summary>
public bool MatchCase
{
get => GetValue(MatchCaseProperty);
set => SetValue(MatchCaseProperty, value);
}
/// <summary>
/// Dependency property for <see cref="WholeWords"/>.
/// </summary>
public static readonly StyledProperty<bool> WholeWordsProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(WholeWords));
/// <summary>
/// Gets/sets whether the search pattern should only match whole words.
/// </summary>
public bool WholeWords
{
get => GetValue(WholeWordsProperty);
set => SetValue(WholeWordsProperty, value);
}
/// <summary>
/// Dependency property for <see cref="SearchPattern"/>.
/// </summary>
public static readonly StyledProperty<string> SearchPatternProperty =
AvaloniaProperty.Register<SearchPanel, string>(nameof(SearchPattern), "");
/// <summary>
/// Gets/sets the search pattern.
/// </summary>
public string SearchPattern
{
get => GetValue(SearchPatternProperty);
set => SetValue(SearchPatternProperty, value);
}
public static readonly StyledProperty<bool> IsReplaceModeProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(IsReplaceMode));
/// <summary>
/// Checks if replacemode is allowed
/// </summary>
/// <returns>False if editor is not null and readonly</returns>
private static bool ValidateReplaceMode(SearchPanel panel, bool v1)
{
if (panel._textEditor == null || !v1) return v1;
return !panel._textEditor.IsReadOnly;
}
public bool IsReplaceMode
{
get => GetValue(IsReplaceModeProperty);
set => SetValue(IsReplaceModeProperty, _textEditor?.IsReadOnly ?? false ? false : value);
}
public static readonly StyledProperty<string> ReplacePatternProperty =
AvaloniaProperty.Register<SearchPanel, string>(nameof(ReplacePattern));
public string ReplacePattern
{
get => GetValue(ReplacePatternProperty);
set => SetValue(ReplacePatternProperty, value);
}
/// <summary>
/// Dependency property for <see cref="MarkerBrush"/>.
/// </summary>
public static readonly StyledProperty<IBrush> MarkerBrushProperty =
AvaloniaProperty.Register<SearchPanel, IBrush>(nameof(MarkerBrush), Brushes.LightGreen);
/// <summary>
/// Gets/sets the Brush used for marking search results in the TextView.
/// </summary>
public IBrush MarkerBrush
{
get => GetValue(MarkerBrushProperty);
set => SetValue(MarkerBrushProperty, value);
}
#endregion
private static void MarkerBrushChangedCallback(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is SearchPanel panel)
{
panel._renderer.MarkerBrush = (IBrush)e.NewValue;
}
}
private ISearchStrategy _strategy;
private static void SearchPatternChangedCallback(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is SearchPanel panel)
{
panel.ValidateSearchText();
panel.UpdateSearch();
}
}
private void UpdateSearch()
{
// only reset as long as there are results
// if no results are found, the "no matches found" message should not flicker.
// if results are found by the next run, the message will be hidden inside DoSearch ...
if (_renderer.CurrentResults.Any())
_messageView.IsOpen = false;
_strategy = SearchStrategyFactory.Create(SearchPattern ?? "", !MatchCase, WholeWords, UseRegex ? SearchMode.RegEx : SearchMode.Normal);
OnSearchOptionsChanged(new SearchOptionsChangedEventArgs(SearchPattern, MatchCase, UseRegex, WholeWords));
DoSearch(true);
}
static SearchPanel()
{
UseRegexProperty.Changed.Subscribe(SearchPatternChangedCallback);
MatchCaseProperty.Changed.Subscribe(SearchPatternChangedCallback);
WholeWordsProperty.Changed.Subscribe(SearchPatternChangedCallback);
SearchPatternProperty.Changed.Subscribe(SearchPatternChangedCallback);
MarkerBrushProperty.Changed.Subscribe(MarkerBrushChangedCallback);
}
/// <summary>
/// Creates a new SearchPanel.
/// </summary>
private SearchPanel()
{
}
/// <summary>
/// Creates a SearchPanel and installs it to the TextEditor's TextArea.
/// </summary>
/// <remarks>This is a convenience wrapper.</remarks>
public static SearchPanel Install(TextEditor editor)
{
if (editor == null) throw new ArgumentNullException(nameof(editor));
SearchPanel searchPanel = Install(editor.TextArea);
searchPanel._textEditor = editor;
return searchPanel;
}
/// <summary>
/// Creates a SearchPanel and installs it to the TextArea.
/// </summary>
public static SearchPanel Install(TextArea textArea)
{
if (textArea == null) throw new ArgumentNullException(nameof(textArea));
var panel = new SearchPanel();
panel.AttachInternal(textArea);
panel._handler = new SearchInputHandler(textArea, panel);
textArea.DefaultInputHandler.NestedInputHandlers.Add(panel._handler);
((ISetLogicalParent)panel).SetParent(textArea);
return panel;
}
/// <summary>
/// Adds the commands used by SearchPanel to the given CommandBindingCollection.
/// </summary>
public void RegisterCommands(ICollection<RoutedCommandBinding> commandBindings)
{
_handler.RegisterGlobalCommands(commandBindings);
}
/// <summary>
/// Removes the SearchPanel from the TextArea.
/// </summary>
public void Uninstall()
{
Close();
_textArea.DocumentChanged -= TextArea_DocumentChanged;
if (_currentDocument != null)
_currentDocument.TextChanged -= TextArea_Document_TextChanged;
_textArea.DefaultInputHandler.NestedInputHandlers.Remove(_handler);
}
private void AttachInternal(TextArea textArea)
{
_textArea = textArea;
_renderer = new SearchResultBackgroundRenderer();
_currentDocument = textArea.Document;
if (_currentDocument != null)
_currentDocument.TextChanged += TextArea_Document_TextChanged;
textArea.DocumentChanged += TextArea_DocumentChanged;
KeyDown += SearchLayerKeyDown;
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.FindNext, (sender, e) => FindNext()));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.FindPrevious, (sender, e) => FindPrevious()));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.CloseSearchPanel, (sender, e) => Close()));
CommandBindings.Add(new RoutedCommandBinding(ApplicationCommands.Find, (sender, e) =>
{
IsReplaceMode = false;
Reactivate();
}));
CommandBindings.Add(new RoutedCommandBinding(ApplicationCommands.Replace, (sender, e) => IsReplaceMode = true));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.ReplaceNext, (sender, e) => ReplaceNext(), (sender, e) => e.CanExecute = IsReplaceMode));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.ReplaceAll, (sender, e) => ReplaceAll(), (sender, e) => e.CanExecute = IsReplaceMode));
IsClosed = true;
}
private void TextArea_DocumentChanged(object sender, EventArgs e)
{
if (_currentDocument != null)
_currentDocument.TextChanged -= TextArea_Document_TextChanged;
_currentDocument = _textArea.Document;
if (_currentDocument != null)
{
_currentDocument.TextChanged += TextArea_Document_TextChanged;
DoSearch(false);
}
}
private void TextArea_Document_TextChanged(object sender, EventArgs e)
{
DoSearch(false);
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
_border = e.NameScope.Find<Border>("PART_Border");
_searchTextBox = e.NameScope.Find<TextBox>("PART_searchTextBox");
_messageView = e.NameScope.Find<Popup>("PART_MessageView");
_messageViewContent = e.NameScope.Find<ContentPresenter>("PART_MessageContent");
}
private void ValidateSearchText()
{
if (_searchTextBox == null)
return;
try
{
UpdateSearch();
_validationError = null;
}
catch (SearchPatternException ex)
{
_validationError = ex.Message;
}
}
/// <summary>
/// Reactivates the SearchPanel by setting the focus on the search box and selecting all text.
/// </summary>
public void Reactivate()
{
if (_searchTextBox == null)
return;
_searchTextBox.Focus();
_searchTextBox.SelectionStart = 0;
_searchTextBox.SelectionEnd = _searchTextBox.Text?.Length ?? 0;
}
/// <summary>
/// Moves to the next occurrence in the file.
/// </summary>
public void FindNext()
{
var result = _renderer.CurrentResults.FindFirstSegmentWithStartAfter(_textArea.Caret.Offset + 1) ??
_renderer.CurrentResults.FirstSegment;
if (result != null)
{
SelectResult(result);
}
}
/// <summary>
/// Moves to the previous occurrence in the file.
/// </summary>
public void FindPrevious()
{
var result = _renderer.CurrentResults.FindFirstSegmentWithStartAfter(_textArea.Caret.Offset);
if (result != null)
result = _renderer.CurrentResults.GetPreviousSegment(result);
if (result == null)
result = _renderer.CurrentResults.LastSegment;
if (result != null)
{
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
}
public void ReplaceAll()
FindNext();
if (!_textArea.Selection.IsEmpty)
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
UpdateSearch();
}
public void ReplaceAll()
{
if (!IsReplaceMode) return;
var replacement = ReplacePattern ?? string.Empty;
var document = _textArea.Document;
using (document.RunUpdate())
{
var segments = _renderer.CurrentResults.OrderByDescending(x => x.EndOffset).ToArray();
foreach (var textSegment in segments)
{
document.Replace(textSegment.StartOffset, textSegment.Length,
new StringTextSource(replacement));
}
}
}
private Popup _messageView;
private ContentPresenter _messageViewContent;
private string _validationError;
private void DoSearch(bool changeSelection)
{
if (IsClosed)
return;
_renderer.CurrentResults.Clear();
if (!string.IsNullOrEmpty(SearchPattern))
{
var offset = _textArea.Caret.Offset;
if (changeSelection)
{
_textArea.ClearSelection();
}
// We cast from ISearchResult to SearchResult; this is safe because we always use the built-in strategy
foreach (var result in _strategy.FindAll(_textArea.Document, 0, _textArea.Document.TextLength).Cast<SearchResult>())
{
if (changeSelection && result.StartOffset >= offset)
{
SelectResult(result);
changeSelection = false;
}
_renderer.CurrentResults.Add(result);
}
}
if (_messageView != null)
{
if (!_renderer.CurrentResults.Any())
{
_messageViewContent.Content = SR.SearchNoMatchesFoundText;
_messageView.PlacementTarget = _searchTextBox;
_messageView.IsOpen = true;
}
else
_messageView.IsOpen = false;
}
_textArea.TextView.InvalidateLayer(KnownLayer.Selection);
}
private void SelectResult(TextSegment result)
{
_textArea.Caret.Offset = result.StartOffset;
_textArea.Selection = Selection.Create(_textArea, result.StartOffset, result.EndOffset);
double distanceToViewBorder = _border == null ?
Caret.MinimumDistanceToViewBorder :
_border.Bounds.Height + _textArea.TextView.DefaultLineHeight;
_textArea.Caret.BringCaretToView(distanceToViewBorder);
// show caret even if the editor does not have the Keyboard Focus
_textArea.Caret.Show();
}
private void SearchLayerKeyDown(object sender, KeyEventArgs e)
{
switch (e.Key)
{
case Key.Enter:
e.Handled = true;
if (e.KeyModifiers.HasFlag(KeyModifiers.Shift))
{
FindPrevious();
}
else
{
FindNext();
}
if (_searchTextBox != null)
{
if (_validationError != null)
{
_messageViewContent.Content = SR.SearchErrorText + " " + _validationError;
_messageView.PlacementTarget = _searchTextBox;
_messageView.IsOpen = true;
}
}
break;
case Key.Escape:
e.Handled = true;
Close();
break;
}
}
/// <summary>
/// Gets whether the Panel is already closed.
/// </summary>
public bool IsClosed { get; private set; }
/// <summary>
/// Gets whether the Panel is currently opened.
/// </summary>
public bool IsOpened => !IsClosed;
/// <summary>
/// Closes the SearchPanel.
/// </summary>
public void Close()
{
_textArea.RemoveChild(this);
_messageView.IsOpen = false;
_textArea.TextView.BackgroundRenderers.Remove(_renderer);
IsClosed = true;
// Clear existing search results so that the segments don't have to be maintained
_renderer.CurrentResults.Clear();
_textArea.Focus();
}
/// <summary>
/// Opens the an existing search panel.
/// </summary>
public void Open()
{
if (!IsClosed) return;
_textArea.AddChild(this);
_textArea.TextView.BackgroundRenderers.Add(_renderer);
IsClosed = false;
DoSearch(false);
}
protected override void OnPointerPressed(PointerPressedEventArgs e)
{
e.Handled = true;
base.OnPointerPressed(e);
}
protected override void OnPointerMoved(PointerEventArgs e)
{
Cursor = Cursor.Default;
base.OnPointerMoved(e);
}
protected override void OnGotFocus(GotFocusEventArgs e)
{
e.Handled = true;
base.OnGotFocus(e);
}
/// <summary>
/// Fired when SearchOptions are changed inside the SearchPanel.
/// </summary>
public event EventHandler<SearchOptionsChangedEventArgs> SearchOptionsChanged;
/// <summary>
/// Raises the <see cref="SearchOptionsChanged" /> event.
/// </summary>
protected virtual void OnSearchOptionsChanged(SearchOptionsChangedEventArgs e)
{
SearchOptionsChanged?.Invoke(this, e);
}
public IList<RoutedCommandBinding> CommandBindings { get; } = new List<RoutedCommandBinding>();
}
/// <summary>
/// EventArgs for <see cref="SearchPanel.SearchOptionsChanged"/> event.
/// </summary>
public class SearchOptionsChangedEventArgs : EventArgs
{
/// <summary>
/// Gets the search pattern.
/// </summary>
public string SearchPattern { get; }
/// <summary>
/// Gets whether the search pattern should be interpreted case-sensitive.
/// </summary>
public bool MatchCase { get; }
/// <summary>
/// Gets whether the search pattern should be interpreted as regular expression.
/// </summary>
public bool UseRegex { get; }
/// <summary>
/// Gets whether the search pattern should only match whole words.
/// </summary>
public bool WholeWords { get; }
/// <summary>
/// Creates a new SearchOptionsChangedEventArgs instance.
/// </summary>
public SearchOptionsChangedEventArgs(string searchPattern, bool matchCase, bool useRegex, bool wholeWords)
{
SearchPattern = searchPattern;
MatchCase = matchCase;
UseRegex = useRegex;
WholeWords = wholeWords;
}
}
}
<MSG> update search after replace
<DFF> @@ -357,6 +357,8 @@ namespace AvaloniaEdit.Search
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
+
+ UpdateSearch();
}
public void ReplaceAll()
| 2 | update search after replace | 0 | .cs | cs | mit | AvaloniaUI/AvaloniaEdit |
10066856 | <NME> SearchPanel.cs
<BEF> // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.VisualTree;
using AvaloniaEdit.Document;
using AvaloniaEdit.Editing;
using AvaloniaEdit.Rendering;
namespace AvaloniaEdit.Search
{
/// <summary>
/// Provides search functionality for AvalonEdit. It is displayed in the top-right corner of the TextArea.
/// </summary>
public class SearchPanel : TemplatedControl, IRoutedCommandBindable
{
private TextArea _textArea;
private SearchInputHandler _handler;
private TextDocument _currentDocument;
private SearchResultBackgroundRenderer _renderer;
private TextBox _searchTextBox;
private TextEditor _textEditor { get; set; }
private Border _border;
#region DependencyProperties
/// <summary>
/// Dependency property for <see cref="UseRegex"/>.
/// </summary>
public static readonly StyledProperty<bool> UseRegexProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(UseRegex));
/// <summary>
/// Gets/sets whether the search pattern should be interpreted as regular expression.
/// </summary>
public bool UseRegex
{
get => GetValue(UseRegexProperty);
set => SetValue(UseRegexProperty, value);
}
/// <summary>
/// Dependency property for <see cref="MatchCase"/>.
/// </summary>
public static readonly StyledProperty<bool> MatchCaseProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(MatchCase));
/// <summary>
/// Gets/sets whether the search pattern should be interpreted case-sensitive.
/// </summary>
public bool MatchCase
{
get => GetValue(MatchCaseProperty);
set => SetValue(MatchCaseProperty, value);
}
/// <summary>
/// Dependency property for <see cref="WholeWords"/>.
/// </summary>
public static readonly StyledProperty<bool> WholeWordsProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(WholeWords));
/// <summary>
/// Gets/sets whether the search pattern should only match whole words.
/// </summary>
public bool WholeWords
{
get => GetValue(WholeWordsProperty);
set => SetValue(WholeWordsProperty, value);
}
/// <summary>
/// Dependency property for <see cref="SearchPattern"/>.
/// </summary>
public static readonly StyledProperty<string> SearchPatternProperty =
AvaloniaProperty.Register<SearchPanel, string>(nameof(SearchPattern), "");
/// <summary>
/// Gets/sets the search pattern.
/// </summary>
public string SearchPattern
{
get => GetValue(SearchPatternProperty);
set => SetValue(SearchPatternProperty, value);
}
public static readonly StyledProperty<bool> IsReplaceModeProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(IsReplaceMode));
/// <summary>
/// Checks if replacemode is allowed
/// </summary>
/// <returns>False if editor is not null and readonly</returns>
private static bool ValidateReplaceMode(SearchPanel panel, bool v1)
{
if (panel._textEditor == null || !v1) return v1;
return !panel._textEditor.IsReadOnly;
}
public bool IsReplaceMode
{
get => GetValue(IsReplaceModeProperty);
set => SetValue(IsReplaceModeProperty, _textEditor?.IsReadOnly ?? false ? false : value);
}
public static readonly StyledProperty<string> ReplacePatternProperty =
AvaloniaProperty.Register<SearchPanel, string>(nameof(ReplacePattern));
public string ReplacePattern
{
get => GetValue(ReplacePatternProperty);
set => SetValue(ReplacePatternProperty, value);
}
/// <summary>
/// Dependency property for <see cref="MarkerBrush"/>.
/// </summary>
public static readonly StyledProperty<IBrush> MarkerBrushProperty =
AvaloniaProperty.Register<SearchPanel, IBrush>(nameof(MarkerBrush), Brushes.LightGreen);
/// <summary>
/// Gets/sets the Brush used for marking search results in the TextView.
/// </summary>
public IBrush MarkerBrush
{
get => GetValue(MarkerBrushProperty);
set => SetValue(MarkerBrushProperty, value);
}
#endregion
private static void MarkerBrushChangedCallback(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is SearchPanel panel)
{
panel._renderer.MarkerBrush = (IBrush)e.NewValue;
}
}
private ISearchStrategy _strategy;
private static void SearchPatternChangedCallback(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is SearchPanel panel)
{
panel.ValidateSearchText();
panel.UpdateSearch();
}
}
private void UpdateSearch()
{
// only reset as long as there are results
// if no results are found, the "no matches found" message should not flicker.
// if results are found by the next run, the message will be hidden inside DoSearch ...
if (_renderer.CurrentResults.Any())
_messageView.IsOpen = false;
_strategy = SearchStrategyFactory.Create(SearchPattern ?? "", !MatchCase, WholeWords, UseRegex ? SearchMode.RegEx : SearchMode.Normal);
OnSearchOptionsChanged(new SearchOptionsChangedEventArgs(SearchPattern, MatchCase, UseRegex, WholeWords));
DoSearch(true);
}
static SearchPanel()
{
UseRegexProperty.Changed.Subscribe(SearchPatternChangedCallback);
MatchCaseProperty.Changed.Subscribe(SearchPatternChangedCallback);
WholeWordsProperty.Changed.Subscribe(SearchPatternChangedCallback);
SearchPatternProperty.Changed.Subscribe(SearchPatternChangedCallback);
MarkerBrushProperty.Changed.Subscribe(MarkerBrushChangedCallback);
}
/// <summary>
/// Creates a new SearchPanel.
/// </summary>
private SearchPanel()
{
}
/// <summary>
/// Creates a SearchPanel and installs it to the TextEditor's TextArea.
/// </summary>
/// <remarks>This is a convenience wrapper.</remarks>
public static SearchPanel Install(TextEditor editor)
{
if (editor == null) throw new ArgumentNullException(nameof(editor));
SearchPanel searchPanel = Install(editor.TextArea);
searchPanel._textEditor = editor;
return searchPanel;
}
/// <summary>
/// Creates a SearchPanel and installs it to the TextArea.
/// </summary>
public static SearchPanel Install(TextArea textArea)
{
if (textArea == null) throw new ArgumentNullException(nameof(textArea));
var panel = new SearchPanel();
panel.AttachInternal(textArea);
panel._handler = new SearchInputHandler(textArea, panel);
textArea.DefaultInputHandler.NestedInputHandlers.Add(panel._handler);
((ISetLogicalParent)panel).SetParent(textArea);
return panel;
}
/// <summary>
/// Adds the commands used by SearchPanel to the given CommandBindingCollection.
/// </summary>
public void RegisterCommands(ICollection<RoutedCommandBinding> commandBindings)
{
_handler.RegisterGlobalCommands(commandBindings);
}
/// <summary>
/// Removes the SearchPanel from the TextArea.
/// </summary>
public void Uninstall()
{
Close();
_textArea.DocumentChanged -= TextArea_DocumentChanged;
if (_currentDocument != null)
_currentDocument.TextChanged -= TextArea_Document_TextChanged;
_textArea.DefaultInputHandler.NestedInputHandlers.Remove(_handler);
}
private void AttachInternal(TextArea textArea)
{
_textArea = textArea;
_renderer = new SearchResultBackgroundRenderer();
_currentDocument = textArea.Document;
if (_currentDocument != null)
_currentDocument.TextChanged += TextArea_Document_TextChanged;
textArea.DocumentChanged += TextArea_DocumentChanged;
KeyDown += SearchLayerKeyDown;
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.FindNext, (sender, e) => FindNext()));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.FindPrevious, (sender, e) => FindPrevious()));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.CloseSearchPanel, (sender, e) => Close()));
CommandBindings.Add(new RoutedCommandBinding(ApplicationCommands.Find, (sender, e) =>
{
IsReplaceMode = false;
Reactivate();
}));
CommandBindings.Add(new RoutedCommandBinding(ApplicationCommands.Replace, (sender, e) => IsReplaceMode = true));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.ReplaceNext, (sender, e) => ReplaceNext(), (sender, e) => e.CanExecute = IsReplaceMode));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.ReplaceAll, (sender, e) => ReplaceAll(), (sender, e) => e.CanExecute = IsReplaceMode));
IsClosed = true;
}
private void TextArea_DocumentChanged(object sender, EventArgs e)
{
if (_currentDocument != null)
_currentDocument.TextChanged -= TextArea_Document_TextChanged;
_currentDocument = _textArea.Document;
if (_currentDocument != null)
{
_currentDocument.TextChanged += TextArea_Document_TextChanged;
DoSearch(false);
}
}
private void TextArea_Document_TextChanged(object sender, EventArgs e)
{
DoSearch(false);
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
_border = e.NameScope.Find<Border>("PART_Border");
_searchTextBox = e.NameScope.Find<TextBox>("PART_searchTextBox");
_messageView = e.NameScope.Find<Popup>("PART_MessageView");
_messageViewContent = e.NameScope.Find<ContentPresenter>("PART_MessageContent");
}
private void ValidateSearchText()
{
if (_searchTextBox == null)
return;
try
{
UpdateSearch();
_validationError = null;
}
catch (SearchPatternException ex)
{
_validationError = ex.Message;
}
}
/// <summary>
/// Reactivates the SearchPanel by setting the focus on the search box and selecting all text.
/// </summary>
public void Reactivate()
{
if (_searchTextBox == null)
return;
_searchTextBox.Focus();
_searchTextBox.SelectionStart = 0;
_searchTextBox.SelectionEnd = _searchTextBox.Text?.Length ?? 0;
}
/// <summary>
/// Moves to the next occurrence in the file.
/// </summary>
public void FindNext()
{
var result = _renderer.CurrentResults.FindFirstSegmentWithStartAfter(_textArea.Caret.Offset + 1) ??
_renderer.CurrentResults.FirstSegment;
if (result != null)
{
SelectResult(result);
}
}
/// <summary>
/// Moves to the previous occurrence in the file.
/// </summary>
public void FindPrevious()
{
var result = _renderer.CurrentResults.FindFirstSegmentWithStartAfter(_textArea.Caret.Offset);
if (result != null)
result = _renderer.CurrentResults.GetPreviousSegment(result);
if (result == null)
result = _renderer.CurrentResults.LastSegment;
if (result != null)
{
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
}
public void ReplaceAll()
FindNext();
if (!_textArea.Selection.IsEmpty)
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
UpdateSearch();
}
public void ReplaceAll()
{
if (!IsReplaceMode) return;
var replacement = ReplacePattern ?? string.Empty;
var document = _textArea.Document;
using (document.RunUpdate())
{
var segments = _renderer.CurrentResults.OrderByDescending(x => x.EndOffset).ToArray();
foreach (var textSegment in segments)
{
document.Replace(textSegment.StartOffset, textSegment.Length,
new StringTextSource(replacement));
}
}
}
private Popup _messageView;
private ContentPresenter _messageViewContent;
private string _validationError;
private void DoSearch(bool changeSelection)
{
if (IsClosed)
return;
_renderer.CurrentResults.Clear();
if (!string.IsNullOrEmpty(SearchPattern))
{
var offset = _textArea.Caret.Offset;
if (changeSelection)
{
_textArea.ClearSelection();
}
// We cast from ISearchResult to SearchResult; this is safe because we always use the built-in strategy
foreach (var result in _strategy.FindAll(_textArea.Document, 0, _textArea.Document.TextLength).Cast<SearchResult>())
{
if (changeSelection && result.StartOffset >= offset)
{
SelectResult(result);
changeSelection = false;
}
_renderer.CurrentResults.Add(result);
}
}
if (_messageView != null)
{
if (!_renderer.CurrentResults.Any())
{
_messageViewContent.Content = SR.SearchNoMatchesFoundText;
_messageView.PlacementTarget = _searchTextBox;
_messageView.IsOpen = true;
}
else
_messageView.IsOpen = false;
}
_textArea.TextView.InvalidateLayer(KnownLayer.Selection);
}
private void SelectResult(TextSegment result)
{
_textArea.Caret.Offset = result.StartOffset;
_textArea.Selection = Selection.Create(_textArea, result.StartOffset, result.EndOffset);
double distanceToViewBorder = _border == null ?
Caret.MinimumDistanceToViewBorder :
_border.Bounds.Height + _textArea.TextView.DefaultLineHeight;
_textArea.Caret.BringCaretToView(distanceToViewBorder);
// show caret even if the editor does not have the Keyboard Focus
_textArea.Caret.Show();
}
private void SearchLayerKeyDown(object sender, KeyEventArgs e)
{
switch (e.Key)
{
case Key.Enter:
e.Handled = true;
if (e.KeyModifiers.HasFlag(KeyModifiers.Shift))
{
FindPrevious();
}
else
{
FindNext();
}
if (_searchTextBox != null)
{
if (_validationError != null)
{
_messageViewContent.Content = SR.SearchErrorText + " " + _validationError;
_messageView.PlacementTarget = _searchTextBox;
_messageView.IsOpen = true;
}
}
break;
case Key.Escape:
e.Handled = true;
Close();
break;
}
}
/// <summary>
/// Gets whether the Panel is already closed.
/// </summary>
public bool IsClosed { get; private set; }
/// <summary>
/// Gets whether the Panel is currently opened.
/// </summary>
public bool IsOpened => !IsClosed;
/// <summary>
/// Closes the SearchPanel.
/// </summary>
public void Close()
{
_textArea.RemoveChild(this);
_messageView.IsOpen = false;
_textArea.TextView.BackgroundRenderers.Remove(_renderer);
IsClosed = true;
// Clear existing search results so that the segments don't have to be maintained
_renderer.CurrentResults.Clear();
_textArea.Focus();
}
/// <summary>
/// Opens the an existing search panel.
/// </summary>
public void Open()
{
if (!IsClosed) return;
_textArea.AddChild(this);
_textArea.TextView.BackgroundRenderers.Add(_renderer);
IsClosed = false;
DoSearch(false);
}
protected override void OnPointerPressed(PointerPressedEventArgs e)
{
e.Handled = true;
base.OnPointerPressed(e);
}
protected override void OnPointerMoved(PointerEventArgs e)
{
Cursor = Cursor.Default;
base.OnPointerMoved(e);
}
protected override void OnGotFocus(GotFocusEventArgs e)
{
e.Handled = true;
base.OnGotFocus(e);
}
/// <summary>
/// Fired when SearchOptions are changed inside the SearchPanel.
/// </summary>
public event EventHandler<SearchOptionsChangedEventArgs> SearchOptionsChanged;
/// <summary>
/// Raises the <see cref="SearchOptionsChanged" /> event.
/// </summary>
protected virtual void OnSearchOptionsChanged(SearchOptionsChangedEventArgs e)
{
SearchOptionsChanged?.Invoke(this, e);
}
public IList<RoutedCommandBinding> CommandBindings { get; } = new List<RoutedCommandBinding>();
}
/// <summary>
/// EventArgs for <see cref="SearchPanel.SearchOptionsChanged"/> event.
/// </summary>
public class SearchOptionsChangedEventArgs : EventArgs
{
/// <summary>
/// Gets the search pattern.
/// </summary>
public string SearchPattern { get; }
/// <summary>
/// Gets whether the search pattern should be interpreted case-sensitive.
/// </summary>
public bool MatchCase { get; }
/// <summary>
/// Gets whether the search pattern should be interpreted as regular expression.
/// </summary>
public bool UseRegex { get; }
/// <summary>
/// Gets whether the search pattern should only match whole words.
/// </summary>
public bool WholeWords { get; }
/// <summary>
/// Creates a new SearchOptionsChangedEventArgs instance.
/// </summary>
public SearchOptionsChangedEventArgs(string searchPattern, bool matchCase, bool useRegex, bool wholeWords)
{
SearchPattern = searchPattern;
MatchCase = matchCase;
UseRegex = useRegex;
WholeWords = wholeWords;
}
}
}
<MSG> update search after replace
<DFF> @@ -357,6 +357,8 @@ namespace AvaloniaEdit.Search
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
+
+ UpdateSearch();
}
public void ReplaceAll()
| 2 | update search after replace | 0 | .cs | cs | mit | AvaloniaUI/AvaloniaEdit |
10066857 | <NME> SearchPanel.cs
<BEF> // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.VisualTree;
using AvaloniaEdit.Document;
using AvaloniaEdit.Editing;
using AvaloniaEdit.Rendering;
namespace AvaloniaEdit.Search
{
/// <summary>
/// Provides search functionality for AvalonEdit. It is displayed in the top-right corner of the TextArea.
/// </summary>
public class SearchPanel : TemplatedControl, IRoutedCommandBindable
{
private TextArea _textArea;
private SearchInputHandler _handler;
private TextDocument _currentDocument;
private SearchResultBackgroundRenderer _renderer;
private TextBox _searchTextBox;
private TextEditor _textEditor { get; set; }
private Border _border;
#region DependencyProperties
/// <summary>
/// Dependency property for <see cref="UseRegex"/>.
/// </summary>
public static readonly StyledProperty<bool> UseRegexProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(UseRegex));
/// <summary>
/// Gets/sets whether the search pattern should be interpreted as regular expression.
/// </summary>
public bool UseRegex
{
get => GetValue(UseRegexProperty);
set => SetValue(UseRegexProperty, value);
}
/// <summary>
/// Dependency property for <see cref="MatchCase"/>.
/// </summary>
public static readonly StyledProperty<bool> MatchCaseProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(MatchCase));
/// <summary>
/// Gets/sets whether the search pattern should be interpreted case-sensitive.
/// </summary>
public bool MatchCase
{
get => GetValue(MatchCaseProperty);
set => SetValue(MatchCaseProperty, value);
}
/// <summary>
/// Dependency property for <see cref="WholeWords"/>.
/// </summary>
public static readonly StyledProperty<bool> WholeWordsProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(WholeWords));
/// <summary>
/// Gets/sets whether the search pattern should only match whole words.
/// </summary>
public bool WholeWords
{
get => GetValue(WholeWordsProperty);
set => SetValue(WholeWordsProperty, value);
}
/// <summary>
/// Dependency property for <see cref="SearchPattern"/>.
/// </summary>
public static readonly StyledProperty<string> SearchPatternProperty =
AvaloniaProperty.Register<SearchPanel, string>(nameof(SearchPattern), "");
/// <summary>
/// Gets/sets the search pattern.
/// </summary>
public string SearchPattern
{
get => GetValue(SearchPatternProperty);
set => SetValue(SearchPatternProperty, value);
}
public static readonly StyledProperty<bool> IsReplaceModeProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(IsReplaceMode));
/// <summary>
/// Checks if replacemode is allowed
/// </summary>
/// <returns>False if editor is not null and readonly</returns>
private static bool ValidateReplaceMode(SearchPanel panel, bool v1)
{
if (panel._textEditor == null || !v1) return v1;
return !panel._textEditor.IsReadOnly;
}
public bool IsReplaceMode
{
get => GetValue(IsReplaceModeProperty);
set => SetValue(IsReplaceModeProperty, _textEditor?.IsReadOnly ?? false ? false : value);
}
public static readonly StyledProperty<string> ReplacePatternProperty =
AvaloniaProperty.Register<SearchPanel, string>(nameof(ReplacePattern));
public string ReplacePattern
{
get => GetValue(ReplacePatternProperty);
set => SetValue(ReplacePatternProperty, value);
}
/// <summary>
/// Dependency property for <see cref="MarkerBrush"/>.
/// </summary>
public static readonly StyledProperty<IBrush> MarkerBrushProperty =
AvaloniaProperty.Register<SearchPanel, IBrush>(nameof(MarkerBrush), Brushes.LightGreen);
/// <summary>
/// Gets/sets the Brush used for marking search results in the TextView.
/// </summary>
public IBrush MarkerBrush
{
get => GetValue(MarkerBrushProperty);
set => SetValue(MarkerBrushProperty, value);
}
#endregion
private static void MarkerBrushChangedCallback(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is SearchPanel panel)
{
panel._renderer.MarkerBrush = (IBrush)e.NewValue;
}
}
private ISearchStrategy _strategy;
private static void SearchPatternChangedCallback(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is SearchPanel panel)
{
panel.ValidateSearchText();
panel.UpdateSearch();
}
}
private void UpdateSearch()
{
// only reset as long as there are results
// if no results are found, the "no matches found" message should not flicker.
// if results are found by the next run, the message will be hidden inside DoSearch ...
if (_renderer.CurrentResults.Any())
_messageView.IsOpen = false;
_strategy = SearchStrategyFactory.Create(SearchPattern ?? "", !MatchCase, WholeWords, UseRegex ? SearchMode.RegEx : SearchMode.Normal);
OnSearchOptionsChanged(new SearchOptionsChangedEventArgs(SearchPattern, MatchCase, UseRegex, WholeWords));
DoSearch(true);
}
static SearchPanel()
{
UseRegexProperty.Changed.Subscribe(SearchPatternChangedCallback);
MatchCaseProperty.Changed.Subscribe(SearchPatternChangedCallback);
WholeWordsProperty.Changed.Subscribe(SearchPatternChangedCallback);
SearchPatternProperty.Changed.Subscribe(SearchPatternChangedCallback);
MarkerBrushProperty.Changed.Subscribe(MarkerBrushChangedCallback);
}
/// <summary>
/// Creates a new SearchPanel.
/// </summary>
private SearchPanel()
{
}
/// <summary>
/// Creates a SearchPanel and installs it to the TextEditor's TextArea.
/// </summary>
/// <remarks>This is a convenience wrapper.</remarks>
public static SearchPanel Install(TextEditor editor)
{
if (editor == null) throw new ArgumentNullException(nameof(editor));
SearchPanel searchPanel = Install(editor.TextArea);
searchPanel._textEditor = editor;
return searchPanel;
}
/// <summary>
/// Creates a SearchPanel and installs it to the TextArea.
/// </summary>
public static SearchPanel Install(TextArea textArea)
{
if (textArea == null) throw new ArgumentNullException(nameof(textArea));
var panel = new SearchPanel();
panel.AttachInternal(textArea);
panel._handler = new SearchInputHandler(textArea, panel);
textArea.DefaultInputHandler.NestedInputHandlers.Add(panel._handler);
((ISetLogicalParent)panel).SetParent(textArea);
return panel;
}
/// <summary>
/// Adds the commands used by SearchPanel to the given CommandBindingCollection.
/// </summary>
public void RegisterCommands(ICollection<RoutedCommandBinding> commandBindings)
{
_handler.RegisterGlobalCommands(commandBindings);
}
/// <summary>
/// Removes the SearchPanel from the TextArea.
/// </summary>
public void Uninstall()
{
Close();
_textArea.DocumentChanged -= TextArea_DocumentChanged;
if (_currentDocument != null)
_currentDocument.TextChanged -= TextArea_Document_TextChanged;
_textArea.DefaultInputHandler.NestedInputHandlers.Remove(_handler);
}
private void AttachInternal(TextArea textArea)
{
_textArea = textArea;
_renderer = new SearchResultBackgroundRenderer();
_currentDocument = textArea.Document;
if (_currentDocument != null)
_currentDocument.TextChanged += TextArea_Document_TextChanged;
textArea.DocumentChanged += TextArea_DocumentChanged;
KeyDown += SearchLayerKeyDown;
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.FindNext, (sender, e) => FindNext()));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.FindPrevious, (sender, e) => FindPrevious()));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.CloseSearchPanel, (sender, e) => Close()));
CommandBindings.Add(new RoutedCommandBinding(ApplicationCommands.Find, (sender, e) =>
{
IsReplaceMode = false;
Reactivate();
}));
CommandBindings.Add(new RoutedCommandBinding(ApplicationCommands.Replace, (sender, e) => IsReplaceMode = true));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.ReplaceNext, (sender, e) => ReplaceNext(), (sender, e) => e.CanExecute = IsReplaceMode));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.ReplaceAll, (sender, e) => ReplaceAll(), (sender, e) => e.CanExecute = IsReplaceMode));
IsClosed = true;
}
private void TextArea_DocumentChanged(object sender, EventArgs e)
{
if (_currentDocument != null)
_currentDocument.TextChanged -= TextArea_Document_TextChanged;
_currentDocument = _textArea.Document;
if (_currentDocument != null)
{
_currentDocument.TextChanged += TextArea_Document_TextChanged;
DoSearch(false);
}
}
private void TextArea_Document_TextChanged(object sender, EventArgs e)
{
DoSearch(false);
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
_border = e.NameScope.Find<Border>("PART_Border");
_searchTextBox = e.NameScope.Find<TextBox>("PART_searchTextBox");
_messageView = e.NameScope.Find<Popup>("PART_MessageView");
_messageViewContent = e.NameScope.Find<ContentPresenter>("PART_MessageContent");
}
private void ValidateSearchText()
{
if (_searchTextBox == null)
return;
try
{
UpdateSearch();
_validationError = null;
}
catch (SearchPatternException ex)
{
_validationError = ex.Message;
}
}
/// <summary>
/// Reactivates the SearchPanel by setting the focus on the search box and selecting all text.
/// </summary>
public void Reactivate()
{
if (_searchTextBox == null)
return;
_searchTextBox.Focus();
_searchTextBox.SelectionStart = 0;
_searchTextBox.SelectionEnd = _searchTextBox.Text?.Length ?? 0;
}
/// <summary>
/// Moves to the next occurrence in the file.
/// </summary>
public void FindNext()
{
var result = _renderer.CurrentResults.FindFirstSegmentWithStartAfter(_textArea.Caret.Offset + 1) ??
_renderer.CurrentResults.FirstSegment;
if (result != null)
{
SelectResult(result);
}
}
/// <summary>
/// Moves to the previous occurrence in the file.
/// </summary>
public void FindPrevious()
{
var result = _renderer.CurrentResults.FindFirstSegmentWithStartAfter(_textArea.Caret.Offset);
if (result != null)
result = _renderer.CurrentResults.GetPreviousSegment(result);
if (result == null)
result = _renderer.CurrentResults.LastSegment;
if (result != null)
{
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
}
public void ReplaceAll()
FindNext();
if (!_textArea.Selection.IsEmpty)
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
UpdateSearch();
}
public void ReplaceAll()
{
if (!IsReplaceMode) return;
var replacement = ReplacePattern ?? string.Empty;
var document = _textArea.Document;
using (document.RunUpdate())
{
var segments = _renderer.CurrentResults.OrderByDescending(x => x.EndOffset).ToArray();
foreach (var textSegment in segments)
{
document.Replace(textSegment.StartOffset, textSegment.Length,
new StringTextSource(replacement));
}
}
}
private Popup _messageView;
private ContentPresenter _messageViewContent;
private string _validationError;
private void DoSearch(bool changeSelection)
{
if (IsClosed)
return;
_renderer.CurrentResults.Clear();
if (!string.IsNullOrEmpty(SearchPattern))
{
var offset = _textArea.Caret.Offset;
if (changeSelection)
{
_textArea.ClearSelection();
}
// We cast from ISearchResult to SearchResult; this is safe because we always use the built-in strategy
foreach (var result in _strategy.FindAll(_textArea.Document, 0, _textArea.Document.TextLength).Cast<SearchResult>())
{
if (changeSelection && result.StartOffset >= offset)
{
SelectResult(result);
changeSelection = false;
}
_renderer.CurrentResults.Add(result);
}
}
if (_messageView != null)
{
if (!_renderer.CurrentResults.Any())
{
_messageViewContent.Content = SR.SearchNoMatchesFoundText;
_messageView.PlacementTarget = _searchTextBox;
_messageView.IsOpen = true;
}
else
_messageView.IsOpen = false;
}
_textArea.TextView.InvalidateLayer(KnownLayer.Selection);
}
private void SelectResult(TextSegment result)
{
_textArea.Caret.Offset = result.StartOffset;
_textArea.Selection = Selection.Create(_textArea, result.StartOffset, result.EndOffset);
double distanceToViewBorder = _border == null ?
Caret.MinimumDistanceToViewBorder :
_border.Bounds.Height + _textArea.TextView.DefaultLineHeight;
_textArea.Caret.BringCaretToView(distanceToViewBorder);
// show caret even if the editor does not have the Keyboard Focus
_textArea.Caret.Show();
}
private void SearchLayerKeyDown(object sender, KeyEventArgs e)
{
switch (e.Key)
{
case Key.Enter:
e.Handled = true;
if (e.KeyModifiers.HasFlag(KeyModifiers.Shift))
{
FindPrevious();
}
else
{
FindNext();
}
if (_searchTextBox != null)
{
if (_validationError != null)
{
_messageViewContent.Content = SR.SearchErrorText + " " + _validationError;
_messageView.PlacementTarget = _searchTextBox;
_messageView.IsOpen = true;
}
}
break;
case Key.Escape:
e.Handled = true;
Close();
break;
}
}
/// <summary>
/// Gets whether the Panel is already closed.
/// </summary>
public bool IsClosed { get; private set; }
/// <summary>
/// Gets whether the Panel is currently opened.
/// </summary>
public bool IsOpened => !IsClosed;
/// <summary>
/// Closes the SearchPanel.
/// </summary>
public void Close()
{
_textArea.RemoveChild(this);
_messageView.IsOpen = false;
_textArea.TextView.BackgroundRenderers.Remove(_renderer);
IsClosed = true;
// Clear existing search results so that the segments don't have to be maintained
_renderer.CurrentResults.Clear();
_textArea.Focus();
}
/// <summary>
/// Opens the an existing search panel.
/// </summary>
public void Open()
{
if (!IsClosed) return;
_textArea.AddChild(this);
_textArea.TextView.BackgroundRenderers.Add(_renderer);
IsClosed = false;
DoSearch(false);
}
protected override void OnPointerPressed(PointerPressedEventArgs e)
{
e.Handled = true;
base.OnPointerPressed(e);
}
protected override void OnPointerMoved(PointerEventArgs e)
{
Cursor = Cursor.Default;
base.OnPointerMoved(e);
}
protected override void OnGotFocus(GotFocusEventArgs e)
{
e.Handled = true;
base.OnGotFocus(e);
}
/// <summary>
/// Fired when SearchOptions are changed inside the SearchPanel.
/// </summary>
public event EventHandler<SearchOptionsChangedEventArgs> SearchOptionsChanged;
/// <summary>
/// Raises the <see cref="SearchOptionsChanged" /> event.
/// </summary>
protected virtual void OnSearchOptionsChanged(SearchOptionsChangedEventArgs e)
{
SearchOptionsChanged?.Invoke(this, e);
}
public IList<RoutedCommandBinding> CommandBindings { get; } = new List<RoutedCommandBinding>();
}
/// <summary>
/// EventArgs for <see cref="SearchPanel.SearchOptionsChanged"/> event.
/// </summary>
public class SearchOptionsChangedEventArgs : EventArgs
{
/// <summary>
/// Gets the search pattern.
/// </summary>
public string SearchPattern { get; }
/// <summary>
/// Gets whether the search pattern should be interpreted case-sensitive.
/// </summary>
public bool MatchCase { get; }
/// <summary>
/// Gets whether the search pattern should be interpreted as regular expression.
/// </summary>
public bool UseRegex { get; }
/// <summary>
/// Gets whether the search pattern should only match whole words.
/// </summary>
public bool WholeWords { get; }
/// <summary>
/// Creates a new SearchOptionsChangedEventArgs instance.
/// </summary>
public SearchOptionsChangedEventArgs(string searchPattern, bool matchCase, bool useRegex, bool wholeWords)
{
SearchPattern = searchPattern;
MatchCase = matchCase;
UseRegex = useRegex;
WholeWords = wholeWords;
}
}
}
<MSG> update search after replace
<DFF> @@ -357,6 +357,8 @@ namespace AvaloniaEdit.Search
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
+
+ UpdateSearch();
}
public void ReplaceAll()
| 2 | update search after replace | 0 | .cs | cs | mit | AvaloniaUI/AvaloniaEdit |
10066858 | <NME> SearchPanel.cs
<BEF> // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.VisualTree;
using AvaloniaEdit.Document;
using AvaloniaEdit.Editing;
using AvaloniaEdit.Rendering;
namespace AvaloniaEdit.Search
{
/// <summary>
/// Provides search functionality for AvalonEdit. It is displayed in the top-right corner of the TextArea.
/// </summary>
public class SearchPanel : TemplatedControl, IRoutedCommandBindable
{
private TextArea _textArea;
private SearchInputHandler _handler;
private TextDocument _currentDocument;
private SearchResultBackgroundRenderer _renderer;
private TextBox _searchTextBox;
private TextEditor _textEditor { get; set; }
private Border _border;
#region DependencyProperties
/// <summary>
/// Dependency property for <see cref="UseRegex"/>.
/// </summary>
public static readonly StyledProperty<bool> UseRegexProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(UseRegex));
/// <summary>
/// Gets/sets whether the search pattern should be interpreted as regular expression.
/// </summary>
public bool UseRegex
{
get => GetValue(UseRegexProperty);
set => SetValue(UseRegexProperty, value);
}
/// <summary>
/// Dependency property for <see cref="MatchCase"/>.
/// </summary>
public static readonly StyledProperty<bool> MatchCaseProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(MatchCase));
/// <summary>
/// Gets/sets whether the search pattern should be interpreted case-sensitive.
/// </summary>
public bool MatchCase
{
get => GetValue(MatchCaseProperty);
set => SetValue(MatchCaseProperty, value);
}
/// <summary>
/// Dependency property for <see cref="WholeWords"/>.
/// </summary>
public static readonly StyledProperty<bool> WholeWordsProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(WholeWords));
/// <summary>
/// Gets/sets whether the search pattern should only match whole words.
/// </summary>
public bool WholeWords
{
get => GetValue(WholeWordsProperty);
set => SetValue(WholeWordsProperty, value);
}
/// <summary>
/// Dependency property for <see cref="SearchPattern"/>.
/// </summary>
public static readonly StyledProperty<string> SearchPatternProperty =
AvaloniaProperty.Register<SearchPanel, string>(nameof(SearchPattern), "");
/// <summary>
/// Gets/sets the search pattern.
/// </summary>
public string SearchPattern
{
get => GetValue(SearchPatternProperty);
set => SetValue(SearchPatternProperty, value);
}
public static readonly StyledProperty<bool> IsReplaceModeProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(IsReplaceMode));
/// <summary>
/// Checks if replacemode is allowed
/// </summary>
/// <returns>False if editor is not null and readonly</returns>
private static bool ValidateReplaceMode(SearchPanel panel, bool v1)
{
if (panel._textEditor == null || !v1) return v1;
return !panel._textEditor.IsReadOnly;
}
public bool IsReplaceMode
{
get => GetValue(IsReplaceModeProperty);
set => SetValue(IsReplaceModeProperty, _textEditor?.IsReadOnly ?? false ? false : value);
}
public static readonly StyledProperty<string> ReplacePatternProperty =
AvaloniaProperty.Register<SearchPanel, string>(nameof(ReplacePattern));
public string ReplacePattern
{
get => GetValue(ReplacePatternProperty);
set => SetValue(ReplacePatternProperty, value);
}
/// <summary>
/// Dependency property for <see cref="MarkerBrush"/>.
/// </summary>
public static readonly StyledProperty<IBrush> MarkerBrushProperty =
AvaloniaProperty.Register<SearchPanel, IBrush>(nameof(MarkerBrush), Brushes.LightGreen);
/// <summary>
/// Gets/sets the Brush used for marking search results in the TextView.
/// </summary>
public IBrush MarkerBrush
{
get => GetValue(MarkerBrushProperty);
set => SetValue(MarkerBrushProperty, value);
}
#endregion
private static void MarkerBrushChangedCallback(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is SearchPanel panel)
{
panel._renderer.MarkerBrush = (IBrush)e.NewValue;
}
}
private ISearchStrategy _strategy;
private static void SearchPatternChangedCallback(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is SearchPanel panel)
{
panel.ValidateSearchText();
panel.UpdateSearch();
}
}
private void UpdateSearch()
{
// only reset as long as there are results
// if no results are found, the "no matches found" message should not flicker.
// if results are found by the next run, the message will be hidden inside DoSearch ...
if (_renderer.CurrentResults.Any())
_messageView.IsOpen = false;
_strategy = SearchStrategyFactory.Create(SearchPattern ?? "", !MatchCase, WholeWords, UseRegex ? SearchMode.RegEx : SearchMode.Normal);
OnSearchOptionsChanged(new SearchOptionsChangedEventArgs(SearchPattern, MatchCase, UseRegex, WholeWords));
DoSearch(true);
}
static SearchPanel()
{
UseRegexProperty.Changed.Subscribe(SearchPatternChangedCallback);
MatchCaseProperty.Changed.Subscribe(SearchPatternChangedCallback);
WholeWordsProperty.Changed.Subscribe(SearchPatternChangedCallback);
SearchPatternProperty.Changed.Subscribe(SearchPatternChangedCallback);
MarkerBrushProperty.Changed.Subscribe(MarkerBrushChangedCallback);
}
/// <summary>
/// Creates a new SearchPanel.
/// </summary>
private SearchPanel()
{
}
/// <summary>
/// Creates a SearchPanel and installs it to the TextEditor's TextArea.
/// </summary>
/// <remarks>This is a convenience wrapper.</remarks>
public static SearchPanel Install(TextEditor editor)
{
if (editor == null) throw new ArgumentNullException(nameof(editor));
SearchPanel searchPanel = Install(editor.TextArea);
searchPanel._textEditor = editor;
return searchPanel;
}
/// <summary>
/// Creates a SearchPanel and installs it to the TextArea.
/// </summary>
public static SearchPanel Install(TextArea textArea)
{
if (textArea == null) throw new ArgumentNullException(nameof(textArea));
var panel = new SearchPanel();
panel.AttachInternal(textArea);
panel._handler = new SearchInputHandler(textArea, panel);
textArea.DefaultInputHandler.NestedInputHandlers.Add(panel._handler);
((ISetLogicalParent)panel).SetParent(textArea);
return panel;
}
/// <summary>
/// Adds the commands used by SearchPanel to the given CommandBindingCollection.
/// </summary>
public void RegisterCommands(ICollection<RoutedCommandBinding> commandBindings)
{
_handler.RegisterGlobalCommands(commandBindings);
}
/// <summary>
/// Removes the SearchPanel from the TextArea.
/// </summary>
public void Uninstall()
{
Close();
_textArea.DocumentChanged -= TextArea_DocumentChanged;
if (_currentDocument != null)
_currentDocument.TextChanged -= TextArea_Document_TextChanged;
_textArea.DefaultInputHandler.NestedInputHandlers.Remove(_handler);
}
private void AttachInternal(TextArea textArea)
{
_textArea = textArea;
_renderer = new SearchResultBackgroundRenderer();
_currentDocument = textArea.Document;
if (_currentDocument != null)
_currentDocument.TextChanged += TextArea_Document_TextChanged;
textArea.DocumentChanged += TextArea_DocumentChanged;
KeyDown += SearchLayerKeyDown;
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.FindNext, (sender, e) => FindNext()));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.FindPrevious, (sender, e) => FindPrevious()));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.CloseSearchPanel, (sender, e) => Close()));
CommandBindings.Add(new RoutedCommandBinding(ApplicationCommands.Find, (sender, e) =>
{
IsReplaceMode = false;
Reactivate();
}));
CommandBindings.Add(new RoutedCommandBinding(ApplicationCommands.Replace, (sender, e) => IsReplaceMode = true));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.ReplaceNext, (sender, e) => ReplaceNext(), (sender, e) => e.CanExecute = IsReplaceMode));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.ReplaceAll, (sender, e) => ReplaceAll(), (sender, e) => e.CanExecute = IsReplaceMode));
IsClosed = true;
}
private void TextArea_DocumentChanged(object sender, EventArgs e)
{
if (_currentDocument != null)
_currentDocument.TextChanged -= TextArea_Document_TextChanged;
_currentDocument = _textArea.Document;
if (_currentDocument != null)
{
_currentDocument.TextChanged += TextArea_Document_TextChanged;
DoSearch(false);
}
}
private void TextArea_Document_TextChanged(object sender, EventArgs e)
{
DoSearch(false);
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
_border = e.NameScope.Find<Border>("PART_Border");
_searchTextBox = e.NameScope.Find<TextBox>("PART_searchTextBox");
_messageView = e.NameScope.Find<Popup>("PART_MessageView");
_messageViewContent = e.NameScope.Find<ContentPresenter>("PART_MessageContent");
}
private void ValidateSearchText()
{
if (_searchTextBox == null)
return;
try
{
UpdateSearch();
_validationError = null;
}
catch (SearchPatternException ex)
{
_validationError = ex.Message;
}
}
/// <summary>
/// Reactivates the SearchPanel by setting the focus on the search box and selecting all text.
/// </summary>
public void Reactivate()
{
if (_searchTextBox == null)
return;
_searchTextBox.Focus();
_searchTextBox.SelectionStart = 0;
_searchTextBox.SelectionEnd = _searchTextBox.Text?.Length ?? 0;
}
/// <summary>
/// Moves to the next occurrence in the file.
/// </summary>
public void FindNext()
{
var result = _renderer.CurrentResults.FindFirstSegmentWithStartAfter(_textArea.Caret.Offset + 1) ??
_renderer.CurrentResults.FirstSegment;
if (result != null)
{
SelectResult(result);
}
}
/// <summary>
/// Moves to the previous occurrence in the file.
/// </summary>
public void FindPrevious()
{
var result = _renderer.CurrentResults.FindFirstSegmentWithStartAfter(_textArea.Caret.Offset);
if (result != null)
result = _renderer.CurrentResults.GetPreviousSegment(result);
if (result == null)
result = _renderer.CurrentResults.LastSegment;
if (result != null)
{
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
}
public void ReplaceAll()
FindNext();
if (!_textArea.Selection.IsEmpty)
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
UpdateSearch();
}
public void ReplaceAll()
{
if (!IsReplaceMode) return;
var replacement = ReplacePattern ?? string.Empty;
var document = _textArea.Document;
using (document.RunUpdate())
{
var segments = _renderer.CurrentResults.OrderByDescending(x => x.EndOffset).ToArray();
foreach (var textSegment in segments)
{
document.Replace(textSegment.StartOffset, textSegment.Length,
new StringTextSource(replacement));
}
}
}
private Popup _messageView;
private ContentPresenter _messageViewContent;
private string _validationError;
private void DoSearch(bool changeSelection)
{
if (IsClosed)
return;
_renderer.CurrentResults.Clear();
if (!string.IsNullOrEmpty(SearchPattern))
{
var offset = _textArea.Caret.Offset;
if (changeSelection)
{
_textArea.ClearSelection();
}
// We cast from ISearchResult to SearchResult; this is safe because we always use the built-in strategy
foreach (var result in _strategy.FindAll(_textArea.Document, 0, _textArea.Document.TextLength).Cast<SearchResult>())
{
if (changeSelection && result.StartOffset >= offset)
{
SelectResult(result);
changeSelection = false;
}
_renderer.CurrentResults.Add(result);
}
}
if (_messageView != null)
{
if (!_renderer.CurrentResults.Any())
{
_messageViewContent.Content = SR.SearchNoMatchesFoundText;
_messageView.PlacementTarget = _searchTextBox;
_messageView.IsOpen = true;
}
else
_messageView.IsOpen = false;
}
_textArea.TextView.InvalidateLayer(KnownLayer.Selection);
}
private void SelectResult(TextSegment result)
{
_textArea.Caret.Offset = result.StartOffset;
_textArea.Selection = Selection.Create(_textArea, result.StartOffset, result.EndOffset);
double distanceToViewBorder = _border == null ?
Caret.MinimumDistanceToViewBorder :
_border.Bounds.Height + _textArea.TextView.DefaultLineHeight;
_textArea.Caret.BringCaretToView(distanceToViewBorder);
// show caret even if the editor does not have the Keyboard Focus
_textArea.Caret.Show();
}
private void SearchLayerKeyDown(object sender, KeyEventArgs e)
{
switch (e.Key)
{
case Key.Enter:
e.Handled = true;
if (e.KeyModifiers.HasFlag(KeyModifiers.Shift))
{
FindPrevious();
}
else
{
FindNext();
}
if (_searchTextBox != null)
{
if (_validationError != null)
{
_messageViewContent.Content = SR.SearchErrorText + " " + _validationError;
_messageView.PlacementTarget = _searchTextBox;
_messageView.IsOpen = true;
}
}
break;
case Key.Escape:
e.Handled = true;
Close();
break;
}
}
/// <summary>
/// Gets whether the Panel is already closed.
/// </summary>
public bool IsClosed { get; private set; }
/// <summary>
/// Gets whether the Panel is currently opened.
/// </summary>
public bool IsOpened => !IsClosed;
/// <summary>
/// Closes the SearchPanel.
/// </summary>
public void Close()
{
_textArea.RemoveChild(this);
_messageView.IsOpen = false;
_textArea.TextView.BackgroundRenderers.Remove(_renderer);
IsClosed = true;
// Clear existing search results so that the segments don't have to be maintained
_renderer.CurrentResults.Clear();
_textArea.Focus();
}
/// <summary>
/// Opens the an existing search panel.
/// </summary>
public void Open()
{
if (!IsClosed) return;
_textArea.AddChild(this);
_textArea.TextView.BackgroundRenderers.Add(_renderer);
IsClosed = false;
DoSearch(false);
}
protected override void OnPointerPressed(PointerPressedEventArgs e)
{
e.Handled = true;
base.OnPointerPressed(e);
}
protected override void OnPointerMoved(PointerEventArgs e)
{
Cursor = Cursor.Default;
base.OnPointerMoved(e);
}
protected override void OnGotFocus(GotFocusEventArgs e)
{
e.Handled = true;
base.OnGotFocus(e);
}
/// <summary>
/// Fired when SearchOptions are changed inside the SearchPanel.
/// </summary>
public event EventHandler<SearchOptionsChangedEventArgs> SearchOptionsChanged;
/// <summary>
/// Raises the <see cref="SearchOptionsChanged" /> event.
/// </summary>
protected virtual void OnSearchOptionsChanged(SearchOptionsChangedEventArgs e)
{
SearchOptionsChanged?.Invoke(this, e);
}
public IList<RoutedCommandBinding> CommandBindings { get; } = new List<RoutedCommandBinding>();
}
/// <summary>
/// EventArgs for <see cref="SearchPanel.SearchOptionsChanged"/> event.
/// </summary>
public class SearchOptionsChangedEventArgs : EventArgs
{
/// <summary>
/// Gets the search pattern.
/// </summary>
public string SearchPattern { get; }
/// <summary>
/// Gets whether the search pattern should be interpreted case-sensitive.
/// </summary>
public bool MatchCase { get; }
/// <summary>
/// Gets whether the search pattern should be interpreted as regular expression.
/// </summary>
public bool UseRegex { get; }
/// <summary>
/// Gets whether the search pattern should only match whole words.
/// </summary>
public bool WholeWords { get; }
/// <summary>
/// Creates a new SearchOptionsChangedEventArgs instance.
/// </summary>
public SearchOptionsChangedEventArgs(string searchPattern, bool matchCase, bool useRegex, bool wholeWords)
{
SearchPattern = searchPattern;
MatchCase = matchCase;
UseRegex = useRegex;
WholeWords = wholeWords;
}
}
}
<MSG> update search after replace
<DFF> @@ -357,6 +357,8 @@ namespace AvaloniaEdit.Search
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
+
+ UpdateSearch();
}
public void ReplaceAll()
| 2 | update search after replace | 0 | .cs | cs | mit | AvaloniaUI/AvaloniaEdit |
10066859 | <NME> SearchPanel.cs
<BEF> // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.VisualTree;
using AvaloniaEdit.Document;
using AvaloniaEdit.Editing;
using AvaloniaEdit.Rendering;
namespace AvaloniaEdit.Search
{
/// <summary>
/// Provides search functionality for AvalonEdit. It is displayed in the top-right corner of the TextArea.
/// </summary>
public class SearchPanel : TemplatedControl, IRoutedCommandBindable
{
private TextArea _textArea;
private SearchInputHandler _handler;
private TextDocument _currentDocument;
private SearchResultBackgroundRenderer _renderer;
private TextBox _searchTextBox;
private TextEditor _textEditor { get; set; }
private Border _border;
#region DependencyProperties
/// <summary>
/// Dependency property for <see cref="UseRegex"/>.
/// </summary>
public static readonly StyledProperty<bool> UseRegexProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(UseRegex));
/// <summary>
/// Gets/sets whether the search pattern should be interpreted as regular expression.
/// </summary>
public bool UseRegex
{
get => GetValue(UseRegexProperty);
set => SetValue(UseRegexProperty, value);
}
/// <summary>
/// Dependency property for <see cref="MatchCase"/>.
/// </summary>
public static readonly StyledProperty<bool> MatchCaseProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(MatchCase));
/// <summary>
/// Gets/sets whether the search pattern should be interpreted case-sensitive.
/// </summary>
public bool MatchCase
{
get => GetValue(MatchCaseProperty);
set => SetValue(MatchCaseProperty, value);
}
/// <summary>
/// Dependency property for <see cref="WholeWords"/>.
/// </summary>
public static readonly StyledProperty<bool> WholeWordsProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(WholeWords));
/// <summary>
/// Gets/sets whether the search pattern should only match whole words.
/// </summary>
public bool WholeWords
{
get => GetValue(WholeWordsProperty);
set => SetValue(WholeWordsProperty, value);
}
/// <summary>
/// Dependency property for <see cref="SearchPattern"/>.
/// </summary>
public static readonly StyledProperty<string> SearchPatternProperty =
AvaloniaProperty.Register<SearchPanel, string>(nameof(SearchPattern), "");
/// <summary>
/// Gets/sets the search pattern.
/// </summary>
public string SearchPattern
{
get => GetValue(SearchPatternProperty);
set => SetValue(SearchPatternProperty, value);
}
public static readonly StyledProperty<bool> IsReplaceModeProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(IsReplaceMode));
/// <summary>
/// Checks if replacemode is allowed
/// </summary>
/// <returns>False if editor is not null and readonly</returns>
private static bool ValidateReplaceMode(SearchPanel panel, bool v1)
{
if (panel._textEditor == null || !v1) return v1;
return !panel._textEditor.IsReadOnly;
}
public bool IsReplaceMode
{
get => GetValue(IsReplaceModeProperty);
set => SetValue(IsReplaceModeProperty, _textEditor?.IsReadOnly ?? false ? false : value);
}
public static readonly StyledProperty<string> ReplacePatternProperty =
AvaloniaProperty.Register<SearchPanel, string>(nameof(ReplacePattern));
public string ReplacePattern
{
get => GetValue(ReplacePatternProperty);
set => SetValue(ReplacePatternProperty, value);
}
/// <summary>
/// Dependency property for <see cref="MarkerBrush"/>.
/// </summary>
public static readonly StyledProperty<IBrush> MarkerBrushProperty =
AvaloniaProperty.Register<SearchPanel, IBrush>(nameof(MarkerBrush), Brushes.LightGreen);
/// <summary>
/// Gets/sets the Brush used for marking search results in the TextView.
/// </summary>
public IBrush MarkerBrush
{
get => GetValue(MarkerBrushProperty);
set => SetValue(MarkerBrushProperty, value);
}
#endregion
private static void MarkerBrushChangedCallback(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is SearchPanel panel)
{
panel._renderer.MarkerBrush = (IBrush)e.NewValue;
}
}
private ISearchStrategy _strategy;
private static void SearchPatternChangedCallback(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is SearchPanel panel)
{
panel.ValidateSearchText();
panel.UpdateSearch();
}
}
private void UpdateSearch()
{
// only reset as long as there are results
// if no results are found, the "no matches found" message should not flicker.
// if results are found by the next run, the message will be hidden inside DoSearch ...
if (_renderer.CurrentResults.Any())
_messageView.IsOpen = false;
_strategy = SearchStrategyFactory.Create(SearchPattern ?? "", !MatchCase, WholeWords, UseRegex ? SearchMode.RegEx : SearchMode.Normal);
OnSearchOptionsChanged(new SearchOptionsChangedEventArgs(SearchPattern, MatchCase, UseRegex, WholeWords));
DoSearch(true);
}
static SearchPanel()
{
UseRegexProperty.Changed.Subscribe(SearchPatternChangedCallback);
MatchCaseProperty.Changed.Subscribe(SearchPatternChangedCallback);
WholeWordsProperty.Changed.Subscribe(SearchPatternChangedCallback);
SearchPatternProperty.Changed.Subscribe(SearchPatternChangedCallback);
MarkerBrushProperty.Changed.Subscribe(MarkerBrushChangedCallback);
}
/// <summary>
/// Creates a new SearchPanel.
/// </summary>
private SearchPanel()
{
}
/// <summary>
/// Creates a SearchPanel and installs it to the TextEditor's TextArea.
/// </summary>
/// <remarks>This is a convenience wrapper.</remarks>
public static SearchPanel Install(TextEditor editor)
{
if (editor == null) throw new ArgumentNullException(nameof(editor));
SearchPanel searchPanel = Install(editor.TextArea);
searchPanel._textEditor = editor;
return searchPanel;
}
/// <summary>
/// Creates a SearchPanel and installs it to the TextArea.
/// </summary>
public static SearchPanel Install(TextArea textArea)
{
if (textArea == null) throw new ArgumentNullException(nameof(textArea));
var panel = new SearchPanel();
panel.AttachInternal(textArea);
panel._handler = new SearchInputHandler(textArea, panel);
textArea.DefaultInputHandler.NestedInputHandlers.Add(panel._handler);
((ISetLogicalParent)panel).SetParent(textArea);
return panel;
}
/// <summary>
/// Adds the commands used by SearchPanel to the given CommandBindingCollection.
/// </summary>
public void RegisterCommands(ICollection<RoutedCommandBinding> commandBindings)
{
_handler.RegisterGlobalCommands(commandBindings);
}
/// <summary>
/// Removes the SearchPanel from the TextArea.
/// </summary>
public void Uninstall()
{
Close();
_textArea.DocumentChanged -= TextArea_DocumentChanged;
if (_currentDocument != null)
_currentDocument.TextChanged -= TextArea_Document_TextChanged;
_textArea.DefaultInputHandler.NestedInputHandlers.Remove(_handler);
}
private void AttachInternal(TextArea textArea)
{
_textArea = textArea;
_renderer = new SearchResultBackgroundRenderer();
_currentDocument = textArea.Document;
if (_currentDocument != null)
_currentDocument.TextChanged += TextArea_Document_TextChanged;
textArea.DocumentChanged += TextArea_DocumentChanged;
KeyDown += SearchLayerKeyDown;
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.FindNext, (sender, e) => FindNext()));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.FindPrevious, (sender, e) => FindPrevious()));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.CloseSearchPanel, (sender, e) => Close()));
CommandBindings.Add(new RoutedCommandBinding(ApplicationCommands.Find, (sender, e) =>
{
IsReplaceMode = false;
Reactivate();
}));
CommandBindings.Add(new RoutedCommandBinding(ApplicationCommands.Replace, (sender, e) => IsReplaceMode = true));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.ReplaceNext, (sender, e) => ReplaceNext(), (sender, e) => e.CanExecute = IsReplaceMode));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.ReplaceAll, (sender, e) => ReplaceAll(), (sender, e) => e.CanExecute = IsReplaceMode));
IsClosed = true;
}
private void TextArea_DocumentChanged(object sender, EventArgs e)
{
if (_currentDocument != null)
_currentDocument.TextChanged -= TextArea_Document_TextChanged;
_currentDocument = _textArea.Document;
if (_currentDocument != null)
{
_currentDocument.TextChanged += TextArea_Document_TextChanged;
DoSearch(false);
}
}
private void TextArea_Document_TextChanged(object sender, EventArgs e)
{
DoSearch(false);
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
_border = e.NameScope.Find<Border>("PART_Border");
_searchTextBox = e.NameScope.Find<TextBox>("PART_searchTextBox");
_messageView = e.NameScope.Find<Popup>("PART_MessageView");
_messageViewContent = e.NameScope.Find<ContentPresenter>("PART_MessageContent");
}
private void ValidateSearchText()
{
if (_searchTextBox == null)
return;
try
{
UpdateSearch();
_validationError = null;
}
catch (SearchPatternException ex)
{
_validationError = ex.Message;
}
}
/// <summary>
/// Reactivates the SearchPanel by setting the focus on the search box and selecting all text.
/// </summary>
public void Reactivate()
{
if (_searchTextBox == null)
return;
_searchTextBox.Focus();
_searchTextBox.SelectionStart = 0;
_searchTextBox.SelectionEnd = _searchTextBox.Text?.Length ?? 0;
}
/// <summary>
/// Moves to the next occurrence in the file.
/// </summary>
public void FindNext()
{
var result = _renderer.CurrentResults.FindFirstSegmentWithStartAfter(_textArea.Caret.Offset + 1) ??
_renderer.CurrentResults.FirstSegment;
if (result != null)
{
SelectResult(result);
}
}
/// <summary>
/// Moves to the previous occurrence in the file.
/// </summary>
public void FindPrevious()
{
var result = _renderer.CurrentResults.FindFirstSegmentWithStartAfter(_textArea.Caret.Offset);
if (result != null)
result = _renderer.CurrentResults.GetPreviousSegment(result);
if (result == null)
result = _renderer.CurrentResults.LastSegment;
if (result != null)
{
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
}
public void ReplaceAll()
FindNext();
if (!_textArea.Selection.IsEmpty)
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
UpdateSearch();
}
public void ReplaceAll()
{
if (!IsReplaceMode) return;
var replacement = ReplacePattern ?? string.Empty;
var document = _textArea.Document;
using (document.RunUpdate())
{
var segments = _renderer.CurrentResults.OrderByDescending(x => x.EndOffset).ToArray();
foreach (var textSegment in segments)
{
document.Replace(textSegment.StartOffset, textSegment.Length,
new StringTextSource(replacement));
}
}
}
private Popup _messageView;
private ContentPresenter _messageViewContent;
private string _validationError;
private void DoSearch(bool changeSelection)
{
if (IsClosed)
return;
_renderer.CurrentResults.Clear();
if (!string.IsNullOrEmpty(SearchPattern))
{
var offset = _textArea.Caret.Offset;
if (changeSelection)
{
_textArea.ClearSelection();
}
// We cast from ISearchResult to SearchResult; this is safe because we always use the built-in strategy
foreach (var result in _strategy.FindAll(_textArea.Document, 0, _textArea.Document.TextLength).Cast<SearchResult>())
{
if (changeSelection && result.StartOffset >= offset)
{
SelectResult(result);
changeSelection = false;
}
_renderer.CurrentResults.Add(result);
}
}
if (_messageView != null)
{
if (!_renderer.CurrentResults.Any())
{
_messageViewContent.Content = SR.SearchNoMatchesFoundText;
_messageView.PlacementTarget = _searchTextBox;
_messageView.IsOpen = true;
}
else
_messageView.IsOpen = false;
}
_textArea.TextView.InvalidateLayer(KnownLayer.Selection);
}
private void SelectResult(TextSegment result)
{
_textArea.Caret.Offset = result.StartOffset;
_textArea.Selection = Selection.Create(_textArea, result.StartOffset, result.EndOffset);
double distanceToViewBorder = _border == null ?
Caret.MinimumDistanceToViewBorder :
_border.Bounds.Height + _textArea.TextView.DefaultLineHeight;
_textArea.Caret.BringCaretToView(distanceToViewBorder);
// show caret even if the editor does not have the Keyboard Focus
_textArea.Caret.Show();
}
private void SearchLayerKeyDown(object sender, KeyEventArgs e)
{
switch (e.Key)
{
case Key.Enter:
e.Handled = true;
if (e.KeyModifiers.HasFlag(KeyModifiers.Shift))
{
FindPrevious();
}
else
{
FindNext();
}
if (_searchTextBox != null)
{
if (_validationError != null)
{
_messageViewContent.Content = SR.SearchErrorText + " " + _validationError;
_messageView.PlacementTarget = _searchTextBox;
_messageView.IsOpen = true;
}
}
break;
case Key.Escape:
e.Handled = true;
Close();
break;
}
}
/// <summary>
/// Gets whether the Panel is already closed.
/// </summary>
public bool IsClosed { get; private set; }
/// <summary>
/// Gets whether the Panel is currently opened.
/// </summary>
public bool IsOpened => !IsClosed;
/// <summary>
/// Closes the SearchPanel.
/// </summary>
public void Close()
{
_textArea.RemoveChild(this);
_messageView.IsOpen = false;
_textArea.TextView.BackgroundRenderers.Remove(_renderer);
IsClosed = true;
// Clear existing search results so that the segments don't have to be maintained
_renderer.CurrentResults.Clear();
_textArea.Focus();
}
/// <summary>
/// Opens the an existing search panel.
/// </summary>
public void Open()
{
if (!IsClosed) return;
_textArea.AddChild(this);
_textArea.TextView.BackgroundRenderers.Add(_renderer);
IsClosed = false;
DoSearch(false);
}
protected override void OnPointerPressed(PointerPressedEventArgs e)
{
e.Handled = true;
base.OnPointerPressed(e);
}
protected override void OnPointerMoved(PointerEventArgs e)
{
Cursor = Cursor.Default;
base.OnPointerMoved(e);
}
protected override void OnGotFocus(GotFocusEventArgs e)
{
e.Handled = true;
base.OnGotFocus(e);
}
/// <summary>
/// Fired when SearchOptions are changed inside the SearchPanel.
/// </summary>
public event EventHandler<SearchOptionsChangedEventArgs> SearchOptionsChanged;
/// <summary>
/// Raises the <see cref="SearchOptionsChanged" /> event.
/// </summary>
protected virtual void OnSearchOptionsChanged(SearchOptionsChangedEventArgs e)
{
SearchOptionsChanged?.Invoke(this, e);
}
public IList<RoutedCommandBinding> CommandBindings { get; } = new List<RoutedCommandBinding>();
}
/// <summary>
/// EventArgs for <see cref="SearchPanel.SearchOptionsChanged"/> event.
/// </summary>
public class SearchOptionsChangedEventArgs : EventArgs
{
/// <summary>
/// Gets the search pattern.
/// </summary>
public string SearchPattern { get; }
/// <summary>
/// Gets whether the search pattern should be interpreted case-sensitive.
/// </summary>
public bool MatchCase { get; }
/// <summary>
/// Gets whether the search pattern should be interpreted as regular expression.
/// </summary>
public bool UseRegex { get; }
/// <summary>
/// Gets whether the search pattern should only match whole words.
/// </summary>
public bool WholeWords { get; }
/// <summary>
/// Creates a new SearchOptionsChangedEventArgs instance.
/// </summary>
public SearchOptionsChangedEventArgs(string searchPattern, bool matchCase, bool useRegex, bool wholeWords)
{
SearchPattern = searchPattern;
MatchCase = matchCase;
UseRegex = useRegex;
WholeWords = wholeWords;
}
}
}
<MSG> update search after replace
<DFF> @@ -357,6 +357,8 @@ namespace AvaloniaEdit.Search
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
+
+ UpdateSearch();
}
public void ReplaceAll()
| 2 | update search after replace | 0 | .cs | cs | mit | AvaloniaUI/AvaloniaEdit |
10066860 | <NME> SearchPanel.cs
<BEF> // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.VisualTree;
using AvaloniaEdit.Document;
using AvaloniaEdit.Editing;
using AvaloniaEdit.Rendering;
namespace AvaloniaEdit.Search
{
/// <summary>
/// Provides search functionality for AvalonEdit. It is displayed in the top-right corner of the TextArea.
/// </summary>
public class SearchPanel : TemplatedControl, IRoutedCommandBindable
{
private TextArea _textArea;
private SearchInputHandler _handler;
private TextDocument _currentDocument;
private SearchResultBackgroundRenderer _renderer;
private TextBox _searchTextBox;
private TextEditor _textEditor { get; set; }
private Border _border;
#region DependencyProperties
/// <summary>
/// Dependency property for <see cref="UseRegex"/>.
/// </summary>
public static readonly StyledProperty<bool> UseRegexProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(UseRegex));
/// <summary>
/// Gets/sets whether the search pattern should be interpreted as regular expression.
/// </summary>
public bool UseRegex
{
get => GetValue(UseRegexProperty);
set => SetValue(UseRegexProperty, value);
}
/// <summary>
/// Dependency property for <see cref="MatchCase"/>.
/// </summary>
public static readonly StyledProperty<bool> MatchCaseProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(MatchCase));
/// <summary>
/// Gets/sets whether the search pattern should be interpreted case-sensitive.
/// </summary>
public bool MatchCase
{
get => GetValue(MatchCaseProperty);
set => SetValue(MatchCaseProperty, value);
}
/// <summary>
/// Dependency property for <see cref="WholeWords"/>.
/// </summary>
public static readonly StyledProperty<bool> WholeWordsProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(WholeWords));
/// <summary>
/// Gets/sets whether the search pattern should only match whole words.
/// </summary>
public bool WholeWords
{
get => GetValue(WholeWordsProperty);
set => SetValue(WholeWordsProperty, value);
}
/// <summary>
/// Dependency property for <see cref="SearchPattern"/>.
/// </summary>
public static readonly StyledProperty<string> SearchPatternProperty =
AvaloniaProperty.Register<SearchPanel, string>(nameof(SearchPattern), "");
/// <summary>
/// Gets/sets the search pattern.
/// </summary>
public string SearchPattern
{
get => GetValue(SearchPatternProperty);
set => SetValue(SearchPatternProperty, value);
}
public static readonly StyledProperty<bool> IsReplaceModeProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(IsReplaceMode));
/// <summary>
/// Checks if replacemode is allowed
/// </summary>
/// <returns>False if editor is not null and readonly</returns>
private static bool ValidateReplaceMode(SearchPanel panel, bool v1)
{
if (panel._textEditor == null || !v1) return v1;
return !panel._textEditor.IsReadOnly;
}
public bool IsReplaceMode
{
get => GetValue(IsReplaceModeProperty);
set => SetValue(IsReplaceModeProperty, _textEditor?.IsReadOnly ?? false ? false : value);
}
public static readonly StyledProperty<string> ReplacePatternProperty =
AvaloniaProperty.Register<SearchPanel, string>(nameof(ReplacePattern));
public string ReplacePattern
{
get => GetValue(ReplacePatternProperty);
set => SetValue(ReplacePatternProperty, value);
}
/// <summary>
/// Dependency property for <see cref="MarkerBrush"/>.
/// </summary>
public static readonly StyledProperty<IBrush> MarkerBrushProperty =
AvaloniaProperty.Register<SearchPanel, IBrush>(nameof(MarkerBrush), Brushes.LightGreen);
/// <summary>
/// Gets/sets the Brush used for marking search results in the TextView.
/// </summary>
public IBrush MarkerBrush
{
get => GetValue(MarkerBrushProperty);
set => SetValue(MarkerBrushProperty, value);
}
#endregion
private static void MarkerBrushChangedCallback(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is SearchPanel panel)
{
panel._renderer.MarkerBrush = (IBrush)e.NewValue;
}
}
private ISearchStrategy _strategy;
private static void SearchPatternChangedCallback(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is SearchPanel panel)
{
panel.ValidateSearchText();
panel.UpdateSearch();
}
}
private void UpdateSearch()
{
// only reset as long as there are results
// if no results are found, the "no matches found" message should not flicker.
// if results are found by the next run, the message will be hidden inside DoSearch ...
if (_renderer.CurrentResults.Any())
_messageView.IsOpen = false;
_strategy = SearchStrategyFactory.Create(SearchPattern ?? "", !MatchCase, WholeWords, UseRegex ? SearchMode.RegEx : SearchMode.Normal);
OnSearchOptionsChanged(new SearchOptionsChangedEventArgs(SearchPattern, MatchCase, UseRegex, WholeWords));
DoSearch(true);
}
static SearchPanel()
{
UseRegexProperty.Changed.Subscribe(SearchPatternChangedCallback);
MatchCaseProperty.Changed.Subscribe(SearchPatternChangedCallback);
WholeWordsProperty.Changed.Subscribe(SearchPatternChangedCallback);
SearchPatternProperty.Changed.Subscribe(SearchPatternChangedCallback);
MarkerBrushProperty.Changed.Subscribe(MarkerBrushChangedCallback);
}
/// <summary>
/// Creates a new SearchPanel.
/// </summary>
private SearchPanel()
{
}
/// <summary>
/// Creates a SearchPanel and installs it to the TextEditor's TextArea.
/// </summary>
/// <remarks>This is a convenience wrapper.</remarks>
public static SearchPanel Install(TextEditor editor)
{
if (editor == null) throw new ArgumentNullException(nameof(editor));
SearchPanel searchPanel = Install(editor.TextArea);
searchPanel._textEditor = editor;
return searchPanel;
}
/// <summary>
/// Creates a SearchPanel and installs it to the TextArea.
/// </summary>
public static SearchPanel Install(TextArea textArea)
{
if (textArea == null) throw new ArgumentNullException(nameof(textArea));
var panel = new SearchPanel();
panel.AttachInternal(textArea);
panel._handler = new SearchInputHandler(textArea, panel);
textArea.DefaultInputHandler.NestedInputHandlers.Add(panel._handler);
((ISetLogicalParent)panel).SetParent(textArea);
return panel;
}
/// <summary>
/// Adds the commands used by SearchPanel to the given CommandBindingCollection.
/// </summary>
public void RegisterCommands(ICollection<RoutedCommandBinding> commandBindings)
{
_handler.RegisterGlobalCommands(commandBindings);
}
/// <summary>
/// Removes the SearchPanel from the TextArea.
/// </summary>
public void Uninstall()
{
Close();
_textArea.DocumentChanged -= TextArea_DocumentChanged;
if (_currentDocument != null)
_currentDocument.TextChanged -= TextArea_Document_TextChanged;
_textArea.DefaultInputHandler.NestedInputHandlers.Remove(_handler);
}
private void AttachInternal(TextArea textArea)
{
_textArea = textArea;
_renderer = new SearchResultBackgroundRenderer();
_currentDocument = textArea.Document;
if (_currentDocument != null)
_currentDocument.TextChanged += TextArea_Document_TextChanged;
textArea.DocumentChanged += TextArea_DocumentChanged;
KeyDown += SearchLayerKeyDown;
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.FindNext, (sender, e) => FindNext()));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.FindPrevious, (sender, e) => FindPrevious()));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.CloseSearchPanel, (sender, e) => Close()));
CommandBindings.Add(new RoutedCommandBinding(ApplicationCommands.Find, (sender, e) =>
{
IsReplaceMode = false;
Reactivate();
}));
CommandBindings.Add(new RoutedCommandBinding(ApplicationCommands.Replace, (sender, e) => IsReplaceMode = true));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.ReplaceNext, (sender, e) => ReplaceNext(), (sender, e) => e.CanExecute = IsReplaceMode));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.ReplaceAll, (sender, e) => ReplaceAll(), (sender, e) => e.CanExecute = IsReplaceMode));
IsClosed = true;
}
private void TextArea_DocumentChanged(object sender, EventArgs e)
{
if (_currentDocument != null)
_currentDocument.TextChanged -= TextArea_Document_TextChanged;
_currentDocument = _textArea.Document;
if (_currentDocument != null)
{
_currentDocument.TextChanged += TextArea_Document_TextChanged;
DoSearch(false);
}
}
private void TextArea_Document_TextChanged(object sender, EventArgs e)
{
DoSearch(false);
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
_border = e.NameScope.Find<Border>("PART_Border");
_searchTextBox = e.NameScope.Find<TextBox>("PART_searchTextBox");
_messageView = e.NameScope.Find<Popup>("PART_MessageView");
_messageViewContent = e.NameScope.Find<ContentPresenter>("PART_MessageContent");
}
private void ValidateSearchText()
{
if (_searchTextBox == null)
return;
try
{
UpdateSearch();
_validationError = null;
}
catch (SearchPatternException ex)
{
_validationError = ex.Message;
}
}
/// <summary>
/// Reactivates the SearchPanel by setting the focus on the search box and selecting all text.
/// </summary>
public void Reactivate()
{
if (_searchTextBox == null)
return;
_searchTextBox.Focus();
_searchTextBox.SelectionStart = 0;
_searchTextBox.SelectionEnd = _searchTextBox.Text?.Length ?? 0;
}
/// <summary>
/// Moves to the next occurrence in the file.
/// </summary>
public void FindNext()
{
var result = _renderer.CurrentResults.FindFirstSegmentWithStartAfter(_textArea.Caret.Offset + 1) ??
_renderer.CurrentResults.FirstSegment;
if (result != null)
{
SelectResult(result);
}
}
/// <summary>
/// Moves to the previous occurrence in the file.
/// </summary>
public void FindPrevious()
{
var result = _renderer.CurrentResults.FindFirstSegmentWithStartAfter(_textArea.Caret.Offset);
if (result != null)
result = _renderer.CurrentResults.GetPreviousSegment(result);
if (result == null)
result = _renderer.CurrentResults.LastSegment;
if (result != null)
{
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
}
public void ReplaceAll()
FindNext();
if (!_textArea.Selection.IsEmpty)
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
UpdateSearch();
}
public void ReplaceAll()
{
if (!IsReplaceMode) return;
var replacement = ReplacePattern ?? string.Empty;
var document = _textArea.Document;
using (document.RunUpdate())
{
var segments = _renderer.CurrentResults.OrderByDescending(x => x.EndOffset).ToArray();
foreach (var textSegment in segments)
{
document.Replace(textSegment.StartOffset, textSegment.Length,
new StringTextSource(replacement));
}
}
}
private Popup _messageView;
private ContentPresenter _messageViewContent;
private string _validationError;
private void DoSearch(bool changeSelection)
{
if (IsClosed)
return;
_renderer.CurrentResults.Clear();
if (!string.IsNullOrEmpty(SearchPattern))
{
var offset = _textArea.Caret.Offset;
if (changeSelection)
{
_textArea.ClearSelection();
}
// We cast from ISearchResult to SearchResult; this is safe because we always use the built-in strategy
foreach (var result in _strategy.FindAll(_textArea.Document, 0, _textArea.Document.TextLength).Cast<SearchResult>())
{
if (changeSelection && result.StartOffset >= offset)
{
SelectResult(result);
changeSelection = false;
}
_renderer.CurrentResults.Add(result);
}
}
if (_messageView != null)
{
if (!_renderer.CurrentResults.Any())
{
_messageViewContent.Content = SR.SearchNoMatchesFoundText;
_messageView.PlacementTarget = _searchTextBox;
_messageView.IsOpen = true;
}
else
_messageView.IsOpen = false;
}
_textArea.TextView.InvalidateLayer(KnownLayer.Selection);
}
private void SelectResult(TextSegment result)
{
_textArea.Caret.Offset = result.StartOffset;
_textArea.Selection = Selection.Create(_textArea, result.StartOffset, result.EndOffset);
double distanceToViewBorder = _border == null ?
Caret.MinimumDistanceToViewBorder :
_border.Bounds.Height + _textArea.TextView.DefaultLineHeight;
_textArea.Caret.BringCaretToView(distanceToViewBorder);
// show caret even if the editor does not have the Keyboard Focus
_textArea.Caret.Show();
}
private void SearchLayerKeyDown(object sender, KeyEventArgs e)
{
switch (e.Key)
{
case Key.Enter:
e.Handled = true;
if (e.KeyModifiers.HasFlag(KeyModifiers.Shift))
{
FindPrevious();
}
else
{
FindNext();
}
if (_searchTextBox != null)
{
if (_validationError != null)
{
_messageViewContent.Content = SR.SearchErrorText + " " + _validationError;
_messageView.PlacementTarget = _searchTextBox;
_messageView.IsOpen = true;
}
}
break;
case Key.Escape:
e.Handled = true;
Close();
break;
}
}
/// <summary>
/// Gets whether the Panel is already closed.
/// </summary>
public bool IsClosed { get; private set; }
/// <summary>
/// Gets whether the Panel is currently opened.
/// </summary>
public bool IsOpened => !IsClosed;
/// <summary>
/// Closes the SearchPanel.
/// </summary>
public void Close()
{
_textArea.RemoveChild(this);
_messageView.IsOpen = false;
_textArea.TextView.BackgroundRenderers.Remove(_renderer);
IsClosed = true;
// Clear existing search results so that the segments don't have to be maintained
_renderer.CurrentResults.Clear();
_textArea.Focus();
}
/// <summary>
/// Opens the an existing search panel.
/// </summary>
public void Open()
{
if (!IsClosed) return;
_textArea.AddChild(this);
_textArea.TextView.BackgroundRenderers.Add(_renderer);
IsClosed = false;
DoSearch(false);
}
protected override void OnPointerPressed(PointerPressedEventArgs e)
{
e.Handled = true;
base.OnPointerPressed(e);
}
protected override void OnPointerMoved(PointerEventArgs e)
{
Cursor = Cursor.Default;
base.OnPointerMoved(e);
}
protected override void OnGotFocus(GotFocusEventArgs e)
{
e.Handled = true;
base.OnGotFocus(e);
}
/// <summary>
/// Fired when SearchOptions are changed inside the SearchPanel.
/// </summary>
public event EventHandler<SearchOptionsChangedEventArgs> SearchOptionsChanged;
/// <summary>
/// Raises the <see cref="SearchOptionsChanged" /> event.
/// </summary>
protected virtual void OnSearchOptionsChanged(SearchOptionsChangedEventArgs e)
{
SearchOptionsChanged?.Invoke(this, e);
}
public IList<RoutedCommandBinding> CommandBindings { get; } = new List<RoutedCommandBinding>();
}
/// <summary>
/// EventArgs for <see cref="SearchPanel.SearchOptionsChanged"/> event.
/// </summary>
public class SearchOptionsChangedEventArgs : EventArgs
{
/// <summary>
/// Gets the search pattern.
/// </summary>
public string SearchPattern { get; }
/// <summary>
/// Gets whether the search pattern should be interpreted case-sensitive.
/// </summary>
public bool MatchCase { get; }
/// <summary>
/// Gets whether the search pattern should be interpreted as regular expression.
/// </summary>
public bool UseRegex { get; }
/// <summary>
/// Gets whether the search pattern should only match whole words.
/// </summary>
public bool WholeWords { get; }
/// <summary>
/// Creates a new SearchOptionsChangedEventArgs instance.
/// </summary>
public SearchOptionsChangedEventArgs(string searchPattern, bool matchCase, bool useRegex, bool wholeWords)
{
SearchPattern = searchPattern;
MatchCase = matchCase;
UseRegex = useRegex;
WholeWords = wholeWords;
}
}
}
<MSG> update search after replace
<DFF> @@ -357,6 +357,8 @@ namespace AvaloniaEdit.Search
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
+
+ UpdateSearch();
}
public void ReplaceAll()
| 2 | update search after replace | 0 | .cs | cs | mit | AvaloniaUI/AvaloniaEdit |
10066861 | <NME> SearchPanel.cs
<BEF> // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.VisualTree;
using AvaloniaEdit.Document;
using AvaloniaEdit.Editing;
using AvaloniaEdit.Rendering;
namespace AvaloniaEdit.Search
{
/// <summary>
/// Provides search functionality for AvalonEdit. It is displayed in the top-right corner of the TextArea.
/// </summary>
public class SearchPanel : TemplatedControl, IRoutedCommandBindable
{
private TextArea _textArea;
private SearchInputHandler _handler;
private TextDocument _currentDocument;
private SearchResultBackgroundRenderer _renderer;
private TextBox _searchTextBox;
private TextEditor _textEditor { get; set; }
private Border _border;
#region DependencyProperties
/// <summary>
/// Dependency property for <see cref="UseRegex"/>.
/// </summary>
public static readonly StyledProperty<bool> UseRegexProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(UseRegex));
/// <summary>
/// Gets/sets whether the search pattern should be interpreted as regular expression.
/// </summary>
public bool UseRegex
{
get => GetValue(UseRegexProperty);
set => SetValue(UseRegexProperty, value);
}
/// <summary>
/// Dependency property for <see cref="MatchCase"/>.
/// </summary>
public static readonly StyledProperty<bool> MatchCaseProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(MatchCase));
/// <summary>
/// Gets/sets whether the search pattern should be interpreted case-sensitive.
/// </summary>
public bool MatchCase
{
get => GetValue(MatchCaseProperty);
set => SetValue(MatchCaseProperty, value);
}
/// <summary>
/// Dependency property for <see cref="WholeWords"/>.
/// </summary>
public static readonly StyledProperty<bool> WholeWordsProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(WholeWords));
/// <summary>
/// Gets/sets whether the search pattern should only match whole words.
/// </summary>
public bool WholeWords
{
get => GetValue(WholeWordsProperty);
set => SetValue(WholeWordsProperty, value);
}
/// <summary>
/// Dependency property for <see cref="SearchPattern"/>.
/// </summary>
public static readonly StyledProperty<string> SearchPatternProperty =
AvaloniaProperty.Register<SearchPanel, string>(nameof(SearchPattern), "");
/// <summary>
/// Gets/sets the search pattern.
/// </summary>
public string SearchPattern
{
get => GetValue(SearchPatternProperty);
set => SetValue(SearchPatternProperty, value);
}
public static readonly StyledProperty<bool> IsReplaceModeProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(IsReplaceMode));
/// <summary>
/// Checks if replacemode is allowed
/// </summary>
/// <returns>False if editor is not null and readonly</returns>
private static bool ValidateReplaceMode(SearchPanel panel, bool v1)
{
if (panel._textEditor == null || !v1) return v1;
return !panel._textEditor.IsReadOnly;
}
public bool IsReplaceMode
{
get => GetValue(IsReplaceModeProperty);
set => SetValue(IsReplaceModeProperty, _textEditor?.IsReadOnly ?? false ? false : value);
}
public static readonly StyledProperty<string> ReplacePatternProperty =
AvaloniaProperty.Register<SearchPanel, string>(nameof(ReplacePattern));
public string ReplacePattern
{
get => GetValue(ReplacePatternProperty);
set => SetValue(ReplacePatternProperty, value);
}
/// <summary>
/// Dependency property for <see cref="MarkerBrush"/>.
/// </summary>
public static readonly StyledProperty<IBrush> MarkerBrushProperty =
AvaloniaProperty.Register<SearchPanel, IBrush>(nameof(MarkerBrush), Brushes.LightGreen);
/// <summary>
/// Gets/sets the Brush used for marking search results in the TextView.
/// </summary>
public IBrush MarkerBrush
{
get => GetValue(MarkerBrushProperty);
set => SetValue(MarkerBrushProperty, value);
}
#endregion
private static void MarkerBrushChangedCallback(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is SearchPanel panel)
{
panel._renderer.MarkerBrush = (IBrush)e.NewValue;
}
}
private ISearchStrategy _strategy;
private static void SearchPatternChangedCallback(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is SearchPanel panel)
{
panel.ValidateSearchText();
panel.UpdateSearch();
}
}
private void UpdateSearch()
{
// only reset as long as there are results
// if no results are found, the "no matches found" message should not flicker.
// if results are found by the next run, the message will be hidden inside DoSearch ...
if (_renderer.CurrentResults.Any())
_messageView.IsOpen = false;
_strategy = SearchStrategyFactory.Create(SearchPattern ?? "", !MatchCase, WholeWords, UseRegex ? SearchMode.RegEx : SearchMode.Normal);
OnSearchOptionsChanged(new SearchOptionsChangedEventArgs(SearchPattern, MatchCase, UseRegex, WholeWords));
DoSearch(true);
}
static SearchPanel()
{
UseRegexProperty.Changed.Subscribe(SearchPatternChangedCallback);
MatchCaseProperty.Changed.Subscribe(SearchPatternChangedCallback);
WholeWordsProperty.Changed.Subscribe(SearchPatternChangedCallback);
SearchPatternProperty.Changed.Subscribe(SearchPatternChangedCallback);
MarkerBrushProperty.Changed.Subscribe(MarkerBrushChangedCallback);
}
/// <summary>
/// Creates a new SearchPanel.
/// </summary>
private SearchPanel()
{
}
/// <summary>
/// Creates a SearchPanel and installs it to the TextEditor's TextArea.
/// </summary>
/// <remarks>This is a convenience wrapper.</remarks>
public static SearchPanel Install(TextEditor editor)
{
if (editor == null) throw new ArgumentNullException(nameof(editor));
SearchPanel searchPanel = Install(editor.TextArea);
searchPanel._textEditor = editor;
return searchPanel;
}
/// <summary>
/// Creates a SearchPanel and installs it to the TextArea.
/// </summary>
public static SearchPanel Install(TextArea textArea)
{
if (textArea == null) throw new ArgumentNullException(nameof(textArea));
var panel = new SearchPanel();
panel.AttachInternal(textArea);
panel._handler = new SearchInputHandler(textArea, panel);
textArea.DefaultInputHandler.NestedInputHandlers.Add(panel._handler);
((ISetLogicalParent)panel).SetParent(textArea);
return panel;
}
/// <summary>
/// Adds the commands used by SearchPanel to the given CommandBindingCollection.
/// </summary>
public void RegisterCommands(ICollection<RoutedCommandBinding> commandBindings)
{
_handler.RegisterGlobalCommands(commandBindings);
}
/// <summary>
/// Removes the SearchPanel from the TextArea.
/// </summary>
public void Uninstall()
{
Close();
_textArea.DocumentChanged -= TextArea_DocumentChanged;
if (_currentDocument != null)
_currentDocument.TextChanged -= TextArea_Document_TextChanged;
_textArea.DefaultInputHandler.NestedInputHandlers.Remove(_handler);
}
private void AttachInternal(TextArea textArea)
{
_textArea = textArea;
_renderer = new SearchResultBackgroundRenderer();
_currentDocument = textArea.Document;
if (_currentDocument != null)
_currentDocument.TextChanged += TextArea_Document_TextChanged;
textArea.DocumentChanged += TextArea_DocumentChanged;
KeyDown += SearchLayerKeyDown;
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.FindNext, (sender, e) => FindNext()));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.FindPrevious, (sender, e) => FindPrevious()));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.CloseSearchPanel, (sender, e) => Close()));
CommandBindings.Add(new RoutedCommandBinding(ApplicationCommands.Find, (sender, e) =>
{
IsReplaceMode = false;
Reactivate();
}));
CommandBindings.Add(new RoutedCommandBinding(ApplicationCommands.Replace, (sender, e) => IsReplaceMode = true));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.ReplaceNext, (sender, e) => ReplaceNext(), (sender, e) => e.CanExecute = IsReplaceMode));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.ReplaceAll, (sender, e) => ReplaceAll(), (sender, e) => e.CanExecute = IsReplaceMode));
IsClosed = true;
}
private void TextArea_DocumentChanged(object sender, EventArgs e)
{
if (_currentDocument != null)
_currentDocument.TextChanged -= TextArea_Document_TextChanged;
_currentDocument = _textArea.Document;
if (_currentDocument != null)
{
_currentDocument.TextChanged += TextArea_Document_TextChanged;
DoSearch(false);
}
}
private void TextArea_Document_TextChanged(object sender, EventArgs e)
{
DoSearch(false);
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
_border = e.NameScope.Find<Border>("PART_Border");
_searchTextBox = e.NameScope.Find<TextBox>("PART_searchTextBox");
_messageView = e.NameScope.Find<Popup>("PART_MessageView");
_messageViewContent = e.NameScope.Find<ContentPresenter>("PART_MessageContent");
}
private void ValidateSearchText()
{
if (_searchTextBox == null)
return;
try
{
UpdateSearch();
_validationError = null;
}
catch (SearchPatternException ex)
{
_validationError = ex.Message;
}
}
/// <summary>
/// Reactivates the SearchPanel by setting the focus on the search box and selecting all text.
/// </summary>
public void Reactivate()
{
if (_searchTextBox == null)
return;
_searchTextBox.Focus();
_searchTextBox.SelectionStart = 0;
_searchTextBox.SelectionEnd = _searchTextBox.Text?.Length ?? 0;
}
/// <summary>
/// Moves to the next occurrence in the file.
/// </summary>
public void FindNext()
{
var result = _renderer.CurrentResults.FindFirstSegmentWithStartAfter(_textArea.Caret.Offset + 1) ??
_renderer.CurrentResults.FirstSegment;
if (result != null)
{
SelectResult(result);
}
}
/// <summary>
/// Moves to the previous occurrence in the file.
/// </summary>
public void FindPrevious()
{
var result = _renderer.CurrentResults.FindFirstSegmentWithStartAfter(_textArea.Caret.Offset);
if (result != null)
result = _renderer.CurrentResults.GetPreviousSegment(result);
if (result == null)
result = _renderer.CurrentResults.LastSegment;
if (result != null)
{
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
}
public void ReplaceAll()
FindNext();
if (!_textArea.Selection.IsEmpty)
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
UpdateSearch();
}
public void ReplaceAll()
{
if (!IsReplaceMode) return;
var replacement = ReplacePattern ?? string.Empty;
var document = _textArea.Document;
using (document.RunUpdate())
{
var segments = _renderer.CurrentResults.OrderByDescending(x => x.EndOffset).ToArray();
foreach (var textSegment in segments)
{
document.Replace(textSegment.StartOffset, textSegment.Length,
new StringTextSource(replacement));
}
}
}
private Popup _messageView;
private ContentPresenter _messageViewContent;
private string _validationError;
private void DoSearch(bool changeSelection)
{
if (IsClosed)
return;
_renderer.CurrentResults.Clear();
if (!string.IsNullOrEmpty(SearchPattern))
{
var offset = _textArea.Caret.Offset;
if (changeSelection)
{
_textArea.ClearSelection();
}
// We cast from ISearchResult to SearchResult; this is safe because we always use the built-in strategy
foreach (var result in _strategy.FindAll(_textArea.Document, 0, _textArea.Document.TextLength).Cast<SearchResult>())
{
if (changeSelection && result.StartOffset >= offset)
{
SelectResult(result);
changeSelection = false;
}
_renderer.CurrentResults.Add(result);
}
}
if (_messageView != null)
{
if (!_renderer.CurrentResults.Any())
{
_messageViewContent.Content = SR.SearchNoMatchesFoundText;
_messageView.PlacementTarget = _searchTextBox;
_messageView.IsOpen = true;
}
else
_messageView.IsOpen = false;
}
_textArea.TextView.InvalidateLayer(KnownLayer.Selection);
}
private void SelectResult(TextSegment result)
{
_textArea.Caret.Offset = result.StartOffset;
_textArea.Selection = Selection.Create(_textArea, result.StartOffset, result.EndOffset);
double distanceToViewBorder = _border == null ?
Caret.MinimumDistanceToViewBorder :
_border.Bounds.Height + _textArea.TextView.DefaultLineHeight;
_textArea.Caret.BringCaretToView(distanceToViewBorder);
// show caret even if the editor does not have the Keyboard Focus
_textArea.Caret.Show();
}
private void SearchLayerKeyDown(object sender, KeyEventArgs e)
{
switch (e.Key)
{
case Key.Enter:
e.Handled = true;
if (e.KeyModifiers.HasFlag(KeyModifiers.Shift))
{
FindPrevious();
}
else
{
FindNext();
}
if (_searchTextBox != null)
{
if (_validationError != null)
{
_messageViewContent.Content = SR.SearchErrorText + " " + _validationError;
_messageView.PlacementTarget = _searchTextBox;
_messageView.IsOpen = true;
}
}
break;
case Key.Escape:
e.Handled = true;
Close();
break;
}
}
/// <summary>
/// Gets whether the Panel is already closed.
/// </summary>
public bool IsClosed { get; private set; }
/// <summary>
/// Gets whether the Panel is currently opened.
/// </summary>
public bool IsOpened => !IsClosed;
/// <summary>
/// Closes the SearchPanel.
/// </summary>
public void Close()
{
_textArea.RemoveChild(this);
_messageView.IsOpen = false;
_textArea.TextView.BackgroundRenderers.Remove(_renderer);
IsClosed = true;
// Clear existing search results so that the segments don't have to be maintained
_renderer.CurrentResults.Clear();
_textArea.Focus();
}
/// <summary>
/// Opens the an existing search panel.
/// </summary>
public void Open()
{
if (!IsClosed) return;
_textArea.AddChild(this);
_textArea.TextView.BackgroundRenderers.Add(_renderer);
IsClosed = false;
DoSearch(false);
}
protected override void OnPointerPressed(PointerPressedEventArgs e)
{
e.Handled = true;
base.OnPointerPressed(e);
}
protected override void OnPointerMoved(PointerEventArgs e)
{
Cursor = Cursor.Default;
base.OnPointerMoved(e);
}
protected override void OnGotFocus(GotFocusEventArgs e)
{
e.Handled = true;
base.OnGotFocus(e);
}
/// <summary>
/// Fired when SearchOptions are changed inside the SearchPanel.
/// </summary>
public event EventHandler<SearchOptionsChangedEventArgs> SearchOptionsChanged;
/// <summary>
/// Raises the <see cref="SearchOptionsChanged" /> event.
/// </summary>
protected virtual void OnSearchOptionsChanged(SearchOptionsChangedEventArgs e)
{
SearchOptionsChanged?.Invoke(this, e);
}
public IList<RoutedCommandBinding> CommandBindings { get; } = new List<RoutedCommandBinding>();
}
/// <summary>
/// EventArgs for <see cref="SearchPanel.SearchOptionsChanged"/> event.
/// </summary>
public class SearchOptionsChangedEventArgs : EventArgs
{
/// <summary>
/// Gets the search pattern.
/// </summary>
public string SearchPattern { get; }
/// <summary>
/// Gets whether the search pattern should be interpreted case-sensitive.
/// </summary>
public bool MatchCase { get; }
/// <summary>
/// Gets whether the search pattern should be interpreted as regular expression.
/// </summary>
public bool UseRegex { get; }
/// <summary>
/// Gets whether the search pattern should only match whole words.
/// </summary>
public bool WholeWords { get; }
/// <summary>
/// Creates a new SearchOptionsChangedEventArgs instance.
/// </summary>
public SearchOptionsChangedEventArgs(string searchPattern, bool matchCase, bool useRegex, bool wholeWords)
{
SearchPattern = searchPattern;
MatchCase = matchCase;
UseRegex = useRegex;
WholeWords = wholeWords;
}
}
}
<MSG> update search after replace
<DFF> @@ -357,6 +357,8 @@ namespace AvaloniaEdit.Search
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
+
+ UpdateSearch();
}
public void ReplaceAll()
| 2 | update search after replace | 0 | .cs | cs | mit | AvaloniaUI/AvaloniaEdit |
10066862 | <NME> SearchPanel.cs
<BEF> // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.VisualTree;
using AvaloniaEdit.Document;
using AvaloniaEdit.Editing;
using AvaloniaEdit.Rendering;
namespace AvaloniaEdit.Search
{
/// <summary>
/// Provides search functionality for AvalonEdit. It is displayed in the top-right corner of the TextArea.
/// </summary>
public class SearchPanel : TemplatedControl, IRoutedCommandBindable
{
private TextArea _textArea;
private SearchInputHandler _handler;
private TextDocument _currentDocument;
private SearchResultBackgroundRenderer _renderer;
private TextBox _searchTextBox;
private TextEditor _textEditor { get; set; }
private Border _border;
#region DependencyProperties
/// <summary>
/// Dependency property for <see cref="UseRegex"/>.
/// </summary>
public static readonly StyledProperty<bool> UseRegexProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(UseRegex));
/// <summary>
/// Gets/sets whether the search pattern should be interpreted as regular expression.
/// </summary>
public bool UseRegex
{
get => GetValue(UseRegexProperty);
set => SetValue(UseRegexProperty, value);
}
/// <summary>
/// Dependency property for <see cref="MatchCase"/>.
/// </summary>
public static readonly StyledProperty<bool> MatchCaseProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(MatchCase));
/// <summary>
/// Gets/sets whether the search pattern should be interpreted case-sensitive.
/// </summary>
public bool MatchCase
{
get => GetValue(MatchCaseProperty);
set => SetValue(MatchCaseProperty, value);
}
/// <summary>
/// Dependency property for <see cref="WholeWords"/>.
/// </summary>
public static readonly StyledProperty<bool> WholeWordsProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(WholeWords));
/// <summary>
/// Gets/sets whether the search pattern should only match whole words.
/// </summary>
public bool WholeWords
{
get => GetValue(WholeWordsProperty);
set => SetValue(WholeWordsProperty, value);
}
/// <summary>
/// Dependency property for <see cref="SearchPattern"/>.
/// </summary>
public static readonly StyledProperty<string> SearchPatternProperty =
AvaloniaProperty.Register<SearchPanel, string>(nameof(SearchPattern), "");
/// <summary>
/// Gets/sets the search pattern.
/// </summary>
public string SearchPattern
{
get => GetValue(SearchPatternProperty);
set => SetValue(SearchPatternProperty, value);
}
public static readonly StyledProperty<bool> IsReplaceModeProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(IsReplaceMode));
/// <summary>
/// Checks if replacemode is allowed
/// </summary>
/// <returns>False if editor is not null and readonly</returns>
private static bool ValidateReplaceMode(SearchPanel panel, bool v1)
{
if (panel._textEditor == null || !v1) return v1;
return !panel._textEditor.IsReadOnly;
}
public bool IsReplaceMode
{
get => GetValue(IsReplaceModeProperty);
set => SetValue(IsReplaceModeProperty, _textEditor?.IsReadOnly ?? false ? false : value);
}
public static readonly StyledProperty<string> ReplacePatternProperty =
AvaloniaProperty.Register<SearchPanel, string>(nameof(ReplacePattern));
public string ReplacePattern
{
get => GetValue(ReplacePatternProperty);
set => SetValue(ReplacePatternProperty, value);
}
/// <summary>
/// Dependency property for <see cref="MarkerBrush"/>.
/// </summary>
public static readonly StyledProperty<IBrush> MarkerBrushProperty =
AvaloniaProperty.Register<SearchPanel, IBrush>(nameof(MarkerBrush), Brushes.LightGreen);
/// <summary>
/// Gets/sets the Brush used for marking search results in the TextView.
/// </summary>
public IBrush MarkerBrush
{
get => GetValue(MarkerBrushProperty);
set => SetValue(MarkerBrushProperty, value);
}
#endregion
private static void MarkerBrushChangedCallback(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is SearchPanel panel)
{
panel._renderer.MarkerBrush = (IBrush)e.NewValue;
}
}
private ISearchStrategy _strategy;
private static void SearchPatternChangedCallback(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is SearchPanel panel)
{
panel.ValidateSearchText();
panel.UpdateSearch();
}
}
private void UpdateSearch()
{
// only reset as long as there are results
// if no results are found, the "no matches found" message should not flicker.
// if results are found by the next run, the message will be hidden inside DoSearch ...
if (_renderer.CurrentResults.Any())
_messageView.IsOpen = false;
_strategy = SearchStrategyFactory.Create(SearchPattern ?? "", !MatchCase, WholeWords, UseRegex ? SearchMode.RegEx : SearchMode.Normal);
OnSearchOptionsChanged(new SearchOptionsChangedEventArgs(SearchPattern, MatchCase, UseRegex, WholeWords));
DoSearch(true);
}
static SearchPanel()
{
UseRegexProperty.Changed.Subscribe(SearchPatternChangedCallback);
MatchCaseProperty.Changed.Subscribe(SearchPatternChangedCallback);
WholeWordsProperty.Changed.Subscribe(SearchPatternChangedCallback);
SearchPatternProperty.Changed.Subscribe(SearchPatternChangedCallback);
MarkerBrushProperty.Changed.Subscribe(MarkerBrushChangedCallback);
}
/// <summary>
/// Creates a new SearchPanel.
/// </summary>
private SearchPanel()
{
}
/// <summary>
/// Creates a SearchPanel and installs it to the TextEditor's TextArea.
/// </summary>
/// <remarks>This is a convenience wrapper.</remarks>
public static SearchPanel Install(TextEditor editor)
{
if (editor == null) throw new ArgumentNullException(nameof(editor));
SearchPanel searchPanel = Install(editor.TextArea);
searchPanel._textEditor = editor;
return searchPanel;
}
/// <summary>
/// Creates a SearchPanel and installs it to the TextArea.
/// </summary>
public static SearchPanel Install(TextArea textArea)
{
if (textArea == null) throw new ArgumentNullException(nameof(textArea));
var panel = new SearchPanel();
panel.AttachInternal(textArea);
panel._handler = new SearchInputHandler(textArea, panel);
textArea.DefaultInputHandler.NestedInputHandlers.Add(panel._handler);
((ISetLogicalParent)panel).SetParent(textArea);
return panel;
}
/// <summary>
/// Adds the commands used by SearchPanel to the given CommandBindingCollection.
/// </summary>
public void RegisterCommands(ICollection<RoutedCommandBinding> commandBindings)
{
_handler.RegisterGlobalCommands(commandBindings);
}
/// <summary>
/// Removes the SearchPanel from the TextArea.
/// </summary>
public void Uninstall()
{
Close();
_textArea.DocumentChanged -= TextArea_DocumentChanged;
if (_currentDocument != null)
_currentDocument.TextChanged -= TextArea_Document_TextChanged;
_textArea.DefaultInputHandler.NestedInputHandlers.Remove(_handler);
}
private void AttachInternal(TextArea textArea)
{
_textArea = textArea;
_renderer = new SearchResultBackgroundRenderer();
_currentDocument = textArea.Document;
if (_currentDocument != null)
_currentDocument.TextChanged += TextArea_Document_TextChanged;
textArea.DocumentChanged += TextArea_DocumentChanged;
KeyDown += SearchLayerKeyDown;
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.FindNext, (sender, e) => FindNext()));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.FindPrevious, (sender, e) => FindPrevious()));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.CloseSearchPanel, (sender, e) => Close()));
CommandBindings.Add(new RoutedCommandBinding(ApplicationCommands.Find, (sender, e) =>
{
IsReplaceMode = false;
Reactivate();
}));
CommandBindings.Add(new RoutedCommandBinding(ApplicationCommands.Replace, (sender, e) => IsReplaceMode = true));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.ReplaceNext, (sender, e) => ReplaceNext(), (sender, e) => e.CanExecute = IsReplaceMode));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.ReplaceAll, (sender, e) => ReplaceAll(), (sender, e) => e.CanExecute = IsReplaceMode));
IsClosed = true;
}
private void TextArea_DocumentChanged(object sender, EventArgs e)
{
if (_currentDocument != null)
_currentDocument.TextChanged -= TextArea_Document_TextChanged;
_currentDocument = _textArea.Document;
if (_currentDocument != null)
{
_currentDocument.TextChanged += TextArea_Document_TextChanged;
DoSearch(false);
}
}
private void TextArea_Document_TextChanged(object sender, EventArgs e)
{
DoSearch(false);
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
_border = e.NameScope.Find<Border>("PART_Border");
_searchTextBox = e.NameScope.Find<TextBox>("PART_searchTextBox");
_messageView = e.NameScope.Find<Popup>("PART_MessageView");
_messageViewContent = e.NameScope.Find<ContentPresenter>("PART_MessageContent");
}
private void ValidateSearchText()
{
if (_searchTextBox == null)
return;
try
{
UpdateSearch();
_validationError = null;
}
catch (SearchPatternException ex)
{
_validationError = ex.Message;
}
}
/// <summary>
/// Reactivates the SearchPanel by setting the focus on the search box and selecting all text.
/// </summary>
public void Reactivate()
{
if (_searchTextBox == null)
return;
_searchTextBox.Focus();
_searchTextBox.SelectionStart = 0;
_searchTextBox.SelectionEnd = _searchTextBox.Text?.Length ?? 0;
}
/// <summary>
/// Moves to the next occurrence in the file.
/// </summary>
public void FindNext()
{
var result = _renderer.CurrentResults.FindFirstSegmentWithStartAfter(_textArea.Caret.Offset + 1) ??
_renderer.CurrentResults.FirstSegment;
if (result != null)
{
SelectResult(result);
}
}
/// <summary>
/// Moves to the previous occurrence in the file.
/// </summary>
public void FindPrevious()
{
var result = _renderer.CurrentResults.FindFirstSegmentWithStartAfter(_textArea.Caret.Offset);
if (result != null)
result = _renderer.CurrentResults.GetPreviousSegment(result);
if (result == null)
result = _renderer.CurrentResults.LastSegment;
if (result != null)
{
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
}
public void ReplaceAll()
FindNext();
if (!_textArea.Selection.IsEmpty)
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
UpdateSearch();
}
public void ReplaceAll()
{
if (!IsReplaceMode) return;
var replacement = ReplacePattern ?? string.Empty;
var document = _textArea.Document;
using (document.RunUpdate())
{
var segments = _renderer.CurrentResults.OrderByDescending(x => x.EndOffset).ToArray();
foreach (var textSegment in segments)
{
document.Replace(textSegment.StartOffset, textSegment.Length,
new StringTextSource(replacement));
}
}
}
private Popup _messageView;
private ContentPresenter _messageViewContent;
private string _validationError;
private void DoSearch(bool changeSelection)
{
if (IsClosed)
return;
_renderer.CurrentResults.Clear();
if (!string.IsNullOrEmpty(SearchPattern))
{
var offset = _textArea.Caret.Offset;
if (changeSelection)
{
_textArea.ClearSelection();
}
// We cast from ISearchResult to SearchResult; this is safe because we always use the built-in strategy
foreach (var result in _strategy.FindAll(_textArea.Document, 0, _textArea.Document.TextLength).Cast<SearchResult>())
{
if (changeSelection && result.StartOffset >= offset)
{
SelectResult(result);
changeSelection = false;
}
_renderer.CurrentResults.Add(result);
}
}
if (_messageView != null)
{
if (!_renderer.CurrentResults.Any())
{
_messageViewContent.Content = SR.SearchNoMatchesFoundText;
_messageView.PlacementTarget = _searchTextBox;
_messageView.IsOpen = true;
}
else
_messageView.IsOpen = false;
}
_textArea.TextView.InvalidateLayer(KnownLayer.Selection);
}
private void SelectResult(TextSegment result)
{
_textArea.Caret.Offset = result.StartOffset;
_textArea.Selection = Selection.Create(_textArea, result.StartOffset, result.EndOffset);
double distanceToViewBorder = _border == null ?
Caret.MinimumDistanceToViewBorder :
_border.Bounds.Height + _textArea.TextView.DefaultLineHeight;
_textArea.Caret.BringCaretToView(distanceToViewBorder);
// show caret even if the editor does not have the Keyboard Focus
_textArea.Caret.Show();
}
private void SearchLayerKeyDown(object sender, KeyEventArgs e)
{
switch (e.Key)
{
case Key.Enter:
e.Handled = true;
if (e.KeyModifiers.HasFlag(KeyModifiers.Shift))
{
FindPrevious();
}
else
{
FindNext();
}
if (_searchTextBox != null)
{
if (_validationError != null)
{
_messageViewContent.Content = SR.SearchErrorText + " " + _validationError;
_messageView.PlacementTarget = _searchTextBox;
_messageView.IsOpen = true;
}
}
break;
case Key.Escape:
e.Handled = true;
Close();
break;
}
}
/// <summary>
/// Gets whether the Panel is already closed.
/// </summary>
public bool IsClosed { get; private set; }
/// <summary>
/// Gets whether the Panel is currently opened.
/// </summary>
public bool IsOpened => !IsClosed;
/// <summary>
/// Closes the SearchPanel.
/// </summary>
public void Close()
{
_textArea.RemoveChild(this);
_messageView.IsOpen = false;
_textArea.TextView.BackgroundRenderers.Remove(_renderer);
IsClosed = true;
// Clear existing search results so that the segments don't have to be maintained
_renderer.CurrentResults.Clear();
_textArea.Focus();
}
/// <summary>
/// Opens the an existing search panel.
/// </summary>
public void Open()
{
if (!IsClosed) return;
_textArea.AddChild(this);
_textArea.TextView.BackgroundRenderers.Add(_renderer);
IsClosed = false;
DoSearch(false);
}
protected override void OnPointerPressed(PointerPressedEventArgs e)
{
e.Handled = true;
base.OnPointerPressed(e);
}
protected override void OnPointerMoved(PointerEventArgs e)
{
Cursor = Cursor.Default;
base.OnPointerMoved(e);
}
protected override void OnGotFocus(GotFocusEventArgs e)
{
e.Handled = true;
base.OnGotFocus(e);
}
/// <summary>
/// Fired when SearchOptions are changed inside the SearchPanel.
/// </summary>
public event EventHandler<SearchOptionsChangedEventArgs> SearchOptionsChanged;
/// <summary>
/// Raises the <see cref="SearchOptionsChanged" /> event.
/// </summary>
protected virtual void OnSearchOptionsChanged(SearchOptionsChangedEventArgs e)
{
SearchOptionsChanged?.Invoke(this, e);
}
public IList<RoutedCommandBinding> CommandBindings { get; } = new List<RoutedCommandBinding>();
}
/// <summary>
/// EventArgs for <see cref="SearchPanel.SearchOptionsChanged"/> event.
/// </summary>
public class SearchOptionsChangedEventArgs : EventArgs
{
/// <summary>
/// Gets the search pattern.
/// </summary>
public string SearchPattern { get; }
/// <summary>
/// Gets whether the search pattern should be interpreted case-sensitive.
/// </summary>
public bool MatchCase { get; }
/// <summary>
/// Gets whether the search pattern should be interpreted as regular expression.
/// </summary>
public bool UseRegex { get; }
/// <summary>
/// Gets whether the search pattern should only match whole words.
/// </summary>
public bool WholeWords { get; }
/// <summary>
/// Creates a new SearchOptionsChangedEventArgs instance.
/// </summary>
public SearchOptionsChangedEventArgs(string searchPattern, bool matchCase, bool useRegex, bool wholeWords)
{
SearchPattern = searchPattern;
MatchCase = matchCase;
UseRegex = useRegex;
WholeWords = wholeWords;
}
}
}
<MSG> update search after replace
<DFF> @@ -357,6 +357,8 @@ namespace AvaloniaEdit.Search
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
+
+ UpdateSearch();
}
public void ReplaceAll()
| 2 | update search after replace | 0 | .cs | cs | mit | AvaloniaUI/AvaloniaEdit |
10066863 | <NME> SearchPanel.cs
<BEF> // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.VisualTree;
using AvaloniaEdit.Document;
using AvaloniaEdit.Editing;
using AvaloniaEdit.Rendering;
namespace AvaloniaEdit.Search
{
/// <summary>
/// Provides search functionality for AvalonEdit. It is displayed in the top-right corner of the TextArea.
/// </summary>
public class SearchPanel : TemplatedControl, IRoutedCommandBindable
{
private TextArea _textArea;
private SearchInputHandler _handler;
private TextDocument _currentDocument;
private SearchResultBackgroundRenderer _renderer;
private TextBox _searchTextBox;
private TextEditor _textEditor { get; set; }
private Border _border;
#region DependencyProperties
/// <summary>
/// Dependency property for <see cref="UseRegex"/>.
/// </summary>
public static readonly StyledProperty<bool> UseRegexProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(UseRegex));
/// <summary>
/// Gets/sets whether the search pattern should be interpreted as regular expression.
/// </summary>
public bool UseRegex
{
get => GetValue(UseRegexProperty);
set => SetValue(UseRegexProperty, value);
}
/// <summary>
/// Dependency property for <see cref="MatchCase"/>.
/// </summary>
public static readonly StyledProperty<bool> MatchCaseProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(MatchCase));
/// <summary>
/// Gets/sets whether the search pattern should be interpreted case-sensitive.
/// </summary>
public bool MatchCase
{
get => GetValue(MatchCaseProperty);
set => SetValue(MatchCaseProperty, value);
}
/// <summary>
/// Dependency property for <see cref="WholeWords"/>.
/// </summary>
public static readonly StyledProperty<bool> WholeWordsProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(WholeWords));
/// <summary>
/// Gets/sets whether the search pattern should only match whole words.
/// </summary>
public bool WholeWords
{
get => GetValue(WholeWordsProperty);
set => SetValue(WholeWordsProperty, value);
}
/// <summary>
/// Dependency property for <see cref="SearchPattern"/>.
/// </summary>
public static readonly StyledProperty<string> SearchPatternProperty =
AvaloniaProperty.Register<SearchPanel, string>(nameof(SearchPattern), "");
/// <summary>
/// Gets/sets the search pattern.
/// </summary>
public string SearchPattern
{
get => GetValue(SearchPatternProperty);
set => SetValue(SearchPatternProperty, value);
}
public static readonly StyledProperty<bool> IsReplaceModeProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(IsReplaceMode));
/// <summary>
/// Checks if replacemode is allowed
/// </summary>
/// <returns>False if editor is not null and readonly</returns>
private static bool ValidateReplaceMode(SearchPanel panel, bool v1)
{
if (panel._textEditor == null || !v1) return v1;
return !panel._textEditor.IsReadOnly;
}
public bool IsReplaceMode
{
get => GetValue(IsReplaceModeProperty);
set => SetValue(IsReplaceModeProperty, _textEditor?.IsReadOnly ?? false ? false : value);
}
public static readonly StyledProperty<string> ReplacePatternProperty =
AvaloniaProperty.Register<SearchPanel, string>(nameof(ReplacePattern));
public string ReplacePattern
{
get => GetValue(ReplacePatternProperty);
set => SetValue(ReplacePatternProperty, value);
}
/// <summary>
/// Dependency property for <see cref="MarkerBrush"/>.
/// </summary>
public static readonly StyledProperty<IBrush> MarkerBrushProperty =
AvaloniaProperty.Register<SearchPanel, IBrush>(nameof(MarkerBrush), Brushes.LightGreen);
/// <summary>
/// Gets/sets the Brush used for marking search results in the TextView.
/// </summary>
public IBrush MarkerBrush
{
get => GetValue(MarkerBrushProperty);
set => SetValue(MarkerBrushProperty, value);
}
#endregion
private static void MarkerBrushChangedCallback(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is SearchPanel panel)
{
panel._renderer.MarkerBrush = (IBrush)e.NewValue;
}
}
private ISearchStrategy _strategy;
private static void SearchPatternChangedCallback(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is SearchPanel panel)
{
panel.ValidateSearchText();
panel.UpdateSearch();
}
}
private void UpdateSearch()
{
// only reset as long as there are results
// if no results are found, the "no matches found" message should not flicker.
// if results are found by the next run, the message will be hidden inside DoSearch ...
if (_renderer.CurrentResults.Any())
_messageView.IsOpen = false;
_strategy = SearchStrategyFactory.Create(SearchPattern ?? "", !MatchCase, WholeWords, UseRegex ? SearchMode.RegEx : SearchMode.Normal);
OnSearchOptionsChanged(new SearchOptionsChangedEventArgs(SearchPattern, MatchCase, UseRegex, WholeWords));
DoSearch(true);
}
static SearchPanel()
{
UseRegexProperty.Changed.Subscribe(SearchPatternChangedCallback);
MatchCaseProperty.Changed.Subscribe(SearchPatternChangedCallback);
WholeWordsProperty.Changed.Subscribe(SearchPatternChangedCallback);
SearchPatternProperty.Changed.Subscribe(SearchPatternChangedCallback);
MarkerBrushProperty.Changed.Subscribe(MarkerBrushChangedCallback);
}
/// <summary>
/// Creates a new SearchPanel.
/// </summary>
private SearchPanel()
{
}
/// <summary>
/// Creates a SearchPanel and installs it to the TextEditor's TextArea.
/// </summary>
/// <remarks>This is a convenience wrapper.</remarks>
public static SearchPanel Install(TextEditor editor)
{
if (editor == null) throw new ArgumentNullException(nameof(editor));
SearchPanel searchPanel = Install(editor.TextArea);
searchPanel._textEditor = editor;
return searchPanel;
}
/// <summary>
/// Creates a SearchPanel and installs it to the TextArea.
/// </summary>
public static SearchPanel Install(TextArea textArea)
{
if (textArea == null) throw new ArgumentNullException(nameof(textArea));
var panel = new SearchPanel();
panel.AttachInternal(textArea);
panel._handler = new SearchInputHandler(textArea, panel);
textArea.DefaultInputHandler.NestedInputHandlers.Add(panel._handler);
((ISetLogicalParent)panel).SetParent(textArea);
return panel;
}
/// <summary>
/// Adds the commands used by SearchPanel to the given CommandBindingCollection.
/// </summary>
public void RegisterCommands(ICollection<RoutedCommandBinding> commandBindings)
{
_handler.RegisterGlobalCommands(commandBindings);
}
/// <summary>
/// Removes the SearchPanel from the TextArea.
/// </summary>
public void Uninstall()
{
Close();
_textArea.DocumentChanged -= TextArea_DocumentChanged;
if (_currentDocument != null)
_currentDocument.TextChanged -= TextArea_Document_TextChanged;
_textArea.DefaultInputHandler.NestedInputHandlers.Remove(_handler);
}
private void AttachInternal(TextArea textArea)
{
_textArea = textArea;
_renderer = new SearchResultBackgroundRenderer();
_currentDocument = textArea.Document;
if (_currentDocument != null)
_currentDocument.TextChanged += TextArea_Document_TextChanged;
textArea.DocumentChanged += TextArea_DocumentChanged;
KeyDown += SearchLayerKeyDown;
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.FindNext, (sender, e) => FindNext()));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.FindPrevious, (sender, e) => FindPrevious()));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.CloseSearchPanel, (sender, e) => Close()));
CommandBindings.Add(new RoutedCommandBinding(ApplicationCommands.Find, (sender, e) =>
{
IsReplaceMode = false;
Reactivate();
}));
CommandBindings.Add(new RoutedCommandBinding(ApplicationCommands.Replace, (sender, e) => IsReplaceMode = true));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.ReplaceNext, (sender, e) => ReplaceNext(), (sender, e) => e.CanExecute = IsReplaceMode));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.ReplaceAll, (sender, e) => ReplaceAll(), (sender, e) => e.CanExecute = IsReplaceMode));
IsClosed = true;
}
private void TextArea_DocumentChanged(object sender, EventArgs e)
{
if (_currentDocument != null)
_currentDocument.TextChanged -= TextArea_Document_TextChanged;
_currentDocument = _textArea.Document;
if (_currentDocument != null)
{
_currentDocument.TextChanged += TextArea_Document_TextChanged;
DoSearch(false);
}
}
private void TextArea_Document_TextChanged(object sender, EventArgs e)
{
DoSearch(false);
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
_border = e.NameScope.Find<Border>("PART_Border");
_searchTextBox = e.NameScope.Find<TextBox>("PART_searchTextBox");
_messageView = e.NameScope.Find<Popup>("PART_MessageView");
_messageViewContent = e.NameScope.Find<ContentPresenter>("PART_MessageContent");
}
private void ValidateSearchText()
{
if (_searchTextBox == null)
return;
try
{
UpdateSearch();
_validationError = null;
}
catch (SearchPatternException ex)
{
_validationError = ex.Message;
}
}
/// <summary>
/// Reactivates the SearchPanel by setting the focus on the search box and selecting all text.
/// </summary>
public void Reactivate()
{
if (_searchTextBox == null)
return;
_searchTextBox.Focus();
_searchTextBox.SelectionStart = 0;
_searchTextBox.SelectionEnd = _searchTextBox.Text?.Length ?? 0;
}
/// <summary>
/// Moves to the next occurrence in the file.
/// </summary>
public void FindNext()
{
var result = _renderer.CurrentResults.FindFirstSegmentWithStartAfter(_textArea.Caret.Offset + 1) ??
_renderer.CurrentResults.FirstSegment;
if (result != null)
{
SelectResult(result);
}
}
/// <summary>
/// Moves to the previous occurrence in the file.
/// </summary>
public void FindPrevious()
{
var result = _renderer.CurrentResults.FindFirstSegmentWithStartAfter(_textArea.Caret.Offset);
if (result != null)
result = _renderer.CurrentResults.GetPreviousSegment(result);
if (result == null)
result = _renderer.CurrentResults.LastSegment;
if (result != null)
{
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
}
public void ReplaceAll()
FindNext();
if (!_textArea.Selection.IsEmpty)
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
UpdateSearch();
}
public void ReplaceAll()
{
if (!IsReplaceMode) return;
var replacement = ReplacePattern ?? string.Empty;
var document = _textArea.Document;
using (document.RunUpdate())
{
var segments = _renderer.CurrentResults.OrderByDescending(x => x.EndOffset).ToArray();
foreach (var textSegment in segments)
{
document.Replace(textSegment.StartOffset, textSegment.Length,
new StringTextSource(replacement));
}
}
}
private Popup _messageView;
private ContentPresenter _messageViewContent;
private string _validationError;
private void DoSearch(bool changeSelection)
{
if (IsClosed)
return;
_renderer.CurrentResults.Clear();
if (!string.IsNullOrEmpty(SearchPattern))
{
var offset = _textArea.Caret.Offset;
if (changeSelection)
{
_textArea.ClearSelection();
}
// We cast from ISearchResult to SearchResult; this is safe because we always use the built-in strategy
foreach (var result in _strategy.FindAll(_textArea.Document, 0, _textArea.Document.TextLength).Cast<SearchResult>())
{
if (changeSelection && result.StartOffset >= offset)
{
SelectResult(result);
changeSelection = false;
}
_renderer.CurrentResults.Add(result);
}
}
if (_messageView != null)
{
if (!_renderer.CurrentResults.Any())
{
_messageViewContent.Content = SR.SearchNoMatchesFoundText;
_messageView.PlacementTarget = _searchTextBox;
_messageView.IsOpen = true;
}
else
_messageView.IsOpen = false;
}
_textArea.TextView.InvalidateLayer(KnownLayer.Selection);
}
private void SelectResult(TextSegment result)
{
_textArea.Caret.Offset = result.StartOffset;
_textArea.Selection = Selection.Create(_textArea, result.StartOffset, result.EndOffset);
double distanceToViewBorder = _border == null ?
Caret.MinimumDistanceToViewBorder :
_border.Bounds.Height + _textArea.TextView.DefaultLineHeight;
_textArea.Caret.BringCaretToView(distanceToViewBorder);
// show caret even if the editor does not have the Keyboard Focus
_textArea.Caret.Show();
}
private void SearchLayerKeyDown(object sender, KeyEventArgs e)
{
switch (e.Key)
{
case Key.Enter:
e.Handled = true;
if (e.KeyModifiers.HasFlag(KeyModifiers.Shift))
{
FindPrevious();
}
else
{
FindNext();
}
if (_searchTextBox != null)
{
if (_validationError != null)
{
_messageViewContent.Content = SR.SearchErrorText + " " + _validationError;
_messageView.PlacementTarget = _searchTextBox;
_messageView.IsOpen = true;
}
}
break;
case Key.Escape:
e.Handled = true;
Close();
break;
}
}
/// <summary>
/// Gets whether the Panel is already closed.
/// </summary>
public bool IsClosed { get; private set; }
/// <summary>
/// Gets whether the Panel is currently opened.
/// </summary>
public bool IsOpened => !IsClosed;
/// <summary>
/// Closes the SearchPanel.
/// </summary>
public void Close()
{
_textArea.RemoveChild(this);
_messageView.IsOpen = false;
_textArea.TextView.BackgroundRenderers.Remove(_renderer);
IsClosed = true;
// Clear existing search results so that the segments don't have to be maintained
_renderer.CurrentResults.Clear();
_textArea.Focus();
}
/// <summary>
/// Opens the an existing search panel.
/// </summary>
public void Open()
{
if (!IsClosed) return;
_textArea.AddChild(this);
_textArea.TextView.BackgroundRenderers.Add(_renderer);
IsClosed = false;
DoSearch(false);
}
protected override void OnPointerPressed(PointerPressedEventArgs e)
{
e.Handled = true;
base.OnPointerPressed(e);
}
protected override void OnPointerMoved(PointerEventArgs e)
{
Cursor = Cursor.Default;
base.OnPointerMoved(e);
}
protected override void OnGotFocus(GotFocusEventArgs e)
{
e.Handled = true;
base.OnGotFocus(e);
}
/// <summary>
/// Fired when SearchOptions are changed inside the SearchPanel.
/// </summary>
public event EventHandler<SearchOptionsChangedEventArgs> SearchOptionsChanged;
/// <summary>
/// Raises the <see cref="SearchOptionsChanged" /> event.
/// </summary>
protected virtual void OnSearchOptionsChanged(SearchOptionsChangedEventArgs e)
{
SearchOptionsChanged?.Invoke(this, e);
}
public IList<RoutedCommandBinding> CommandBindings { get; } = new List<RoutedCommandBinding>();
}
/// <summary>
/// EventArgs for <see cref="SearchPanel.SearchOptionsChanged"/> event.
/// </summary>
public class SearchOptionsChangedEventArgs : EventArgs
{
/// <summary>
/// Gets the search pattern.
/// </summary>
public string SearchPattern { get; }
/// <summary>
/// Gets whether the search pattern should be interpreted case-sensitive.
/// </summary>
public bool MatchCase { get; }
/// <summary>
/// Gets whether the search pattern should be interpreted as regular expression.
/// </summary>
public bool UseRegex { get; }
/// <summary>
/// Gets whether the search pattern should only match whole words.
/// </summary>
public bool WholeWords { get; }
/// <summary>
/// Creates a new SearchOptionsChangedEventArgs instance.
/// </summary>
public SearchOptionsChangedEventArgs(string searchPattern, bool matchCase, bool useRegex, bool wholeWords)
{
SearchPattern = searchPattern;
MatchCase = matchCase;
UseRegex = useRegex;
WholeWords = wholeWords;
}
}
}
<MSG> update search after replace
<DFF> @@ -357,6 +357,8 @@ namespace AvaloniaEdit.Search
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
+
+ UpdateSearch();
}
public void ReplaceAll()
| 2 | update search after replace | 0 | .cs | cs | mit | AvaloniaUI/AvaloniaEdit |
10066864 | <NME> SearchPanel.cs
<BEF> // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.VisualTree;
using AvaloniaEdit.Document;
using AvaloniaEdit.Editing;
using AvaloniaEdit.Rendering;
namespace AvaloniaEdit.Search
{
/// <summary>
/// Provides search functionality for AvalonEdit. It is displayed in the top-right corner of the TextArea.
/// </summary>
public class SearchPanel : TemplatedControl, IRoutedCommandBindable
{
private TextArea _textArea;
private SearchInputHandler _handler;
private TextDocument _currentDocument;
private SearchResultBackgroundRenderer _renderer;
private TextBox _searchTextBox;
private TextEditor _textEditor { get; set; }
private Border _border;
#region DependencyProperties
/// <summary>
/// Dependency property for <see cref="UseRegex"/>.
/// </summary>
public static readonly StyledProperty<bool> UseRegexProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(UseRegex));
/// <summary>
/// Gets/sets whether the search pattern should be interpreted as regular expression.
/// </summary>
public bool UseRegex
{
get => GetValue(UseRegexProperty);
set => SetValue(UseRegexProperty, value);
}
/// <summary>
/// Dependency property for <see cref="MatchCase"/>.
/// </summary>
public static readonly StyledProperty<bool> MatchCaseProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(MatchCase));
/// <summary>
/// Gets/sets whether the search pattern should be interpreted case-sensitive.
/// </summary>
public bool MatchCase
{
get => GetValue(MatchCaseProperty);
set => SetValue(MatchCaseProperty, value);
}
/// <summary>
/// Dependency property for <see cref="WholeWords"/>.
/// </summary>
public static readonly StyledProperty<bool> WholeWordsProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(WholeWords));
/// <summary>
/// Gets/sets whether the search pattern should only match whole words.
/// </summary>
public bool WholeWords
{
get => GetValue(WholeWordsProperty);
set => SetValue(WholeWordsProperty, value);
}
/// <summary>
/// Dependency property for <see cref="SearchPattern"/>.
/// </summary>
public static readonly StyledProperty<string> SearchPatternProperty =
AvaloniaProperty.Register<SearchPanel, string>(nameof(SearchPattern), "");
/// <summary>
/// Gets/sets the search pattern.
/// </summary>
public string SearchPattern
{
get => GetValue(SearchPatternProperty);
set => SetValue(SearchPatternProperty, value);
}
public static readonly StyledProperty<bool> IsReplaceModeProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(IsReplaceMode));
/// <summary>
/// Checks if replacemode is allowed
/// </summary>
/// <returns>False if editor is not null and readonly</returns>
private static bool ValidateReplaceMode(SearchPanel panel, bool v1)
{
if (panel._textEditor == null || !v1) return v1;
return !panel._textEditor.IsReadOnly;
}
public bool IsReplaceMode
{
get => GetValue(IsReplaceModeProperty);
set => SetValue(IsReplaceModeProperty, _textEditor?.IsReadOnly ?? false ? false : value);
}
public static readonly StyledProperty<string> ReplacePatternProperty =
AvaloniaProperty.Register<SearchPanel, string>(nameof(ReplacePattern));
public string ReplacePattern
{
get => GetValue(ReplacePatternProperty);
set => SetValue(ReplacePatternProperty, value);
}
/// <summary>
/// Dependency property for <see cref="MarkerBrush"/>.
/// </summary>
public static readonly StyledProperty<IBrush> MarkerBrushProperty =
AvaloniaProperty.Register<SearchPanel, IBrush>(nameof(MarkerBrush), Brushes.LightGreen);
/// <summary>
/// Gets/sets the Brush used for marking search results in the TextView.
/// </summary>
public IBrush MarkerBrush
{
get => GetValue(MarkerBrushProperty);
set => SetValue(MarkerBrushProperty, value);
}
#endregion
private static void MarkerBrushChangedCallback(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is SearchPanel panel)
{
panel._renderer.MarkerBrush = (IBrush)e.NewValue;
}
}
private ISearchStrategy _strategy;
private static void SearchPatternChangedCallback(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is SearchPanel panel)
{
panel.ValidateSearchText();
panel.UpdateSearch();
}
}
private void UpdateSearch()
{
// only reset as long as there are results
// if no results are found, the "no matches found" message should not flicker.
// if results are found by the next run, the message will be hidden inside DoSearch ...
if (_renderer.CurrentResults.Any())
_messageView.IsOpen = false;
_strategy = SearchStrategyFactory.Create(SearchPattern ?? "", !MatchCase, WholeWords, UseRegex ? SearchMode.RegEx : SearchMode.Normal);
OnSearchOptionsChanged(new SearchOptionsChangedEventArgs(SearchPattern, MatchCase, UseRegex, WholeWords));
DoSearch(true);
}
static SearchPanel()
{
UseRegexProperty.Changed.Subscribe(SearchPatternChangedCallback);
MatchCaseProperty.Changed.Subscribe(SearchPatternChangedCallback);
WholeWordsProperty.Changed.Subscribe(SearchPatternChangedCallback);
SearchPatternProperty.Changed.Subscribe(SearchPatternChangedCallback);
MarkerBrushProperty.Changed.Subscribe(MarkerBrushChangedCallback);
}
/// <summary>
/// Creates a new SearchPanel.
/// </summary>
private SearchPanel()
{
}
/// <summary>
/// Creates a SearchPanel and installs it to the TextEditor's TextArea.
/// </summary>
/// <remarks>This is a convenience wrapper.</remarks>
public static SearchPanel Install(TextEditor editor)
{
if (editor == null) throw new ArgumentNullException(nameof(editor));
SearchPanel searchPanel = Install(editor.TextArea);
searchPanel._textEditor = editor;
return searchPanel;
}
/// <summary>
/// Creates a SearchPanel and installs it to the TextArea.
/// </summary>
public static SearchPanel Install(TextArea textArea)
{
if (textArea == null) throw new ArgumentNullException(nameof(textArea));
var panel = new SearchPanel();
panel.AttachInternal(textArea);
panel._handler = new SearchInputHandler(textArea, panel);
textArea.DefaultInputHandler.NestedInputHandlers.Add(panel._handler);
((ISetLogicalParent)panel).SetParent(textArea);
return panel;
}
/// <summary>
/// Adds the commands used by SearchPanel to the given CommandBindingCollection.
/// </summary>
public void RegisterCommands(ICollection<RoutedCommandBinding> commandBindings)
{
_handler.RegisterGlobalCommands(commandBindings);
}
/// <summary>
/// Removes the SearchPanel from the TextArea.
/// </summary>
public void Uninstall()
{
Close();
_textArea.DocumentChanged -= TextArea_DocumentChanged;
if (_currentDocument != null)
_currentDocument.TextChanged -= TextArea_Document_TextChanged;
_textArea.DefaultInputHandler.NestedInputHandlers.Remove(_handler);
}
private void AttachInternal(TextArea textArea)
{
_textArea = textArea;
_renderer = new SearchResultBackgroundRenderer();
_currentDocument = textArea.Document;
if (_currentDocument != null)
_currentDocument.TextChanged += TextArea_Document_TextChanged;
textArea.DocumentChanged += TextArea_DocumentChanged;
KeyDown += SearchLayerKeyDown;
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.FindNext, (sender, e) => FindNext()));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.FindPrevious, (sender, e) => FindPrevious()));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.CloseSearchPanel, (sender, e) => Close()));
CommandBindings.Add(new RoutedCommandBinding(ApplicationCommands.Find, (sender, e) =>
{
IsReplaceMode = false;
Reactivate();
}));
CommandBindings.Add(new RoutedCommandBinding(ApplicationCommands.Replace, (sender, e) => IsReplaceMode = true));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.ReplaceNext, (sender, e) => ReplaceNext(), (sender, e) => e.CanExecute = IsReplaceMode));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.ReplaceAll, (sender, e) => ReplaceAll(), (sender, e) => e.CanExecute = IsReplaceMode));
IsClosed = true;
}
private void TextArea_DocumentChanged(object sender, EventArgs e)
{
if (_currentDocument != null)
_currentDocument.TextChanged -= TextArea_Document_TextChanged;
_currentDocument = _textArea.Document;
if (_currentDocument != null)
{
_currentDocument.TextChanged += TextArea_Document_TextChanged;
DoSearch(false);
}
}
private void TextArea_Document_TextChanged(object sender, EventArgs e)
{
DoSearch(false);
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
_border = e.NameScope.Find<Border>("PART_Border");
_searchTextBox = e.NameScope.Find<TextBox>("PART_searchTextBox");
_messageView = e.NameScope.Find<Popup>("PART_MessageView");
_messageViewContent = e.NameScope.Find<ContentPresenter>("PART_MessageContent");
}
private void ValidateSearchText()
{
if (_searchTextBox == null)
return;
try
{
UpdateSearch();
_validationError = null;
}
catch (SearchPatternException ex)
{
_validationError = ex.Message;
}
}
/// <summary>
/// Reactivates the SearchPanel by setting the focus on the search box and selecting all text.
/// </summary>
public void Reactivate()
{
if (_searchTextBox == null)
return;
_searchTextBox.Focus();
_searchTextBox.SelectionStart = 0;
_searchTextBox.SelectionEnd = _searchTextBox.Text?.Length ?? 0;
}
/// <summary>
/// Moves to the next occurrence in the file.
/// </summary>
public void FindNext()
{
var result = _renderer.CurrentResults.FindFirstSegmentWithStartAfter(_textArea.Caret.Offset + 1) ??
_renderer.CurrentResults.FirstSegment;
if (result != null)
{
SelectResult(result);
}
}
/// <summary>
/// Moves to the previous occurrence in the file.
/// </summary>
public void FindPrevious()
{
var result = _renderer.CurrentResults.FindFirstSegmentWithStartAfter(_textArea.Caret.Offset);
if (result != null)
result = _renderer.CurrentResults.GetPreviousSegment(result);
if (result == null)
result = _renderer.CurrentResults.LastSegment;
if (result != null)
{
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
}
public void ReplaceAll()
FindNext();
if (!_textArea.Selection.IsEmpty)
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
UpdateSearch();
}
public void ReplaceAll()
{
if (!IsReplaceMode) return;
var replacement = ReplacePattern ?? string.Empty;
var document = _textArea.Document;
using (document.RunUpdate())
{
var segments = _renderer.CurrentResults.OrderByDescending(x => x.EndOffset).ToArray();
foreach (var textSegment in segments)
{
document.Replace(textSegment.StartOffset, textSegment.Length,
new StringTextSource(replacement));
}
}
}
private Popup _messageView;
private ContentPresenter _messageViewContent;
private string _validationError;
private void DoSearch(bool changeSelection)
{
if (IsClosed)
return;
_renderer.CurrentResults.Clear();
if (!string.IsNullOrEmpty(SearchPattern))
{
var offset = _textArea.Caret.Offset;
if (changeSelection)
{
_textArea.ClearSelection();
}
// We cast from ISearchResult to SearchResult; this is safe because we always use the built-in strategy
foreach (var result in _strategy.FindAll(_textArea.Document, 0, _textArea.Document.TextLength).Cast<SearchResult>())
{
if (changeSelection && result.StartOffset >= offset)
{
SelectResult(result);
changeSelection = false;
}
_renderer.CurrentResults.Add(result);
}
}
if (_messageView != null)
{
if (!_renderer.CurrentResults.Any())
{
_messageViewContent.Content = SR.SearchNoMatchesFoundText;
_messageView.PlacementTarget = _searchTextBox;
_messageView.IsOpen = true;
}
else
_messageView.IsOpen = false;
}
_textArea.TextView.InvalidateLayer(KnownLayer.Selection);
}
private void SelectResult(TextSegment result)
{
_textArea.Caret.Offset = result.StartOffset;
_textArea.Selection = Selection.Create(_textArea, result.StartOffset, result.EndOffset);
double distanceToViewBorder = _border == null ?
Caret.MinimumDistanceToViewBorder :
_border.Bounds.Height + _textArea.TextView.DefaultLineHeight;
_textArea.Caret.BringCaretToView(distanceToViewBorder);
// show caret even if the editor does not have the Keyboard Focus
_textArea.Caret.Show();
}
private void SearchLayerKeyDown(object sender, KeyEventArgs e)
{
switch (e.Key)
{
case Key.Enter:
e.Handled = true;
if (e.KeyModifiers.HasFlag(KeyModifiers.Shift))
{
FindPrevious();
}
else
{
FindNext();
}
if (_searchTextBox != null)
{
if (_validationError != null)
{
_messageViewContent.Content = SR.SearchErrorText + " " + _validationError;
_messageView.PlacementTarget = _searchTextBox;
_messageView.IsOpen = true;
}
}
break;
case Key.Escape:
e.Handled = true;
Close();
break;
}
}
/// <summary>
/// Gets whether the Panel is already closed.
/// </summary>
public bool IsClosed { get; private set; }
/// <summary>
/// Gets whether the Panel is currently opened.
/// </summary>
public bool IsOpened => !IsClosed;
/// <summary>
/// Closes the SearchPanel.
/// </summary>
public void Close()
{
_textArea.RemoveChild(this);
_messageView.IsOpen = false;
_textArea.TextView.BackgroundRenderers.Remove(_renderer);
IsClosed = true;
// Clear existing search results so that the segments don't have to be maintained
_renderer.CurrentResults.Clear();
_textArea.Focus();
}
/// <summary>
/// Opens the an existing search panel.
/// </summary>
public void Open()
{
if (!IsClosed) return;
_textArea.AddChild(this);
_textArea.TextView.BackgroundRenderers.Add(_renderer);
IsClosed = false;
DoSearch(false);
}
protected override void OnPointerPressed(PointerPressedEventArgs e)
{
e.Handled = true;
base.OnPointerPressed(e);
}
protected override void OnPointerMoved(PointerEventArgs e)
{
Cursor = Cursor.Default;
base.OnPointerMoved(e);
}
protected override void OnGotFocus(GotFocusEventArgs e)
{
e.Handled = true;
base.OnGotFocus(e);
}
/// <summary>
/// Fired when SearchOptions are changed inside the SearchPanel.
/// </summary>
public event EventHandler<SearchOptionsChangedEventArgs> SearchOptionsChanged;
/// <summary>
/// Raises the <see cref="SearchOptionsChanged" /> event.
/// </summary>
protected virtual void OnSearchOptionsChanged(SearchOptionsChangedEventArgs e)
{
SearchOptionsChanged?.Invoke(this, e);
}
public IList<RoutedCommandBinding> CommandBindings { get; } = new List<RoutedCommandBinding>();
}
/// <summary>
/// EventArgs for <see cref="SearchPanel.SearchOptionsChanged"/> event.
/// </summary>
public class SearchOptionsChangedEventArgs : EventArgs
{
/// <summary>
/// Gets the search pattern.
/// </summary>
public string SearchPattern { get; }
/// <summary>
/// Gets whether the search pattern should be interpreted case-sensitive.
/// </summary>
public bool MatchCase { get; }
/// <summary>
/// Gets whether the search pattern should be interpreted as regular expression.
/// </summary>
public bool UseRegex { get; }
/// <summary>
/// Gets whether the search pattern should only match whole words.
/// </summary>
public bool WholeWords { get; }
/// <summary>
/// Creates a new SearchOptionsChangedEventArgs instance.
/// </summary>
public SearchOptionsChangedEventArgs(string searchPattern, bool matchCase, bool useRegex, bool wholeWords)
{
SearchPattern = searchPattern;
MatchCase = matchCase;
UseRegex = useRegex;
WholeWords = wholeWords;
}
}
}
<MSG> update search after replace
<DFF> @@ -357,6 +357,8 @@ namespace AvaloniaEdit.Search
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
+
+ UpdateSearch();
}
public void ReplaceAll()
| 2 | update search after replace | 0 | .cs | cs | mit | AvaloniaUI/AvaloniaEdit |
10066865 | <NME> SearchPanel.cs
<BEF> // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.VisualTree;
using AvaloniaEdit.Document;
using AvaloniaEdit.Editing;
using AvaloniaEdit.Rendering;
namespace AvaloniaEdit.Search
{
/// <summary>
/// Provides search functionality for AvalonEdit. It is displayed in the top-right corner of the TextArea.
/// </summary>
public class SearchPanel : TemplatedControl, IRoutedCommandBindable
{
private TextArea _textArea;
private SearchInputHandler _handler;
private TextDocument _currentDocument;
private SearchResultBackgroundRenderer _renderer;
private TextBox _searchTextBox;
private TextEditor _textEditor { get; set; }
private Border _border;
#region DependencyProperties
/// <summary>
/// Dependency property for <see cref="UseRegex"/>.
/// </summary>
public static readonly StyledProperty<bool> UseRegexProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(UseRegex));
/// <summary>
/// Gets/sets whether the search pattern should be interpreted as regular expression.
/// </summary>
public bool UseRegex
{
get => GetValue(UseRegexProperty);
set => SetValue(UseRegexProperty, value);
}
/// <summary>
/// Dependency property for <see cref="MatchCase"/>.
/// </summary>
public static readonly StyledProperty<bool> MatchCaseProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(MatchCase));
/// <summary>
/// Gets/sets whether the search pattern should be interpreted case-sensitive.
/// </summary>
public bool MatchCase
{
get => GetValue(MatchCaseProperty);
set => SetValue(MatchCaseProperty, value);
}
/// <summary>
/// Dependency property for <see cref="WholeWords"/>.
/// </summary>
public static readonly StyledProperty<bool> WholeWordsProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(WholeWords));
/// <summary>
/// Gets/sets whether the search pattern should only match whole words.
/// </summary>
public bool WholeWords
{
get => GetValue(WholeWordsProperty);
set => SetValue(WholeWordsProperty, value);
}
/// <summary>
/// Dependency property for <see cref="SearchPattern"/>.
/// </summary>
public static readonly StyledProperty<string> SearchPatternProperty =
AvaloniaProperty.Register<SearchPanel, string>(nameof(SearchPattern), "");
/// <summary>
/// Gets/sets the search pattern.
/// </summary>
public string SearchPattern
{
get => GetValue(SearchPatternProperty);
set => SetValue(SearchPatternProperty, value);
}
public static readonly StyledProperty<bool> IsReplaceModeProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(IsReplaceMode));
/// <summary>
/// Checks if replacemode is allowed
/// </summary>
/// <returns>False if editor is not null and readonly</returns>
private static bool ValidateReplaceMode(SearchPanel panel, bool v1)
{
if (panel._textEditor == null || !v1) return v1;
return !panel._textEditor.IsReadOnly;
}
public bool IsReplaceMode
{
get => GetValue(IsReplaceModeProperty);
set => SetValue(IsReplaceModeProperty, _textEditor?.IsReadOnly ?? false ? false : value);
}
public static readonly StyledProperty<string> ReplacePatternProperty =
AvaloniaProperty.Register<SearchPanel, string>(nameof(ReplacePattern));
public string ReplacePattern
{
get => GetValue(ReplacePatternProperty);
set => SetValue(ReplacePatternProperty, value);
}
/// <summary>
/// Dependency property for <see cref="MarkerBrush"/>.
/// </summary>
public static readonly StyledProperty<IBrush> MarkerBrushProperty =
AvaloniaProperty.Register<SearchPanel, IBrush>(nameof(MarkerBrush), Brushes.LightGreen);
/// <summary>
/// Gets/sets the Brush used for marking search results in the TextView.
/// </summary>
public IBrush MarkerBrush
{
get => GetValue(MarkerBrushProperty);
set => SetValue(MarkerBrushProperty, value);
}
#endregion
private static void MarkerBrushChangedCallback(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is SearchPanel panel)
{
panel._renderer.MarkerBrush = (IBrush)e.NewValue;
}
}
private ISearchStrategy _strategy;
private static void SearchPatternChangedCallback(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is SearchPanel panel)
{
panel.ValidateSearchText();
panel.UpdateSearch();
}
}
private void UpdateSearch()
{
// only reset as long as there are results
// if no results are found, the "no matches found" message should not flicker.
// if results are found by the next run, the message will be hidden inside DoSearch ...
if (_renderer.CurrentResults.Any())
_messageView.IsOpen = false;
_strategy = SearchStrategyFactory.Create(SearchPattern ?? "", !MatchCase, WholeWords, UseRegex ? SearchMode.RegEx : SearchMode.Normal);
OnSearchOptionsChanged(new SearchOptionsChangedEventArgs(SearchPattern, MatchCase, UseRegex, WholeWords));
DoSearch(true);
}
static SearchPanel()
{
UseRegexProperty.Changed.Subscribe(SearchPatternChangedCallback);
MatchCaseProperty.Changed.Subscribe(SearchPatternChangedCallback);
WholeWordsProperty.Changed.Subscribe(SearchPatternChangedCallback);
SearchPatternProperty.Changed.Subscribe(SearchPatternChangedCallback);
MarkerBrushProperty.Changed.Subscribe(MarkerBrushChangedCallback);
}
/// <summary>
/// Creates a new SearchPanel.
/// </summary>
private SearchPanel()
{
}
/// <summary>
/// Creates a SearchPanel and installs it to the TextEditor's TextArea.
/// </summary>
/// <remarks>This is a convenience wrapper.</remarks>
public static SearchPanel Install(TextEditor editor)
{
if (editor == null) throw new ArgumentNullException(nameof(editor));
SearchPanel searchPanel = Install(editor.TextArea);
searchPanel._textEditor = editor;
return searchPanel;
}
/// <summary>
/// Creates a SearchPanel and installs it to the TextArea.
/// </summary>
public static SearchPanel Install(TextArea textArea)
{
if (textArea == null) throw new ArgumentNullException(nameof(textArea));
var panel = new SearchPanel();
panel.AttachInternal(textArea);
panel._handler = new SearchInputHandler(textArea, panel);
textArea.DefaultInputHandler.NestedInputHandlers.Add(panel._handler);
((ISetLogicalParent)panel).SetParent(textArea);
return panel;
}
/// <summary>
/// Adds the commands used by SearchPanel to the given CommandBindingCollection.
/// </summary>
public void RegisterCommands(ICollection<RoutedCommandBinding> commandBindings)
{
_handler.RegisterGlobalCommands(commandBindings);
}
/// <summary>
/// Removes the SearchPanel from the TextArea.
/// </summary>
public void Uninstall()
{
Close();
_textArea.DocumentChanged -= TextArea_DocumentChanged;
if (_currentDocument != null)
_currentDocument.TextChanged -= TextArea_Document_TextChanged;
_textArea.DefaultInputHandler.NestedInputHandlers.Remove(_handler);
}
private void AttachInternal(TextArea textArea)
{
_textArea = textArea;
_renderer = new SearchResultBackgroundRenderer();
_currentDocument = textArea.Document;
if (_currentDocument != null)
_currentDocument.TextChanged += TextArea_Document_TextChanged;
textArea.DocumentChanged += TextArea_DocumentChanged;
KeyDown += SearchLayerKeyDown;
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.FindNext, (sender, e) => FindNext()));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.FindPrevious, (sender, e) => FindPrevious()));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.CloseSearchPanel, (sender, e) => Close()));
CommandBindings.Add(new RoutedCommandBinding(ApplicationCommands.Find, (sender, e) =>
{
IsReplaceMode = false;
Reactivate();
}));
CommandBindings.Add(new RoutedCommandBinding(ApplicationCommands.Replace, (sender, e) => IsReplaceMode = true));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.ReplaceNext, (sender, e) => ReplaceNext(), (sender, e) => e.CanExecute = IsReplaceMode));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.ReplaceAll, (sender, e) => ReplaceAll(), (sender, e) => e.CanExecute = IsReplaceMode));
IsClosed = true;
}
private void TextArea_DocumentChanged(object sender, EventArgs e)
{
if (_currentDocument != null)
_currentDocument.TextChanged -= TextArea_Document_TextChanged;
_currentDocument = _textArea.Document;
if (_currentDocument != null)
{
_currentDocument.TextChanged += TextArea_Document_TextChanged;
DoSearch(false);
}
}
private void TextArea_Document_TextChanged(object sender, EventArgs e)
{
DoSearch(false);
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
_border = e.NameScope.Find<Border>("PART_Border");
_searchTextBox = e.NameScope.Find<TextBox>("PART_searchTextBox");
_messageView = e.NameScope.Find<Popup>("PART_MessageView");
_messageViewContent = e.NameScope.Find<ContentPresenter>("PART_MessageContent");
}
private void ValidateSearchText()
{
if (_searchTextBox == null)
return;
try
{
UpdateSearch();
_validationError = null;
}
catch (SearchPatternException ex)
{
_validationError = ex.Message;
}
}
/// <summary>
/// Reactivates the SearchPanel by setting the focus on the search box and selecting all text.
/// </summary>
public void Reactivate()
{
if (_searchTextBox == null)
return;
_searchTextBox.Focus();
_searchTextBox.SelectionStart = 0;
_searchTextBox.SelectionEnd = _searchTextBox.Text?.Length ?? 0;
}
/// <summary>
/// Moves to the next occurrence in the file.
/// </summary>
public void FindNext()
{
var result = _renderer.CurrentResults.FindFirstSegmentWithStartAfter(_textArea.Caret.Offset + 1) ??
_renderer.CurrentResults.FirstSegment;
if (result != null)
{
SelectResult(result);
}
}
/// <summary>
/// Moves to the previous occurrence in the file.
/// </summary>
public void FindPrevious()
{
var result = _renderer.CurrentResults.FindFirstSegmentWithStartAfter(_textArea.Caret.Offset);
if (result != null)
result = _renderer.CurrentResults.GetPreviousSegment(result);
if (result == null)
result = _renderer.CurrentResults.LastSegment;
if (result != null)
{
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
}
public void ReplaceAll()
FindNext();
if (!_textArea.Selection.IsEmpty)
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
UpdateSearch();
}
public void ReplaceAll()
{
if (!IsReplaceMode) return;
var replacement = ReplacePattern ?? string.Empty;
var document = _textArea.Document;
using (document.RunUpdate())
{
var segments = _renderer.CurrentResults.OrderByDescending(x => x.EndOffset).ToArray();
foreach (var textSegment in segments)
{
document.Replace(textSegment.StartOffset, textSegment.Length,
new StringTextSource(replacement));
}
}
}
private Popup _messageView;
private ContentPresenter _messageViewContent;
private string _validationError;
private void DoSearch(bool changeSelection)
{
if (IsClosed)
return;
_renderer.CurrentResults.Clear();
if (!string.IsNullOrEmpty(SearchPattern))
{
var offset = _textArea.Caret.Offset;
if (changeSelection)
{
_textArea.ClearSelection();
}
// We cast from ISearchResult to SearchResult; this is safe because we always use the built-in strategy
foreach (var result in _strategy.FindAll(_textArea.Document, 0, _textArea.Document.TextLength).Cast<SearchResult>())
{
if (changeSelection && result.StartOffset >= offset)
{
SelectResult(result);
changeSelection = false;
}
_renderer.CurrentResults.Add(result);
}
}
if (_messageView != null)
{
if (!_renderer.CurrentResults.Any())
{
_messageViewContent.Content = SR.SearchNoMatchesFoundText;
_messageView.PlacementTarget = _searchTextBox;
_messageView.IsOpen = true;
}
else
_messageView.IsOpen = false;
}
_textArea.TextView.InvalidateLayer(KnownLayer.Selection);
}
private void SelectResult(TextSegment result)
{
_textArea.Caret.Offset = result.StartOffset;
_textArea.Selection = Selection.Create(_textArea, result.StartOffset, result.EndOffset);
double distanceToViewBorder = _border == null ?
Caret.MinimumDistanceToViewBorder :
_border.Bounds.Height + _textArea.TextView.DefaultLineHeight;
_textArea.Caret.BringCaretToView(distanceToViewBorder);
// show caret even if the editor does not have the Keyboard Focus
_textArea.Caret.Show();
}
private void SearchLayerKeyDown(object sender, KeyEventArgs e)
{
switch (e.Key)
{
case Key.Enter:
e.Handled = true;
if (e.KeyModifiers.HasFlag(KeyModifiers.Shift))
{
FindPrevious();
}
else
{
FindNext();
}
if (_searchTextBox != null)
{
if (_validationError != null)
{
_messageViewContent.Content = SR.SearchErrorText + " " + _validationError;
_messageView.PlacementTarget = _searchTextBox;
_messageView.IsOpen = true;
}
}
break;
case Key.Escape:
e.Handled = true;
Close();
break;
}
}
/// <summary>
/// Gets whether the Panel is already closed.
/// </summary>
public bool IsClosed { get; private set; }
/// <summary>
/// Gets whether the Panel is currently opened.
/// </summary>
public bool IsOpened => !IsClosed;
/// <summary>
/// Closes the SearchPanel.
/// </summary>
public void Close()
{
_textArea.RemoveChild(this);
_messageView.IsOpen = false;
_textArea.TextView.BackgroundRenderers.Remove(_renderer);
IsClosed = true;
// Clear existing search results so that the segments don't have to be maintained
_renderer.CurrentResults.Clear();
_textArea.Focus();
}
/// <summary>
/// Opens the an existing search panel.
/// </summary>
public void Open()
{
if (!IsClosed) return;
_textArea.AddChild(this);
_textArea.TextView.BackgroundRenderers.Add(_renderer);
IsClosed = false;
DoSearch(false);
}
protected override void OnPointerPressed(PointerPressedEventArgs e)
{
e.Handled = true;
base.OnPointerPressed(e);
}
protected override void OnPointerMoved(PointerEventArgs e)
{
Cursor = Cursor.Default;
base.OnPointerMoved(e);
}
protected override void OnGotFocus(GotFocusEventArgs e)
{
e.Handled = true;
base.OnGotFocus(e);
}
/// <summary>
/// Fired when SearchOptions are changed inside the SearchPanel.
/// </summary>
public event EventHandler<SearchOptionsChangedEventArgs> SearchOptionsChanged;
/// <summary>
/// Raises the <see cref="SearchOptionsChanged" /> event.
/// </summary>
protected virtual void OnSearchOptionsChanged(SearchOptionsChangedEventArgs e)
{
SearchOptionsChanged?.Invoke(this, e);
}
public IList<RoutedCommandBinding> CommandBindings { get; } = new List<RoutedCommandBinding>();
}
/// <summary>
/// EventArgs for <see cref="SearchPanel.SearchOptionsChanged"/> event.
/// </summary>
public class SearchOptionsChangedEventArgs : EventArgs
{
/// <summary>
/// Gets the search pattern.
/// </summary>
public string SearchPattern { get; }
/// <summary>
/// Gets whether the search pattern should be interpreted case-sensitive.
/// </summary>
public bool MatchCase { get; }
/// <summary>
/// Gets whether the search pattern should be interpreted as regular expression.
/// </summary>
public bool UseRegex { get; }
/// <summary>
/// Gets whether the search pattern should only match whole words.
/// </summary>
public bool WholeWords { get; }
/// <summary>
/// Creates a new SearchOptionsChangedEventArgs instance.
/// </summary>
public SearchOptionsChangedEventArgs(string searchPattern, bool matchCase, bool useRegex, bool wholeWords)
{
SearchPattern = searchPattern;
MatchCase = matchCase;
UseRegex = useRegex;
WholeWords = wholeWords;
}
}
}
<MSG> update search after replace
<DFF> @@ -357,6 +357,8 @@ namespace AvaloniaEdit.Search
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
+
+ UpdateSearch();
}
public void ReplaceAll()
| 2 | update search after replace | 0 | .cs | cs | mit | AvaloniaUI/AvaloniaEdit |
10066866 | <NME> SearchPanel.cs
<BEF> // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.VisualTree;
using AvaloniaEdit.Document;
using AvaloniaEdit.Editing;
using AvaloniaEdit.Rendering;
namespace AvaloniaEdit.Search
{
/// <summary>
/// Provides search functionality for AvalonEdit. It is displayed in the top-right corner of the TextArea.
/// </summary>
public class SearchPanel : TemplatedControl, IRoutedCommandBindable
{
private TextArea _textArea;
private SearchInputHandler _handler;
private TextDocument _currentDocument;
private SearchResultBackgroundRenderer _renderer;
private TextBox _searchTextBox;
private TextEditor _textEditor { get; set; }
private Border _border;
#region DependencyProperties
/// <summary>
/// Dependency property for <see cref="UseRegex"/>.
/// </summary>
public static readonly StyledProperty<bool> UseRegexProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(UseRegex));
/// <summary>
/// Gets/sets whether the search pattern should be interpreted as regular expression.
/// </summary>
public bool UseRegex
{
get => GetValue(UseRegexProperty);
set => SetValue(UseRegexProperty, value);
}
/// <summary>
/// Dependency property for <see cref="MatchCase"/>.
/// </summary>
public static readonly StyledProperty<bool> MatchCaseProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(MatchCase));
/// <summary>
/// Gets/sets whether the search pattern should be interpreted case-sensitive.
/// </summary>
public bool MatchCase
{
get => GetValue(MatchCaseProperty);
set => SetValue(MatchCaseProperty, value);
}
/// <summary>
/// Dependency property for <see cref="WholeWords"/>.
/// </summary>
public static readonly StyledProperty<bool> WholeWordsProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(WholeWords));
/// <summary>
/// Gets/sets whether the search pattern should only match whole words.
/// </summary>
public bool WholeWords
{
get => GetValue(WholeWordsProperty);
set => SetValue(WholeWordsProperty, value);
}
/// <summary>
/// Dependency property for <see cref="SearchPattern"/>.
/// </summary>
public static readonly StyledProperty<string> SearchPatternProperty =
AvaloniaProperty.Register<SearchPanel, string>(nameof(SearchPattern), "");
/// <summary>
/// Gets/sets the search pattern.
/// </summary>
public string SearchPattern
{
get => GetValue(SearchPatternProperty);
set => SetValue(SearchPatternProperty, value);
}
public static readonly StyledProperty<bool> IsReplaceModeProperty =
AvaloniaProperty.Register<SearchPanel, bool>(nameof(IsReplaceMode));
/// <summary>
/// Checks if replacemode is allowed
/// </summary>
/// <returns>False if editor is not null and readonly</returns>
private static bool ValidateReplaceMode(SearchPanel panel, bool v1)
{
if (panel._textEditor == null || !v1) return v1;
return !panel._textEditor.IsReadOnly;
}
public bool IsReplaceMode
{
get => GetValue(IsReplaceModeProperty);
set => SetValue(IsReplaceModeProperty, _textEditor?.IsReadOnly ?? false ? false : value);
}
public static readonly StyledProperty<string> ReplacePatternProperty =
AvaloniaProperty.Register<SearchPanel, string>(nameof(ReplacePattern));
public string ReplacePattern
{
get => GetValue(ReplacePatternProperty);
set => SetValue(ReplacePatternProperty, value);
}
/// <summary>
/// Dependency property for <see cref="MarkerBrush"/>.
/// </summary>
public static readonly StyledProperty<IBrush> MarkerBrushProperty =
AvaloniaProperty.Register<SearchPanel, IBrush>(nameof(MarkerBrush), Brushes.LightGreen);
/// <summary>
/// Gets/sets the Brush used for marking search results in the TextView.
/// </summary>
public IBrush MarkerBrush
{
get => GetValue(MarkerBrushProperty);
set => SetValue(MarkerBrushProperty, value);
}
#endregion
private static void MarkerBrushChangedCallback(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is SearchPanel panel)
{
panel._renderer.MarkerBrush = (IBrush)e.NewValue;
}
}
private ISearchStrategy _strategy;
private static void SearchPatternChangedCallback(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is SearchPanel panel)
{
panel.ValidateSearchText();
panel.UpdateSearch();
}
}
private void UpdateSearch()
{
// only reset as long as there are results
// if no results are found, the "no matches found" message should not flicker.
// if results are found by the next run, the message will be hidden inside DoSearch ...
if (_renderer.CurrentResults.Any())
_messageView.IsOpen = false;
_strategy = SearchStrategyFactory.Create(SearchPattern ?? "", !MatchCase, WholeWords, UseRegex ? SearchMode.RegEx : SearchMode.Normal);
OnSearchOptionsChanged(new SearchOptionsChangedEventArgs(SearchPattern, MatchCase, UseRegex, WholeWords));
DoSearch(true);
}
static SearchPanel()
{
UseRegexProperty.Changed.Subscribe(SearchPatternChangedCallback);
MatchCaseProperty.Changed.Subscribe(SearchPatternChangedCallback);
WholeWordsProperty.Changed.Subscribe(SearchPatternChangedCallback);
SearchPatternProperty.Changed.Subscribe(SearchPatternChangedCallback);
MarkerBrushProperty.Changed.Subscribe(MarkerBrushChangedCallback);
}
/// <summary>
/// Creates a new SearchPanel.
/// </summary>
private SearchPanel()
{
}
/// <summary>
/// Creates a SearchPanel and installs it to the TextEditor's TextArea.
/// </summary>
/// <remarks>This is a convenience wrapper.</remarks>
public static SearchPanel Install(TextEditor editor)
{
if (editor == null) throw new ArgumentNullException(nameof(editor));
SearchPanel searchPanel = Install(editor.TextArea);
searchPanel._textEditor = editor;
return searchPanel;
}
/// <summary>
/// Creates a SearchPanel and installs it to the TextArea.
/// </summary>
public static SearchPanel Install(TextArea textArea)
{
if (textArea == null) throw new ArgumentNullException(nameof(textArea));
var panel = new SearchPanel();
panel.AttachInternal(textArea);
panel._handler = new SearchInputHandler(textArea, panel);
textArea.DefaultInputHandler.NestedInputHandlers.Add(panel._handler);
((ISetLogicalParent)panel).SetParent(textArea);
return panel;
}
/// <summary>
/// Adds the commands used by SearchPanel to the given CommandBindingCollection.
/// </summary>
public void RegisterCommands(ICollection<RoutedCommandBinding> commandBindings)
{
_handler.RegisterGlobalCommands(commandBindings);
}
/// <summary>
/// Removes the SearchPanel from the TextArea.
/// </summary>
public void Uninstall()
{
Close();
_textArea.DocumentChanged -= TextArea_DocumentChanged;
if (_currentDocument != null)
_currentDocument.TextChanged -= TextArea_Document_TextChanged;
_textArea.DefaultInputHandler.NestedInputHandlers.Remove(_handler);
}
private void AttachInternal(TextArea textArea)
{
_textArea = textArea;
_renderer = new SearchResultBackgroundRenderer();
_currentDocument = textArea.Document;
if (_currentDocument != null)
_currentDocument.TextChanged += TextArea_Document_TextChanged;
textArea.DocumentChanged += TextArea_DocumentChanged;
KeyDown += SearchLayerKeyDown;
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.FindNext, (sender, e) => FindNext()));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.FindPrevious, (sender, e) => FindPrevious()));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.CloseSearchPanel, (sender, e) => Close()));
CommandBindings.Add(new RoutedCommandBinding(ApplicationCommands.Find, (sender, e) =>
{
IsReplaceMode = false;
Reactivate();
}));
CommandBindings.Add(new RoutedCommandBinding(ApplicationCommands.Replace, (sender, e) => IsReplaceMode = true));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.ReplaceNext, (sender, e) => ReplaceNext(), (sender, e) => e.CanExecute = IsReplaceMode));
CommandBindings.Add(new RoutedCommandBinding(SearchCommands.ReplaceAll, (sender, e) => ReplaceAll(), (sender, e) => e.CanExecute = IsReplaceMode));
IsClosed = true;
}
private void TextArea_DocumentChanged(object sender, EventArgs e)
{
if (_currentDocument != null)
_currentDocument.TextChanged -= TextArea_Document_TextChanged;
_currentDocument = _textArea.Document;
if (_currentDocument != null)
{
_currentDocument.TextChanged += TextArea_Document_TextChanged;
DoSearch(false);
}
}
private void TextArea_Document_TextChanged(object sender, EventArgs e)
{
DoSearch(false);
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
_border = e.NameScope.Find<Border>("PART_Border");
_searchTextBox = e.NameScope.Find<TextBox>("PART_searchTextBox");
_messageView = e.NameScope.Find<Popup>("PART_MessageView");
_messageViewContent = e.NameScope.Find<ContentPresenter>("PART_MessageContent");
}
private void ValidateSearchText()
{
if (_searchTextBox == null)
return;
try
{
UpdateSearch();
_validationError = null;
}
catch (SearchPatternException ex)
{
_validationError = ex.Message;
}
}
/// <summary>
/// Reactivates the SearchPanel by setting the focus on the search box and selecting all text.
/// </summary>
public void Reactivate()
{
if (_searchTextBox == null)
return;
_searchTextBox.Focus();
_searchTextBox.SelectionStart = 0;
_searchTextBox.SelectionEnd = _searchTextBox.Text?.Length ?? 0;
}
/// <summary>
/// Moves to the next occurrence in the file.
/// </summary>
public void FindNext()
{
var result = _renderer.CurrentResults.FindFirstSegmentWithStartAfter(_textArea.Caret.Offset + 1) ??
_renderer.CurrentResults.FirstSegment;
if (result != null)
{
SelectResult(result);
}
}
/// <summary>
/// Moves to the previous occurrence in the file.
/// </summary>
public void FindPrevious()
{
var result = _renderer.CurrentResults.FindFirstSegmentWithStartAfter(_textArea.Caret.Offset);
if (result != null)
result = _renderer.CurrentResults.GetPreviousSegment(result);
if (result == null)
result = _renderer.CurrentResults.LastSegment;
if (result != null)
{
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
}
public void ReplaceAll()
FindNext();
if (!_textArea.Selection.IsEmpty)
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
UpdateSearch();
}
public void ReplaceAll()
{
if (!IsReplaceMode) return;
var replacement = ReplacePattern ?? string.Empty;
var document = _textArea.Document;
using (document.RunUpdate())
{
var segments = _renderer.CurrentResults.OrderByDescending(x => x.EndOffset).ToArray();
foreach (var textSegment in segments)
{
document.Replace(textSegment.StartOffset, textSegment.Length,
new StringTextSource(replacement));
}
}
}
private Popup _messageView;
private ContentPresenter _messageViewContent;
private string _validationError;
private void DoSearch(bool changeSelection)
{
if (IsClosed)
return;
_renderer.CurrentResults.Clear();
if (!string.IsNullOrEmpty(SearchPattern))
{
var offset = _textArea.Caret.Offset;
if (changeSelection)
{
_textArea.ClearSelection();
}
// We cast from ISearchResult to SearchResult; this is safe because we always use the built-in strategy
foreach (var result in _strategy.FindAll(_textArea.Document, 0, _textArea.Document.TextLength).Cast<SearchResult>())
{
if (changeSelection && result.StartOffset >= offset)
{
SelectResult(result);
changeSelection = false;
}
_renderer.CurrentResults.Add(result);
}
}
if (_messageView != null)
{
if (!_renderer.CurrentResults.Any())
{
_messageViewContent.Content = SR.SearchNoMatchesFoundText;
_messageView.PlacementTarget = _searchTextBox;
_messageView.IsOpen = true;
}
else
_messageView.IsOpen = false;
}
_textArea.TextView.InvalidateLayer(KnownLayer.Selection);
}
private void SelectResult(TextSegment result)
{
_textArea.Caret.Offset = result.StartOffset;
_textArea.Selection = Selection.Create(_textArea, result.StartOffset, result.EndOffset);
double distanceToViewBorder = _border == null ?
Caret.MinimumDistanceToViewBorder :
_border.Bounds.Height + _textArea.TextView.DefaultLineHeight;
_textArea.Caret.BringCaretToView(distanceToViewBorder);
// show caret even if the editor does not have the Keyboard Focus
_textArea.Caret.Show();
}
private void SearchLayerKeyDown(object sender, KeyEventArgs e)
{
switch (e.Key)
{
case Key.Enter:
e.Handled = true;
if (e.KeyModifiers.HasFlag(KeyModifiers.Shift))
{
FindPrevious();
}
else
{
FindNext();
}
if (_searchTextBox != null)
{
if (_validationError != null)
{
_messageViewContent.Content = SR.SearchErrorText + " " + _validationError;
_messageView.PlacementTarget = _searchTextBox;
_messageView.IsOpen = true;
}
}
break;
case Key.Escape:
e.Handled = true;
Close();
break;
}
}
/// <summary>
/// Gets whether the Panel is already closed.
/// </summary>
public bool IsClosed { get; private set; }
/// <summary>
/// Gets whether the Panel is currently opened.
/// </summary>
public bool IsOpened => !IsClosed;
/// <summary>
/// Closes the SearchPanel.
/// </summary>
public void Close()
{
_textArea.RemoveChild(this);
_messageView.IsOpen = false;
_textArea.TextView.BackgroundRenderers.Remove(_renderer);
IsClosed = true;
// Clear existing search results so that the segments don't have to be maintained
_renderer.CurrentResults.Clear();
_textArea.Focus();
}
/// <summary>
/// Opens the an existing search panel.
/// </summary>
public void Open()
{
if (!IsClosed) return;
_textArea.AddChild(this);
_textArea.TextView.BackgroundRenderers.Add(_renderer);
IsClosed = false;
DoSearch(false);
}
protected override void OnPointerPressed(PointerPressedEventArgs e)
{
e.Handled = true;
base.OnPointerPressed(e);
}
protected override void OnPointerMoved(PointerEventArgs e)
{
Cursor = Cursor.Default;
base.OnPointerMoved(e);
}
protected override void OnGotFocus(GotFocusEventArgs e)
{
e.Handled = true;
base.OnGotFocus(e);
}
/// <summary>
/// Fired when SearchOptions are changed inside the SearchPanel.
/// </summary>
public event EventHandler<SearchOptionsChangedEventArgs> SearchOptionsChanged;
/// <summary>
/// Raises the <see cref="SearchOptionsChanged" /> event.
/// </summary>
protected virtual void OnSearchOptionsChanged(SearchOptionsChangedEventArgs e)
{
SearchOptionsChanged?.Invoke(this, e);
}
public IList<RoutedCommandBinding> CommandBindings { get; } = new List<RoutedCommandBinding>();
}
/// <summary>
/// EventArgs for <see cref="SearchPanel.SearchOptionsChanged"/> event.
/// </summary>
public class SearchOptionsChangedEventArgs : EventArgs
{
/// <summary>
/// Gets the search pattern.
/// </summary>
public string SearchPattern { get; }
/// <summary>
/// Gets whether the search pattern should be interpreted case-sensitive.
/// </summary>
public bool MatchCase { get; }
/// <summary>
/// Gets whether the search pattern should be interpreted as regular expression.
/// </summary>
public bool UseRegex { get; }
/// <summary>
/// Gets whether the search pattern should only match whole words.
/// </summary>
public bool WholeWords { get; }
/// <summary>
/// Creates a new SearchOptionsChangedEventArgs instance.
/// </summary>
public SearchOptionsChangedEventArgs(string searchPattern, bool matchCase, bool useRegex, bool wholeWords)
{
SearchPattern = searchPattern;
MatchCase = matchCase;
UseRegex = useRegex;
WholeWords = wholeWords;
}
}
}
<MSG> update search after replace
<DFF> @@ -357,6 +357,8 @@ namespace AvaloniaEdit.Search
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
+
+ UpdateSearch();
}
public void ReplaceAll()
| 2 | update search after replace | 0 | .cs | cs | mit | AvaloniaUI/AvaloniaEdit |
10066867 | <NME> module.render.js
<BEF>
describe('View#render()', function() {
var viewToTest;
beforeEach(function() {
viewToTest = helpers.createView();
});
test("The master view should have an element post render.", function() {
viewToTest.render();
expect(viewToTest.el).toBeDefined();
});
test("before render and render events should be fired", function() {
var beforeRenderSpy = jest.fn();
var renderSpy = jest.fn();
viewToTest.on('before render', beforeRenderSpy);
viewToTest.on('render', renderSpy);
viewToTest.render();
expect(beforeRenderSpy.mock.invocationCallOrder[0]).toBeLessThan(renderSpy.mock.invocationCallOrder[0]);
});
test("Data should be present in the generated markup.", function() {
var text = 'some orange text';
var orange = new Orange({
model: {
text: text
}
});
orange
.render()
.inject(sandbox);
expect(orange.el.innerHTML).toEqual(text);
});
test("Should be able to use Backbone models", function() {
var orange = new Orange({
model: {
text: 'orange text'
}
});
orange.render();
expect(orange.el.innerHTML).toEqual('orange text');
});
test("Child html should be present in the parent.", function() {
var layout = new Layout();
var apple = new Apple();
layout
.add(apple, 1)
.render();
firstChild = layout.el.firstElementChild;
expect(firstChild.classList.contains('apple')).toBe(true);
});
test("Should be of the tag specified", function() {
var apple = new Apple({ tag: 'ul' });
apple.render();
expect('UL').toEqual(apple.el.tagName);
});
test("Should have classes on the element", function() {
var apple = new Apple({
classes: ['foo', 'bar']
});
apple.render();
expect('apple foo bar').toEqual(apple.el.className);
});
test("Should have an id attribute with the value of `fmid`", function() {
var apple = new Apple({
classes: ['foo', 'bar']
});
apple.render();
expect(apple._fmid).toEqual(apple.el.id);
});
test("Should have populated all child module.el properties", function() {
var layout = new Layout({
children: {
1: {
module: 'apple',
children: {
1: {
module: 'apple',
children: {
1: {
module: 'apple'
}
}
}
}
}
}
});
}
});
layout.render();
layout.el.classList.add('should-not-be-blown-away');
layout.module('apple').el.classList.add('should-be-blown-away');
layout.render();
assert(layout.el.classList.contains('should-not-be-blown-away'), 'the DOM node of the FM module that render is called on should be recycled');
refute(layout.module('apple').el.classList.contains('should-be-blown-away'), 'the DOM node of a child FM module to the one render is called on should not be recycled');
},
"tearDown": helpers.destroyView
layout.render();
// The DOM node of the FM module that render is called on should be recycled
expect(layout.el.getAttribute('data-test')).toEqual('should-not-be-blown-away');
// The DOM node of a child FM module to the one render is called on should not be recycled
expect(layout.module('apple').el.getAttribute('data-test')).not.toEqual('should-be-blown-away');
});
test("Classes should be updated on render", function() {
var layout = new Layout();
layout.render();
layout.classes = ['should-be-added'];
layout.render();
expect(layout.el.className).toEqual('layout should-be-added');
});
test("Classes added through the DOM should persist between renders", function() {
var layout = new Layout();
layout.render();
layout.el.classList.add('should-persist');
layout.render();
expect(layout.el.className).toEqual('layout should-persist');
});
test("Should fire unmount on children when rerendering", function() {
var appleSpy = jest.fn();
var orangeSpy = jest.fn();
var pearSpy = jest.fn();
viewToTest.module('apple').on('unmount', appleSpy);
viewToTest.module('orange').on('unmount', orangeSpy);
viewToTest.module('pear').on('unmount', pearSpy);
viewToTest.render();
expect(appleSpy).not.toHaveBeenCalled();
expect(orangeSpy).not.toHaveBeenCalled();
expect(pearSpy).not.toHaveBeenCalled();
viewToTest.render();
expect(appleSpy).toHaveBeenCalled();
expect(orangeSpy).toHaveBeenCalled();
expect(pearSpy).toHaveBeenCalled();
});
afterEach(function() {
helpers.destroyView();
viewToTest = null;
});
});
<MSG> Update classes on each recycled render
<DFF> @@ -107,12 +107,20 @@ buster.testCase('View#render()', {
}
});
layout.render();
- layout.el.classList.add('should-not-be-blown-away');
- layout.module('apple').el.classList.add('should-be-blown-away');
+ layout.el.setAttribute('data-test', 'should-not-be-blown-away');
+ layout.module('apple').el.setAttribute('data-test', 'should-be-blown-away');
layout.render();
- assert(layout.el.classList.contains('should-not-be-blown-away'), 'the DOM node of the FM module that render is called on should be recycled');
- refute(layout.module('apple').el.classList.contains('should-be-blown-away'), 'the DOM node of a child FM module to the one render is called on should not be recycled');
+ assert.equals(layout.el.getAttribute('data-test'), 'should-not-be-blown-away', 'the DOM node of the FM module that render is called on should be recycled');
+ refute.equals(layout.module('apple').el.getAttribute('data-test'), 'should-be-blown-away', 'the DOM node of a child FM module to the one render is called on should not be recycled');
+ },
+
+ "Classes should be updated on render": function() {
+ var layout = new Layout();
+ layout.render();
+ layout.classes = ['should-be-added'];
+ layout.render();
+ assert.equals(layout.el.className, 'layout should-be-added');
},
"tearDown": helpers.destroyView
| 12 | Update classes on each recycled render | 4 | .js | render | mit | ftlabs/fruitmachine |
10066868 | <NME> fruitmachine.js
<BEF> /*jslint browser:true, node:true*/
/**
* FruitMachine
*
* Renders layouts/modules from a basic layout definition.
* If views require custom interactions devs can extend
* the basic functionality.
*
* @version 0.3.3
* @copyright The Financial Times Limited [All Rights Reserved]
* @author Wilson Page <[email protected]>
*/
'use strict';
/**
* Module Dependencies
*/
var mod = require('./module');
var define = require('./define');
var utils = require('utils');
var events = require('evt');
/**
* Creates a fruitmachine
*
* Options:
*
* - `Model` A model constructor to use (must have `.toJSON()`)
*
* @param {Object} options
*/
module.exports = function(options) {
/**
* Shortcut method for
* creating lazy views.
*
* @param {Object} options
* @return {Module}
*/
function fm(options) {
var Module = fm.modules[options.module];
if (Module) {
return new Module(options);
}
throw new Error("Unable to find module '" + options.module + "'");
}
fm.create = module.exports;
fm.Model = options.Model;
fm.Events = events;
fm.Module = mod(fm);
fm.define = define(fm);
fm.util = utils;
fm.modules = {};
fm.config = {
templateIterator: 'children',
templateInstance: 'child'
};
// Mixin events and return
return events(fm);
};
return new Module(options);
}
var stopPropagation = function() {
this.propagate = false;
};
/**
* Configures the new View
* with the options passed
// in, or make a fresh one
event = event || {
target: this,
stopPropagation: stopPropagation
};
// Trigger event
<MSG> Move stopPropagation method inside trigger
<DFF> @@ -267,10 +267,6 @@
return new Module(options);
}
- var stopPropagation = function() {
- this.propagate = false;
- };
-
/**
* Configures the new View
* with the options passed
@@ -337,7 +333,7 @@
// in, or make a fresh one
event = event || {
target: this,
- stopPropagation: stopPropagation
+ stopPropagation: function() { this.propagate = false; }
};
// Trigger event
| 1 | Move stopPropagation method inside trigger | 5 | .js | js | mit | ftlabs/fruitmachine |
10066869 | <NME> module.js
<BEF> var Backbone = require('backbone');
describe('View', function() {
test("Should add any children passed into the constructor", function() {
var children = [
assert.defined(FruitMachine.store.modules['my-module']);
},
tearDown: function() {
FruitMachine.module.clear();
}
});
test("Should store a reference to the slot if passed", function() {
var view = new fruitmachine({
module: 'apple',
children: [
{
module: 'pear',
slot: 1
},
{
module: 'orange',
slot: 2
}
]
});
expect(view.slots[1]).toBeTruthy();
expect(view.slots[2]).toBeTruthy();
});
test("Should store a reference to the slot if slot is passed as key of children object", function() {
var view = new fruitmachine({
module: 'apple',
children: {
1: { module: 'pear' },
2: { module: 'orange' }
}
});
expect(view.slots[1]).toBeTruthy();
expect(view.slots[2]).toBeTruthy();
});
test("Should store a reference to the slot if the view is instantiated with a slot", function() {
var apple = new Apple({ slot: 1 });
expect(apple.slot).toBe(1);
});
test("Should prefer the slot on the children object in case of conflict", function() {
var apple = new Apple({ slot: 1 });
var layout = new Layout({
children: {
2: apple
}
});
expect(layout.module('apple').slot).toBe('2');
});
test("Should create a model", function() {
var view = new fruitmachine({ module: 'apple' });
expect(view.model instanceof fruitmachine.Model).toBe(true);
});
test("Should adopt the fmid if passed", function() {
var view = new fruitmachine({ fmid: '1234', module: 'apple' });
expect(view._fmid).toBe('1234');
});
test("Should fire an 'inflation' event on fm instance if instantiated with an fmid", function() {
var spy = jest.fn();
fruitmachine.on('inflation', spy);
var layout = new fruitmachine({
fmid: '1',
module: 'layout',
children: {
1: {
fmid: '2',
module: 'apple'
}
}
});
expect(spy).toHaveBeenCalledTimes(2);
});
test("Should fire an 'inflation' event on fm instance with the view as the first arg", function() {
var spy = jest.fn();
fruitmachine.on('inflation', spy);
var layout = new fruitmachine({
fmid: '1',
module: 'layout',
children: {
1: {
fmid: '2',
module: 'apple'
}
}
});
expect(spy.mock.calls[0][0]).toBe(layout);
expect(spy.mock.calls[1][0]).toBe(layout.module('apple'));
});
test("Should fire an 'inflation' event on fm instance with the options as the second arg", function() {
var spy = jest.fn();
var options = {
fmid: '1',
module: 'layout'
};
fruitmachine.on('inflation', spy);
var layout = new fruitmachine(options);
expect(spy.mock.calls[0][1]).toEqual(options);
});
test("Should be able to use Backbone models", function() {
var orange = new Orange({
model: new Backbone.Model({ text: 'orange text' })
});
orange.render();
expect(orange.el.innerHTML.indexOf('orange text')).toBe(0);
});
test("Should define a global default model", function() {
var previous = fruitmachine.Module.prototype.Model;
fruitmachine.Module.prototype.Model = Backbone.Model;
var orange = new Orange({
model: { text: 'orange text' }
});
orange.render();
expect(orange.model instanceof Backbone.Model).toBe(true);
expect(orange.el.innerHTML.indexOf('orange text')).toBe(0);
// Restore
fruitmachine.Module.prototype.Model = previous;
});
test("Should define a module default model", function() {
var Berry = fruitmachine.define({
name: 'berry',
Model: Backbone.Model
});
var berry = new Berry({ model: { foo: 'bar' }});
expect(berry.model instanceof Backbone.Model).toBe(true);
});
test.skip("Should not modify the options object", function() {
var options = {
classes: ['my class']
};
var orange = new Orange(options);
orange.classes.push('added');
expect(['my class']).toBe(options.classes);
});
});
<MSG> Module registration tests
<DFF> @@ -7,6 +7,14 @@ buster.testCase('FruitMachine.module()', {
assert.defined(FruitMachine.store.modules['my-module']);
},
+ "Should return an instantiable constructor": function() {
+ var View = FruitMachine.module({ module: 'apple' });
+ var view = new View();
+
+ assert.defined(view._fmid);
+ assert.equals('apple', view.module());
+ },
+
tearDown: function() {
FruitMachine.module.clear();
}
| 8 | Module registration tests | 0 | .js | js | mit | ftlabs/fruitmachine |
10066870 | <NME> module.render.js
<BEF>
describe('View#render()', function() {
var viewToTest;
beforeEach(function() {
viewToTest = helpers.createView();
});
test("The master view should have an element post render.", function() {
viewToTest.render();
expect(viewToTest.el).toBeDefined();
});
test("before render and render events should be fired", function() {
var beforeRenderSpy = jest.fn();
var renderSpy = jest.fn();
viewToTest.on('before render', beforeRenderSpy);
viewToTest.on('render', renderSpy);
viewToTest.render();
expect(beforeRenderSpy.mock.invocationCallOrder[0]).toBeLessThan(renderSpy.mock.invocationCallOrder[0]);
});
test("Data should be present in the generated markup.", function() {
var text = 'some orange text';
var orange = new Orange({
model: {
text: text
}
});
orange
.render()
.inject(sandbox);
expect(orange.el.innerHTML).toEqual(text);
});
test("Should be able to use Backbone models", function() {
var orange = new Orange({
model: {
text: 'orange text'
}
});
orange.render();
expect(orange.el.innerHTML).toEqual('orange text');
});
test("Child html should be present in the parent.", function() {
var layout = new Layout();
var apple = new Apple();
layout
.add(apple, 1)
.render();
firstChild = layout.el.firstElementChild;
expect(firstChild.classList.contains('apple')).toBe(true);
});
test("Should be of the tag specified", function() {
var apple = new Apple({ tag: 'ul' });
apple.render();
expect('UL').toEqual(apple.el.tagName);
});
test("Should have classes on the element", function() {
var apple = new Apple({
classes: ['foo', 'bar']
});
apple.render();
expect('apple foo bar').toEqual(apple.el.className);
});
test("Should have an id attribute with the value of `fmid`", function() {
var apple = new Apple({
classes: ['foo', 'bar']
});
apple.render();
expect(apple._fmid).toEqual(apple.el.id);
});
test("Should have populated all child module.el properties", function() {
var layout = new Layout({
children: {
1: {
module: 'apple',
children: {
1: {
module: 'apple',
children: {
1: {
module: 'apple'
}
}
}
}
}
}
});
var apple1 = layout.module('apple');
var apple2 = apple1.module('apple');
var apple3 = apple2.module('apple');
layout.render();
expect(apple1.el).toBeTruthy();
expect(apple2.el).toBeTruthy();
expect(apple3.el).toBeTruthy();
});
test("The outer DOM node should be recycled between #renders", function() {
var layout = new Layout({
children: {
1: { module: 'apple' }
}
assert.equals(layout.el.className, 'layout should-be-added');
},
"tearDown": helpers.destroyView
});
test("Classes should be updated on render", function() {
var layout = new Layout();
layout.render();
layout.classes = ['should-be-added'];
layout.render();
expect(layout.el.className).toEqual('layout should-be-added');
});
test("Classes added through the DOM should persist between renders", function() {
var layout = new Layout();
layout.render();
layout.el.classList.add('should-persist');
layout.render();
expect(layout.el.className).toEqual('layout should-persist');
});
test("Should fire unmount on children when rerendering", function() {
var appleSpy = jest.fn();
var orangeSpy = jest.fn();
var pearSpy = jest.fn();
viewToTest.module('apple').on('unmount', appleSpy);
viewToTest.module('orange').on('unmount', orangeSpy);
viewToTest.module('pear').on('unmount', pearSpy);
viewToTest.render();
expect(appleSpy).not.toHaveBeenCalled();
expect(orangeSpy).not.toHaveBeenCalled();
expect(pearSpy).not.toHaveBeenCalled();
viewToTest.render();
expect(appleSpy).toHaveBeenCalled();
expect(orangeSpy).toHaveBeenCalled();
expect(pearSpy).toHaveBeenCalled();
});
afterEach(function() {
helpers.destroyView();
viewToTest = null;
});
});
<MSG> Persist directly added outer layer classes between renders - addresses @orangemug's feedback
<DFF> @@ -123,5 +123,13 @@ buster.testCase('View#render()', {
assert.equals(layout.el.className, 'layout should-be-added');
},
+ "Classes added through the DOM should persist between renders": function() {
+ var layout = new Layout();
+ layout.render();
+ layout.el.classList.add('should-persist');
+ layout.render();
+ assert.equals(layout.el.className, 'layout should-persist');
+ },
+
"tearDown": helpers.destroyView
});
| 8 | Persist directly added outer layer classes between renders - addresses @orangemug's feedback | 0 | .js | render | mit | ftlabs/fruitmachine |
10066871 | <NME> tests.js
<BEF> /**
* loadjs tests
* @module test/tests.js
*/
var pathsLoaded = null, // file register
testEl = null,
assert = chai.assert,
expect = chai.expect;
describe('LoadJS tests', function() {
beforeEach(function() {
// reset register
pathsLoaded = {};
// reset loadjs dependencies
loadjs.reset();
});
// ==========================================================================
// JavaScript file loading tests
// ==========================================================================
describe('JavaScript file loading tests', function() {
it('should call success callback on valid path', function(done) {
loadjs(['assets/file1.js'], {
success: function() {
assert.equal(pathsLoaded['file1.js'], true);
done();
}
});
});
it('should call error callback on invalid path', function(done) {
loadjs(['assets/file-doesntexist.js'], {
success: function() {
throw "Executed success callback";
},
error: function(pathsNotFound) {
assert.equal(pathsNotFound.length, 1);
assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js');
done();
}
});
});
it('should call before callback before embedding into document', function(done) {
var scriptTags = [];
loadjs(['assets/file1.js', 'assets/file2.js'], {
before: function(path, el) {
scriptTags.push({
path: path,
el: el
});
// add cross origin script for file2
if (path === 'assets/file2.js') {
el.crossOrigin = 'anonymous';
}
},
success: function() {
assert.equal(scriptTags[0].path, 'assets/file1.js');
assert.equal(scriptTags[1].path, 'assets/file2.js');
assert.equal(scriptTags[0].el.crossOrigin, undefined);
assert.equal(scriptTags[1].el.crossOrigin, 'anonymous');
done();
}
});
});
it('should bypass insertion if before returns `false`', function(done) {
loadjs(['assets/file1.js'], {
// run tests sequentially
var testFn = function(paths) {
loadjs(paths, {
success: function() {
var f1 = paths[0].replace('assets/', '');
var f2 = paths[1].replace('assets/', '');
el;
for (var i=0; i < els.length; i++) {
el = els[i];
if (el.src.indexOf('assets/file1.js') !== -1) done();
}
}
});
});
it('should call success callback on two valid paths', function(done) {
loadjs(['assets/file1.js', 'assets/file2.js'], {
success: function() {
assert.equal(pathsLoaded['file1.js'], true);
assert.equal(pathsLoaded['file2.js'], true);
done();
}
});
});
it('should call error callback on one invalid path', function(done) {
loadjs(['assets/file1.js', 'assets/file-doesntexist.js'], {
success: function() {
throw "Executed success callback";
},
error: function(pathsNotFound) {
assert.equal(pathsLoaded['file1.js'], true);
assert.equal(pathsNotFound.length, 1);
assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js');
done();
}
});
});
it('should support async false', function(done) {
this.timeout(5000);
var numCompleted = 0,
numTests = 20,
paths = ['assets/asyncfalse1.js', 'assets/asyncfalse2.js'];
// run tests sequentially
var testFn = function(paths) {
// add cache busters
var pathsUncached = paths.slice(0);
pathsUncached[0] += '?_=' + Math.random();
pathsUncached[1] += '?_=' + Math.random();
loadjs(pathsUncached, {
success: function() {
var f1 = paths[0].replace('assets/', '');
var f2 = paths[1].replace('assets/', '');
// check load order
assert.isTrue(pathsLoaded[f1]);
assert.isFalse(pathsLoaded[f2]);
// increment tests
numCompleted += 1;
if (numCompleted === numTests) {
// exit
done();
} else {
// reset register
pathsLoaded = {};
// run test again
paths.reverse();
testFn(paths);
}
},
async: false
});
};
// run tests
testFn(paths);
});
it('should support multiple tries', function(done) {
loadjs('assets/file-numretries.js', {
error: function() {
// check number of scripts in document
var selector = 'script[src="assets/file-numretries.js"]',
scripts = document.querySelectorAll(selector);
if (scripts.length === 2) done();
},
numRetries: 1
});
});
// Un-'x' this for testing ad blocked scripts.
// Ghostery: Disallow "Google Adservices"
// AdBlock Plus: Add "www.googletagservices.com/tag/js/gpt.js" as a
// custom filter under Options
//
xit('it should report ad blocked scripts as missing', function(done) {
var s1 = 'https://www.googletagservices.com/tag/js/gpt.js',
s2 = 'https://munchkin.marketo.net/munchkin-beta.js';
loadjs([s1, s2, 'assets/file1.js'], {
success: function() {
throw new Error('Executed success callback');
},
error: function(pathsNotFound) {
assert.equal(pathsLoaded['file1.js'], true);
assert.equal(pathsNotFound.length, 2);
assert.equal(pathsNotFound[0], s1);
assert.equal(pathsNotFound[1], s2);
done();
}
});
});
});
// ==========================================================================
// CSS file loading tests
// ==========================================================================
describe('CSS file loading tests', function() {
before(function() {
// add test div to body for css tests
testEl = document.createElement('div');
testEl.className = 'test-div mui-container';
testEl.style.display = 'inline-block';
document.body.appendChild(testEl);
});
afterEach(function() {
var els = document.getElementsByTagName('link'),
i = els.length,
el;
// iteratete through stylesheets
while (i--) {
el = els[i];
// remove test stylesheets
if (el.href.indexOf('mocha.css') === -1) {
el.parentNode.removeChild(el);
}
}
});
it('should load one file', function(done) {
loadjs(['assets/file1.css'], {
success: function() {
assert.equal(testEl.offsetWidth, 100);
done();
}
});
});
it('should load multiple files', function(done) {
loadjs(['assets/file1.css', 'assets/file2.css'], {
success: function() {
assert.equal(testEl.offsetWidth, 200);
done();
}
});
});
it('should call error callback on one invalid path', function(done) {
loadjs(['assets/file1.css', 'assets/file-doesntexist.css'], {
success: function() {
throw new Error('Executed success callback');
},
error: function(pathsNotFound) {
assert.equal(testEl.offsetWidth, 100);
assert.equal(pathsNotFound.length, 1);
assert.equal(pathsNotFound[0], 'assets/file-doesntexist.css');
done();
}
});
});
it('should support mix of css and js', function(done) {
loadjs(['assets/file1.css', 'assets/file1.js'], {
success: function() {
assert.equal(pathsLoaded['file1.js'], true);
assert.equal(testEl.offsetWidth, 100);
done();
}
});
});
it('should support forced "css!" files', function(done) {
loadjs(['css!assets/file1.css'], {
success: function() {
// loop through files
var els = document.getElementsByTagName('link'),
i = els.length,
el;
while (i--) {
if (els[i].href.indexOf('file1.css') !== -1) done();
}
}
});
});
it('supports urls with query arguments', function(done) {
loadjs(['assets/file1.css?x=x'], {
success: function() {
assert.equal(testEl.offsetWidth, 100);
done();
}
});
});
it('supports urls with anchor tags', function(done) {
loadjs(['assets/file1.css#anchortag'], {
success: function() {
assert.equal(testEl.offsetWidth, 100);
done();
}
});
});
it('supports urls with query arguments and anchor tags', function(done) {
loadjs(['assets/file1.css?x=x#anchortag'], {
success: function() {
assert.equal(testEl.offsetWidth, 100);
done();
}
});
});
it('should load external css files', function(done) {
this.timeout(0);
loadjs(['//cdn.muicss.com/mui-0.6.8/css/mui.min.css'], {
success: function() {
var styleObj = getComputedStyle(testEl);
assert.equal(styleObj.getPropertyValue('padding-left'), '15px');
done();
}
});
});
it('should call error on missing external file', function(done) {
this.timeout(0);
loadjs(['//cdn.muicss.com/mui-0.6.8/css/mui-doesnotexist.min.css'], {
success: function() {
throw new Error('Executed success callback');
},
error: function(pathsNotFound) {
var styleObj = getComputedStyle(testEl);
assert.equal(styleObj.getPropertyValue('padding-left'), '0px');
assert.equal(pathsNotFound.length, 1);
done();
}
});
});
// teardown
return after(function() {
// remove test div
testEl.parentNode.removeChild(testEl);
});
});
// ==========================================================================
// Image file loading tests
// ==========================================================================
describe('Image file loading tests', function() {
function assertLoaded(src) {
// loop through images
var imgs = document.getElementsByTagName('img');
Array.prototype.slice.call(imgs).forEach(function(img) {
// verify image was loaded
if (img.src === src) assert.equal(img.naturalWidth > 0, true);
});
}
function assertNotLoaded(src) {
// loop through images
var imgs = document.getElementsByTagName('img');
Array.prototype.slice.call(imgs).forEach(function(img) {
// fail if image was loaded
if (img.src === src) assert.equal(img.naturalWidth, 0);
});
}
it('should load one file', function(done) {
loadjs(['assets/flash.png'], {
success: function() {
assertLoaded('assets/flash.png');
done();
}
});
});
it('should load multiple files', function(done) {
loadjs(['assets/flash.png', 'assets/flash.jpg'], {
success: function() {
assertLoaded('assets/flash.png');
assertLoaded('assets/flash.jpg');
done();
}
});
});
it('detects png|gif|jpg|svg|webp extensions', function(done) {
let files = [
'assets/flash.png',
'assets/flash.gif',
'assets/flash.jpg',
'assets/flash.svg',
'assets/flash.webp'
];
loadjs(files, function() {
files.forEach(file => {assertLoaded(file);});
done();
});
});
it('supports urls with query arguments', function(done) {
var src = 'assets/flash.png?' + Math.random();
loadjs([src], {
success: function() {
assertLoaded(src);
done();
}
});
});
it('supports urls with anchor tags', function(done) {
var src = 'assets/flash.png#' + Math.random();
loadjs([src], {
success: function() {
assertLoaded(src);
done();
}
});
});
it('supports urls with query arguments and anchor tags', function(done) {
var src = 'assets/flash.png';
src += '?' + Math.random();
src += '#' + Math.random();
loadjs([src], {
success: function() {
assertLoaded(src);
done();
}
});
});
it('should support forced "img!" files', function(done) {
var src = 'assets/flash.png?' + Math.random();
loadjs(['img!' + src], {
success: function() {
assertLoaded(src);
done();
}
});
});
it('should call error callback on one invalid path', function(done) {
var src1 = 'assets/flash.png?' + Math.random(),
src2 = 'assets/flash-doesntexist.png?' + Math.random();
loadjs(['img!' + src1, 'img!' + src2], {
success: function() {
throw new Error('Executed success callback');
},
error: function(pathsNotFound) {
assert.equal(pathsNotFound.length, 1);
assertLoaded(src1);
assertNotLoaded(src2);
done();
}
});
});
it('should support mix of img and js', function(done) {
var src = 'assets/flash.png?' + Math.random();
loadjs(['img!' + src, 'assets/file1.js'], {
success: function() {
assert.equal(pathsLoaded['file1.js'], true);
assertLoaded(src);
done();
}
});
});
it('should load external img files', function(done) {
this.timeout(0);
var src = 'https://www.muicss.com/static/images/mui-logo.png?';
src += Math.random();
loadjs(['img!' + src], {
success: function() {
assertLoaded(src);
done();
}
});
});
it('should call error on missing external file', function(done) {
this.timeout(0);
var src = 'https://www.muicss.com/static/images/';
src += 'mui-logo-doesntexist.png?' + Math.random();
loadjs(['img!' + src], {
success: function() {
throw new Error('Executed success callback');
},
error: function(pathsNotFound) {
assertNotLoaded(src);
done();
}
});
});
});
// ==========================================================================
// API tests
// ==========================================================================
describe('API tests', function() {
it('should throw an error if bundle is already defined', function() {
// define bundle
loadjs(['assets/file1.js'], 'bundle');
// define bundle again
var fn = function() {
loadjs(['assets/file1.js'], 'bundle');
};
expect(fn).to.throw("LoadJS");
});
it('should create a bundle id and a callback inline', function(done) {
loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle', {
success: function() {
assert.equal(pathsLoaded['file1.js'], true);
assert.equal(pathsLoaded['file2.js'], true);
done();
}
});
});
it('should chain loadjs object', function(done) {
function bothDone() {
if (pathsLoaded['file1.js'] && pathsLoaded['file2.js']) done();
}
// define bundles
loadjs('assets/file1.js', 'bundle1');
loadjs('assets/file2.js', 'bundle2');
loadjs
.ready('bundle1', {
success: function() {
assert.equal(pathsLoaded['file1.js'], true);
bothDone();
}})
.ready('bundle2', {
success: function() {
assert.equal(pathsLoaded['file2.js'], true);
bothDone();
}
});
});
it('should handle multiple dependencies', function(done) {
loadjs('assets/file1.js', 'bundle1');
loadjs('assets/file2.js', 'bundle2');
loadjs.ready(['bundle1', 'bundle2'], {
success: function() {
assert.equal(pathsLoaded['file1.js'], true);
assert.equal(pathsLoaded['file2.js'], true);
done();
}
});
});
it('should error on missing depdendencies', function(done) {
loadjs('assets/file1.js', 'bundle1');
loadjs('assets/file-doesntexist.js', 'bundle2');
loadjs.ready(['bundle1', 'bundle2'], {
success: function() {
throw "Executed success callback";
},
error: function(depsNotFound) {
assert.equal(pathsLoaded['file1.js'], true);
assert.equal(depsNotFound.length, 1);
assert.equal(depsNotFound[0], 'bundle2');
done();
}
});
});
it('should execute callbacks on .done()', function(done) {
// add handler
loadjs.ready('plugin', {
success: function() {
done();
}
});
// execute done
loadjs.done('plugin');
});
it('should execute callbacks created after .done()', function(done) {
// execute done
loadjs.done('plugin');
// add handler
loadjs.ready('plugin', {
success: function() {
done();
}
});
});
it('should define bundles', function(done) {
// define bundle
loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle');
// use 1 second delay to let files load
setTimeout(function() {
loadjs.ready('bundle', {
success: function() {
assert.equal(pathsLoaded['file1.js'], true);
assert.equal(pathsLoaded['file2.js'], true);
done();
}
});
}, 1000);
});
it('should allow bundle callbacks before definitions', function(done) {
// define callback
loadjs.ready('bundle', {
success: function() {
assert.equal(pathsLoaded['file1.js'], true);
assert.equal(pathsLoaded['file2.js'], true);
done();
}
});
// use 1 second delay
setTimeout(function() {
loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle');
}, 1000);
});
it('should reset dependencies statuses', function() {
loadjs(['assets/file1.js'], 'cleared');
loadjs.reset();
// define bundle again
var fn = function() {
loadjs(['assets/file1.js'], 'cleared');
};
expect(fn).not.to.throw("LoadJS");
});
it('should indicate if bundle has already been defined', function() {
loadjs(['assets/file1/js'], 'bundle1');
assert.equal(loadjs.isDefined('bundle1'), true);
assert.equal(loadjs.isDefined('bundleXX'), false);
});
it('should accept success callback functions to loadjs()', function(done) {
loadjs('assets/file1.js', function() {
done();
});
});
it('should accept success callback functions to .ready()', function(done) {
loadjs.done('plugin');
loadjs.ready('plugin', function() {
done();
});
});
it('should return Promise object if returnPromise is true', function() {
var prom = loadjs(['assets/file1.js'], {returnPromise: true});
// verify that response object is a Promise
assert.equal(prom instanceof Promise, true);
});
it('Promise object should support resolutions', function(done) {
var prom = loadjs(['assets/file1.js'], {returnPromise: true});
prom.then(function() {
assert.equal(pathsLoaded['file1.js'], true);
done();
});
});
it('Promise object should support rejections', function(done) {
var prom = loadjs(['assets/file-doesntexist.js'], {returnPromise: true});
prom.then(
function(){},
function(pathsNotFound) {
assert.equal(pathsNotFound.length, 1);
assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js');
done();
}
);
});
it('Promise object should support catches', function(done) {
var prom = loadjs(['assets/file-doesntexist.js'], {returnPromise: true});
prom
.catch(function(pathsNotFound) {
assert.equal(pathsNotFound.length, 1);
assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js');
done();
});
});
it('supports Promises and success callbacks', function(done) {
var numCompleted = 0;
function completedFn() {
numCompleted += 1;
if (numCompleted === 2) done();
};
var prom = loadjs('assets/file1.js', {
success: completedFn,
returnPromise: true
});
prom.then(completedFn);
});
it('supports Promises and bundle ready events', function(done) {
var numCompleted = 0;
function completedFn() {
numCompleted += 1;
if (numCompleted === 2) done();
};
loadjs('assets/file1.js', 'bundle1', {returnPromise: true})
.then(completedFn);
loadjs.ready('bundle1', completedFn);
});
});
});
<MSG> added cache busters to async false test
<DFF> @@ -82,7 +82,12 @@ describe('LoadJS tests', function() {
// run tests sequentially
var testFn = function(paths) {
- loadjs(paths, {
+ // add cache busters
+ var pathsUncached = paths.slice(0);
+ pathsUncached[0] += '?_=' + Math.random();
+ pathsUncached[1] += '?_=' + Math.random();
+
+ loadjs(pathsUncached, {
success: function() {
var f1 = paths[0].replace('assets/', '');
var f2 = paths[1].replace('assets/', '');
| 6 | added cache busters to async false test | 1 | .js | js | mit | muicss/loadjs |
10066872 | <NME> tests.js
<BEF> /**
* loadjs tests
* @module test/tests.js
*/
var pathsLoaded = null, // file register
testEl = null,
assert = chai.assert,
expect = chai.expect;
describe('LoadJS tests', function() {
beforeEach(function() {
// reset register
pathsLoaded = {};
// reset loadjs dependencies
loadjs.reset();
});
// ==========================================================================
// JavaScript file loading tests
// ==========================================================================
describe('JavaScript file loading tests', function() {
it('should call success callback on valid path', function(done) {
loadjs(['assets/file1.js'], {
success: function() {
assert.equal(pathsLoaded['file1.js'], true);
done();
}
});
});
it('should call error callback on invalid path', function(done) {
loadjs(['assets/file-doesntexist.js'], {
success: function() {
throw "Executed success callback";
},
error: function(pathsNotFound) {
assert.equal(pathsNotFound.length, 1);
assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js');
done();
}
});
});
it('should call before callback before embedding into document', function(done) {
var scriptTags = [];
loadjs(['assets/file1.js', 'assets/file2.js'], {
before: function(path, el) {
scriptTags.push({
path: path,
el: el
});
// add cross origin script for file2
if (path === 'assets/file2.js') {
el.crossOrigin = 'anonymous';
}
},
success: function() {
assert.equal(scriptTags[0].path, 'assets/file1.js');
assert.equal(scriptTags[1].path, 'assets/file2.js');
assert.equal(scriptTags[0].el.crossOrigin, undefined);
assert.equal(scriptTags[1].el.crossOrigin, 'anonymous');
done();
}
});
});
it('should bypass insertion if before returns `false`', function(done) {
loadjs(['assets/file1.js'], {
// run tests sequentially
var testFn = function(paths) {
loadjs(paths, {
success: function() {
var f1 = paths[0].replace('assets/', '');
var f2 = paths[1].replace('assets/', '');
el;
for (var i=0; i < els.length; i++) {
el = els[i];
if (el.src.indexOf('assets/file1.js') !== -1) done();
}
}
});
});
it('should call success callback on two valid paths', function(done) {
loadjs(['assets/file1.js', 'assets/file2.js'], {
success: function() {
assert.equal(pathsLoaded['file1.js'], true);
assert.equal(pathsLoaded['file2.js'], true);
done();
}
});
});
it('should call error callback on one invalid path', function(done) {
loadjs(['assets/file1.js', 'assets/file-doesntexist.js'], {
success: function() {
throw "Executed success callback";
},
error: function(pathsNotFound) {
assert.equal(pathsLoaded['file1.js'], true);
assert.equal(pathsNotFound.length, 1);
assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js');
done();
}
});
});
it('should support async false', function(done) {
this.timeout(5000);
var numCompleted = 0,
numTests = 20,
paths = ['assets/asyncfalse1.js', 'assets/asyncfalse2.js'];
// run tests sequentially
var testFn = function(paths) {
// add cache busters
var pathsUncached = paths.slice(0);
pathsUncached[0] += '?_=' + Math.random();
pathsUncached[1] += '?_=' + Math.random();
loadjs(pathsUncached, {
success: function() {
var f1 = paths[0].replace('assets/', '');
var f2 = paths[1].replace('assets/', '');
// check load order
assert.isTrue(pathsLoaded[f1]);
assert.isFalse(pathsLoaded[f2]);
// increment tests
numCompleted += 1;
if (numCompleted === numTests) {
// exit
done();
} else {
// reset register
pathsLoaded = {};
// run test again
paths.reverse();
testFn(paths);
}
},
async: false
});
};
// run tests
testFn(paths);
});
it('should support multiple tries', function(done) {
loadjs('assets/file-numretries.js', {
error: function() {
// check number of scripts in document
var selector = 'script[src="assets/file-numretries.js"]',
scripts = document.querySelectorAll(selector);
if (scripts.length === 2) done();
},
numRetries: 1
});
});
// Un-'x' this for testing ad blocked scripts.
// Ghostery: Disallow "Google Adservices"
// AdBlock Plus: Add "www.googletagservices.com/tag/js/gpt.js" as a
// custom filter under Options
//
xit('it should report ad blocked scripts as missing', function(done) {
var s1 = 'https://www.googletagservices.com/tag/js/gpt.js',
s2 = 'https://munchkin.marketo.net/munchkin-beta.js';
loadjs([s1, s2, 'assets/file1.js'], {
success: function() {
throw new Error('Executed success callback');
},
error: function(pathsNotFound) {
assert.equal(pathsLoaded['file1.js'], true);
assert.equal(pathsNotFound.length, 2);
assert.equal(pathsNotFound[0], s1);
assert.equal(pathsNotFound[1], s2);
done();
}
});
});
});
// ==========================================================================
// CSS file loading tests
// ==========================================================================
describe('CSS file loading tests', function() {
before(function() {
// add test div to body for css tests
testEl = document.createElement('div');
testEl.className = 'test-div mui-container';
testEl.style.display = 'inline-block';
document.body.appendChild(testEl);
});
afterEach(function() {
var els = document.getElementsByTagName('link'),
i = els.length,
el;
// iteratete through stylesheets
while (i--) {
el = els[i];
// remove test stylesheets
if (el.href.indexOf('mocha.css') === -1) {
el.parentNode.removeChild(el);
}
}
});
it('should load one file', function(done) {
loadjs(['assets/file1.css'], {
success: function() {
assert.equal(testEl.offsetWidth, 100);
done();
}
});
});
it('should load multiple files', function(done) {
loadjs(['assets/file1.css', 'assets/file2.css'], {
success: function() {
assert.equal(testEl.offsetWidth, 200);
done();
}
});
});
it('should call error callback on one invalid path', function(done) {
loadjs(['assets/file1.css', 'assets/file-doesntexist.css'], {
success: function() {
throw new Error('Executed success callback');
},
error: function(pathsNotFound) {
assert.equal(testEl.offsetWidth, 100);
assert.equal(pathsNotFound.length, 1);
assert.equal(pathsNotFound[0], 'assets/file-doesntexist.css');
done();
}
});
});
it('should support mix of css and js', function(done) {
loadjs(['assets/file1.css', 'assets/file1.js'], {
success: function() {
assert.equal(pathsLoaded['file1.js'], true);
assert.equal(testEl.offsetWidth, 100);
done();
}
});
});
it('should support forced "css!" files', function(done) {
loadjs(['css!assets/file1.css'], {
success: function() {
// loop through files
var els = document.getElementsByTagName('link'),
i = els.length,
el;
while (i--) {
if (els[i].href.indexOf('file1.css') !== -1) done();
}
}
});
});
it('supports urls with query arguments', function(done) {
loadjs(['assets/file1.css?x=x'], {
success: function() {
assert.equal(testEl.offsetWidth, 100);
done();
}
});
});
it('supports urls with anchor tags', function(done) {
loadjs(['assets/file1.css#anchortag'], {
success: function() {
assert.equal(testEl.offsetWidth, 100);
done();
}
});
});
it('supports urls with query arguments and anchor tags', function(done) {
loadjs(['assets/file1.css?x=x#anchortag'], {
success: function() {
assert.equal(testEl.offsetWidth, 100);
done();
}
});
});
it('should load external css files', function(done) {
this.timeout(0);
loadjs(['//cdn.muicss.com/mui-0.6.8/css/mui.min.css'], {
success: function() {
var styleObj = getComputedStyle(testEl);
assert.equal(styleObj.getPropertyValue('padding-left'), '15px');
done();
}
});
});
it('should call error on missing external file', function(done) {
this.timeout(0);
loadjs(['//cdn.muicss.com/mui-0.6.8/css/mui-doesnotexist.min.css'], {
success: function() {
throw new Error('Executed success callback');
},
error: function(pathsNotFound) {
var styleObj = getComputedStyle(testEl);
assert.equal(styleObj.getPropertyValue('padding-left'), '0px');
assert.equal(pathsNotFound.length, 1);
done();
}
});
});
// teardown
return after(function() {
// remove test div
testEl.parentNode.removeChild(testEl);
});
});
// ==========================================================================
// Image file loading tests
// ==========================================================================
describe('Image file loading tests', function() {
function assertLoaded(src) {
// loop through images
var imgs = document.getElementsByTagName('img');
Array.prototype.slice.call(imgs).forEach(function(img) {
// verify image was loaded
if (img.src === src) assert.equal(img.naturalWidth > 0, true);
});
}
function assertNotLoaded(src) {
// loop through images
var imgs = document.getElementsByTagName('img');
Array.prototype.slice.call(imgs).forEach(function(img) {
// fail if image was loaded
if (img.src === src) assert.equal(img.naturalWidth, 0);
});
}
it('should load one file', function(done) {
loadjs(['assets/flash.png'], {
success: function() {
assertLoaded('assets/flash.png');
done();
}
});
});
it('should load multiple files', function(done) {
loadjs(['assets/flash.png', 'assets/flash.jpg'], {
success: function() {
assertLoaded('assets/flash.png');
assertLoaded('assets/flash.jpg');
done();
}
});
});
it('detects png|gif|jpg|svg|webp extensions', function(done) {
let files = [
'assets/flash.png',
'assets/flash.gif',
'assets/flash.jpg',
'assets/flash.svg',
'assets/flash.webp'
];
loadjs(files, function() {
files.forEach(file => {assertLoaded(file);});
done();
});
});
it('supports urls with query arguments', function(done) {
var src = 'assets/flash.png?' + Math.random();
loadjs([src], {
success: function() {
assertLoaded(src);
done();
}
});
});
it('supports urls with anchor tags', function(done) {
var src = 'assets/flash.png#' + Math.random();
loadjs([src], {
success: function() {
assertLoaded(src);
done();
}
});
});
it('supports urls with query arguments and anchor tags', function(done) {
var src = 'assets/flash.png';
src += '?' + Math.random();
src += '#' + Math.random();
loadjs([src], {
success: function() {
assertLoaded(src);
done();
}
});
});
it('should support forced "img!" files', function(done) {
var src = 'assets/flash.png?' + Math.random();
loadjs(['img!' + src], {
success: function() {
assertLoaded(src);
done();
}
});
});
it('should call error callback on one invalid path', function(done) {
var src1 = 'assets/flash.png?' + Math.random(),
src2 = 'assets/flash-doesntexist.png?' + Math.random();
loadjs(['img!' + src1, 'img!' + src2], {
success: function() {
throw new Error('Executed success callback');
},
error: function(pathsNotFound) {
assert.equal(pathsNotFound.length, 1);
assertLoaded(src1);
assertNotLoaded(src2);
done();
}
});
});
it('should support mix of img and js', function(done) {
var src = 'assets/flash.png?' + Math.random();
loadjs(['img!' + src, 'assets/file1.js'], {
success: function() {
assert.equal(pathsLoaded['file1.js'], true);
assertLoaded(src);
done();
}
});
});
it('should load external img files', function(done) {
this.timeout(0);
var src = 'https://www.muicss.com/static/images/mui-logo.png?';
src += Math.random();
loadjs(['img!' + src], {
success: function() {
assertLoaded(src);
done();
}
});
});
it('should call error on missing external file', function(done) {
this.timeout(0);
var src = 'https://www.muicss.com/static/images/';
src += 'mui-logo-doesntexist.png?' + Math.random();
loadjs(['img!' + src], {
success: function() {
throw new Error('Executed success callback');
},
error: function(pathsNotFound) {
assertNotLoaded(src);
done();
}
});
});
});
// ==========================================================================
// API tests
// ==========================================================================
describe('API tests', function() {
it('should throw an error if bundle is already defined', function() {
// define bundle
loadjs(['assets/file1.js'], 'bundle');
// define bundle again
var fn = function() {
loadjs(['assets/file1.js'], 'bundle');
};
expect(fn).to.throw("LoadJS");
});
it('should create a bundle id and a callback inline', function(done) {
loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle', {
success: function() {
assert.equal(pathsLoaded['file1.js'], true);
assert.equal(pathsLoaded['file2.js'], true);
done();
}
});
});
it('should chain loadjs object', function(done) {
function bothDone() {
if (pathsLoaded['file1.js'] && pathsLoaded['file2.js']) done();
}
// define bundles
loadjs('assets/file1.js', 'bundle1');
loadjs('assets/file2.js', 'bundle2');
loadjs
.ready('bundle1', {
success: function() {
assert.equal(pathsLoaded['file1.js'], true);
bothDone();
}})
.ready('bundle2', {
success: function() {
assert.equal(pathsLoaded['file2.js'], true);
bothDone();
}
});
});
it('should handle multiple dependencies', function(done) {
loadjs('assets/file1.js', 'bundle1');
loadjs('assets/file2.js', 'bundle2');
loadjs.ready(['bundle1', 'bundle2'], {
success: function() {
assert.equal(pathsLoaded['file1.js'], true);
assert.equal(pathsLoaded['file2.js'], true);
done();
}
});
});
it('should error on missing depdendencies', function(done) {
loadjs('assets/file1.js', 'bundle1');
loadjs('assets/file-doesntexist.js', 'bundle2');
loadjs.ready(['bundle1', 'bundle2'], {
success: function() {
throw "Executed success callback";
},
error: function(depsNotFound) {
assert.equal(pathsLoaded['file1.js'], true);
assert.equal(depsNotFound.length, 1);
assert.equal(depsNotFound[0], 'bundle2');
done();
}
});
});
it('should execute callbacks on .done()', function(done) {
// add handler
loadjs.ready('plugin', {
success: function() {
done();
}
});
// execute done
loadjs.done('plugin');
});
it('should execute callbacks created after .done()', function(done) {
// execute done
loadjs.done('plugin');
// add handler
loadjs.ready('plugin', {
success: function() {
done();
}
});
});
it('should define bundles', function(done) {
// define bundle
loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle');
// use 1 second delay to let files load
setTimeout(function() {
loadjs.ready('bundle', {
success: function() {
assert.equal(pathsLoaded['file1.js'], true);
assert.equal(pathsLoaded['file2.js'], true);
done();
}
});
}, 1000);
});
it('should allow bundle callbacks before definitions', function(done) {
// define callback
loadjs.ready('bundle', {
success: function() {
assert.equal(pathsLoaded['file1.js'], true);
assert.equal(pathsLoaded['file2.js'], true);
done();
}
});
// use 1 second delay
setTimeout(function() {
loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle');
}, 1000);
});
it('should reset dependencies statuses', function() {
loadjs(['assets/file1.js'], 'cleared');
loadjs.reset();
// define bundle again
var fn = function() {
loadjs(['assets/file1.js'], 'cleared');
};
expect(fn).not.to.throw("LoadJS");
});
it('should indicate if bundle has already been defined', function() {
loadjs(['assets/file1/js'], 'bundle1');
assert.equal(loadjs.isDefined('bundle1'), true);
assert.equal(loadjs.isDefined('bundleXX'), false);
});
it('should accept success callback functions to loadjs()', function(done) {
loadjs('assets/file1.js', function() {
done();
});
});
it('should accept success callback functions to .ready()', function(done) {
loadjs.done('plugin');
loadjs.ready('plugin', function() {
done();
});
});
it('should return Promise object if returnPromise is true', function() {
var prom = loadjs(['assets/file1.js'], {returnPromise: true});
// verify that response object is a Promise
assert.equal(prom instanceof Promise, true);
});
it('Promise object should support resolutions', function(done) {
var prom = loadjs(['assets/file1.js'], {returnPromise: true});
prom.then(function() {
assert.equal(pathsLoaded['file1.js'], true);
done();
});
});
it('Promise object should support rejections', function(done) {
var prom = loadjs(['assets/file-doesntexist.js'], {returnPromise: true});
prom.then(
function(){},
function(pathsNotFound) {
assert.equal(pathsNotFound.length, 1);
assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js');
done();
}
);
});
it('Promise object should support catches', function(done) {
var prom = loadjs(['assets/file-doesntexist.js'], {returnPromise: true});
prom
.catch(function(pathsNotFound) {
assert.equal(pathsNotFound.length, 1);
assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js');
done();
});
});
it('supports Promises and success callbacks', function(done) {
var numCompleted = 0;
function completedFn() {
numCompleted += 1;
if (numCompleted === 2) done();
};
var prom = loadjs('assets/file1.js', {
success: completedFn,
returnPromise: true
});
prom.then(completedFn);
});
it('supports Promises and bundle ready events', function(done) {
var numCompleted = 0;
function completedFn() {
numCompleted += 1;
if (numCompleted === 2) done();
};
loadjs('assets/file1.js', 'bundle1', {returnPromise: true})
.then(completedFn);
loadjs.ready('bundle1', completedFn);
});
});
});
<MSG> added cache busters to async false test
<DFF> @@ -82,7 +82,12 @@ describe('LoadJS tests', function() {
// run tests sequentially
var testFn = function(paths) {
- loadjs(paths, {
+ // add cache busters
+ var pathsUncached = paths.slice(0);
+ pathsUncached[0] += '?_=' + Math.random();
+ pathsUncached[1] += '?_=' + Math.random();
+
+ loadjs(pathsUncached, {
success: function() {
var f1 = paths[0].replace('assets/', '');
var f2 = paths[1].replace('assets/', '');
| 6 | added cache busters to async false test | 1 | .js | js | mit | muicss/loadjs |
10066873 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>0612,0618</WarningsNotAsErrors>
<PackageId>Avalonia.AvaloniaEdit</PackageId>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="**\*.xshd;**\*.resx;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.6.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> update nugets.
<DFF> @@ -11,7 +11,7 @@
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.6.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
- <PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
+ <PackageReference Include="System.Xml.ReaderWriter" Version="4.3.1" />
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
| 1 | update nugets. | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066874 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>0612,0618</WarningsNotAsErrors>
<PackageId>Avalonia.AvaloniaEdit</PackageId>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="**\*.xshd;**\*.resx;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.6.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> update nugets.
<DFF> @@ -11,7 +11,7 @@
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.6.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
- <PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
+ <PackageReference Include="System.Xml.ReaderWriter" Version="4.3.1" />
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
| 1 | update nugets. | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066875 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>0612,0618</WarningsNotAsErrors>
<PackageId>Avalonia.AvaloniaEdit</PackageId>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="**\*.xshd;**\*.resx;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.6.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> update nugets.
<DFF> @@ -11,7 +11,7 @@
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.6.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
- <PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
+ <PackageReference Include="System.Xml.ReaderWriter" Version="4.3.1" />
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
| 1 | update nugets. | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066876 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>0612,0618</WarningsNotAsErrors>
<PackageId>Avalonia.AvaloniaEdit</PackageId>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="**\*.xshd;**\*.resx;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.6.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> update nugets.
<DFF> @@ -11,7 +11,7 @@
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.6.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
- <PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
+ <PackageReference Include="System.Xml.ReaderWriter" Version="4.3.1" />
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
| 1 | update nugets. | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066877 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>0612,0618</WarningsNotAsErrors>
<PackageId>Avalonia.AvaloniaEdit</PackageId>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="**\*.xshd;**\*.resx;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.6.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> update nugets.
<DFF> @@ -11,7 +11,7 @@
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.6.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
- <PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
+ <PackageReference Include="System.Xml.ReaderWriter" Version="4.3.1" />
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
| 1 | update nugets. | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066878 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>0612,0618</WarningsNotAsErrors>
<PackageId>Avalonia.AvaloniaEdit</PackageId>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="**\*.xshd;**\*.resx;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.6.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> update nugets.
<DFF> @@ -11,7 +11,7 @@
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.6.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
- <PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
+ <PackageReference Include="System.Xml.ReaderWriter" Version="4.3.1" />
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
| 1 | update nugets. | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066879 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>0612,0618</WarningsNotAsErrors>
<PackageId>Avalonia.AvaloniaEdit</PackageId>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="**\*.xshd;**\*.resx;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.6.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> update nugets.
<DFF> @@ -11,7 +11,7 @@
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.6.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
- <PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
+ <PackageReference Include="System.Xml.ReaderWriter" Version="4.3.1" />
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
| 1 | update nugets. | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066880 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>0612,0618</WarningsNotAsErrors>
<PackageId>Avalonia.AvaloniaEdit</PackageId>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="**\*.xshd;**\*.resx;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.6.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> update nugets.
<DFF> @@ -11,7 +11,7 @@
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.6.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
- <PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
+ <PackageReference Include="System.Xml.ReaderWriter" Version="4.3.1" />
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
| 1 | update nugets. | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066881 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>0612,0618</WarningsNotAsErrors>
<PackageId>Avalonia.AvaloniaEdit</PackageId>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="**\*.xshd;**\*.resx;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.6.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> update nugets.
<DFF> @@ -11,7 +11,7 @@
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.6.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
- <PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
+ <PackageReference Include="System.Xml.ReaderWriter" Version="4.3.1" />
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
| 1 | update nugets. | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066882 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>0612,0618</WarningsNotAsErrors>
<PackageId>Avalonia.AvaloniaEdit</PackageId>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="**\*.xshd;**\*.resx;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.6.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> update nugets.
<DFF> @@ -11,7 +11,7 @@
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.6.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
- <PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
+ <PackageReference Include="System.Xml.ReaderWriter" Version="4.3.1" />
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
| 1 | update nugets. | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066883 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>0612,0618</WarningsNotAsErrors>
<PackageId>Avalonia.AvaloniaEdit</PackageId>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="**\*.xshd;**\*.resx;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.6.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> update nugets.
<DFF> @@ -11,7 +11,7 @@
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.6.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
- <PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
+ <PackageReference Include="System.Xml.ReaderWriter" Version="4.3.1" />
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
| 1 | update nugets. | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066884 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>0612,0618</WarningsNotAsErrors>
<PackageId>Avalonia.AvaloniaEdit</PackageId>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="**\*.xshd;**\*.resx;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.6.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> update nugets.
<DFF> @@ -11,7 +11,7 @@
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.6.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
- <PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
+ <PackageReference Include="System.Xml.ReaderWriter" Version="4.3.1" />
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
| 1 | update nugets. | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066885 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>0612,0618</WarningsNotAsErrors>
<PackageId>Avalonia.AvaloniaEdit</PackageId>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="**\*.xshd;**\*.resx;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.6.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> update nugets.
<DFF> @@ -11,7 +11,7 @@
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.6.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
- <PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
+ <PackageReference Include="System.Xml.ReaderWriter" Version="4.3.1" />
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
| 1 | update nugets. | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066886 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>0612,0618</WarningsNotAsErrors>
<PackageId>Avalonia.AvaloniaEdit</PackageId>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="**\*.xshd;**\*.resx;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.6.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> update nugets.
<DFF> @@ -11,7 +11,7 @@
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.6.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
- <PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
+ <PackageReference Include="System.Xml.ReaderWriter" Version="4.3.1" />
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
| 1 | update nugets. | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066887 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>0612,0618</WarningsNotAsErrors>
<PackageId>Avalonia.AvaloniaEdit</PackageId>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="**\*.xshd;**\*.resx;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.6.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> update nugets.
<DFF> @@ -11,7 +11,7 @@
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.6.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
- <PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
+ <PackageReference Include="System.Xml.ReaderWriter" Version="4.3.1" />
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
| 1 | update nugets. | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066888 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>612,618</WarningsNotAsErrors>
<Version>0.10.0-rc1</Version>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="**\*.xshd;**\*.resx;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
<AvaloniaResource Include="**\*.xaml;Assets\*;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
</ItemGroup>
<ItemGroup>
<None Remove="Search\Assets\CaseSensitive.png" />
<None Remove="Search\Assets\CompleteWord.png" />
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> update avalonia edit.
<DFF> @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>612,618</WarningsNotAsErrors>
- <Version>0.10.0-rc1</Version>
+ <Version>0.10.0</Version>
</PropertyGroup>
<ItemGroup>
| 1 | update avalonia edit. | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066889 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>612,618</WarningsNotAsErrors>
<Version>0.10.0-rc1</Version>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="**\*.xshd;**\*.resx;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
<AvaloniaResource Include="**\*.xaml;Assets\*;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
</ItemGroup>
<ItemGroup>
<None Remove="Search\Assets\CaseSensitive.png" />
<None Remove="Search\Assets\CompleteWord.png" />
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> update avalonia edit.
<DFF> @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>612,618</WarningsNotAsErrors>
- <Version>0.10.0-rc1</Version>
+ <Version>0.10.0</Version>
</PropertyGroup>
<ItemGroup>
| 1 | update avalonia edit. | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066890 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>612,618</WarningsNotAsErrors>
<Version>0.10.0-rc1</Version>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="**\*.xshd;**\*.resx;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
<AvaloniaResource Include="**\*.xaml;Assets\*;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
</ItemGroup>
<ItemGroup>
<None Remove="Search\Assets\CaseSensitive.png" />
<None Remove="Search\Assets\CompleteWord.png" />
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> update avalonia edit.
<DFF> @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>612,618</WarningsNotAsErrors>
- <Version>0.10.0-rc1</Version>
+ <Version>0.10.0</Version>
</PropertyGroup>
<ItemGroup>
| 1 | update avalonia edit. | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066891 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>612,618</WarningsNotAsErrors>
<Version>0.10.0-rc1</Version>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="**\*.xshd;**\*.resx;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
<AvaloniaResource Include="**\*.xaml;Assets\*;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
</ItemGroup>
<ItemGroup>
<None Remove="Search\Assets\CaseSensitive.png" />
<None Remove="Search\Assets\CompleteWord.png" />
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> update avalonia edit.
<DFF> @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>612,618</WarningsNotAsErrors>
- <Version>0.10.0-rc1</Version>
+ <Version>0.10.0</Version>
</PropertyGroup>
<ItemGroup>
| 1 | update avalonia edit. | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066892 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>612,618</WarningsNotAsErrors>
<Version>0.10.0-rc1</Version>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="**\*.xshd;**\*.resx;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
<AvaloniaResource Include="**\*.xaml;Assets\*;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
</ItemGroup>
<ItemGroup>
<None Remove="Search\Assets\CaseSensitive.png" />
<None Remove="Search\Assets\CompleteWord.png" />
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> update avalonia edit.
<DFF> @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>612,618</WarningsNotAsErrors>
- <Version>0.10.0-rc1</Version>
+ <Version>0.10.0</Version>
</PropertyGroup>
<ItemGroup>
| 1 | update avalonia edit. | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066893 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>612,618</WarningsNotAsErrors>
<Version>0.10.0-rc1</Version>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="**\*.xshd;**\*.resx;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
<AvaloniaResource Include="**\*.xaml;Assets\*;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
</ItemGroup>
<ItemGroup>
<None Remove="Search\Assets\CaseSensitive.png" />
<None Remove="Search\Assets\CompleteWord.png" />
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> update avalonia edit.
<DFF> @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>612,618</WarningsNotAsErrors>
- <Version>0.10.0-rc1</Version>
+ <Version>0.10.0</Version>
</PropertyGroup>
<ItemGroup>
| 1 | update avalonia edit. | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066894 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>612,618</WarningsNotAsErrors>
<Version>0.10.0-rc1</Version>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="**\*.xshd;**\*.resx;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
<AvaloniaResource Include="**\*.xaml;Assets\*;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
</ItemGroup>
<ItemGroup>
<None Remove="Search\Assets\CaseSensitive.png" />
<None Remove="Search\Assets\CompleteWord.png" />
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> update avalonia edit.
<DFF> @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>612,618</WarningsNotAsErrors>
- <Version>0.10.0-rc1</Version>
+ <Version>0.10.0</Version>
</PropertyGroup>
<ItemGroup>
| 1 | update avalonia edit. | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066895 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>612,618</WarningsNotAsErrors>
<Version>0.10.0-rc1</Version>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="**\*.xshd;**\*.resx;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
<AvaloniaResource Include="**\*.xaml;Assets\*;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
</ItemGroup>
<ItemGroup>
<None Remove="Search\Assets\CaseSensitive.png" />
<None Remove="Search\Assets\CompleteWord.png" />
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> update avalonia edit.
<DFF> @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>612,618</WarningsNotAsErrors>
- <Version>0.10.0-rc1</Version>
+ <Version>0.10.0</Version>
</PropertyGroup>
<ItemGroup>
| 1 | update avalonia edit. | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066896 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>612,618</WarningsNotAsErrors>
<Version>0.10.0-rc1</Version>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="**\*.xshd;**\*.resx;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
<AvaloniaResource Include="**\*.xaml;Assets\*;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
</ItemGroup>
<ItemGroup>
<None Remove="Search\Assets\CaseSensitive.png" />
<None Remove="Search\Assets\CompleteWord.png" />
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> update avalonia edit.
<DFF> @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>612,618</WarningsNotAsErrors>
- <Version>0.10.0-rc1</Version>
+ <Version>0.10.0</Version>
</PropertyGroup>
<ItemGroup>
| 1 | update avalonia edit. | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066897 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>612,618</WarningsNotAsErrors>
<Version>0.10.0-rc1</Version>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="**\*.xshd;**\*.resx;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
<AvaloniaResource Include="**\*.xaml;Assets\*;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
</ItemGroup>
<ItemGroup>
<None Remove="Search\Assets\CaseSensitive.png" />
<None Remove="Search\Assets\CompleteWord.png" />
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> update avalonia edit.
<DFF> @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>612,618</WarningsNotAsErrors>
- <Version>0.10.0-rc1</Version>
+ <Version>0.10.0</Version>
</PropertyGroup>
<ItemGroup>
| 1 | update avalonia edit. | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066898 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>612,618</WarningsNotAsErrors>
<Version>0.10.0-rc1</Version>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="**\*.xshd;**\*.resx;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
<AvaloniaResource Include="**\*.xaml;Assets\*;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
</ItemGroup>
<ItemGroup>
<None Remove="Search\Assets\CaseSensitive.png" />
<None Remove="Search\Assets\CompleteWord.png" />
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> update avalonia edit.
<DFF> @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>612,618</WarningsNotAsErrors>
- <Version>0.10.0-rc1</Version>
+ <Version>0.10.0</Version>
</PropertyGroup>
<ItemGroup>
| 1 | update avalonia edit. | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066899 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>612,618</WarningsNotAsErrors>
<Version>0.10.0-rc1</Version>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="**\*.xshd;**\*.resx;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
<AvaloniaResource Include="**\*.xaml;Assets\*;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
</ItemGroup>
<ItemGroup>
<None Remove="Search\Assets\CaseSensitive.png" />
<None Remove="Search\Assets\CompleteWord.png" />
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> update avalonia edit.
<DFF> @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>612,618</WarningsNotAsErrors>
- <Version>0.10.0-rc1</Version>
+ <Version>0.10.0</Version>
</PropertyGroup>
<ItemGroup>
| 1 | update avalonia edit. | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066900 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>612,618</WarningsNotAsErrors>
<Version>0.10.0-rc1</Version>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="**\*.xshd;**\*.resx;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
<AvaloniaResource Include="**\*.xaml;Assets\*;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
</ItemGroup>
<ItemGroup>
<None Remove="Search\Assets\CaseSensitive.png" />
<None Remove="Search\Assets\CompleteWord.png" />
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> update avalonia edit.
<DFF> @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>612,618</WarningsNotAsErrors>
- <Version>0.10.0-rc1</Version>
+ <Version>0.10.0</Version>
</PropertyGroup>
<ItemGroup>
| 1 | update avalonia edit. | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066901 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>612,618</WarningsNotAsErrors>
<Version>0.10.0-rc1</Version>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="**\*.xshd;**\*.resx;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
<AvaloniaResource Include="**\*.xaml;Assets\*;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
</ItemGroup>
<ItemGroup>
<None Remove="Search\Assets\CaseSensitive.png" />
<None Remove="Search\Assets\CompleteWord.png" />
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> update avalonia edit.
<DFF> @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>612,618</WarningsNotAsErrors>
- <Version>0.10.0-rc1</Version>
+ <Version>0.10.0</Version>
</PropertyGroup>
<ItemGroup>
| 1 | update avalonia edit. | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066902 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>612,618</WarningsNotAsErrors>
<Version>0.10.0-rc1</Version>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="**\*.xshd;**\*.resx;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
<AvaloniaResource Include="**\*.xaml;Assets\*;" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
</ItemGroup>
<ItemGroup>
<None Remove="Search\Assets\CaseSensitive.png" />
<None Remove="Search\Assets\CompleteWord.png" />
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> update avalonia edit.
<DFF> @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>612,618</WarningsNotAsErrors>
- <Version>0.10.0-rc1</Version>
+ <Version>0.10.0</Version>
</PropertyGroup>
<ItemGroup>
| 1 | update avalonia edit. | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066903 | <NME> TextEditor.cs
<BEF> // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using Avalonia;
using AvaloniaEdit.Document;
using AvaloniaEdit.Editing;
using AvaloniaEdit.Highlighting;
using AvaloniaEdit.Rendering;
using AvaloniaEdit.Utils;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Shapes;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.LogicalTree;
using Avalonia.Media;
using Avalonia.Data;
using AvaloniaEdit.Search;
namespace AvaloniaEdit
{
/// <summary>
/// The text editor control.
/// Contains a scrollable TextArea.
/// </summary>
public class TextEditor : TemplatedControl, ITextEditorComponent
static TextEditor()
{
FocusableProperty.OverrideDefaultValue<TextEditor>(true);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
SyntaxHighlightingProperty.Changed.Subscribe(OnSyntaxHighlightingChanged);
IsReadOnlyProperty.Changed.Subscribe(OnIsReadOnlyChanged);
IsModifiedProperty.Changed.Subscribe(OnIsModifiedChanged);
ShowLineNumbersProperty.Changed.Subscribe(OnShowLineNumbersChanged);
LineNumbersForegroundProperty.Changed.Subscribe(OnLineNumbersForegroundChanged);
FontFamilyProperty.Changed.Subscribe(OnFontFamilyPropertyChanged);
FontSizeProperty.Changed.Subscribe(OnFontSizePropertyChanged);
}
/// <summary>
/// Creates a new TextEditor instance.
/// </summary>
public TextEditor() : this(new TextArea())
{
}
/// <summary>
/// Creates a new TextEditor instance.
/// </summary>
protected TextEditor(TextArea textArea) : this(textArea, new TextDocument())
{
}
protected TextEditor(TextArea textArea, TextDocument document)
{
this.textArea = textArea ?? throw new ArgumentNullException(nameof(textArea));
textArea.TextView.Services.AddService(this);
SetValue(OptionsProperty, textArea.Options);
SetValue(DocumentProperty, document);
textArea[!BackgroundProperty] = this[!BackgroundProperty];
}
#endregion
protected override void OnGotFocus(GotFocusEventArgs e)
{
base.OnGotFocus(e);
TextArea.Focus();
e.Handled = true;
}
#region Document property
/// <summary>
/// Document property.
/// </summary>
public static readonly StyledProperty<TextDocument> DocumentProperty
= TextView.DocumentProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the document displayed by the text editor.
/// This is a dependency property.
/// </summary>
public TextDocument Document
{
get => GetValue(DocumentProperty);
set => SetValue(DocumentProperty, value);
}
/// <summary>
/// Occurs when the document property has changed.
/// </summary>
public event EventHandler DocumentChanged;
/// <summary>
/// Raises the <see cref="DocumentChanged"/> event.
/// </summary>
protected virtual void OnDocumentChanged(EventArgs e)
{
DocumentChanged?.Invoke(this, e);
}
private static void OnDocumentChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnDocumentChanged((TextDocument)e.OldValue, (TextDocument)e.NewValue);
}
private void OnDocumentChanged(TextDocument oldValue, TextDocument newValue)
{
if (oldValue != null)
{
TextDocumentWeakEventManager.TextChanged.RemoveHandler(oldValue, OnTextChanged);
PropertyChangedWeakEventManager.RemoveHandler(oldValue.UndoStack, OnUndoStackPropertyChangedHandler);
}
TextArea.Document = newValue;
if (newValue != null)
{
TextDocumentWeakEventManager.TextChanged.AddHandler(newValue, OnTextChanged);
PropertyChangedWeakEventManager.AddHandler(newValue.UndoStack, OnUndoStackPropertyChangedHandler);
}
OnDocumentChanged(EventArgs.Empty);
OnTextChanged(EventArgs.Empty);
}
#endregion
#region Options property
/// <summary>
/// Options property.
/// </summary>
public static readonly StyledProperty<TextEditorOptions> OptionsProperty
= TextView.OptionsProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the options currently used by the text editor.
/// </summary>
public TextEditorOptions Options
{
get => GetValue(OptionsProperty);
set => SetValue(OptionsProperty, value);
}
/// <summary>
/// Occurs when a text editor option has changed.
/// </summary>
public event PropertyChangedEventHandler OptionChanged;
/// <summary>
/// Raises the <see cref="OptionChanged"/> event.
/// </summary>
protected virtual void OnOptionChanged(PropertyChangedEventArgs e)
{
OptionChanged?.Invoke(this, e);
}
private static void OnOptionsChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnOptionsChanged((TextEditorOptions)e.OldValue, (TextEditorOptions)e.NewValue);
}
private void OnOptionsChanged(TextEditorOptions oldValue, TextEditorOptions newValue)
{
if (oldValue != null)
{
PropertyChangedWeakEventManager.RemoveHandler(oldValue, OnPropertyChangedHandler);
}
TextArea.Options = newValue;
if (newValue != null)
{
PropertyChangedWeakEventManager.AddHandler(newValue, OnPropertyChangedHandler);
}
OnOptionChanged(new PropertyChangedEventArgs(null));
}
private void OnPropertyChangedHandler(object sender, PropertyChangedEventArgs e)
{
OnOptionChanged(e);
}
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
base.OnPropertyChanged(change);
if (change.Property == WordWrapProperty)
{
if (WordWrap)
{
_horizontalScrollBarVisibilityBck = HorizontalScrollBarVisibility;
HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
}
else
{
HorizontalScrollBarVisibility = _horizontalScrollBarVisibilityBck;
}
}
}
private void OnUndoStackPropertyChangedHandler(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsOriginalFile")
{
HandleIsOriginalChanged(e);
}
}
private void OnTextChanged(object sender, EventArgs e)
{
OnTextChanged(e);
}
#endregion
#region Text property
/// <summary>
/// Gets/Sets the text of the current document.
/// </summary>
public string Text
{
get
{
var document = Document;
return document != null ? document.Text : string.Empty;
}
set
{
var document = GetDocument();
document.Text = value ?? string.Empty;
// after replacing the full text, the caret is positioned at the end of the document
// - reset it to the beginning.
CaretOffset = 0;
document.UndoStack.ClearAll();
}
}
private TextDocument GetDocument()
{
var document = Document;
if (document == null)
throw ThrowUtil.NoDocumentAssigned();
return document;
}
/// <summary>
/// Occurs when the Text property changes.
/// </summary>
public event EventHandler TextChanged;
/// <summary>
/// Raises the <see cref="TextChanged"/> event.
/// </summary>
protected virtual void OnTextChanged(EventArgs e)
{
TextChanged?.Invoke(this, e);
}
#endregion
#region TextArea / ScrollViewer properties
private readonly TextArea textArea;
private SearchPanel searchPanel;
private bool wasSearchPanelOpened;
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
ScrollViewer = (ScrollViewer)e.NameScope.Find("PART_ScrollViewer");
ScrollViewer.Content = TextArea;
searchPanel = SearchPanel.Install(this);
}
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnAttachedToLogicalTree(e);
if (searchPanel != null && wasSearchPanelOpened)
{
searchPanel.Open();
}
}
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnDetachedFromLogicalTree(e);
if (searchPanel != null)
{
wasSearchPanelOpened = searchPanel.IsOpened;
if (searchPanel.IsOpened)
searchPanel.Close();
}
}
/// <summary>
/// Gets the text area.
/// </summary>
public TextArea TextArea => textArea;
/// <summary>
/// Gets the search panel.
/// </summary>
public SearchPanel SearchPanel => searchPanel;
/// <summary>
/// Gets the scroll viewer used by the text editor.
/// This property can return null if the template has not been applied / does not contain a scroll viewer.
/// </summary>
internal ScrollViewer ScrollViewer { get; private set; }
#endregion
#region Syntax highlighting
/// <summary>
/// The <see cref="SyntaxHighlighting"/> property.
/// </summary>
public static readonly StyledProperty<IHighlightingDefinition> SyntaxHighlightingProperty =
AvaloniaProperty.Register<TextEditor, IHighlightingDefinition>("SyntaxHighlighting");
/// <summary>
/// Gets/sets the syntax highlighting definition used to colorize the text.
/// </summary>
public IHighlightingDefinition SyntaxHighlighting
{
get => GetValue(SyntaxHighlightingProperty);
set => SetValue(SyntaxHighlightingProperty, value);
}
private IVisualLineTransformer _colorizer;
private static void OnSyntaxHighlightingChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnSyntaxHighlightingChanged(e.NewValue as IHighlightingDefinition);
}
private void OnSyntaxHighlightingChanged(IHighlightingDefinition newValue)
{
if (_colorizer != null)
{
textArea.TextView.LineTransformers.Remove(_colorizer);
_colorizer = null;
}
if (newValue != null)
{
_colorizer = CreateColorizer(newValue);
if (_colorizer != null)
{
textArea.TextView.LineTransformers.Insert(0, _colorizer);
}
}
}
/// <summary>
/// Creates the highlighting colorizer for the specified highlighting definition.
/// Allows derived classes to provide custom colorizer implementations for special highlighting definitions.
/// </summary>
/// <returns></returns>
protected virtual IVisualLineTransformer CreateColorizer(IHighlightingDefinition highlightingDefinition)
{
if (highlightingDefinition == null)
throw new ArgumentNullException(nameof(highlightingDefinition));
return new HighlightingColorizer(highlightingDefinition);
}
#endregion
#region WordWrap
/// <summary>
/// Word wrap dependency property.
/// </summary>
public static readonly StyledProperty<bool> WordWrapProperty =
AvaloniaProperty.Register<TextEditor, bool>("WordWrap");
/// <summary>
/// Specifies whether the text editor uses word wrapping.
/// </summary>
/// <remarks>
/// Setting WordWrap=true has the same effect as setting HorizontalScrollBarVisibility=Disabled and will override the
/// HorizontalScrollBarVisibility setting.
/// </remarks>
public bool WordWrap
{
get => GetValue(WordWrapProperty);
set => SetValue(WordWrapProperty, value);
}
#endregion
#region IsReadOnly
/// <summary>
/// IsReadOnly dependency property.
/// </summary>
public static readonly StyledProperty<bool> IsReadOnlyProperty =
AvaloniaProperty.Register<TextEditor, bool>("IsReadOnly");
/// <summary>
/// Specifies whether the user can change the text editor content.
/// Setting this property will replace the
/// <see cref="Editing.TextArea.ReadOnlySectionProvider">TextArea.ReadOnlySectionProvider</see>.
/// </summary>
public bool IsReadOnly
{
get => GetValue(IsReadOnlyProperty);
set => SetValue(IsReadOnlyProperty, value);
}
private static void OnIsReadOnlyChanged(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is TextEditor editor)
{
if ((bool)e.NewValue)
editor.TextArea.ReadOnlySectionProvider = ReadOnlySectionDocument.Instance;
else
editor.TextArea.ReadOnlySectionProvider = NoReadOnlySections.Instance;
}
}
#endregion
#region IsModified
/// <summary>
/// Dependency property for <see cref="IsModified"/>
/// </summary>
public static readonly StyledProperty<bool> IsModifiedProperty =
AvaloniaProperty.Register<TextEditor, bool>("IsModified");
/// <summary>
/// Gets/Sets the 'modified' flag.
/// </summary>
public bool IsModified
{
get => GetValue(IsModifiedProperty);
set => SetValue(IsModifiedProperty, value);
}
private static void OnIsModifiedChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
var document = editor?.Document;
if (document != null)
{
var undoStack = document.UndoStack;
if ((bool)e.NewValue)
{
if (undoStack.IsOriginalFile)
undoStack.DiscardOriginalFileMarker();
}
else
{
undoStack.MarkAsOriginalFile();
}
}
}
private void HandleIsOriginalChanged(PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsOriginalFile")
{
var document = Document;
if (document != null)
{
SetValue(IsModifiedProperty, (object)!document.UndoStack.IsOriginalFile);
}
}
}
#endregion
#region ShowLineNumbers
/// <summary>
/// ShowLineNumbers dependency property.
/// </summary>
public static readonly StyledProperty<bool> ShowLineNumbersProperty =
AvaloniaProperty.Register<TextEditor, bool>("ShowLineNumbers");
/// <summary>
/// Specifies whether line numbers are shown on the left to the text view.
/// </summary>
public bool ShowLineNumbers
{
get => GetValue(ShowLineNumbersProperty);
set => SetValue(ShowLineNumbersProperty, value);
}
private static void OnShowLineNumbersChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
if (editor == null) return;
var leftMargins = editor.TextArea.LeftMargins;
if ((bool)e.NewValue)
{
var lineNumbers = new LineNumberMargin();
var line = (Line)DottedLineMargin.Create();
leftMargins.Insert(0, lineNumbers);
leftMargins.Insert(1, line);
var lineNumbersForeground = new Binding("LineNumbersForeground") { Source = editor };
line.Bind(Shape.StrokeProperty, lineNumbersForeground);
lineNumbers.Bind(ForegroundProperty, lineNumbersForeground);
}
else
{
for (var i = 0; i < leftMargins.Count; i++)
{
if (leftMargins[i] is LineNumberMargin)
{
leftMargins.RemoveAt(i);
if (i < leftMargins.Count && DottedLineMargin.IsDottedLineMargin(leftMargins[i]))
{
leftMargins.RemoveAt(i);
}
break;
}
}
}
}
#endregion
#region LineNumbersForeground
/// <summary>
/// LineNumbersForeground dependency property.
/// </summary>
public static readonly StyledProperty<IBrush> LineNumbersForegroundProperty =
AvaloniaProperty.Register<TextEditor, IBrush>("LineNumbersForeground", Brushes.Gray);
/// <summary>
/// Gets/sets the Brush used for displaying the foreground color of line numbers.
/// </summary>
public IBrush LineNumbersForeground
{
get => GetValue(LineNumbersForegroundProperty);
set => SetValue(LineNumbersForegroundProperty, value);
}
private static void OnLineNumbersForegroundChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
var lineNumberMargin = editor?.TextArea.LeftMargins.FirstOrDefault(margin => margin is LineNumberMargin) as LineNumberMargin;
lineNumberMargin?.SetValue(ForegroundProperty, e.NewValue);
}
private static void OnFontFamilyPropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
editor?.TextArea.TextView.SetValue(FontFamilyProperty, e.NewValue);
}
private static void OnFontSizePropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
editor?.TextArea.TextView.SetValue(FontSizeProperty, e.NewValue);
}
#endregion
#region TextBoxBase-like methods
/// <summary>
/// Appends text to the end of the document.
/// </summary>
public void AppendText(string textData)
{
var document = GetDocument();
document.Insert(document.TextLength, textData);
}
/// <summary>
/// Begins a group of document changes.
/// </summary>
public void BeginChange()
{
GetDocument().BeginUpdate();
}
/// <summary>
/// Copies the current selection to the clipboard.
/// </summary>
public void Copy()
{
if (CanCopy)
{
ApplicationCommands.Copy.Execute(null, TextArea);
}
}
/// <summary>
/// Removes the current selection and copies it to the clipboard.
/// </summary>
public void Cut()
{
if (CanCut)
{
ApplicationCommands.Cut.Execute(null, TextArea);
}
}
/// <summary>
/// Begins a group of document changes and returns an object that ends the group of document
/// changes when it is disposed.
/// </summary>
public IDisposable DeclareChangeBlock()
{
return GetDocument().RunUpdate();
}
/// <summary>
/// Removes the current selection without copying it to the clipboard.
/// </summary>
public void Delete()
{
if(CanDelete)
{
ApplicationCommands.Delete.Execute(null, TextArea);
}
}
/// <summary>
/// Ends the current group of document changes.
/// </summary>
public void EndChange()
{
GetDocument().EndUpdate();
}
/// <summary>
/// Scrolls one line down.
/// </summary>
public void LineDown()
{
//if (scrollViewer != null)
// scrollViewer.LineDown();
}
/// <summary>
/// Scrolls to the left.
/// </summary>
public void LineLeft()
{
//if (scrollViewer != null)
// scrollViewer.LineLeft();
}
/// <summary>
/// Scrolls to the right.
/// </summary>
public void LineRight()
{
//if (scrollViewer != null)
// scrollViewer.LineRight();
}
/// <summary>
/// Scrolls one line up.
/// </summary>
public void LineUp()
{
//if (scrollViewer != null)
// scrollViewer.LineUp();
}
/// <summary>
/// Scrolls one page down.
/// </summary>
public void PageDown()
{
//if (scrollViewer != null)
// scrollViewer.PageDown();
}
/// <summary>
/// Scrolls one page up.
/// </summary>
public void PageUp()
{
//if (scrollViewer != null)
// scrollViewer.PageUp();
}
/// <summary>
/// Scrolls one page left.
/// </summary>
public void PageLeft()
{
//if (scrollViewer != null)
// scrollViewer.PageLeft();
}
/// <summary>
/// Scrolls one page right.
/// </summary>
public void PageRight()
{
//if (scrollViewer != null)
// scrollViewer.PageRight();
}
/// <summary>
/// Pastes the clipboard content.
/// </summary>
public void Paste()
{
if (CanPaste)
{
ApplicationCommands.Paste.Execute(null, TextArea);
}
}
/// <summary>
/// Redoes the most recent undone command.
/// </summary>
/// <returns>True is the redo operation was successful, false is the redo stack is empty.</returns>
public bool Redo()
{
if (CanRedo)
{
ApplicationCommands.Redo.Execute(null, TextArea);
return true;
}
return false;
}
/// <summary>
/// Scrolls to the end of the document.
/// </summary>
public void ScrollToEnd()
{
ApplyTemplate(); // ensure scrollViewer is created
ScrollViewer?.ScrollToEnd();
}
/// <summary>
/// Scrolls to the start of the document.
/// </summary>
public void ScrollToHome()
{
ApplyTemplate(); // ensure scrollViewer is created
ScrollViewer?.ScrollToHome();
}
/// <summary>
/// Scrolls to the specified position in the document.
/// </summary>
public void ScrollToHorizontalOffset(double offset)
{
ApplyTemplate(); // ensure scrollViewer is created
//if (scrollViewer != null)
// scrollViewer.ScrollToHorizontalOffset(offset);
}
/// <summary>
/// Scrolls to the specified position in the document.
/// </summary>
public void ScrollToVerticalOffset(double offset)
{
ApplyTemplate(); // ensure scrollViewer is created
//if (scrollViewer != null)
// scrollViewer.ScrollToVerticalOffset(offset);
}
/// <summary>
/// Selects the entire text.
/// </summary>
public void SelectAll()
{
if (CanSelectAll)
{
ApplicationCommands.SelectAll.Execute(null, TextArea);
}
}
/// <summary>
/// Undoes the most recent command.
/// </summary>
/// <returns>True is the undo operation was successful, false is the undo stack is empty.</returns>
public bool Undo()
{
if (CanUndo)
{
ApplicationCommands.Undo.Execute(null, TextArea);
return true;
}
return false;
}
/// <summary>
/// Gets if the most recent undone command can be redone.
/// </summary>
public bool CanRedo
{
get { return ApplicationCommands.Redo.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if the most recent command can be undone.
/// </summary>
public bool CanUndo
{
get { return ApplicationCommands.Undo.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be copied
/// </summary>
public bool CanCopy
{
get { return ApplicationCommands.Copy.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be cut
/// </summary>
public bool CanCut
{
get { return ApplicationCommands.Cut.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be pasted
/// </summary>
public bool CanPaste
{
get { return ApplicationCommands.Paste.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if selected text in editor can be deleted
/// </summary>
public bool CanDelete
{
get { return ApplicationCommands.Delete.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text the editor can select all
/// </summary>
public bool CanSelectAll
{
get { return ApplicationCommands.SelectAll.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text editor can activate the search panel
/// </summary>
public bool CanSearch
{
get { return searchPanel != null; }
}
/// <summary>
/// Gets the vertical size of the document.
/// </summary>
public double ExtentHeight => ScrollViewer?.Extent.Height ?? 0;
/// <summary>
/// Gets the horizontal size of the current document region.
/// </summary>
public double ExtentWidth => ScrollViewer?.Extent.Width ?? 0;
/// <summary>
/// Gets the horizontal size of the viewport.
/// </summary>
public double ViewportHeight => ScrollViewer?.Viewport.Height ?? 0;
/// <summary>
/// Gets the horizontal size of the viewport.
/// </summary>
public double ViewportWidth => ScrollViewer?.Viewport.Width ?? 0;
/// <summary>
/// Gets the vertical scroll position.
/// </summary>
public double VerticalOffset => ScrollViewer?.Offset.Y ?? 0;
/// <summary>
/// Gets the horizontal scroll position.
/// </summary>
public double HorizontalOffset => ScrollViewer?.Offset.X ?? 0;
#endregion
#region TextBox methods
/// <summary>
/// Gets/Sets the selected text.
/// </summary>
public string SelectedText
{
get
{
// We'll get the text from the whole surrounding segment.
// This is done to ensure that SelectedText.Length == SelectionLength.
if (textArea.Document != null && !textArea.Selection.IsEmpty)
return textArea.Document.GetText(textArea.Selection.SurroundingSegment);
return string.Empty;
}
set
{
if (value == null)
throw new ArgumentNullException(nameof(value));
var textArea = TextArea;
if (textArea.Document != null)
{
var offset = SelectionStart;
var length = SelectionLength;
textArea.Document.Replace(offset, length, value);
// keep inserted text selected
textArea.Selection = Selection.Create(textArea, offset, offset + value.Length);
}
}
}
/// <summary>
/// Gets/sets the caret position.
/// </summary>
public int CaretOffset
{
get
{
return textArea.Caret.Offset;
}
set
{
textArea.Caret.Offset = value;
}
}
/// <summary>
/// Gets/sets the start position of the selection.
/// </summary>
public int SelectionStart
{
get
{
if (textArea.Selection.IsEmpty)
return textArea.Caret.Offset;
else
return textArea.Selection.SurroundingSegment.Offset;
}
set => Select(value, SelectionLength);
}
/// <summary>
/// Gets/sets the length of the selection.
/// </summary>
public int SelectionLength
{
get
{
if (!textArea.Selection.IsEmpty)
return textArea.Selection.SurroundingSegment.Length;
else
return 0;
}
set => Select(SelectionStart, value);
}
/// <summary>
/// Selects the specified text section.
/// </summary>
public void Select(int start, int length)
{
var documentLength = Document?.TextLength ?? 0;
if (start < 0 || start > documentLength)
throw new ArgumentOutOfRangeException(nameof(start), start, "Value must be between 0 and " + documentLength);
if (length < 0 || start + length > documentLength)
throw new ArgumentOutOfRangeException(nameof(length), length, "Value must be between 0 and " + (documentLength - start));
TextArea.Selection = Selection.Create(TextArea, start, start + length);
TextArea.Caret.Offset = start + length;
}
/// <summary>
/// Gets the number of lines in the document.
/// </summary>
public int LineCount
{
get
{
var document = Document;
if (document != null)
return document.LineCount;
return 1;
}
}
/// <summary>
/// Clears the text.
/// </summary>
public void Clear()
{
Text = string.Empty;
}
#endregion
#region Loading from stream
/// <summary>
/// Loads the text from the stream, auto-detecting the encoding.
/// </summary>
/// <remarks>
/// This method sets <see cref="IsModified"/> to false.
/// </remarks>
public void Load(Stream stream)
{
using (var reader = FileReader.OpenStream(stream, Encoding ?? Encoding.UTF8))
{
Text = reader.ReadToEnd();
SetValue(EncodingProperty, (object)reader.CurrentEncoding);
}
SetValue(IsModifiedProperty, (object)false);
}
/// <summary>
/// Loads the text from the stream, auto-detecting the encoding.
/// </summary>
public void Load(string fileName)
{
if (fileName == null)
throw new ArgumentNullException(nameof(fileName));
// TODO:load
//using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
//{
// Load(fs);
//}
}
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
public static readonly AvaloniaProperty HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
get => (ScrollBarVisibility)GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
public static readonly AvaloniaProperty VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
get => (ScrollBarVisibility)GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
if (stream == null)
throw new ArgumentNullException(nameof(stream));
var encoding = Encoding;
var document = Document;
var writer = encoding != null ? new StreamWriter(stream, encoding) : new StreamWriter(stream);
document?.WriteTextTo(writer);
writer.Flush();
// do not close the stream
SetValue(IsModifiedProperty, (object)false);
}
/// <summary>
/// Saves the text to the file.
/// </summary>
public void Save(string fileName)
{
if (fileName == null)
throw new ArgumentNullException(nameof(fileName));
// TODO: save
//using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
//{
// Save(fs);
//}
}
#endregion
#region PointerHover events
/// <summary>
/// The PreviewPointerHover event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PreviewPointerHoverEvent =
TextView.PreviewPointerHoverEvent;
/// <summary>
/// the pointerHover event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PointerHoverEvent =
TextView.PointerHoverEvent;
/// <summary>
/// The PreviewPointerHoverStopped event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PreviewPointerHoverStoppedEvent =
TextView.PreviewPointerHoverStoppedEvent;
/// <summary>
/// the pointerHoverStopped event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PointerHoverStoppedEvent =
TextView.PointerHoverStoppedEvent;
/// <summary>
/// Occurs when the pointer has hovered over a fixed location for some time.
/// </summary>
public event EventHandler<PointerEventArgs> PreviewPointerHover
{
add => AddHandler(PreviewPointerHoverEvent, value);
remove => RemoveHandler(PreviewPointerHoverEvent, value);
}
/// <summary>
/// Occurs when the pointer has hovered over a fixed location for some time.
/// </summary>
public event EventHandler<PointerEventArgs> PointerHover
{
add => AddHandler(PointerHoverEvent, value);
remove => RemoveHandler(PointerHoverEvent, value);
}
/// <summary>
/// Occurs when the pointer had previously hovered but now started moving again.
/// </summary>
public event EventHandler<PointerEventArgs> PreviewPointerHoverStopped
{
add => AddHandler(PreviewPointerHoverStoppedEvent, value);
remove => RemoveHandler(PreviewPointerHoverStoppedEvent, value);
}
/// <summary>
/// Occurs when the pointer had previously hovered but now started moving again.
/// </summary>
public event EventHandler<PointerEventArgs> PointerHoverStopped
{
add => AddHandler(PointerHoverStoppedEvent, value);
remove => RemoveHandler(PointerHoverStoppedEvent, value);
}
#endregion
#region ScrollBarVisibility
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
public static readonly AttachedProperty<ScrollBarVisibility> HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
get => GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
private ScrollBarVisibility _horizontalScrollBarVisibilityBck = ScrollBarVisibility.Auto;
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
public static readonly AttachedProperty<ScrollBarVisibility> VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
get => GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
object IServiceProvider.GetService(Type serviceType)
{
return TextArea.GetService(serviceType);
}
/// <summary>
/// Gets the text view position from a point inside the editor.
/// </summary>
/// <param name="point">The position, relative to top left
/// corner of TextEditor control</param>
/// <returns>The text view position, or null if the point is outside the document.</returns>
public TextViewPosition? GetPositionFromPoint(Point point)
{
if (Document == null)
return null;
var textView = TextArea.TextView;
Point tpoint = (Point)this.TranslatePoint(point + new Point(textView.ScrollOffset.X, Math.Floor(textView.ScrollOffset.Y)), textView);
return textView.GetPosition(tpoint);
}
/// <summary>
/// Scrolls to the specified line.
/// This method requires that the TextEditor was already assigned a size (layout engine must have run prior).
/// </summary>
public void ScrollToLine(int line)
{
ScrollTo(line, -1);
}
/// <summary>
/// Scrolls to the specified line/column.
/// This method requires that the TextEditor was already assigned a size (layout engine must have run prior).
/// </summary>
public void ScrollTo(int line, int column)
{
const double MinimumScrollFraction = 0.3;
ScrollTo(line, column, VisualYPosition.LineMiddle,
null != ScrollViewer ? ScrollViewer.Viewport.Height / 2 : 0.0, MinimumScrollFraction);
}
/// <summary>
/// Scrolls to the specified line/column.
/// This method requires that the TextEditor was already assigned a size (WPF layout must have run prior).
/// </summary>
/// <param name="line">Line to scroll to.</param>
/// <param name="column">Column to scroll to (important if wrapping is 'on', and for the horizontal scroll position).</param>
/// <param name="yPositionMode">The mode how to reference the Y position of the line.</param>
/// <param name="referencedVerticalViewPortOffset">Offset from the top of the viewport to where the referenced line/column should be positioned.</param>
/// <param name="minimumScrollFraction">The minimum vertical and/or horizontal scroll offset, expressed as fraction of the height or width of the viewport window, respectively.</param>
public void ScrollTo(int line, int column, VisualYPosition yPositionMode,
double referencedVerticalViewPortOffset, double minimumScrollFraction)
{
TextView textView = textArea.TextView;
TextDocument document = textView.Document;
if (ScrollViewer != null && document != null)
{
if (line < 1)
line = 1;
if (line > document.LineCount)
line = document.LineCount;
ILogicalScrollable scrollInfo = textView;
if (!scrollInfo.CanHorizontallyScroll)
{
// Word wrap is enabled. Ensure that we have up-to-date info about line height so that we scroll
// to the correct position.
// This avoids that the user has to repeat the ScrollTo() call several times when there are very long lines.
VisualLine vl = textView.GetOrConstructVisualLine(document.GetLineByNumber(line));
double remainingHeight = referencedVerticalViewPortOffset;
while (remainingHeight > 0)
{
DocumentLine prevLine = vl.FirstDocumentLine.PreviousLine;
if (prevLine == null)
break;
vl = textView.GetOrConstructVisualLine(prevLine);
remainingHeight -= vl.Height;
}
}
Point p = textArea.TextView.GetVisualPosition(
new TextViewPosition(line, Math.Max(1, column)),
yPositionMode);
double targetX = ScrollViewer.Offset.X;
double targetY = ScrollViewer.Offset.Y;
double verticalPos = p.Y - referencedVerticalViewPortOffset;
if (Math.Abs(verticalPos - ScrollViewer.Offset.Y) >
minimumScrollFraction * ScrollViewer.Viewport.Height)
{
targetY = Math.Max(0, verticalPos);
}
if (column > 0)
{
if (p.X > ScrollViewer.Viewport.Width - Caret.MinimumDistanceToViewBorder * 2)
{
double horizontalPos = Math.Max(0, p.X - ScrollViewer.Viewport.Width / 2);
if (Math.Abs(horizontalPos - ScrollViewer.Offset.X) >
minimumScrollFraction * ScrollViewer.Viewport.Width)
{
targetX = 0;
}
}
else
{
targetX = 0;
}
}
if (targetX != ScrollViewer.Offset.X || targetY != ScrollViewer.Offset.Y)
ScrollViewer.Offset = new Vector(targetX, targetY);
}
}
}
}
<MSG> Merge pull request #73 from jeffreye/fix-scroll
Fix scroll
<DFF> @@ -47,6 +47,8 @@ namespace AvaloniaEdit
static TextEditor()
{
FocusableProperty.OverrideDefaultValue<TextEditor>(true);
+ HorizontalScrollBarVisibilityProperty.OverrideDefaultValue<TextEditor>(ScrollBarVisibility.Auto);
+ VerticalScrollBarVisibilityProperty.OverrideDefaultValue<TextEditor>(ScrollBarVisibility.Auto);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
@@ -1049,28 +1051,28 @@ namespace AvaloniaEdit
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
- public static readonly AvaloniaProperty HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
+ public static readonly AttachedProperty<ScrollBarVisibility> HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
- get => (ScrollBarVisibility)GetValue(HorizontalScrollBarVisibilityProperty);
+ get => GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
- public static readonly AvaloniaProperty VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
+ public static readonly AttachedProperty<ScrollBarVisibility> VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
- get => (ScrollBarVisibility)GetValue(VerticalScrollBarVisibilityProperty);
+ get => GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
| 6 | Merge pull request #73 from jeffreye/fix-scroll | 4 | .cs | cs | mit | AvaloniaUI/AvaloniaEdit |
10066904 | <NME> TextEditor.cs
<BEF> // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using Avalonia;
using AvaloniaEdit.Document;
using AvaloniaEdit.Editing;
using AvaloniaEdit.Highlighting;
using AvaloniaEdit.Rendering;
using AvaloniaEdit.Utils;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Shapes;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.LogicalTree;
using Avalonia.Media;
using Avalonia.Data;
using AvaloniaEdit.Search;
namespace AvaloniaEdit
{
/// <summary>
/// The text editor control.
/// Contains a scrollable TextArea.
/// </summary>
public class TextEditor : TemplatedControl, ITextEditorComponent
static TextEditor()
{
FocusableProperty.OverrideDefaultValue<TextEditor>(true);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
SyntaxHighlightingProperty.Changed.Subscribe(OnSyntaxHighlightingChanged);
IsReadOnlyProperty.Changed.Subscribe(OnIsReadOnlyChanged);
IsModifiedProperty.Changed.Subscribe(OnIsModifiedChanged);
ShowLineNumbersProperty.Changed.Subscribe(OnShowLineNumbersChanged);
LineNumbersForegroundProperty.Changed.Subscribe(OnLineNumbersForegroundChanged);
FontFamilyProperty.Changed.Subscribe(OnFontFamilyPropertyChanged);
FontSizeProperty.Changed.Subscribe(OnFontSizePropertyChanged);
}
/// <summary>
/// Creates a new TextEditor instance.
/// </summary>
public TextEditor() : this(new TextArea())
{
}
/// <summary>
/// Creates a new TextEditor instance.
/// </summary>
protected TextEditor(TextArea textArea) : this(textArea, new TextDocument())
{
}
protected TextEditor(TextArea textArea, TextDocument document)
{
this.textArea = textArea ?? throw new ArgumentNullException(nameof(textArea));
textArea.TextView.Services.AddService(this);
SetValue(OptionsProperty, textArea.Options);
SetValue(DocumentProperty, document);
textArea[!BackgroundProperty] = this[!BackgroundProperty];
}
#endregion
protected override void OnGotFocus(GotFocusEventArgs e)
{
base.OnGotFocus(e);
TextArea.Focus();
e.Handled = true;
}
#region Document property
/// <summary>
/// Document property.
/// </summary>
public static readonly StyledProperty<TextDocument> DocumentProperty
= TextView.DocumentProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the document displayed by the text editor.
/// This is a dependency property.
/// </summary>
public TextDocument Document
{
get => GetValue(DocumentProperty);
set => SetValue(DocumentProperty, value);
}
/// <summary>
/// Occurs when the document property has changed.
/// </summary>
public event EventHandler DocumentChanged;
/// <summary>
/// Raises the <see cref="DocumentChanged"/> event.
/// </summary>
protected virtual void OnDocumentChanged(EventArgs e)
{
DocumentChanged?.Invoke(this, e);
}
private static void OnDocumentChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnDocumentChanged((TextDocument)e.OldValue, (TextDocument)e.NewValue);
}
private void OnDocumentChanged(TextDocument oldValue, TextDocument newValue)
{
if (oldValue != null)
{
TextDocumentWeakEventManager.TextChanged.RemoveHandler(oldValue, OnTextChanged);
PropertyChangedWeakEventManager.RemoveHandler(oldValue.UndoStack, OnUndoStackPropertyChangedHandler);
}
TextArea.Document = newValue;
if (newValue != null)
{
TextDocumentWeakEventManager.TextChanged.AddHandler(newValue, OnTextChanged);
PropertyChangedWeakEventManager.AddHandler(newValue.UndoStack, OnUndoStackPropertyChangedHandler);
}
OnDocumentChanged(EventArgs.Empty);
OnTextChanged(EventArgs.Empty);
}
#endregion
#region Options property
/// <summary>
/// Options property.
/// </summary>
public static readonly StyledProperty<TextEditorOptions> OptionsProperty
= TextView.OptionsProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the options currently used by the text editor.
/// </summary>
public TextEditorOptions Options
{
get => GetValue(OptionsProperty);
set => SetValue(OptionsProperty, value);
}
/// <summary>
/// Occurs when a text editor option has changed.
/// </summary>
public event PropertyChangedEventHandler OptionChanged;
/// <summary>
/// Raises the <see cref="OptionChanged"/> event.
/// </summary>
protected virtual void OnOptionChanged(PropertyChangedEventArgs e)
{
OptionChanged?.Invoke(this, e);
}
private static void OnOptionsChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnOptionsChanged((TextEditorOptions)e.OldValue, (TextEditorOptions)e.NewValue);
}
private void OnOptionsChanged(TextEditorOptions oldValue, TextEditorOptions newValue)
{
if (oldValue != null)
{
PropertyChangedWeakEventManager.RemoveHandler(oldValue, OnPropertyChangedHandler);
}
TextArea.Options = newValue;
if (newValue != null)
{
PropertyChangedWeakEventManager.AddHandler(newValue, OnPropertyChangedHandler);
}
OnOptionChanged(new PropertyChangedEventArgs(null));
}
private void OnPropertyChangedHandler(object sender, PropertyChangedEventArgs e)
{
OnOptionChanged(e);
}
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
base.OnPropertyChanged(change);
if (change.Property == WordWrapProperty)
{
if (WordWrap)
{
_horizontalScrollBarVisibilityBck = HorizontalScrollBarVisibility;
HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
}
else
{
HorizontalScrollBarVisibility = _horizontalScrollBarVisibilityBck;
}
}
}
private void OnUndoStackPropertyChangedHandler(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsOriginalFile")
{
HandleIsOriginalChanged(e);
}
}
private void OnTextChanged(object sender, EventArgs e)
{
OnTextChanged(e);
}
#endregion
#region Text property
/// <summary>
/// Gets/Sets the text of the current document.
/// </summary>
public string Text
{
get
{
var document = Document;
return document != null ? document.Text : string.Empty;
}
set
{
var document = GetDocument();
document.Text = value ?? string.Empty;
// after replacing the full text, the caret is positioned at the end of the document
// - reset it to the beginning.
CaretOffset = 0;
document.UndoStack.ClearAll();
}
}
private TextDocument GetDocument()
{
var document = Document;
if (document == null)
throw ThrowUtil.NoDocumentAssigned();
return document;
}
/// <summary>
/// Occurs when the Text property changes.
/// </summary>
public event EventHandler TextChanged;
/// <summary>
/// Raises the <see cref="TextChanged"/> event.
/// </summary>
protected virtual void OnTextChanged(EventArgs e)
{
TextChanged?.Invoke(this, e);
}
#endregion
#region TextArea / ScrollViewer properties
private readonly TextArea textArea;
private SearchPanel searchPanel;
private bool wasSearchPanelOpened;
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
ScrollViewer = (ScrollViewer)e.NameScope.Find("PART_ScrollViewer");
ScrollViewer.Content = TextArea;
searchPanel = SearchPanel.Install(this);
}
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnAttachedToLogicalTree(e);
if (searchPanel != null && wasSearchPanelOpened)
{
searchPanel.Open();
}
}
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnDetachedFromLogicalTree(e);
if (searchPanel != null)
{
wasSearchPanelOpened = searchPanel.IsOpened;
if (searchPanel.IsOpened)
searchPanel.Close();
}
}
/// <summary>
/// Gets the text area.
/// </summary>
public TextArea TextArea => textArea;
/// <summary>
/// Gets the search panel.
/// </summary>
public SearchPanel SearchPanel => searchPanel;
/// <summary>
/// Gets the scroll viewer used by the text editor.
/// This property can return null if the template has not been applied / does not contain a scroll viewer.
/// </summary>
internal ScrollViewer ScrollViewer { get; private set; }
#endregion
#region Syntax highlighting
/// <summary>
/// The <see cref="SyntaxHighlighting"/> property.
/// </summary>
public static readonly StyledProperty<IHighlightingDefinition> SyntaxHighlightingProperty =
AvaloniaProperty.Register<TextEditor, IHighlightingDefinition>("SyntaxHighlighting");
/// <summary>
/// Gets/sets the syntax highlighting definition used to colorize the text.
/// </summary>
public IHighlightingDefinition SyntaxHighlighting
{
get => GetValue(SyntaxHighlightingProperty);
set => SetValue(SyntaxHighlightingProperty, value);
}
private IVisualLineTransformer _colorizer;
private static void OnSyntaxHighlightingChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnSyntaxHighlightingChanged(e.NewValue as IHighlightingDefinition);
}
private void OnSyntaxHighlightingChanged(IHighlightingDefinition newValue)
{
if (_colorizer != null)
{
textArea.TextView.LineTransformers.Remove(_colorizer);
_colorizer = null;
}
if (newValue != null)
{
_colorizer = CreateColorizer(newValue);
if (_colorizer != null)
{
textArea.TextView.LineTransformers.Insert(0, _colorizer);
}
}
}
/// <summary>
/// Creates the highlighting colorizer for the specified highlighting definition.
/// Allows derived classes to provide custom colorizer implementations for special highlighting definitions.
/// </summary>
/// <returns></returns>
protected virtual IVisualLineTransformer CreateColorizer(IHighlightingDefinition highlightingDefinition)
{
if (highlightingDefinition == null)
throw new ArgumentNullException(nameof(highlightingDefinition));
return new HighlightingColorizer(highlightingDefinition);
}
#endregion
#region WordWrap
/// <summary>
/// Word wrap dependency property.
/// </summary>
public static readonly StyledProperty<bool> WordWrapProperty =
AvaloniaProperty.Register<TextEditor, bool>("WordWrap");
/// <summary>
/// Specifies whether the text editor uses word wrapping.
/// </summary>
/// <remarks>
/// Setting WordWrap=true has the same effect as setting HorizontalScrollBarVisibility=Disabled and will override the
/// HorizontalScrollBarVisibility setting.
/// </remarks>
public bool WordWrap
{
get => GetValue(WordWrapProperty);
set => SetValue(WordWrapProperty, value);
}
#endregion
#region IsReadOnly
/// <summary>
/// IsReadOnly dependency property.
/// </summary>
public static readonly StyledProperty<bool> IsReadOnlyProperty =
AvaloniaProperty.Register<TextEditor, bool>("IsReadOnly");
/// <summary>
/// Specifies whether the user can change the text editor content.
/// Setting this property will replace the
/// <see cref="Editing.TextArea.ReadOnlySectionProvider">TextArea.ReadOnlySectionProvider</see>.
/// </summary>
public bool IsReadOnly
{
get => GetValue(IsReadOnlyProperty);
set => SetValue(IsReadOnlyProperty, value);
}
private static void OnIsReadOnlyChanged(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is TextEditor editor)
{
if ((bool)e.NewValue)
editor.TextArea.ReadOnlySectionProvider = ReadOnlySectionDocument.Instance;
else
editor.TextArea.ReadOnlySectionProvider = NoReadOnlySections.Instance;
}
}
#endregion
#region IsModified
/// <summary>
/// Dependency property for <see cref="IsModified"/>
/// </summary>
public static readonly StyledProperty<bool> IsModifiedProperty =
AvaloniaProperty.Register<TextEditor, bool>("IsModified");
/// <summary>
/// Gets/Sets the 'modified' flag.
/// </summary>
public bool IsModified
{
get => GetValue(IsModifiedProperty);
set => SetValue(IsModifiedProperty, value);
}
private static void OnIsModifiedChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
var document = editor?.Document;
if (document != null)
{
var undoStack = document.UndoStack;
if ((bool)e.NewValue)
{
if (undoStack.IsOriginalFile)
undoStack.DiscardOriginalFileMarker();
}
else
{
undoStack.MarkAsOriginalFile();
}
}
}
private void HandleIsOriginalChanged(PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsOriginalFile")
{
var document = Document;
if (document != null)
{
SetValue(IsModifiedProperty, (object)!document.UndoStack.IsOriginalFile);
}
}
}
#endregion
#region ShowLineNumbers
/// <summary>
/// ShowLineNumbers dependency property.
/// </summary>
public static readonly StyledProperty<bool> ShowLineNumbersProperty =
AvaloniaProperty.Register<TextEditor, bool>("ShowLineNumbers");
/// <summary>
/// Specifies whether line numbers are shown on the left to the text view.
/// </summary>
public bool ShowLineNumbers
{
get => GetValue(ShowLineNumbersProperty);
set => SetValue(ShowLineNumbersProperty, value);
}
private static void OnShowLineNumbersChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
if (editor == null) return;
var leftMargins = editor.TextArea.LeftMargins;
if ((bool)e.NewValue)
{
var lineNumbers = new LineNumberMargin();
var line = (Line)DottedLineMargin.Create();
leftMargins.Insert(0, lineNumbers);
leftMargins.Insert(1, line);
var lineNumbersForeground = new Binding("LineNumbersForeground") { Source = editor };
line.Bind(Shape.StrokeProperty, lineNumbersForeground);
lineNumbers.Bind(ForegroundProperty, lineNumbersForeground);
}
else
{
for (var i = 0; i < leftMargins.Count; i++)
{
if (leftMargins[i] is LineNumberMargin)
{
leftMargins.RemoveAt(i);
if (i < leftMargins.Count && DottedLineMargin.IsDottedLineMargin(leftMargins[i]))
{
leftMargins.RemoveAt(i);
}
break;
}
}
}
}
#endregion
#region LineNumbersForeground
/// <summary>
/// LineNumbersForeground dependency property.
/// </summary>
public static readonly StyledProperty<IBrush> LineNumbersForegroundProperty =
AvaloniaProperty.Register<TextEditor, IBrush>("LineNumbersForeground", Brushes.Gray);
/// <summary>
/// Gets/sets the Brush used for displaying the foreground color of line numbers.
/// </summary>
public IBrush LineNumbersForeground
{
get => GetValue(LineNumbersForegroundProperty);
set => SetValue(LineNumbersForegroundProperty, value);
}
private static void OnLineNumbersForegroundChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
var lineNumberMargin = editor?.TextArea.LeftMargins.FirstOrDefault(margin => margin is LineNumberMargin) as LineNumberMargin;
lineNumberMargin?.SetValue(ForegroundProperty, e.NewValue);
}
private static void OnFontFamilyPropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
editor?.TextArea.TextView.SetValue(FontFamilyProperty, e.NewValue);
}
private static void OnFontSizePropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
editor?.TextArea.TextView.SetValue(FontSizeProperty, e.NewValue);
}
#endregion
#region TextBoxBase-like methods
/// <summary>
/// Appends text to the end of the document.
/// </summary>
public void AppendText(string textData)
{
var document = GetDocument();
document.Insert(document.TextLength, textData);
}
/// <summary>
/// Begins a group of document changes.
/// </summary>
public void BeginChange()
{
GetDocument().BeginUpdate();
}
/// <summary>
/// Copies the current selection to the clipboard.
/// </summary>
public void Copy()
{
if (CanCopy)
{
ApplicationCommands.Copy.Execute(null, TextArea);
}
}
/// <summary>
/// Removes the current selection and copies it to the clipboard.
/// </summary>
public void Cut()
{
if (CanCut)
{
ApplicationCommands.Cut.Execute(null, TextArea);
}
}
/// <summary>
/// Begins a group of document changes and returns an object that ends the group of document
/// changes when it is disposed.
/// </summary>
public IDisposable DeclareChangeBlock()
{
return GetDocument().RunUpdate();
}
/// <summary>
/// Removes the current selection without copying it to the clipboard.
/// </summary>
public void Delete()
{
if(CanDelete)
{
ApplicationCommands.Delete.Execute(null, TextArea);
}
}
/// <summary>
/// Ends the current group of document changes.
/// </summary>
public void EndChange()
{
GetDocument().EndUpdate();
}
/// <summary>
/// Scrolls one line down.
/// </summary>
public void LineDown()
{
//if (scrollViewer != null)
// scrollViewer.LineDown();
}
/// <summary>
/// Scrolls to the left.
/// </summary>
public void LineLeft()
{
//if (scrollViewer != null)
// scrollViewer.LineLeft();
}
/// <summary>
/// Scrolls to the right.
/// </summary>
public void LineRight()
{
//if (scrollViewer != null)
// scrollViewer.LineRight();
}
/// <summary>
/// Scrolls one line up.
/// </summary>
public void LineUp()
{
//if (scrollViewer != null)
// scrollViewer.LineUp();
}
/// <summary>
/// Scrolls one page down.
/// </summary>
public void PageDown()
{
//if (scrollViewer != null)
// scrollViewer.PageDown();
}
/// <summary>
/// Scrolls one page up.
/// </summary>
public void PageUp()
{
//if (scrollViewer != null)
// scrollViewer.PageUp();
}
/// <summary>
/// Scrolls one page left.
/// </summary>
public void PageLeft()
{
//if (scrollViewer != null)
// scrollViewer.PageLeft();
}
/// <summary>
/// Scrolls one page right.
/// </summary>
public void PageRight()
{
//if (scrollViewer != null)
// scrollViewer.PageRight();
}
/// <summary>
/// Pastes the clipboard content.
/// </summary>
public void Paste()
{
if (CanPaste)
{
ApplicationCommands.Paste.Execute(null, TextArea);
}
}
/// <summary>
/// Redoes the most recent undone command.
/// </summary>
/// <returns>True is the redo operation was successful, false is the redo stack is empty.</returns>
public bool Redo()
{
if (CanRedo)
{
ApplicationCommands.Redo.Execute(null, TextArea);
return true;
}
return false;
}
/// <summary>
/// Scrolls to the end of the document.
/// </summary>
public void ScrollToEnd()
{
ApplyTemplate(); // ensure scrollViewer is created
ScrollViewer?.ScrollToEnd();
}
/// <summary>
/// Scrolls to the start of the document.
/// </summary>
public void ScrollToHome()
{
ApplyTemplate(); // ensure scrollViewer is created
ScrollViewer?.ScrollToHome();
}
/// <summary>
/// Scrolls to the specified position in the document.
/// </summary>
public void ScrollToHorizontalOffset(double offset)
{
ApplyTemplate(); // ensure scrollViewer is created
//if (scrollViewer != null)
// scrollViewer.ScrollToHorizontalOffset(offset);
}
/// <summary>
/// Scrolls to the specified position in the document.
/// </summary>
public void ScrollToVerticalOffset(double offset)
{
ApplyTemplate(); // ensure scrollViewer is created
//if (scrollViewer != null)
// scrollViewer.ScrollToVerticalOffset(offset);
}
/// <summary>
/// Selects the entire text.
/// </summary>
public void SelectAll()
{
if (CanSelectAll)
{
ApplicationCommands.SelectAll.Execute(null, TextArea);
}
}
/// <summary>
/// Undoes the most recent command.
/// </summary>
/// <returns>True is the undo operation was successful, false is the undo stack is empty.</returns>
public bool Undo()
{
if (CanUndo)
{
ApplicationCommands.Undo.Execute(null, TextArea);
return true;
}
return false;
}
/// <summary>
/// Gets if the most recent undone command can be redone.
/// </summary>
public bool CanRedo
{
get { return ApplicationCommands.Redo.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if the most recent command can be undone.
/// </summary>
public bool CanUndo
{
get { return ApplicationCommands.Undo.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be copied
/// </summary>
public bool CanCopy
{
get { return ApplicationCommands.Copy.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be cut
/// </summary>
public bool CanCut
{
get { return ApplicationCommands.Cut.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be pasted
/// </summary>
public bool CanPaste
{
get { return ApplicationCommands.Paste.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if selected text in editor can be deleted
/// </summary>
public bool CanDelete
{
get { return ApplicationCommands.Delete.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text the editor can select all
/// </summary>
public bool CanSelectAll
{
get { return ApplicationCommands.SelectAll.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text editor can activate the search panel
/// </summary>
public bool CanSearch
{
get { return searchPanel != null; }
}
/// <summary>
/// Gets the vertical size of the document.
/// </summary>
public double ExtentHeight => ScrollViewer?.Extent.Height ?? 0;
/// <summary>
/// Gets the horizontal size of the current document region.
/// </summary>
public double ExtentWidth => ScrollViewer?.Extent.Width ?? 0;
/// <summary>
/// Gets the horizontal size of the viewport.
/// </summary>
public double ViewportHeight => ScrollViewer?.Viewport.Height ?? 0;
/// <summary>
/// Gets the horizontal size of the viewport.
/// </summary>
public double ViewportWidth => ScrollViewer?.Viewport.Width ?? 0;
/// <summary>
/// Gets the vertical scroll position.
/// </summary>
public double VerticalOffset => ScrollViewer?.Offset.Y ?? 0;
/// <summary>
/// Gets the horizontal scroll position.
/// </summary>
public double HorizontalOffset => ScrollViewer?.Offset.X ?? 0;
#endregion
#region TextBox methods
/// <summary>
/// Gets/Sets the selected text.
/// </summary>
public string SelectedText
{
get
{
// We'll get the text from the whole surrounding segment.
// This is done to ensure that SelectedText.Length == SelectionLength.
if (textArea.Document != null && !textArea.Selection.IsEmpty)
return textArea.Document.GetText(textArea.Selection.SurroundingSegment);
return string.Empty;
}
set
{
if (value == null)
throw new ArgumentNullException(nameof(value));
var textArea = TextArea;
if (textArea.Document != null)
{
var offset = SelectionStart;
var length = SelectionLength;
textArea.Document.Replace(offset, length, value);
// keep inserted text selected
textArea.Selection = Selection.Create(textArea, offset, offset + value.Length);
}
}
}
/// <summary>
/// Gets/sets the caret position.
/// </summary>
public int CaretOffset
{
get
{
return textArea.Caret.Offset;
}
set
{
textArea.Caret.Offset = value;
}
}
/// <summary>
/// Gets/sets the start position of the selection.
/// </summary>
public int SelectionStart
{
get
{
if (textArea.Selection.IsEmpty)
return textArea.Caret.Offset;
else
return textArea.Selection.SurroundingSegment.Offset;
}
set => Select(value, SelectionLength);
}
/// <summary>
/// Gets/sets the length of the selection.
/// </summary>
public int SelectionLength
{
get
{
if (!textArea.Selection.IsEmpty)
return textArea.Selection.SurroundingSegment.Length;
else
return 0;
}
set => Select(SelectionStart, value);
}
/// <summary>
/// Selects the specified text section.
/// </summary>
public void Select(int start, int length)
{
var documentLength = Document?.TextLength ?? 0;
if (start < 0 || start > documentLength)
throw new ArgumentOutOfRangeException(nameof(start), start, "Value must be between 0 and " + documentLength);
if (length < 0 || start + length > documentLength)
throw new ArgumentOutOfRangeException(nameof(length), length, "Value must be between 0 and " + (documentLength - start));
TextArea.Selection = Selection.Create(TextArea, start, start + length);
TextArea.Caret.Offset = start + length;
}
/// <summary>
/// Gets the number of lines in the document.
/// </summary>
public int LineCount
{
get
{
var document = Document;
if (document != null)
return document.LineCount;
return 1;
}
}
/// <summary>
/// Clears the text.
/// </summary>
public void Clear()
{
Text = string.Empty;
}
#endregion
#region Loading from stream
/// <summary>
/// Loads the text from the stream, auto-detecting the encoding.
/// </summary>
/// <remarks>
/// This method sets <see cref="IsModified"/> to false.
/// </remarks>
public void Load(Stream stream)
{
using (var reader = FileReader.OpenStream(stream, Encoding ?? Encoding.UTF8))
{
Text = reader.ReadToEnd();
SetValue(EncodingProperty, (object)reader.CurrentEncoding);
}
SetValue(IsModifiedProperty, (object)false);
}
/// <summary>
/// Loads the text from the stream, auto-detecting the encoding.
/// </summary>
public void Load(string fileName)
{
if (fileName == null)
throw new ArgumentNullException(nameof(fileName));
// TODO:load
//using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
//{
// Load(fs);
//}
}
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
public static readonly AvaloniaProperty HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
get => (ScrollBarVisibility)GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
public static readonly AvaloniaProperty VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
get => (ScrollBarVisibility)GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
if (stream == null)
throw new ArgumentNullException(nameof(stream));
var encoding = Encoding;
var document = Document;
var writer = encoding != null ? new StreamWriter(stream, encoding) : new StreamWriter(stream);
document?.WriteTextTo(writer);
writer.Flush();
// do not close the stream
SetValue(IsModifiedProperty, (object)false);
}
/// <summary>
/// Saves the text to the file.
/// </summary>
public void Save(string fileName)
{
if (fileName == null)
throw new ArgumentNullException(nameof(fileName));
// TODO: save
//using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
//{
// Save(fs);
//}
}
#endregion
#region PointerHover events
/// <summary>
/// The PreviewPointerHover event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PreviewPointerHoverEvent =
TextView.PreviewPointerHoverEvent;
/// <summary>
/// the pointerHover event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PointerHoverEvent =
TextView.PointerHoverEvent;
/// <summary>
/// The PreviewPointerHoverStopped event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PreviewPointerHoverStoppedEvent =
TextView.PreviewPointerHoverStoppedEvent;
/// <summary>
/// the pointerHoverStopped event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PointerHoverStoppedEvent =
TextView.PointerHoverStoppedEvent;
/// <summary>
/// Occurs when the pointer has hovered over a fixed location for some time.
/// </summary>
public event EventHandler<PointerEventArgs> PreviewPointerHover
{
add => AddHandler(PreviewPointerHoverEvent, value);
remove => RemoveHandler(PreviewPointerHoverEvent, value);
}
/// <summary>
/// Occurs when the pointer has hovered over a fixed location for some time.
/// </summary>
public event EventHandler<PointerEventArgs> PointerHover
{
add => AddHandler(PointerHoverEvent, value);
remove => RemoveHandler(PointerHoverEvent, value);
}
/// <summary>
/// Occurs when the pointer had previously hovered but now started moving again.
/// </summary>
public event EventHandler<PointerEventArgs> PreviewPointerHoverStopped
{
add => AddHandler(PreviewPointerHoverStoppedEvent, value);
remove => RemoveHandler(PreviewPointerHoverStoppedEvent, value);
}
/// <summary>
/// Occurs when the pointer had previously hovered but now started moving again.
/// </summary>
public event EventHandler<PointerEventArgs> PointerHoverStopped
{
add => AddHandler(PointerHoverStoppedEvent, value);
remove => RemoveHandler(PointerHoverStoppedEvent, value);
}
#endregion
#region ScrollBarVisibility
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
public static readonly AttachedProperty<ScrollBarVisibility> HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
get => GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
private ScrollBarVisibility _horizontalScrollBarVisibilityBck = ScrollBarVisibility.Auto;
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
public static readonly AttachedProperty<ScrollBarVisibility> VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
get => GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
object IServiceProvider.GetService(Type serviceType)
{
return TextArea.GetService(serviceType);
}
/// <summary>
/// Gets the text view position from a point inside the editor.
/// </summary>
/// <param name="point">The position, relative to top left
/// corner of TextEditor control</param>
/// <returns>The text view position, or null if the point is outside the document.</returns>
public TextViewPosition? GetPositionFromPoint(Point point)
{
if (Document == null)
return null;
var textView = TextArea.TextView;
Point tpoint = (Point)this.TranslatePoint(point + new Point(textView.ScrollOffset.X, Math.Floor(textView.ScrollOffset.Y)), textView);
return textView.GetPosition(tpoint);
}
/// <summary>
/// Scrolls to the specified line.
/// This method requires that the TextEditor was already assigned a size (layout engine must have run prior).
/// </summary>
public void ScrollToLine(int line)
{
ScrollTo(line, -1);
}
/// <summary>
/// Scrolls to the specified line/column.
/// This method requires that the TextEditor was already assigned a size (layout engine must have run prior).
/// </summary>
public void ScrollTo(int line, int column)
{
const double MinimumScrollFraction = 0.3;
ScrollTo(line, column, VisualYPosition.LineMiddle,
null != ScrollViewer ? ScrollViewer.Viewport.Height / 2 : 0.0, MinimumScrollFraction);
}
/// <summary>
/// Scrolls to the specified line/column.
/// This method requires that the TextEditor was already assigned a size (WPF layout must have run prior).
/// </summary>
/// <param name="line">Line to scroll to.</param>
/// <param name="column">Column to scroll to (important if wrapping is 'on', and for the horizontal scroll position).</param>
/// <param name="yPositionMode">The mode how to reference the Y position of the line.</param>
/// <param name="referencedVerticalViewPortOffset">Offset from the top of the viewport to where the referenced line/column should be positioned.</param>
/// <param name="minimumScrollFraction">The minimum vertical and/or horizontal scroll offset, expressed as fraction of the height or width of the viewport window, respectively.</param>
public void ScrollTo(int line, int column, VisualYPosition yPositionMode,
double referencedVerticalViewPortOffset, double minimumScrollFraction)
{
TextView textView = textArea.TextView;
TextDocument document = textView.Document;
if (ScrollViewer != null && document != null)
{
if (line < 1)
line = 1;
if (line > document.LineCount)
line = document.LineCount;
ILogicalScrollable scrollInfo = textView;
if (!scrollInfo.CanHorizontallyScroll)
{
// Word wrap is enabled. Ensure that we have up-to-date info about line height so that we scroll
// to the correct position.
// This avoids that the user has to repeat the ScrollTo() call several times when there are very long lines.
VisualLine vl = textView.GetOrConstructVisualLine(document.GetLineByNumber(line));
double remainingHeight = referencedVerticalViewPortOffset;
while (remainingHeight > 0)
{
DocumentLine prevLine = vl.FirstDocumentLine.PreviousLine;
if (prevLine == null)
break;
vl = textView.GetOrConstructVisualLine(prevLine);
remainingHeight -= vl.Height;
}
}
Point p = textArea.TextView.GetVisualPosition(
new TextViewPosition(line, Math.Max(1, column)),
yPositionMode);
double targetX = ScrollViewer.Offset.X;
double targetY = ScrollViewer.Offset.Y;
double verticalPos = p.Y - referencedVerticalViewPortOffset;
if (Math.Abs(verticalPos - ScrollViewer.Offset.Y) >
minimumScrollFraction * ScrollViewer.Viewport.Height)
{
targetY = Math.Max(0, verticalPos);
}
if (column > 0)
{
if (p.X > ScrollViewer.Viewport.Width - Caret.MinimumDistanceToViewBorder * 2)
{
double horizontalPos = Math.Max(0, p.X - ScrollViewer.Viewport.Width / 2);
if (Math.Abs(horizontalPos - ScrollViewer.Offset.X) >
minimumScrollFraction * ScrollViewer.Viewport.Width)
{
targetX = 0;
}
}
else
{
targetX = 0;
}
}
if (targetX != ScrollViewer.Offset.X || targetY != ScrollViewer.Offset.Y)
ScrollViewer.Offset = new Vector(targetX, targetY);
}
}
}
}
<MSG> Merge pull request #73 from jeffreye/fix-scroll
Fix scroll
<DFF> @@ -47,6 +47,8 @@ namespace AvaloniaEdit
static TextEditor()
{
FocusableProperty.OverrideDefaultValue<TextEditor>(true);
+ HorizontalScrollBarVisibilityProperty.OverrideDefaultValue<TextEditor>(ScrollBarVisibility.Auto);
+ VerticalScrollBarVisibilityProperty.OverrideDefaultValue<TextEditor>(ScrollBarVisibility.Auto);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
@@ -1049,28 +1051,28 @@ namespace AvaloniaEdit
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
- public static readonly AvaloniaProperty HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
+ public static readonly AttachedProperty<ScrollBarVisibility> HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
- get => (ScrollBarVisibility)GetValue(HorizontalScrollBarVisibilityProperty);
+ get => GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
- public static readonly AvaloniaProperty VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
+ public static readonly AttachedProperty<ScrollBarVisibility> VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
- get => (ScrollBarVisibility)GetValue(VerticalScrollBarVisibilityProperty);
+ get => GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
| 6 | Merge pull request #73 from jeffreye/fix-scroll | 4 | .cs | cs | mit | AvaloniaUI/AvaloniaEdit |
10066905 | <NME> TextEditor.cs
<BEF> // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using Avalonia;
using AvaloniaEdit.Document;
using AvaloniaEdit.Editing;
using AvaloniaEdit.Highlighting;
using AvaloniaEdit.Rendering;
using AvaloniaEdit.Utils;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Shapes;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.LogicalTree;
using Avalonia.Media;
using Avalonia.Data;
using AvaloniaEdit.Search;
namespace AvaloniaEdit
{
/// <summary>
/// The text editor control.
/// Contains a scrollable TextArea.
/// </summary>
public class TextEditor : TemplatedControl, ITextEditorComponent
static TextEditor()
{
FocusableProperty.OverrideDefaultValue<TextEditor>(true);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
SyntaxHighlightingProperty.Changed.Subscribe(OnSyntaxHighlightingChanged);
IsReadOnlyProperty.Changed.Subscribe(OnIsReadOnlyChanged);
IsModifiedProperty.Changed.Subscribe(OnIsModifiedChanged);
ShowLineNumbersProperty.Changed.Subscribe(OnShowLineNumbersChanged);
LineNumbersForegroundProperty.Changed.Subscribe(OnLineNumbersForegroundChanged);
FontFamilyProperty.Changed.Subscribe(OnFontFamilyPropertyChanged);
FontSizeProperty.Changed.Subscribe(OnFontSizePropertyChanged);
}
/// <summary>
/// Creates a new TextEditor instance.
/// </summary>
public TextEditor() : this(new TextArea())
{
}
/// <summary>
/// Creates a new TextEditor instance.
/// </summary>
protected TextEditor(TextArea textArea) : this(textArea, new TextDocument())
{
}
protected TextEditor(TextArea textArea, TextDocument document)
{
this.textArea = textArea ?? throw new ArgumentNullException(nameof(textArea));
textArea.TextView.Services.AddService(this);
SetValue(OptionsProperty, textArea.Options);
SetValue(DocumentProperty, document);
textArea[!BackgroundProperty] = this[!BackgroundProperty];
}
#endregion
protected override void OnGotFocus(GotFocusEventArgs e)
{
base.OnGotFocus(e);
TextArea.Focus();
e.Handled = true;
}
#region Document property
/// <summary>
/// Document property.
/// </summary>
public static readonly StyledProperty<TextDocument> DocumentProperty
= TextView.DocumentProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the document displayed by the text editor.
/// This is a dependency property.
/// </summary>
public TextDocument Document
{
get => GetValue(DocumentProperty);
set => SetValue(DocumentProperty, value);
}
/// <summary>
/// Occurs when the document property has changed.
/// </summary>
public event EventHandler DocumentChanged;
/// <summary>
/// Raises the <see cref="DocumentChanged"/> event.
/// </summary>
protected virtual void OnDocumentChanged(EventArgs e)
{
DocumentChanged?.Invoke(this, e);
}
private static void OnDocumentChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnDocumentChanged((TextDocument)e.OldValue, (TextDocument)e.NewValue);
}
private void OnDocumentChanged(TextDocument oldValue, TextDocument newValue)
{
if (oldValue != null)
{
TextDocumentWeakEventManager.TextChanged.RemoveHandler(oldValue, OnTextChanged);
PropertyChangedWeakEventManager.RemoveHandler(oldValue.UndoStack, OnUndoStackPropertyChangedHandler);
}
TextArea.Document = newValue;
if (newValue != null)
{
TextDocumentWeakEventManager.TextChanged.AddHandler(newValue, OnTextChanged);
PropertyChangedWeakEventManager.AddHandler(newValue.UndoStack, OnUndoStackPropertyChangedHandler);
}
OnDocumentChanged(EventArgs.Empty);
OnTextChanged(EventArgs.Empty);
}
#endregion
#region Options property
/// <summary>
/// Options property.
/// </summary>
public static readonly StyledProperty<TextEditorOptions> OptionsProperty
= TextView.OptionsProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the options currently used by the text editor.
/// </summary>
public TextEditorOptions Options
{
get => GetValue(OptionsProperty);
set => SetValue(OptionsProperty, value);
}
/// <summary>
/// Occurs when a text editor option has changed.
/// </summary>
public event PropertyChangedEventHandler OptionChanged;
/// <summary>
/// Raises the <see cref="OptionChanged"/> event.
/// </summary>
protected virtual void OnOptionChanged(PropertyChangedEventArgs e)
{
OptionChanged?.Invoke(this, e);
}
private static void OnOptionsChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnOptionsChanged((TextEditorOptions)e.OldValue, (TextEditorOptions)e.NewValue);
}
private void OnOptionsChanged(TextEditorOptions oldValue, TextEditorOptions newValue)
{
if (oldValue != null)
{
PropertyChangedWeakEventManager.RemoveHandler(oldValue, OnPropertyChangedHandler);
}
TextArea.Options = newValue;
if (newValue != null)
{
PropertyChangedWeakEventManager.AddHandler(newValue, OnPropertyChangedHandler);
}
OnOptionChanged(new PropertyChangedEventArgs(null));
}
private void OnPropertyChangedHandler(object sender, PropertyChangedEventArgs e)
{
OnOptionChanged(e);
}
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
base.OnPropertyChanged(change);
if (change.Property == WordWrapProperty)
{
if (WordWrap)
{
_horizontalScrollBarVisibilityBck = HorizontalScrollBarVisibility;
HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
}
else
{
HorizontalScrollBarVisibility = _horizontalScrollBarVisibilityBck;
}
}
}
private void OnUndoStackPropertyChangedHandler(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsOriginalFile")
{
HandleIsOriginalChanged(e);
}
}
private void OnTextChanged(object sender, EventArgs e)
{
OnTextChanged(e);
}
#endregion
#region Text property
/// <summary>
/// Gets/Sets the text of the current document.
/// </summary>
public string Text
{
get
{
var document = Document;
return document != null ? document.Text : string.Empty;
}
set
{
var document = GetDocument();
document.Text = value ?? string.Empty;
// after replacing the full text, the caret is positioned at the end of the document
// - reset it to the beginning.
CaretOffset = 0;
document.UndoStack.ClearAll();
}
}
private TextDocument GetDocument()
{
var document = Document;
if (document == null)
throw ThrowUtil.NoDocumentAssigned();
return document;
}
/// <summary>
/// Occurs when the Text property changes.
/// </summary>
public event EventHandler TextChanged;
/// <summary>
/// Raises the <see cref="TextChanged"/> event.
/// </summary>
protected virtual void OnTextChanged(EventArgs e)
{
TextChanged?.Invoke(this, e);
}
#endregion
#region TextArea / ScrollViewer properties
private readonly TextArea textArea;
private SearchPanel searchPanel;
private bool wasSearchPanelOpened;
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
ScrollViewer = (ScrollViewer)e.NameScope.Find("PART_ScrollViewer");
ScrollViewer.Content = TextArea;
searchPanel = SearchPanel.Install(this);
}
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnAttachedToLogicalTree(e);
if (searchPanel != null && wasSearchPanelOpened)
{
searchPanel.Open();
}
}
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnDetachedFromLogicalTree(e);
if (searchPanel != null)
{
wasSearchPanelOpened = searchPanel.IsOpened;
if (searchPanel.IsOpened)
searchPanel.Close();
}
}
/// <summary>
/// Gets the text area.
/// </summary>
public TextArea TextArea => textArea;
/// <summary>
/// Gets the search panel.
/// </summary>
public SearchPanel SearchPanel => searchPanel;
/// <summary>
/// Gets the scroll viewer used by the text editor.
/// This property can return null if the template has not been applied / does not contain a scroll viewer.
/// </summary>
internal ScrollViewer ScrollViewer { get; private set; }
#endregion
#region Syntax highlighting
/// <summary>
/// The <see cref="SyntaxHighlighting"/> property.
/// </summary>
public static readonly StyledProperty<IHighlightingDefinition> SyntaxHighlightingProperty =
AvaloniaProperty.Register<TextEditor, IHighlightingDefinition>("SyntaxHighlighting");
/// <summary>
/// Gets/sets the syntax highlighting definition used to colorize the text.
/// </summary>
public IHighlightingDefinition SyntaxHighlighting
{
get => GetValue(SyntaxHighlightingProperty);
set => SetValue(SyntaxHighlightingProperty, value);
}
private IVisualLineTransformer _colorizer;
private static void OnSyntaxHighlightingChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnSyntaxHighlightingChanged(e.NewValue as IHighlightingDefinition);
}
private void OnSyntaxHighlightingChanged(IHighlightingDefinition newValue)
{
if (_colorizer != null)
{
textArea.TextView.LineTransformers.Remove(_colorizer);
_colorizer = null;
}
if (newValue != null)
{
_colorizer = CreateColorizer(newValue);
if (_colorizer != null)
{
textArea.TextView.LineTransformers.Insert(0, _colorizer);
}
}
}
/// <summary>
/// Creates the highlighting colorizer for the specified highlighting definition.
/// Allows derived classes to provide custom colorizer implementations for special highlighting definitions.
/// </summary>
/// <returns></returns>
protected virtual IVisualLineTransformer CreateColorizer(IHighlightingDefinition highlightingDefinition)
{
if (highlightingDefinition == null)
throw new ArgumentNullException(nameof(highlightingDefinition));
return new HighlightingColorizer(highlightingDefinition);
}
#endregion
#region WordWrap
/// <summary>
/// Word wrap dependency property.
/// </summary>
public static readonly StyledProperty<bool> WordWrapProperty =
AvaloniaProperty.Register<TextEditor, bool>("WordWrap");
/// <summary>
/// Specifies whether the text editor uses word wrapping.
/// </summary>
/// <remarks>
/// Setting WordWrap=true has the same effect as setting HorizontalScrollBarVisibility=Disabled and will override the
/// HorizontalScrollBarVisibility setting.
/// </remarks>
public bool WordWrap
{
get => GetValue(WordWrapProperty);
set => SetValue(WordWrapProperty, value);
}
#endregion
#region IsReadOnly
/// <summary>
/// IsReadOnly dependency property.
/// </summary>
public static readonly StyledProperty<bool> IsReadOnlyProperty =
AvaloniaProperty.Register<TextEditor, bool>("IsReadOnly");
/// <summary>
/// Specifies whether the user can change the text editor content.
/// Setting this property will replace the
/// <see cref="Editing.TextArea.ReadOnlySectionProvider">TextArea.ReadOnlySectionProvider</see>.
/// </summary>
public bool IsReadOnly
{
get => GetValue(IsReadOnlyProperty);
set => SetValue(IsReadOnlyProperty, value);
}
private static void OnIsReadOnlyChanged(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is TextEditor editor)
{
if ((bool)e.NewValue)
editor.TextArea.ReadOnlySectionProvider = ReadOnlySectionDocument.Instance;
else
editor.TextArea.ReadOnlySectionProvider = NoReadOnlySections.Instance;
}
}
#endregion
#region IsModified
/// <summary>
/// Dependency property for <see cref="IsModified"/>
/// </summary>
public static readonly StyledProperty<bool> IsModifiedProperty =
AvaloniaProperty.Register<TextEditor, bool>("IsModified");
/// <summary>
/// Gets/Sets the 'modified' flag.
/// </summary>
public bool IsModified
{
get => GetValue(IsModifiedProperty);
set => SetValue(IsModifiedProperty, value);
}
private static void OnIsModifiedChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
var document = editor?.Document;
if (document != null)
{
var undoStack = document.UndoStack;
if ((bool)e.NewValue)
{
if (undoStack.IsOriginalFile)
undoStack.DiscardOriginalFileMarker();
}
else
{
undoStack.MarkAsOriginalFile();
}
}
}
private void HandleIsOriginalChanged(PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsOriginalFile")
{
var document = Document;
if (document != null)
{
SetValue(IsModifiedProperty, (object)!document.UndoStack.IsOriginalFile);
}
}
}
#endregion
#region ShowLineNumbers
/// <summary>
/// ShowLineNumbers dependency property.
/// </summary>
public static readonly StyledProperty<bool> ShowLineNumbersProperty =
AvaloniaProperty.Register<TextEditor, bool>("ShowLineNumbers");
/// <summary>
/// Specifies whether line numbers are shown on the left to the text view.
/// </summary>
public bool ShowLineNumbers
{
get => GetValue(ShowLineNumbersProperty);
set => SetValue(ShowLineNumbersProperty, value);
}
private static void OnShowLineNumbersChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
if (editor == null) return;
var leftMargins = editor.TextArea.LeftMargins;
if ((bool)e.NewValue)
{
var lineNumbers = new LineNumberMargin();
var line = (Line)DottedLineMargin.Create();
leftMargins.Insert(0, lineNumbers);
leftMargins.Insert(1, line);
var lineNumbersForeground = new Binding("LineNumbersForeground") { Source = editor };
line.Bind(Shape.StrokeProperty, lineNumbersForeground);
lineNumbers.Bind(ForegroundProperty, lineNumbersForeground);
}
else
{
for (var i = 0; i < leftMargins.Count; i++)
{
if (leftMargins[i] is LineNumberMargin)
{
leftMargins.RemoveAt(i);
if (i < leftMargins.Count && DottedLineMargin.IsDottedLineMargin(leftMargins[i]))
{
leftMargins.RemoveAt(i);
}
break;
}
}
}
}
#endregion
#region LineNumbersForeground
/// <summary>
/// LineNumbersForeground dependency property.
/// </summary>
public static readonly StyledProperty<IBrush> LineNumbersForegroundProperty =
AvaloniaProperty.Register<TextEditor, IBrush>("LineNumbersForeground", Brushes.Gray);
/// <summary>
/// Gets/sets the Brush used for displaying the foreground color of line numbers.
/// </summary>
public IBrush LineNumbersForeground
{
get => GetValue(LineNumbersForegroundProperty);
set => SetValue(LineNumbersForegroundProperty, value);
}
private static void OnLineNumbersForegroundChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
var lineNumberMargin = editor?.TextArea.LeftMargins.FirstOrDefault(margin => margin is LineNumberMargin) as LineNumberMargin;
lineNumberMargin?.SetValue(ForegroundProperty, e.NewValue);
}
private static void OnFontFamilyPropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
editor?.TextArea.TextView.SetValue(FontFamilyProperty, e.NewValue);
}
private static void OnFontSizePropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
editor?.TextArea.TextView.SetValue(FontSizeProperty, e.NewValue);
}
#endregion
#region TextBoxBase-like methods
/// <summary>
/// Appends text to the end of the document.
/// </summary>
public void AppendText(string textData)
{
var document = GetDocument();
document.Insert(document.TextLength, textData);
}
/// <summary>
/// Begins a group of document changes.
/// </summary>
public void BeginChange()
{
GetDocument().BeginUpdate();
}
/// <summary>
/// Copies the current selection to the clipboard.
/// </summary>
public void Copy()
{
if (CanCopy)
{
ApplicationCommands.Copy.Execute(null, TextArea);
}
}
/// <summary>
/// Removes the current selection and copies it to the clipboard.
/// </summary>
public void Cut()
{
if (CanCut)
{
ApplicationCommands.Cut.Execute(null, TextArea);
}
}
/// <summary>
/// Begins a group of document changes and returns an object that ends the group of document
/// changes when it is disposed.
/// </summary>
public IDisposable DeclareChangeBlock()
{
return GetDocument().RunUpdate();
}
/// <summary>
/// Removes the current selection without copying it to the clipboard.
/// </summary>
public void Delete()
{
if(CanDelete)
{
ApplicationCommands.Delete.Execute(null, TextArea);
}
}
/// <summary>
/// Ends the current group of document changes.
/// </summary>
public void EndChange()
{
GetDocument().EndUpdate();
}
/// <summary>
/// Scrolls one line down.
/// </summary>
public void LineDown()
{
//if (scrollViewer != null)
// scrollViewer.LineDown();
}
/// <summary>
/// Scrolls to the left.
/// </summary>
public void LineLeft()
{
//if (scrollViewer != null)
// scrollViewer.LineLeft();
}
/// <summary>
/// Scrolls to the right.
/// </summary>
public void LineRight()
{
//if (scrollViewer != null)
// scrollViewer.LineRight();
}
/// <summary>
/// Scrolls one line up.
/// </summary>
public void LineUp()
{
//if (scrollViewer != null)
// scrollViewer.LineUp();
}
/// <summary>
/// Scrolls one page down.
/// </summary>
public void PageDown()
{
//if (scrollViewer != null)
// scrollViewer.PageDown();
}
/// <summary>
/// Scrolls one page up.
/// </summary>
public void PageUp()
{
//if (scrollViewer != null)
// scrollViewer.PageUp();
}
/// <summary>
/// Scrolls one page left.
/// </summary>
public void PageLeft()
{
//if (scrollViewer != null)
// scrollViewer.PageLeft();
}
/// <summary>
/// Scrolls one page right.
/// </summary>
public void PageRight()
{
//if (scrollViewer != null)
// scrollViewer.PageRight();
}
/// <summary>
/// Pastes the clipboard content.
/// </summary>
public void Paste()
{
if (CanPaste)
{
ApplicationCommands.Paste.Execute(null, TextArea);
}
}
/// <summary>
/// Redoes the most recent undone command.
/// </summary>
/// <returns>True is the redo operation was successful, false is the redo stack is empty.</returns>
public bool Redo()
{
if (CanRedo)
{
ApplicationCommands.Redo.Execute(null, TextArea);
return true;
}
return false;
}
/// <summary>
/// Scrolls to the end of the document.
/// </summary>
public void ScrollToEnd()
{
ApplyTemplate(); // ensure scrollViewer is created
ScrollViewer?.ScrollToEnd();
}
/// <summary>
/// Scrolls to the start of the document.
/// </summary>
public void ScrollToHome()
{
ApplyTemplate(); // ensure scrollViewer is created
ScrollViewer?.ScrollToHome();
}
/// <summary>
/// Scrolls to the specified position in the document.
/// </summary>
public void ScrollToHorizontalOffset(double offset)
{
ApplyTemplate(); // ensure scrollViewer is created
//if (scrollViewer != null)
// scrollViewer.ScrollToHorizontalOffset(offset);
}
/// <summary>
/// Scrolls to the specified position in the document.
/// </summary>
public void ScrollToVerticalOffset(double offset)
{
ApplyTemplate(); // ensure scrollViewer is created
//if (scrollViewer != null)
// scrollViewer.ScrollToVerticalOffset(offset);
}
/// <summary>
/// Selects the entire text.
/// </summary>
public void SelectAll()
{
if (CanSelectAll)
{
ApplicationCommands.SelectAll.Execute(null, TextArea);
}
}
/// <summary>
/// Undoes the most recent command.
/// </summary>
/// <returns>True is the undo operation was successful, false is the undo stack is empty.</returns>
public bool Undo()
{
if (CanUndo)
{
ApplicationCommands.Undo.Execute(null, TextArea);
return true;
}
return false;
}
/// <summary>
/// Gets if the most recent undone command can be redone.
/// </summary>
public bool CanRedo
{
get { return ApplicationCommands.Redo.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if the most recent command can be undone.
/// </summary>
public bool CanUndo
{
get { return ApplicationCommands.Undo.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be copied
/// </summary>
public bool CanCopy
{
get { return ApplicationCommands.Copy.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be cut
/// </summary>
public bool CanCut
{
get { return ApplicationCommands.Cut.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be pasted
/// </summary>
public bool CanPaste
{
get { return ApplicationCommands.Paste.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if selected text in editor can be deleted
/// </summary>
public bool CanDelete
{
get { return ApplicationCommands.Delete.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text the editor can select all
/// </summary>
public bool CanSelectAll
{
get { return ApplicationCommands.SelectAll.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text editor can activate the search panel
/// </summary>
public bool CanSearch
{
get { return searchPanel != null; }
}
/// <summary>
/// Gets the vertical size of the document.
/// </summary>
public double ExtentHeight => ScrollViewer?.Extent.Height ?? 0;
/// <summary>
/// Gets the horizontal size of the current document region.
/// </summary>
public double ExtentWidth => ScrollViewer?.Extent.Width ?? 0;
/// <summary>
/// Gets the horizontal size of the viewport.
/// </summary>
public double ViewportHeight => ScrollViewer?.Viewport.Height ?? 0;
/// <summary>
/// Gets the horizontal size of the viewport.
/// </summary>
public double ViewportWidth => ScrollViewer?.Viewport.Width ?? 0;
/// <summary>
/// Gets the vertical scroll position.
/// </summary>
public double VerticalOffset => ScrollViewer?.Offset.Y ?? 0;
/// <summary>
/// Gets the horizontal scroll position.
/// </summary>
public double HorizontalOffset => ScrollViewer?.Offset.X ?? 0;
#endregion
#region TextBox methods
/// <summary>
/// Gets/Sets the selected text.
/// </summary>
public string SelectedText
{
get
{
// We'll get the text from the whole surrounding segment.
// This is done to ensure that SelectedText.Length == SelectionLength.
if (textArea.Document != null && !textArea.Selection.IsEmpty)
return textArea.Document.GetText(textArea.Selection.SurroundingSegment);
return string.Empty;
}
set
{
if (value == null)
throw new ArgumentNullException(nameof(value));
var textArea = TextArea;
if (textArea.Document != null)
{
var offset = SelectionStart;
var length = SelectionLength;
textArea.Document.Replace(offset, length, value);
// keep inserted text selected
textArea.Selection = Selection.Create(textArea, offset, offset + value.Length);
}
}
}
/// <summary>
/// Gets/sets the caret position.
/// </summary>
public int CaretOffset
{
get
{
return textArea.Caret.Offset;
}
set
{
textArea.Caret.Offset = value;
}
}
/// <summary>
/// Gets/sets the start position of the selection.
/// </summary>
public int SelectionStart
{
get
{
if (textArea.Selection.IsEmpty)
return textArea.Caret.Offset;
else
return textArea.Selection.SurroundingSegment.Offset;
}
set => Select(value, SelectionLength);
}
/// <summary>
/// Gets/sets the length of the selection.
/// </summary>
public int SelectionLength
{
get
{
if (!textArea.Selection.IsEmpty)
return textArea.Selection.SurroundingSegment.Length;
else
return 0;
}
set => Select(SelectionStart, value);
}
/// <summary>
/// Selects the specified text section.
/// </summary>
public void Select(int start, int length)
{
var documentLength = Document?.TextLength ?? 0;
if (start < 0 || start > documentLength)
throw new ArgumentOutOfRangeException(nameof(start), start, "Value must be between 0 and " + documentLength);
if (length < 0 || start + length > documentLength)
throw new ArgumentOutOfRangeException(nameof(length), length, "Value must be between 0 and " + (documentLength - start));
TextArea.Selection = Selection.Create(TextArea, start, start + length);
TextArea.Caret.Offset = start + length;
}
/// <summary>
/// Gets the number of lines in the document.
/// </summary>
public int LineCount
{
get
{
var document = Document;
if (document != null)
return document.LineCount;
return 1;
}
}
/// <summary>
/// Clears the text.
/// </summary>
public void Clear()
{
Text = string.Empty;
}
#endregion
#region Loading from stream
/// <summary>
/// Loads the text from the stream, auto-detecting the encoding.
/// </summary>
/// <remarks>
/// This method sets <see cref="IsModified"/> to false.
/// </remarks>
public void Load(Stream stream)
{
using (var reader = FileReader.OpenStream(stream, Encoding ?? Encoding.UTF8))
{
Text = reader.ReadToEnd();
SetValue(EncodingProperty, (object)reader.CurrentEncoding);
}
SetValue(IsModifiedProperty, (object)false);
}
/// <summary>
/// Loads the text from the stream, auto-detecting the encoding.
/// </summary>
public void Load(string fileName)
{
if (fileName == null)
throw new ArgumentNullException(nameof(fileName));
// TODO:load
//using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
//{
// Load(fs);
//}
}
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
public static readonly AvaloniaProperty HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
get => (ScrollBarVisibility)GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
public static readonly AvaloniaProperty VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
get => (ScrollBarVisibility)GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
if (stream == null)
throw new ArgumentNullException(nameof(stream));
var encoding = Encoding;
var document = Document;
var writer = encoding != null ? new StreamWriter(stream, encoding) : new StreamWriter(stream);
document?.WriteTextTo(writer);
writer.Flush();
// do not close the stream
SetValue(IsModifiedProperty, (object)false);
}
/// <summary>
/// Saves the text to the file.
/// </summary>
public void Save(string fileName)
{
if (fileName == null)
throw new ArgumentNullException(nameof(fileName));
// TODO: save
//using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
//{
// Save(fs);
//}
}
#endregion
#region PointerHover events
/// <summary>
/// The PreviewPointerHover event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PreviewPointerHoverEvent =
TextView.PreviewPointerHoverEvent;
/// <summary>
/// the pointerHover event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PointerHoverEvent =
TextView.PointerHoverEvent;
/// <summary>
/// The PreviewPointerHoverStopped event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PreviewPointerHoverStoppedEvent =
TextView.PreviewPointerHoverStoppedEvent;
/// <summary>
/// the pointerHoverStopped event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PointerHoverStoppedEvent =
TextView.PointerHoverStoppedEvent;
/// <summary>
/// Occurs when the pointer has hovered over a fixed location for some time.
/// </summary>
public event EventHandler<PointerEventArgs> PreviewPointerHover
{
add => AddHandler(PreviewPointerHoverEvent, value);
remove => RemoveHandler(PreviewPointerHoverEvent, value);
}
/// <summary>
/// Occurs when the pointer has hovered over a fixed location for some time.
/// </summary>
public event EventHandler<PointerEventArgs> PointerHover
{
add => AddHandler(PointerHoverEvent, value);
remove => RemoveHandler(PointerHoverEvent, value);
}
/// <summary>
/// Occurs when the pointer had previously hovered but now started moving again.
/// </summary>
public event EventHandler<PointerEventArgs> PreviewPointerHoverStopped
{
add => AddHandler(PreviewPointerHoverStoppedEvent, value);
remove => RemoveHandler(PreviewPointerHoverStoppedEvent, value);
}
/// <summary>
/// Occurs when the pointer had previously hovered but now started moving again.
/// </summary>
public event EventHandler<PointerEventArgs> PointerHoverStopped
{
add => AddHandler(PointerHoverStoppedEvent, value);
remove => RemoveHandler(PointerHoverStoppedEvent, value);
}
#endregion
#region ScrollBarVisibility
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
public static readonly AttachedProperty<ScrollBarVisibility> HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
get => GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
private ScrollBarVisibility _horizontalScrollBarVisibilityBck = ScrollBarVisibility.Auto;
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
public static readonly AttachedProperty<ScrollBarVisibility> VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
get => GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
object IServiceProvider.GetService(Type serviceType)
{
return TextArea.GetService(serviceType);
}
/// <summary>
/// Gets the text view position from a point inside the editor.
/// </summary>
/// <param name="point">The position, relative to top left
/// corner of TextEditor control</param>
/// <returns>The text view position, or null if the point is outside the document.</returns>
public TextViewPosition? GetPositionFromPoint(Point point)
{
if (Document == null)
return null;
var textView = TextArea.TextView;
Point tpoint = (Point)this.TranslatePoint(point + new Point(textView.ScrollOffset.X, Math.Floor(textView.ScrollOffset.Y)), textView);
return textView.GetPosition(tpoint);
}
/// <summary>
/// Scrolls to the specified line.
/// This method requires that the TextEditor was already assigned a size (layout engine must have run prior).
/// </summary>
public void ScrollToLine(int line)
{
ScrollTo(line, -1);
}
/// <summary>
/// Scrolls to the specified line/column.
/// This method requires that the TextEditor was already assigned a size (layout engine must have run prior).
/// </summary>
public void ScrollTo(int line, int column)
{
const double MinimumScrollFraction = 0.3;
ScrollTo(line, column, VisualYPosition.LineMiddle,
null != ScrollViewer ? ScrollViewer.Viewport.Height / 2 : 0.0, MinimumScrollFraction);
}
/// <summary>
/// Scrolls to the specified line/column.
/// This method requires that the TextEditor was already assigned a size (WPF layout must have run prior).
/// </summary>
/// <param name="line">Line to scroll to.</param>
/// <param name="column">Column to scroll to (important if wrapping is 'on', and for the horizontal scroll position).</param>
/// <param name="yPositionMode">The mode how to reference the Y position of the line.</param>
/// <param name="referencedVerticalViewPortOffset">Offset from the top of the viewport to where the referenced line/column should be positioned.</param>
/// <param name="minimumScrollFraction">The minimum vertical and/or horizontal scroll offset, expressed as fraction of the height or width of the viewport window, respectively.</param>
public void ScrollTo(int line, int column, VisualYPosition yPositionMode,
double referencedVerticalViewPortOffset, double minimumScrollFraction)
{
TextView textView = textArea.TextView;
TextDocument document = textView.Document;
if (ScrollViewer != null && document != null)
{
if (line < 1)
line = 1;
if (line > document.LineCount)
line = document.LineCount;
ILogicalScrollable scrollInfo = textView;
if (!scrollInfo.CanHorizontallyScroll)
{
// Word wrap is enabled. Ensure that we have up-to-date info about line height so that we scroll
// to the correct position.
// This avoids that the user has to repeat the ScrollTo() call several times when there are very long lines.
VisualLine vl = textView.GetOrConstructVisualLine(document.GetLineByNumber(line));
double remainingHeight = referencedVerticalViewPortOffset;
while (remainingHeight > 0)
{
DocumentLine prevLine = vl.FirstDocumentLine.PreviousLine;
if (prevLine == null)
break;
vl = textView.GetOrConstructVisualLine(prevLine);
remainingHeight -= vl.Height;
}
}
Point p = textArea.TextView.GetVisualPosition(
new TextViewPosition(line, Math.Max(1, column)),
yPositionMode);
double targetX = ScrollViewer.Offset.X;
double targetY = ScrollViewer.Offset.Y;
double verticalPos = p.Y - referencedVerticalViewPortOffset;
if (Math.Abs(verticalPos - ScrollViewer.Offset.Y) >
minimumScrollFraction * ScrollViewer.Viewport.Height)
{
targetY = Math.Max(0, verticalPos);
}
if (column > 0)
{
if (p.X > ScrollViewer.Viewport.Width - Caret.MinimumDistanceToViewBorder * 2)
{
double horizontalPos = Math.Max(0, p.X - ScrollViewer.Viewport.Width / 2);
if (Math.Abs(horizontalPos - ScrollViewer.Offset.X) >
minimumScrollFraction * ScrollViewer.Viewport.Width)
{
targetX = 0;
}
}
else
{
targetX = 0;
}
}
if (targetX != ScrollViewer.Offset.X || targetY != ScrollViewer.Offset.Y)
ScrollViewer.Offset = new Vector(targetX, targetY);
}
}
}
}
<MSG> Merge pull request #73 from jeffreye/fix-scroll
Fix scroll
<DFF> @@ -47,6 +47,8 @@ namespace AvaloniaEdit
static TextEditor()
{
FocusableProperty.OverrideDefaultValue<TextEditor>(true);
+ HorizontalScrollBarVisibilityProperty.OverrideDefaultValue<TextEditor>(ScrollBarVisibility.Auto);
+ VerticalScrollBarVisibilityProperty.OverrideDefaultValue<TextEditor>(ScrollBarVisibility.Auto);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
@@ -1049,28 +1051,28 @@ namespace AvaloniaEdit
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
- public static readonly AvaloniaProperty HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
+ public static readonly AttachedProperty<ScrollBarVisibility> HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
- get => (ScrollBarVisibility)GetValue(HorizontalScrollBarVisibilityProperty);
+ get => GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
- public static readonly AvaloniaProperty VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
+ public static readonly AttachedProperty<ScrollBarVisibility> VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
- get => (ScrollBarVisibility)GetValue(VerticalScrollBarVisibilityProperty);
+ get => GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
| 6 | Merge pull request #73 from jeffreye/fix-scroll | 4 | .cs | cs | mit | AvaloniaUI/AvaloniaEdit |
10066906 | <NME> TextEditor.cs
<BEF> // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using Avalonia;
using AvaloniaEdit.Document;
using AvaloniaEdit.Editing;
using AvaloniaEdit.Highlighting;
using AvaloniaEdit.Rendering;
using AvaloniaEdit.Utils;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Shapes;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.LogicalTree;
using Avalonia.Media;
using Avalonia.Data;
using AvaloniaEdit.Search;
namespace AvaloniaEdit
{
/// <summary>
/// The text editor control.
/// Contains a scrollable TextArea.
/// </summary>
public class TextEditor : TemplatedControl, ITextEditorComponent
static TextEditor()
{
FocusableProperty.OverrideDefaultValue<TextEditor>(true);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
SyntaxHighlightingProperty.Changed.Subscribe(OnSyntaxHighlightingChanged);
IsReadOnlyProperty.Changed.Subscribe(OnIsReadOnlyChanged);
IsModifiedProperty.Changed.Subscribe(OnIsModifiedChanged);
ShowLineNumbersProperty.Changed.Subscribe(OnShowLineNumbersChanged);
LineNumbersForegroundProperty.Changed.Subscribe(OnLineNumbersForegroundChanged);
FontFamilyProperty.Changed.Subscribe(OnFontFamilyPropertyChanged);
FontSizeProperty.Changed.Subscribe(OnFontSizePropertyChanged);
}
/// <summary>
/// Creates a new TextEditor instance.
/// </summary>
public TextEditor() : this(new TextArea())
{
}
/// <summary>
/// Creates a new TextEditor instance.
/// </summary>
protected TextEditor(TextArea textArea) : this(textArea, new TextDocument())
{
}
protected TextEditor(TextArea textArea, TextDocument document)
{
this.textArea = textArea ?? throw new ArgumentNullException(nameof(textArea));
textArea.TextView.Services.AddService(this);
SetValue(OptionsProperty, textArea.Options);
SetValue(DocumentProperty, document);
textArea[!BackgroundProperty] = this[!BackgroundProperty];
}
#endregion
protected override void OnGotFocus(GotFocusEventArgs e)
{
base.OnGotFocus(e);
TextArea.Focus();
e.Handled = true;
}
#region Document property
/// <summary>
/// Document property.
/// </summary>
public static readonly StyledProperty<TextDocument> DocumentProperty
= TextView.DocumentProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the document displayed by the text editor.
/// This is a dependency property.
/// </summary>
public TextDocument Document
{
get => GetValue(DocumentProperty);
set => SetValue(DocumentProperty, value);
}
/// <summary>
/// Occurs when the document property has changed.
/// </summary>
public event EventHandler DocumentChanged;
/// <summary>
/// Raises the <see cref="DocumentChanged"/> event.
/// </summary>
protected virtual void OnDocumentChanged(EventArgs e)
{
DocumentChanged?.Invoke(this, e);
}
private static void OnDocumentChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnDocumentChanged((TextDocument)e.OldValue, (TextDocument)e.NewValue);
}
private void OnDocumentChanged(TextDocument oldValue, TextDocument newValue)
{
if (oldValue != null)
{
TextDocumentWeakEventManager.TextChanged.RemoveHandler(oldValue, OnTextChanged);
PropertyChangedWeakEventManager.RemoveHandler(oldValue.UndoStack, OnUndoStackPropertyChangedHandler);
}
TextArea.Document = newValue;
if (newValue != null)
{
TextDocumentWeakEventManager.TextChanged.AddHandler(newValue, OnTextChanged);
PropertyChangedWeakEventManager.AddHandler(newValue.UndoStack, OnUndoStackPropertyChangedHandler);
}
OnDocumentChanged(EventArgs.Empty);
OnTextChanged(EventArgs.Empty);
}
#endregion
#region Options property
/// <summary>
/// Options property.
/// </summary>
public static readonly StyledProperty<TextEditorOptions> OptionsProperty
= TextView.OptionsProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the options currently used by the text editor.
/// </summary>
public TextEditorOptions Options
{
get => GetValue(OptionsProperty);
set => SetValue(OptionsProperty, value);
}
/// <summary>
/// Occurs when a text editor option has changed.
/// </summary>
public event PropertyChangedEventHandler OptionChanged;
/// <summary>
/// Raises the <see cref="OptionChanged"/> event.
/// </summary>
protected virtual void OnOptionChanged(PropertyChangedEventArgs e)
{
OptionChanged?.Invoke(this, e);
}
private static void OnOptionsChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnOptionsChanged((TextEditorOptions)e.OldValue, (TextEditorOptions)e.NewValue);
}
private void OnOptionsChanged(TextEditorOptions oldValue, TextEditorOptions newValue)
{
if (oldValue != null)
{
PropertyChangedWeakEventManager.RemoveHandler(oldValue, OnPropertyChangedHandler);
}
TextArea.Options = newValue;
if (newValue != null)
{
PropertyChangedWeakEventManager.AddHandler(newValue, OnPropertyChangedHandler);
}
OnOptionChanged(new PropertyChangedEventArgs(null));
}
private void OnPropertyChangedHandler(object sender, PropertyChangedEventArgs e)
{
OnOptionChanged(e);
}
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
base.OnPropertyChanged(change);
if (change.Property == WordWrapProperty)
{
if (WordWrap)
{
_horizontalScrollBarVisibilityBck = HorizontalScrollBarVisibility;
HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
}
else
{
HorizontalScrollBarVisibility = _horizontalScrollBarVisibilityBck;
}
}
}
private void OnUndoStackPropertyChangedHandler(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsOriginalFile")
{
HandleIsOriginalChanged(e);
}
}
private void OnTextChanged(object sender, EventArgs e)
{
OnTextChanged(e);
}
#endregion
#region Text property
/// <summary>
/// Gets/Sets the text of the current document.
/// </summary>
public string Text
{
get
{
var document = Document;
return document != null ? document.Text : string.Empty;
}
set
{
var document = GetDocument();
document.Text = value ?? string.Empty;
// after replacing the full text, the caret is positioned at the end of the document
// - reset it to the beginning.
CaretOffset = 0;
document.UndoStack.ClearAll();
}
}
private TextDocument GetDocument()
{
var document = Document;
if (document == null)
throw ThrowUtil.NoDocumentAssigned();
return document;
}
/// <summary>
/// Occurs when the Text property changes.
/// </summary>
public event EventHandler TextChanged;
/// <summary>
/// Raises the <see cref="TextChanged"/> event.
/// </summary>
protected virtual void OnTextChanged(EventArgs e)
{
TextChanged?.Invoke(this, e);
}
#endregion
#region TextArea / ScrollViewer properties
private readonly TextArea textArea;
private SearchPanel searchPanel;
private bool wasSearchPanelOpened;
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
ScrollViewer = (ScrollViewer)e.NameScope.Find("PART_ScrollViewer");
ScrollViewer.Content = TextArea;
searchPanel = SearchPanel.Install(this);
}
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnAttachedToLogicalTree(e);
if (searchPanel != null && wasSearchPanelOpened)
{
searchPanel.Open();
}
}
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnDetachedFromLogicalTree(e);
if (searchPanel != null)
{
wasSearchPanelOpened = searchPanel.IsOpened;
if (searchPanel.IsOpened)
searchPanel.Close();
}
}
/// <summary>
/// Gets the text area.
/// </summary>
public TextArea TextArea => textArea;
/// <summary>
/// Gets the search panel.
/// </summary>
public SearchPanel SearchPanel => searchPanel;
/// <summary>
/// Gets the scroll viewer used by the text editor.
/// This property can return null if the template has not been applied / does not contain a scroll viewer.
/// </summary>
internal ScrollViewer ScrollViewer { get; private set; }
#endregion
#region Syntax highlighting
/// <summary>
/// The <see cref="SyntaxHighlighting"/> property.
/// </summary>
public static readonly StyledProperty<IHighlightingDefinition> SyntaxHighlightingProperty =
AvaloniaProperty.Register<TextEditor, IHighlightingDefinition>("SyntaxHighlighting");
/// <summary>
/// Gets/sets the syntax highlighting definition used to colorize the text.
/// </summary>
public IHighlightingDefinition SyntaxHighlighting
{
get => GetValue(SyntaxHighlightingProperty);
set => SetValue(SyntaxHighlightingProperty, value);
}
private IVisualLineTransformer _colorizer;
private static void OnSyntaxHighlightingChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnSyntaxHighlightingChanged(e.NewValue as IHighlightingDefinition);
}
private void OnSyntaxHighlightingChanged(IHighlightingDefinition newValue)
{
if (_colorizer != null)
{
textArea.TextView.LineTransformers.Remove(_colorizer);
_colorizer = null;
}
if (newValue != null)
{
_colorizer = CreateColorizer(newValue);
if (_colorizer != null)
{
textArea.TextView.LineTransformers.Insert(0, _colorizer);
}
}
}
/// <summary>
/// Creates the highlighting colorizer for the specified highlighting definition.
/// Allows derived classes to provide custom colorizer implementations for special highlighting definitions.
/// </summary>
/// <returns></returns>
protected virtual IVisualLineTransformer CreateColorizer(IHighlightingDefinition highlightingDefinition)
{
if (highlightingDefinition == null)
throw new ArgumentNullException(nameof(highlightingDefinition));
return new HighlightingColorizer(highlightingDefinition);
}
#endregion
#region WordWrap
/// <summary>
/// Word wrap dependency property.
/// </summary>
public static readonly StyledProperty<bool> WordWrapProperty =
AvaloniaProperty.Register<TextEditor, bool>("WordWrap");
/// <summary>
/// Specifies whether the text editor uses word wrapping.
/// </summary>
/// <remarks>
/// Setting WordWrap=true has the same effect as setting HorizontalScrollBarVisibility=Disabled and will override the
/// HorizontalScrollBarVisibility setting.
/// </remarks>
public bool WordWrap
{
get => GetValue(WordWrapProperty);
set => SetValue(WordWrapProperty, value);
}
#endregion
#region IsReadOnly
/// <summary>
/// IsReadOnly dependency property.
/// </summary>
public static readonly StyledProperty<bool> IsReadOnlyProperty =
AvaloniaProperty.Register<TextEditor, bool>("IsReadOnly");
/// <summary>
/// Specifies whether the user can change the text editor content.
/// Setting this property will replace the
/// <see cref="Editing.TextArea.ReadOnlySectionProvider">TextArea.ReadOnlySectionProvider</see>.
/// </summary>
public bool IsReadOnly
{
get => GetValue(IsReadOnlyProperty);
set => SetValue(IsReadOnlyProperty, value);
}
private static void OnIsReadOnlyChanged(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is TextEditor editor)
{
if ((bool)e.NewValue)
editor.TextArea.ReadOnlySectionProvider = ReadOnlySectionDocument.Instance;
else
editor.TextArea.ReadOnlySectionProvider = NoReadOnlySections.Instance;
}
}
#endregion
#region IsModified
/// <summary>
/// Dependency property for <see cref="IsModified"/>
/// </summary>
public static readonly StyledProperty<bool> IsModifiedProperty =
AvaloniaProperty.Register<TextEditor, bool>("IsModified");
/// <summary>
/// Gets/Sets the 'modified' flag.
/// </summary>
public bool IsModified
{
get => GetValue(IsModifiedProperty);
set => SetValue(IsModifiedProperty, value);
}
private static void OnIsModifiedChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
var document = editor?.Document;
if (document != null)
{
var undoStack = document.UndoStack;
if ((bool)e.NewValue)
{
if (undoStack.IsOriginalFile)
undoStack.DiscardOriginalFileMarker();
}
else
{
undoStack.MarkAsOriginalFile();
}
}
}
private void HandleIsOriginalChanged(PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsOriginalFile")
{
var document = Document;
if (document != null)
{
SetValue(IsModifiedProperty, (object)!document.UndoStack.IsOriginalFile);
}
}
}
#endregion
#region ShowLineNumbers
/// <summary>
/// ShowLineNumbers dependency property.
/// </summary>
public static readonly StyledProperty<bool> ShowLineNumbersProperty =
AvaloniaProperty.Register<TextEditor, bool>("ShowLineNumbers");
/// <summary>
/// Specifies whether line numbers are shown on the left to the text view.
/// </summary>
public bool ShowLineNumbers
{
get => GetValue(ShowLineNumbersProperty);
set => SetValue(ShowLineNumbersProperty, value);
}
private static void OnShowLineNumbersChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
if (editor == null) return;
var leftMargins = editor.TextArea.LeftMargins;
if ((bool)e.NewValue)
{
var lineNumbers = new LineNumberMargin();
var line = (Line)DottedLineMargin.Create();
leftMargins.Insert(0, lineNumbers);
leftMargins.Insert(1, line);
var lineNumbersForeground = new Binding("LineNumbersForeground") { Source = editor };
line.Bind(Shape.StrokeProperty, lineNumbersForeground);
lineNumbers.Bind(ForegroundProperty, lineNumbersForeground);
}
else
{
for (var i = 0; i < leftMargins.Count; i++)
{
if (leftMargins[i] is LineNumberMargin)
{
leftMargins.RemoveAt(i);
if (i < leftMargins.Count && DottedLineMargin.IsDottedLineMargin(leftMargins[i]))
{
leftMargins.RemoveAt(i);
}
break;
}
}
}
}
#endregion
#region LineNumbersForeground
/// <summary>
/// LineNumbersForeground dependency property.
/// </summary>
public static readonly StyledProperty<IBrush> LineNumbersForegroundProperty =
AvaloniaProperty.Register<TextEditor, IBrush>("LineNumbersForeground", Brushes.Gray);
/// <summary>
/// Gets/sets the Brush used for displaying the foreground color of line numbers.
/// </summary>
public IBrush LineNumbersForeground
{
get => GetValue(LineNumbersForegroundProperty);
set => SetValue(LineNumbersForegroundProperty, value);
}
private static void OnLineNumbersForegroundChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
var lineNumberMargin = editor?.TextArea.LeftMargins.FirstOrDefault(margin => margin is LineNumberMargin) as LineNumberMargin;
lineNumberMargin?.SetValue(ForegroundProperty, e.NewValue);
}
private static void OnFontFamilyPropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
editor?.TextArea.TextView.SetValue(FontFamilyProperty, e.NewValue);
}
private static void OnFontSizePropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
editor?.TextArea.TextView.SetValue(FontSizeProperty, e.NewValue);
}
#endregion
#region TextBoxBase-like methods
/// <summary>
/// Appends text to the end of the document.
/// </summary>
public void AppendText(string textData)
{
var document = GetDocument();
document.Insert(document.TextLength, textData);
}
/// <summary>
/// Begins a group of document changes.
/// </summary>
public void BeginChange()
{
GetDocument().BeginUpdate();
}
/// <summary>
/// Copies the current selection to the clipboard.
/// </summary>
public void Copy()
{
if (CanCopy)
{
ApplicationCommands.Copy.Execute(null, TextArea);
}
}
/// <summary>
/// Removes the current selection and copies it to the clipboard.
/// </summary>
public void Cut()
{
if (CanCut)
{
ApplicationCommands.Cut.Execute(null, TextArea);
}
}
/// <summary>
/// Begins a group of document changes and returns an object that ends the group of document
/// changes when it is disposed.
/// </summary>
public IDisposable DeclareChangeBlock()
{
return GetDocument().RunUpdate();
}
/// <summary>
/// Removes the current selection without copying it to the clipboard.
/// </summary>
public void Delete()
{
if(CanDelete)
{
ApplicationCommands.Delete.Execute(null, TextArea);
}
}
/// <summary>
/// Ends the current group of document changes.
/// </summary>
public void EndChange()
{
GetDocument().EndUpdate();
}
/// <summary>
/// Scrolls one line down.
/// </summary>
public void LineDown()
{
//if (scrollViewer != null)
// scrollViewer.LineDown();
}
/// <summary>
/// Scrolls to the left.
/// </summary>
public void LineLeft()
{
//if (scrollViewer != null)
// scrollViewer.LineLeft();
}
/// <summary>
/// Scrolls to the right.
/// </summary>
public void LineRight()
{
//if (scrollViewer != null)
// scrollViewer.LineRight();
}
/// <summary>
/// Scrolls one line up.
/// </summary>
public void LineUp()
{
//if (scrollViewer != null)
// scrollViewer.LineUp();
}
/// <summary>
/// Scrolls one page down.
/// </summary>
public void PageDown()
{
//if (scrollViewer != null)
// scrollViewer.PageDown();
}
/// <summary>
/// Scrolls one page up.
/// </summary>
public void PageUp()
{
//if (scrollViewer != null)
// scrollViewer.PageUp();
}
/// <summary>
/// Scrolls one page left.
/// </summary>
public void PageLeft()
{
//if (scrollViewer != null)
// scrollViewer.PageLeft();
}
/// <summary>
/// Scrolls one page right.
/// </summary>
public void PageRight()
{
//if (scrollViewer != null)
// scrollViewer.PageRight();
}
/// <summary>
/// Pastes the clipboard content.
/// </summary>
public void Paste()
{
if (CanPaste)
{
ApplicationCommands.Paste.Execute(null, TextArea);
}
}
/// <summary>
/// Redoes the most recent undone command.
/// </summary>
/// <returns>True is the redo operation was successful, false is the redo stack is empty.</returns>
public bool Redo()
{
if (CanRedo)
{
ApplicationCommands.Redo.Execute(null, TextArea);
return true;
}
return false;
}
/// <summary>
/// Scrolls to the end of the document.
/// </summary>
public void ScrollToEnd()
{
ApplyTemplate(); // ensure scrollViewer is created
ScrollViewer?.ScrollToEnd();
}
/// <summary>
/// Scrolls to the start of the document.
/// </summary>
public void ScrollToHome()
{
ApplyTemplate(); // ensure scrollViewer is created
ScrollViewer?.ScrollToHome();
}
/// <summary>
/// Scrolls to the specified position in the document.
/// </summary>
public void ScrollToHorizontalOffset(double offset)
{
ApplyTemplate(); // ensure scrollViewer is created
//if (scrollViewer != null)
// scrollViewer.ScrollToHorizontalOffset(offset);
}
/// <summary>
/// Scrolls to the specified position in the document.
/// </summary>
public void ScrollToVerticalOffset(double offset)
{
ApplyTemplate(); // ensure scrollViewer is created
//if (scrollViewer != null)
// scrollViewer.ScrollToVerticalOffset(offset);
}
/// <summary>
/// Selects the entire text.
/// </summary>
public void SelectAll()
{
if (CanSelectAll)
{
ApplicationCommands.SelectAll.Execute(null, TextArea);
}
}
/// <summary>
/// Undoes the most recent command.
/// </summary>
/// <returns>True is the undo operation was successful, false is the undo stack is empty.</returns>
public bool Undo()
{
if (CanUndo)
{
ApplicationCommands.Undo.Execute(null, TextArea);
return true;
}
return false;
}
/// <summary>
/// Gets if the most recent undone command can be redone.
/// </summary>
public bool CanRedo
{
get { return ApplicationCommands.Redo.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if the most recent command can be undone.
/// </summary>
public bool CanUndo
{
get { return ApplicationCommands.Undo.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be copied
/// </summary>
public bool CanCopy
{
get { return ApplicationCommands.Copy.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be cut
/// </summary>
public bool CanCut
{
get { return ApplicationCommands.Cut.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be pasted
/// </summary>
public bool CanPaste
{
get { return ApplicationCommands.Paste.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if selected text in editor can be deleted
/// </summary>
public bool CanDelete
{
get { return ApplicationCommands.Delete.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text the editor can select all
/// </summary>
public bool CanSelectAll
{
get { return ApplicationCommands.SelectAll.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text editor can activate the search panel
/// </summary>
public bool CanSearch
{
get { return searchPanel != null; }
}
/// <summary>
/// Gets the vertical size of the document.
/// </summary>
public double ExtentHeight => ScrollViewer?.Extent.Height ?? 0;
/// <summary>
/// Gets the horizontal size of the current document region.
/// </summary>
public double ExtentWidth => ScrollViewer?.Extent.Width ?? 0;
/// <summary>
/// Gets the horizontal size of the viewport.
/// </summary>
public double ViewportHeight => ScrollViewer?.Viewport.Height ?? 0;
/// <summary>
/// Gets the horizontal size of the viewport.
/// </summary>
public double ViewportWidth => ScrollViewer?.Viewport.Width ?? 0;
/// <summary>
/// Gets the vertical scroll position.
/// </summary>
public double VerticalOffset => ScrollViewer?.Offset.Y ?? 0;
/// <summary>
/// Gets the horizontal scroll position.
/// </summary>
public double HorizontalOffset => ScrollViewer?.Offset.X ?? 0;
#endregion
#region TextBox methods
/// <summary>
/// Gets/Sets the selected text.
/// </summary>
public string SelectedText
{
get
{
// We'll get the text from the whole surrounding segment.
// This is done to ensure that SelectedText.Length == SelectionLength.
if (textArea.Document != null && !textArea.Selection.IsEmpty)
return textArea.Document.GetText(textArea.Selection.SurroundingSegment);
return string.Empty;
}
set
{
if (value == null)
throw new ArgumentNullException(nameof(value));
var textArea = TextArea;
if (textArea.Document != null)
{
var offset = SelectionStart;
var length = SelectionLength;
textArea.Document.Replace(offset, length, value);
// keep inserted text selected
textArea.Selection = Selection.Create(textArea, offset, offset + value.Length);
}
}
}
/// <summary>
/// Gets/sets the caret position.
/// </summary>
public int CaretOffset
{
get
{
return textArea.Caret.Offset;
}
set
{
textArea.Caret.Offset = value;
}
}
/// <summary>
/// Gets/sets the start position of the selection.
/// </summary>
public int SelectionStart
{
get
{
if (textArea.Selection.IsEmpty)
return textArea.Caret.Offset;
else
return textArea.Selection.SurroundingSegment.Offset;
}
set => Select(value, SelectionLength);
}
/// <summary>
/// Gets/sets the length of the selection.
/// </summary>
public int SelectionLength
{
get
{
if (!textArea.Selection.IsEmpty)
return textArea.Selection.SurroundingSegment.Length;
else
return 0;
}
set => Select(SelectionStart, value);
}
/// <summary>
/// Selects the specified text section.
/// </summary>
public void Select(int start, int length)
{
var documentLength = Document?.TextLength ?? 0;
if (start < 0 || start > documentLength)
throw new ArgumentOutOfRangeException(nameof(start), start, "Value must be between 0 and " + documentLength);
if (length < 0 || start + length > documentLength)
throw new ArgumentOutOfRangeException(nameof(length), length, "Value must be between 0 and " + (documentLength - start));
TextArea.Selection = Selection.Create(TextArea, start, start + length);
TextArea.Caret.Offset = start + length;
}
/// <summary>
/// Gets the number of lines in the document.
/// </summary>
public int LineCount
{
get
{
var document = Document;
if (document != null)
return document.LineCount;
return 1;
}
}
/// <summary>
/// Clears the text.
/// </summary>
public void Clear()
{
Text = string.Empty;
}
#endregion
#region Loading from stream
/// <summary>
/// Loads the text from the stream, auto-detecting the encoding.
/// </summary>
/// <remarks>
/// This method sets <see cref="IsModified"/> to false.
/// </remarks>
public void Load(Stream stream)
{
using (var reader = FileReader.OpenStream(stream, Encoding ?? Encoding.UTF8))
{
Text = reader.ReadToEnd();
SetValue(EncodingProperty, (object)reader.CurrentEncoding);
}
SetValue(IsModifiedProperty, (object)false);
}
/// <summary>
/// Loads the text from the stream, auto-detecting the encoding.
/// </summary>
public void Load(string fileName)
{
if (fileName == null)
throw new ArgumentNullException(nameof(fileName));
// TODO:load
//using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
//{
// Load(fs);
//}
}
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
public static readonly AvaloniaProperty HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
get => (ScrollBarVisibility)GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
public static readonly AvaloniaProperty VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
get => (ScrollBarVisibility)GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
if (stream == null)
throw new ArgumentNullException(nameof(stream));
var encoding = Encoding;
var document = Document;
var writer = encoding != null ? new StreamWriter(stream, encoding) : new StreamWriter(stream);
document?.WriteTextTo(writer);
writer.Flush();
// do not close the stream
SetValue(IsModifiedProperty, (object)false);
}
/// <summary>
/// Saves the text to the file.
/// </summary>
public void Save(string fileName)
{
if (fileName == null)
throw new ArgumentNullException(nameof(fileName));
// TODO: save
//using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
//{
// Save(fs);
//}
}
#endregion
#region PointerHover events
/// <summary>
/// The PreviewPointerHover event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PreviewPointerHoverEvent =
TextView.PreviewPointerHoverEvent;
/// <summary>
/// the pointerHover event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PointerHoverEvent =
TextView.PointerHoverEvent;
/// <summary>
/// The PreviewPointerHoverStopped event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PreviewPointerHoverStoppedEvent =
TextView.PreviewPointerHoverStoppedEvent;
/// <summary>
/// the pointerHoverStopped event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PointerHoverStoppedEvent =
TextView.PointerHoverStoppedEvent;
/// <summary>
/// Occurs when the pointer has hovered over a fixed location for some time.
/// </summary>
public event EventHandler<PointerEventArgs> PreviewPointerHover
{
add => AddHandler(PreviewPointerHoverEvent, value);
remove => RemoveHandler(PreviewPointerHoverEvent, value);
}
/// <summary>
/// Occurs when the pointer has hovered over a fixed location for some time.
/// </summary>
public event EventHandler<PointerEventArgs> PointerHover
{
add => AddHandler(PointerHoverEvent, value);
remove => RemoveHandler(PointerHoverEvent, value);
}
/// <summary>
/// Occurs when the pointer had previously hovered but now started moving again.
/// </summary>
public event EventHandler<PointerEventArgs> PreviewPointerHoverStopped
{
add => AddHandler(PreviewPointerHoverStoppedEvent, value);
remove => RemoveHandler(PreviewPointerHoverStoppedEvent, value);
}
/// <summary>
/// Occurs when the pointer had previously hovered but now started moving again.
/// </summary>
public event EventHandler<PointerEventArgs> PointerHoverStopped
{
add => AddHandler(PointerHoverStoppedEvent, value);
remove => RemoveHandler(PointerHoverStoppedEvent, value);
}
#endregion
#region ScrollBarVisibility
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
public static readonly AttachedProperty<ScrollBarVisibility> HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
get => GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
private ScrollBarVisibility _horizontalScrollBarVisibilityBck = ScrollBarVisibility.Auto;
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
public static readonly AttachedProperty<ScrollBarVisibility> VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
get => GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
object IServiceProvider.GetService(Type serviceType)
{
return TextArea.GetService(serviceType);
}
/// <summary>
/// Gets the text view position from a point inside the editor.
/// </summary>
/// <param name="point">The position, relative to top left
/// corner of TextEditor control</param>
/// <returns>The text view position, or null if the point is outside the document.</returns>
public TextViewPosition? GetPositionFromPoint(Point point)
{
if (Document == null)
return null;
var textView = TextArea.TextView;
Point tpoint = (Point)this.TranslatePoint(point + new Point(textView.ScrollOffset.X, Math.Floor(textView.ScrollOffset.Y)), textView);
return textView.GetPosition(tpoint);
}
/// <summary>
/// Scrolls to the specified line.
/// This method requires that the TextEditor was already assigned a size (layout engine must have run prior).
/// </summary>
public void ScrollToLine(int line)
{
ScrollTo(line, -1);
}
/// <summary>
/// Scrolls to the specified line/column.
/// This method requires that the TextEditor was already assigned a size (layout engine must have run prior).
/// </summary>
public void ScrollTo(int line, int column)
{
const double MinimumScrollFraction = 0.3;
ScrollTo(line, column, VisualYPosition.LineMiddle,
null != ScrollViewer ? ScrollViewer.Viewport.Height / 2 : 0.0, MinimumScrollFraction);
}
/// <summary>
/// Scrolls to the specified line/column.
/// This method requires that the TextEditor was already assigned a size (WPF layout must have run prior).
/// </summary>
/// <param name="line">Line to scroll to.</param>
/// <param name="column">Column to scroll to (important if wrapping is 'on', and for the horizontal scroll position).</param>
/// <param name="yPositionMode">The mode how to reference the Y position of the line.</param>
/// <param name="referencedVerticalViewPortOffset">Offset from the top of the viewport to where the referenced line/column should be positioned.</param>
/// <param name="minimumScrollFraction">The minimum vertical and/or horizontal scroll offset, expressed as fraction of the height or width of the viewport window, respectively.</param>
public void ScrollTo(int line, int column, VisualYPosition yPositionMode,
double referencedVerticalViewPortOffset, double minimumScrollFraction)
{
TextView textView = textArea.TextView;
TextDocument document = textView.Document;
if (ScrollViewer != null && document != null)
{
if (line < 1)
line = 1;
if (line > document.LineCount)
line = document.LineCount;
ILogicalScrollable scrollInfo = textView;
if (!scrollInfo.CanHorizontallyScroll)
{
// Word wrap is enabled. Ensure that we have up-to-date info about line height so that we scroll
// to the correct position.
// This avoids that the user has to repeat the ScrollTo() call several times when there are very long lines.
VisualLine vl = textView.GetOrConstructVisualLine(document.GetLineByNumber(line));
double remainingHeight = referencedVerticalViewPortOffset;
while (remainingHeight > 0)
{
DocumentLine prevLine = vl.FirstDocumentLine.PreviousLine;
if (prevLine == null)
break;
vl = textView.GetOrConstructVisualLine(prevLine);
remainingHeight -= vl.Height;
}
}
Point p = textArea.TextView.GetVisualPosition(
new TextViewPosition(line, Math.Max(1, column)),
yPositionMode);
double targetX = ScrollViewer.Offset.X;
double targetY = ScrollViewer.Offset.Y;
double verticalPos = p.Y - referencedVerticalViewPortOffset;
if (Math.Abs(verticalPos - ScrollViewer.Offset.Y) >
minimumScrollFraction * ScrollViewer.Viewport.Height)
{
targetY = Math.Max(0, verticalPos);
}
if (column > 0)
{
if (p.X > ScrollViewer.Viewport.Width - Caret.MinimumDistanceToViewBorder * 2)
{
double horizontalPos = Math.Max(0, p.X - ScrollViewer.Viewport.Width / 2);
if (Math.Abs(horizontalPos - ScrollViewer.Offset.X) >
minimumScrollFraction * ScrollViewer.Viewport.Width)
{
targetX = 0;
}
}
else
{
targetX = 0;
}
}
if (targetX != ScrollViewer.Offset.X || targetY != ScrollViewer.Offset.Y)
ScrollViewer.Offset = new Vector(targetX, targetY);
}
}
}
}
<MSG> Merge pull request #73 from jeffreye/fix-scroll
Fix scroll
<DFF> @@ -47,6 +47,8 @@ namespace AvaloniaEdit
static TextEditor()
{
FocusableProperty.OverrideDefaultValue<TextEditor>(true);
+ HorizontalScrollBarVisibilityProperty.OverrideDefaultValue<TextEditor>(ScrollBarVisibility.Auto);
+ VerticalScrollBarVisibilityProperty.OverrideDefaultValue<TextEditor>(ScrollBarVisibility.Auto);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
@@ -1049,28 +1051,28 @@ namespace AvaloniaEdit
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
- public static readonly AvaloniaProperty HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
+ public static readonly AttachedProperty<ScrollBarVisibility> HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
- get => (ScrollBarVisibility)GetValue(HorizontalScrollBarVisibilityProperty);
+ get => GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
- public static readonly AvaloniaProperty VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
+ public static readonly AttachedProperty<ScrollBarVisibility> VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
- get => (ScrollBarVisibility)GetValue(VerticalScrollBarVisibilityProperty);
+ get => GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
| 6 | Merge pull request #73 from jeffreye/fix-scroll | 4 | .cs | cs | mit | AvaloniaUI/AvaloniaEdit |
10066907 | <NME> TextEditor.cs
<BEF> // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using Avalonia;
using AvaloniaEdit.Document;
using AvaloniaEdit.Editing;
using AvaloniaEdit.Highlighting;
using AvaloniaEdit.Rendering;
using AvaloniaEdit.Utils;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Shapes;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.LogicalTree;
using Avalonia.Media;
using Avalonia.Data;
using AvaloniaEdit.Search;
namespace AvaloniaEdit
{
/// <summary>
/// The text editor control.
/// Contains a scrollable TextArea.
/// </summary>
public class TextEditor : TemplatedControl, ITextEditorComponent
static TextEditor()
{
FocusableProperty.OverrideDefaultValue<TextEditor>(true);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
SyntaxHighlightingProperty.Changed.Subscribe(OnSyntaxHighlightingChanged);
IsReadOnlyProperty.Changed.Subscribe(OnIsReadOnlyChanged);
IsModifiedProperty.Changed.Subscribe(OnIsModifiedChanged);
ShowLineNumbersProperty.Changed.Subscribe(OnShowLineNumbersChanged);
LineNumbersForegroundProperty.Changed.Subscribe(OnLineNumbersForegroundChanged);
FontFamilyProperty.Changed.Subscribe(OnFontFamilyPropertyChanged);
FontSizeProperty.Changed.Subscribe(OnFontSizePropertyChanged);
}
/// <summary>
/// Creates a new TextEditor instance.
/// </summary>
public TextEditor() : this(new TextArea())
{
}
/// <summary>
/// Creates a new TextEditor instance.
/// </summary>
protected TextEditor(TextArea textArea) : this(textArea, new TextDocument())
{
}
protected TextEditor(TextArea textArea, TextDocument document)
{
this.textArea = textArea ?? throw new ArgumentNullException(nameof(textArea));
textArea.TextView.Services.AddService(this);
SetValue(OptionsProperty, textArea.Options);
SetValue(DocumentProperty, document);
textArea[!BackgroundProperty] = this[!BackgroundProperty];
}
#endregion
protected override void OnGotFocus(GotFocusEventArgs e)
{
base.OnGotFocus(e);
TextArea.Focus();
e.Handled = true;
}
#region Document property
/// <summary>
/// Document property.
/// </summary>
public static readonly StyledProperty<TextDocument> DocumentProperty
= TextView.DocumentProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the document displayed by the text editor.
/// This is a dependency property.
/// </summary>
public TextDocument Document
{
get => GetValue(DocumentProperty);
set => SetValue(DocumentProperty, value);
}
/// <summary>
/// Occurs when the document property has changed.
/// </summary>
public event EventHandler DocumentChanged;
/// <summary>
/// Raises the <see cref="DocumentChanged"/> event.
/// </summary>
protected virtual void OnDocumentChanged(EventArgs e)
{
DocumentChanged?.Invoke(this, e);
}
private static void OnDocumentChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnDocumentChanged((TextDocument)e.OldValue, (TextDocument)e.NewValue);
}
private void OnDocumentChanged(TextDocument oldValue, TextDocument newValue)
{
if (oldValue != null)
{
TextDocumentWeakEventManager.TextChanged.RemoveHandler(oldValue, OnTextChanged);
PropertyChangedWeakEventManager.RemoveHandler(oldValue.UndoStack, OnUndoStackPropertyChangedHandler);
}
TextArea.Document = newValue;
if (newValue != null)
{
TextDocumentWeakEventManager.TextChanged.AddHandler(newValue, OnTextChanged);
PropertyChangedWeakEventManager.AddHandler(newValue.UndoStack, OnUndoStackPropertyChangedHandler);
}
OnDocumentChanged(EventArgs.Empty);
OnTextChanged(EventArgs.Empty);
}
#endregion
#region Options property
/// <summary>
/// Options property.
/// </summary>
public static readonly StyledProperty<TextEditorOptions> OptionsProperty
= TextView.OptionsProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the options currently used by the text editor.
/// </summary>
public TextEditorOptions Options
{
get => GetValue(OptionsProperty);
set => SetValue(OptionsProperty, value);
}
/// <summary>
/// Occurs when a text editor option has changed.
/// </summary>
public event PropertyChangedEventHandler OptionChanged;
/// <summary>
/// Raises the <see cref="OptionChanged"/> event.
/// </summary>
protected virtual void OnOptionChanged(PropertyChangedEventArgs e)
{
OptionChanged?.Invoke(this, e);
}
private static void OnOptionsChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnOptionsChanged((TextEditorOptions)e.OldValue, (TextEditorOptions)e.NewValue);
}
private void OnOptionsChanged(TextEditorOptions oldValue, TextEditorOptions newValue)
{
if (oldValue != null)
{
PropertyChangedWeakEventManager.RemoveHandler(oldValue, OnPropertyChangedHandler);
}
TextArea.Options = newValue;
if (newValue != null)
{
PropertyChangedWeakEventManager.AddHandler(newValue, OnPropertyChangedHandler);
}
OnOptionChanged(new PropertyChangedEventArgs(null));
}
private void OnPropertyChangedHandler(object sender, PropertyChangedEventArgs e)
{
OnOptionChanged(e);
}
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
base.OnPropertyChanged(change);
if (change.Property == WordWrapProperty)
{
if (WordWrap)
{
_horizontalScrollBarVisibilityBck = HorizontalScrollBarVisibility;
HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
}
else
{
HorizontalScrollBarVisibility = _horizontalScrollBarVisibilityBck;
}
}
}
private void OnUndoStackPropertyChangedHandler(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsOriginalFile")
{
HandleIsOriginalChanged(e);
}
}
private void OnTextChanged(object sender, EventArgs e)
{
OnTextChanged(e);
}
#endregion
#region Text property
/// <summary>
/// Gets/Sets the text of the current document.
/// </summary>
public string Text
{
get
{
var document = Document;
return document != null ? document.Text : string.Empty;
}
set
{
var document = GetDocument();
document.Text = value ?? string.Empty;
// after replacing the full text, the caret is positioned at the end of the document
// - reset it to the beginning.
CaretOffset = 0;
document.UndoStack.ClearAll();
}
}
private TextDocument GetDocument()
{
var document = Document;
if (document == null)
throw ThrowUtil.NoDocumentAssigned();
return document;
}
/// <summary>
/// Occurs when the Text property changes.
/// </summary>
public event EventHandler TextChanged;
/// <summary>
/// Raises the <see cref="TextChanged"/> event.
/// </summary>
protected virtual void OnTextChanged(EventArgs e)
{
TextChanged?.Invoke(this, e);
}
#endregion
#region TextArea / ScrollViewer properties
private readonly TextArea textArea;
private SearchPanel searchPanel;
private bool wasSearchPanelOpened;
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
ScrollViewer = (ScrollViewer)e.NameScope.Find("PART_ScrollViewer");
ScrollViewer.Content = TextArea;
searchPanel = SearchPanel.Install(this);
}
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnAttachedToLogicalTree(e);
if (searchPanel != null && wasSearchPanelOpened)
{
searchPanel.Open();
}
}
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnDetachedFromLogicalTree(e);
if (searchPanel != null)
{
wasSearchPanelOpened = searchPanel.IsOpened;
if (searchPanel.IsOpened)
searchPanel.Close();
}
}
/// <summary>
/// Gets the text area.
/// </summary>
public TextArea TextArea => textArea;
/// <summary>
/// Gets the search panel.
/// </summary>
public SearchPanel SearchPanel => searchPanel;
/// <summary>
/// Gets the scroll viewer used by the text editor.
/// This property can return null if the template has not been applied / does not contain a scroll viewer.
/// </summary>
internal ScrollViewer ScrollViewer { get; private set; }
#endregion
#region Syntax highlighting
/// <summary>
/// The <see cref="SyntaxHighlighting"/> property.
/// </summary>
public static readonly StyledProperty<IHighlightingDefinition> SyntaxHighlightingProperty =
AvaloniaProperty.Register<TextEditor, IHighlightingDefinition>("SyntaxHighlighting");
/// <summary>
/// Gets/sets the syntax highlighting definition used to colorize the text.
/// </summary>
public IHighlightingDefinition SyntaxHighlighting
{
get => GetValue(SyntaxHighlightingProperty);
set => SetValue(SyntaxHighlightingProperty, value);
}
private IVisualLineTransformer _colorizer;
private static void OnSyntaxHighlightingChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnSyntaxHighlightingChanged(e.NewValue as IHighlightingDefinition);
}
private void OnSyntaxHighlightingChanged(IHighlightingDefinition newValue)
{
if (_colorizer != null)
{
textArea.TextView.LineTransformers.Remove(_colorizer);
_colorizer = null;
}
if (newValue != null)
{
_colorizer = CreateColorizer(newValue);
if (_colorizer != null)
{
textArea.TextView.LineTransformers.Insert(0, _colorizer);
}
}
}
/// <summary>
/// Creates the highlighting colorizer for the specified highlighting definition.
/// Allows derived classes to provide custom colorizer implementations for special highlighting definitions.
/// </summary>
/// <returns></returns>
protected virtual IVisualLineTransformer CreateColorizer(IHighlightingDefinition highlightingDefinition)
{
if (highlightingDefinition == null)
throw new ArgumentNullException(nameof(highlightingDefinition));
return new HighlightingColorizer(highlightingDefinition);
}
#endregion
#region WordWrap
/// <summary>
/// Word wrap dependency property.
/// </summary>
public static readonly StyledProperty<bool> WordWrapProperty =
AvaloniaProperty.Register<TextEditor, bool>("WordWrap");
/// <summary>
/// Specifies whether the text editor uses word wrapping.
/// </summary>
/// <remarks>
/// Setting WordWrap=true has the same effect as setting HorizontalScrollBarVisibility=Disabled and will override the
/// HorizontalScrollBarVisibility setting.
/// </remarks>
public bool WordWrap
{
get => GetValue(WordWrapProperty);
set => SetValue(WordWrapProperty, value);
}
#endregion
#region IsReadOnly
/// <summary>
/// IsReadOnly dependency property.
/// </summary>
public static readonly StyledProperty<bool> IsReadOnlyProperty =
AvaloniaProperty.Register<TextEditor, bool>("IsReadOnly");
/// <summary>
/// Specifies whether the user can change the text editor content.
/// Setting this property will replace the
/// <see cref="Editing.TextArea.ReadOnlySectionProvider">TextArea.ReadOnlySectionProvider</see>.
/// </summary>
public bool IsReadOnly
{
get => GetValue(IsReadOnlyProperty);
set => SetValue(IsReadOnlyProperty, value);
}
private static void OnIsReadOnlyChanged(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is TextEditor editor)
{
if ((bool)e.NewValue)
editor.TextArea.ReadOnlySectionProvider = ReadOnlySectionDocument.Instance;
else
editor.TextArea.ReadOnlySectionProvider = NoReadOnlySections.Instance;
}
}
#endregion
#region IsModified
/// <summary>
/// Dependency property for <see cref="IsModified"/>
/// </summary>
public static readonly StyledProperty<bool> IsModifiedProperty =
AvaloniaProperty.Register<TextEditor, bool>("IsModified");
/// <summary>
/// Gets/Sets the 'modified' flag.
/// </summary>
public bool IsModified
{
get => GetValue(IsModifiedProperty);
set => SetValue(IsModifiedProperty, value);
}
private static void OnIsModifiedChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
var document = editor?.Document;
if (document != null)
{
var undoStack = document.UndoStack;
if ((bool)e.NewValue)
{
if (undoStack.IsOriginalFile)
undoStack.DiscardOriginalFileMarker();
}
else
{
undoStack.MarkAsOriginalFile();
}
}
}
private void HandleIsOriginalChanged(PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsOriginalFile")
{
var document = Document;
if (document != null)
{
SetValue(IsModifiedProperty, (object)!document.UndoStack.IsOriginalFile);
}
}
}
#endregion
#region ShowLineNumbers
/// <summary>
/// ShowLineNumbers dependency property.
/// </summary>
public static readonly StyledProperty<bool> ShowLineNumbersProperty =
AvaloniaProperty.Register<TextEditor, bool>("ShowLineNumbers");
/// <summary>
/// Specifies whether line numbers are shown on the left to the text view.
/// </summary>
public bool ShowLineNumbers
{
get => GetValue(ShowLineNumbersProperty);
set => SetValue(ShowLineNumbersProperty, value);
}
private static void OnShowLineNumbersChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
if (editor == null) return;
var leftMargins = editor.TextArea.LeftMargins;
if ((bool)e.NewValue)
{
var lineNumbers = new LineNumberMargin();
var line = (Line)DottedLineMargin.Create();
leftMargins.Insert(0, lineNumbers);
leftMargins.Insert(1, line);
var lineNumbersForeground = new Binding("LineNumbersForeground") { Source = editor };
line.Bind(Shape.StrokeProperty, lineNumbersForeground);
lineNumbers.Bind(ForegroundProperty, lineNumbersForeground);
}
else
{
for (var i = 0; i < leftMargins.Count; i++)
{
if (leftMargins[i] is LineNumberMargin)
{
leftMargins.RemoveAt(i);
if (i < leftMargins.Count && DottedLineMargin.IsDottedLineMargin(leftMargins[i]))
{
leftMargins.RemoveAt(i);
}
break;
}
}
}
}
#endregion
#region LineNumbersForeground
/// <summary>
/// LineNumbersForeground dependency property.
/// </summary>
public static readonly StyledProperty<IBrush> LineNumbersForegroundProperty =
AvaloniaProperty.Register<TextEditor, IBrush>("LineNumbersForeground", Brushes.Gray);
/// <summary>
/// Gets/sets the Brush used for displaying the foreground color of line numbers.
/// </summary>
public IBrush LineNumbersForeground
{
get => GetValue(LineNumbersForegroundProperty);
set => SetValue(LineNumbersForegroundProperty, value);
}
private static void OnLineNumbersForegroundChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
var lineNumberMargin = editor?.TextArea.LeftMargins.FirstOrDefault(margin => margin is LineNumberMargin) as LineNumberMargin;
lineNumberMargin?.SetValue(ForegroundProperty, e.NewValue);
}
private static void OnFontFamilyPropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
editor?.TextArea.TextView.SetValue(FontFamilyProperty, e.NewValue);
}
private static void OnFontSizePropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
editor?.TextArea.TextView.SetValue(FontSizeProperty, e.NewValue);
}
#endregion
#region TextBoxBase-like methods
/// <summary>
/// Appends text to the end of the document.
/// </summary>
public void AppendText(string textData)
{
var document = GetDocument();
document.Insert(document.TextLength, textData);
}
/// <summary>
/// Begins a group of document changes.
/// </summary>
public void BeginChange()
{
GetDocument().BeginUpdate();
}
/// <summary>
/// Copies the current selection to the clipboard.
/// </summary>
public void Copy()
{
if (CanCopy)
{
ApplicationCommands.Copy.Execute(null, TextArea);
}
}
/// <summary>
/// Removes the current selection and copies it to the clipboard.
/// </summary>
public void Cut()
{
if (CanCut)
{
ApplicationCommands.Cut.Execute(null, TextArea);
}
}
/// <summary>
/// Begins a group of document changes and returns an object that ends the group of document
/// changes when it is disposed.
/// </summary>
public IDisposable DeclareChangeBlock()
{
return GetDocument().RunUpdate();
}
/// <summary>
/// Removes the current selection without copying it to the clipboard.
/// </summary>
public void Delete()
{
if(CanDelete)
{
ApplicationCommands.Delete.Execute(null, TextArea);
}
}
/// <summary>
/// Ends the current group of document changes.
/// </summary>
public void EndChange()
{
GetDocument().EndUpdate();
}
/// <summary>
/// Scrolls one line down.
/// </summary>
public void LineDown()
{
//if (scrollViewer != null)
// scrollViewer.LineDown();
}
/// <summary>
/// Scrolls to the left.
/// </summary>
public void LineLeft()
{
//if (scrollViewer != null)
// scrollViewer.LineLeft();
}
/// <summary>
/// Scrolls to the right.
/// </summary>
public void LineRight()
{
//if (scrollViewer != null)
// scrollViewer.LineRight();
}
/// <summary>
/// Scrolls one line up.
/// </summary>
public void LineUp()
{
//if (scrollViewer != null)
// scrollViewer.LineUp();
}
/// <summary>
/// Scrolls one page down.
/// </summary>
public void PageDown()
{
//if (scrollViewer != null)
// scrollViewer.PageDown();
}
/// <summary>
/// Scrolls one page up.
/// </summary>
public void PageUp()
{
//if (scrollViewer != null)
// scrollViewer.PageUp();
}
/// <summary>
/// Scrolls one page left.
/// </summary>
public void PageLeft()
{
//if (scrollViewer != null)
// scrollViewer.PageLeft();
}
/// <summary>
/// Scrolls one page right.
/// </summary>
public void PageRight()
{
//if (scrollViewer != null)
// scrollViewer.PageRight();
}
/// <summary>
/// Pastes the clipboard content.
/// </summary>
public void Paste()
{
if (CanPaste)
{
ApplicationCommands.Paste.Execute(null, TextArea);
}
}
/// <summary>
/// Redoes the most recent undone command.
/// </summary>
/// <returns>True is the redo operation was successful, false is the redo stack is empty.</returns>
public bool Redo()
{
if (CanRedo)
{
ApplicationCommands.Redo.Execute(null, TextArea);
return true;
}
return false;
}
/// <summary>
/// Scrolls to the end of the document.
/// </summary>
public void ScrollToEnd()
{
ApplyTemplate(); // ensure scrollViewer is created
ScrollViewer?.ScrollToEnd();
}
/// <summary>
/// Scrolls to the start of the document.
/// </summary>
public void ScrollToHome()
{
ApplyTemplate(); // ensure scrollViewer is created
ScrollViewer?.ScrollToHome();
}
/// <summary>
/// Scrolls to the specified position in the document.
/// </summary>
public void ScrollToHorizontalOffset(double offset)
{
ApplyTemplate(); // ensure scrollViewer is created
//if (scrollViewer != null)
// scrollViewer.ScrollToHorizontalOffset(offset);
}
/// <summary>
/// Scrolls to the specified position in the document.
/// </summary>
public void ScrollToVerticalOffset(double offset)
{
ApplyTemplate(); // ensure scrollViewer is created
//if (scrollViewer != null)
// scrollViewer.ScrollToVerticalOffset(offset);
}
/// <summary>
/// Selects the entire text.
/// </summary>
public void SelectAll()
{
if (CanSelectAll)
{
ApplicationCommands.SelectAll.Execute(null, TextArea);
}
}
/// <summary>
/// Undoes the most recent command.
/// </summary>
/// <returns>True is the undo operation was successful, false is the undo stack is empty.</returns>
public bool Undo()
{
if (CanUndo)
{
ApplicationCommands.Undo.Execute(null, TextArea);
return true;
}
return false;
}
/// <summary>
/// Gets if the most recent undone command can be redone.
/// </summary>
public bool CanRedo
{
get { return ApplicationCommands.Redo.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if the most recent command can be undone.
/// </summary>
public bool CanUndo
{
get { return ApplicationCommands.Undo.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be copied
/// </summary>
public bool CanCopy
{
get { return ApplicationCommands.Copy.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be cut
/// </summary>
public bool CanCut
{
get { return ApplicationCommands.Cut.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be pasted
/// </summary>
public bool CanPaste
{
get { return ApplicationCommands.Paste.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if selected text in editor can be deleted
/// </summary>
public bool CanDelete
{
get { return ApplicationCommands.Delete.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text the editor can select all
/// </summary>
public bool CanSelectAll
{
get { return ApplicationCommands.SelectAll.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text editor can activate the search panel
/// </summary>
public bool CanSearch
{
get { return searchPanel != null; }
}
/// <summary>
/// Gets the vertical size of the document.
/// </summary>
public double ExtentHeight => ScrollViewer?.Extent.Height ?? 0;
/// <summary>
/// Gets the horizontal size of the current document region.
/// </summary>
public double ExtentWidth => ScrollViewer?.Extent.Width ?? 0;
/// <summary>
/// Gets the horizontal size of the viewport.
/// </summary>
public double ViewportHeight => ScrollViewer?.Viewport.Height ?? 0;
/// <summary>
/// Gets the horizontal size of the viewport.
/// </summary>
public double ViewportWidth => ScrollViewer?.Viewport.Width ?? 0;
/// <summary>
/// Gets the vertical scroll position.
/// </summary>
public double VerticalOffset => ScrollViewer?.Offset.Y ?? 0;
/// <summary>
/// Gets the horizontal scroll position.
/// </summary>
public double HorizontalOffset => ScrollViewer?.Offset.X ?? 0;
#endregion
#region TextBox methods
/// <summary>
/// Gets/Sets the selected text.
/// </summary>
public string SelectedText
{
get
{
// We'll get the text from the whole surrounding segment.
// This is done to ensure that SelectedText.Length == SelectionLength.
if (textArea.Document != null && !textArea.Selection.IsEmpty)
return textArea.Document.GetText(textArea.Selection.SurroundingSegment);
return string.Empty;
}
set
{
if (value == null)
throw new ArgumentNullException(nameof(value));
var textArea = TextArea;
if (textArea.Document != null)
{
var offset = SelectionStart;
var length = SelectionLength;
textArea.Document.Replace(offset, length, value);
// keep inserted text selected
textArea.Selection = Selection.Create(textArea, offset, offset + value.Length);
}
}
}
/// <summary>
/// Gets/sets the caret position.
/// </summary>
public int CaretOffset
{
get
{
return textArea.Caret.Offset;
}
set
{
textArea.Caret.Offset = value;
}
}
/// <summary>
/// Gets/sets the start position of the selection.
/// </summary>
public int SelectionStart
{
get
{
if (textArea.Selection.IsEmpty)
return textArea.Caret.Offset;
else
return textArea.Selection.SurroundingSegment.Offset;
}
set => Select(value, SelectionLength);
}
/// <summary>
/// Gets/sets the length of the selection.
/// </summary>
public int SelectionLength
{
get
{
if (!textArea.Selection.IsEmpty)
return textArea.Selection.SurroundingSegment.Length;
else
return 0;
}
set => Select(SelectionStart, value);
}
/// <summary>
/// Selects the specified text section.
/// </summary>
public void Select(int start, int length)
{
var documentLength = Document?.TextLength ?? 0;
if (start < 0 || start > documentLength)
throw new ArgumentOutOfRangeException(nameof(start), start, "Value must be between 0 and " + documentLength);
if (length < 0 || start + length > documentLength)
throw new ArgumentOutOfRangeException(nameof(length), length, "Value must be between 0 and " + (documentLength - start));
TextArea.Selection = Selection.Create(TextArea, start, start + length);
TextArea.Caret.Offset = start + length;
}
/// <summary>
/// Gets the number of lines in the document.
/// </summary>
public int LineCount
{
get
{
var document = Document;
if (document != null)
return document.LineCount;
return 1;
}
}
/// <summary>
/// Clears the text.
/// </summary>
public void Clear()
{
Text = string.Empty;
}
#endregion
#region Loading from stream
/// <summary>
/// Loads the text from the stream, auto-detecting the encoding.
/// </summary>
/// <remarks>
/// This method sets <see cref="IsModified"/> to false.
/// </remarks>
public void Load(Stream stream)
{
using (var reader = FileReader.OpenStream(stream, Encoding ?? Encoding.UTF8))
{
Text = reader.ReadToEnd();
SetValue(EncodingProperty, (object)reader.CurrentEncoding);
}
SetValue(IsModifiedProperty, (object)false);
}
/// <summary>
/// Loads the text from the stream, auto-detecting the encoding.
/// </summary>
public void Load(string fileName)
{
if (fileName == null)
throw new ArgumentNullException(nameof(fileName));
// TODO:load
//using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
//{
// Load(fs);
//}
}
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
public static readonly AvaloniaProperty HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
get => (ScrollBarVisibility)GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
public static readonly AvaloniaProperty VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
get => (ScrollBarVisibility)GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
if (stream == null)
throw new ArgumentNullException(nameof(stream));
var encoding = Encoding;
var document = Document;
var writer = encoding != null ? new StreamWriter(stream, encoding) : new StreamWriter(stream);
document?.WriteTextTo(writer);
writer.Flush();
// do not close the stream
SetValue(IsModifiedProperty, (object)false);
}
/// <summary>
/// Saves the text to the file.
/// </summary>
public void Save(string fileName)
{
if (fileName == null)
throw new ArgumentNullException(nameof(fileName));
// TODO: save
//using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
//{
// Save(fs);
//}
}
#endregion
#region PointerHover events
/// <summary>
/// The PreviewPointerHover event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PreviewPointerHoverEvent =
TextView.PreviewPointerHoverEvent;
/// <summary>
/// the pointerHover event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PointerHoverEvent =
TextView.PointerHoverEvent;
/// <summary>
/// The PreviewPointerHoverStopped event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PreviewPointerHoverStoppedEvent =
TextView.PreviewPointerHoverStoppedEvent;
/// <summary>
/// the pointerHoverStopped event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PointerHoverStoppedEvent =
TextView.PointerHoverStoppedEvent;
/// <summary>
/// Occurs when the pointer has hovered over a fixed location for some time.
/// </summary>
public event EventHandler<PointerEventArgs> PreviewPointerHover
{
add => AddHandler(PreviewPointerHoverEvent, value);
remove => RemoveHandler(PreviewPointerHoverEvent, value);
}
/// <summary>
/// Occurs when the pointer has hovered over a fixed location for some time.
/// </summary>
public event EventHandler<PointerEventArgs> PointerHover
{
add => AddHandler(PointerHoverEvent, value);
remove => RemoveHandler(PointerHoverEvent, value);
}
/// <summary>
/// Occurs when the pointer had previously hovered but now started moving again.
/// </summary>
public event EventHandler<PointerEventArgs> PreviewPointerHoverStopped
{
add => AddHandler(PreviewPointerHoverStoppedEvent, value);
remove => RemoveHandler(PreviewPointerHoverStoppedEvent, value);
}
/// <summary>
/// Occurs when the pointer had previously hovered but now started moving again.
/// </summary>
public event EventHandler<PointerEventArgs> PointerHoverStopped
{
add => AddHandler(PointerHoverStoppedEvent, value);
remove => RemoveHandler(PointerHoverStoppedEvent, value);
}
#endregion
#region ScrollBarVisibility
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
public static readonly AttachedProperty<ScrollBarVisibility> HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
get => GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
private ScrollBarVisibility _horizontalScrollBarVisibilityBck = ScrollBarVisibility.Auto;
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
public static readonly AttachedProperty<ScrollBarVisibility> VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
get => GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
object IServiceProvider.GetService(Type serviceType)
{
return TextArea.GetService(serviceType);
}
/// <summary>
/// Gets the text view position from a point inside the editor.
/// </summary>
/// <param name="point">The position, relative to top left
/// corner of TextEditor control</param>
/// <returns>The text view position, or null if the point is outside the document.</returns>
public TextViewPosition? GetPositionFromPoint(Point point)
{
if (Document == null)
return null;
var textView = TextArea.TextView;
Point tpoint = (Point)this.TranslatePoint(point + new Point(textView.ScrollOffset.X, Math.Floor(textView.ScrollOffset.Y)), textView);
return textView.GetPosition(tpoint);
}
/// <summary>
/// Scrolls to the specified line.
/// This method requires that the TextEditor was already assigned a size (layout engine must have run prior).
/// </summary>
public void ScrollToLine(int line)
{
ScrollTo(line, -1);
}
/// <summary>
/// Scrolls to the specified line/column.
/// This method requires that the TextEditor was already assigned a size (layout engine must have run prior).
/// </summary>
public void ScrollTo(int line, int column)
{
const double MinimumScrollFraction = 0.3;
ScrollTo(line, column, VisualYPosition.LineMiddle,
null != ScrollViewer ? ScrollViewer.Viewport.Height / 2 : 0.0, MinimumScrollFraction);
}
/// <summary>
/// Scrolls to the specified line/column.
/// This method requires that the TextEditor was already assigned a size (WPF layout must have run prior).
/// </summary>
/// <param name="line">Line to scroll to.</param>
/// <param name="column">Column to scroll to (important if wrapping is 'on', and for the horizontal scroll position).</param>
/// <param name="yPositionMode">The mode how to reference the Y position of the line.</param>
/// <param name="referencedVerticalViewPortOffset">Offset from the top of the viewport to where the referenced line/column should be positioned.</param>
/// <param name="minimumScrollFraction">The minimum vertical and/or horizontal scroll offset, expressed as fraction of the height or width of the viewport window, respectively.</param>
public void ScrollTo(int line, int column, VisualYPosition yPositionMode,
double referencedVerticalViewPortOffset, double minimumScrollFraction)
{
TextView textView = textArea.TextView;
TextDocument document = textView.Document;
if (ScrollViewer != null && document != null)
{
if (line < 1)
line = 1;
if (line > document.LineCount)
line = document.LineCount;
ILogicalScrollable scrollInfo = textView;
if (!scrollInfo.CanHorizontallyScroll)
{
// Word wrap is enabled. Ensure that we have up-to-date info about line height so that we scroll
// to the correct position.
// This avoids that the user has to repeat the ScrollTo() call several times when there are very long lines.
VisualLine vl = textView.GetOrConstructVisualLine(document.GetLineByNumber(line));
double remainingHeight = referencedVerticalViewPortOffset;
while (remainingHeight > 0)
{
DocumentLine prevLine = vl.FirstDocumentLine.PreviousLine;
if (prevLine == null)
break;
vl = textView.GetOrConstructVisualLine(prevLine);
remainingHeight -= vl.Height;
}
}
Point p = textArea.TextView.GetVisualPosition(
new TextViewPosition(line, Math.Max(1, column)),
yPositionMode);
double targetX = ScrollViewer.Offset.X;
double targetY = ScrollViewer.Offset.Y;
double verticalPos = p.Y - referencedVerticalViewPortOffset;
if (Math.Abs(verticalPos - ScrollViewer.Offset.Y) >
minimumScrollFraction * ScrollViewer.Viewport.Height)
{
targetY = Math.Max(0, verticalPos);
}
if (column > 0)
{
if (p.X > ScrollViewer.Viewport.Width - Caret.MinimumDistanceToViewBorder * 2)
{
double horizontalPos = Math.Max(0, p.X - ScrollViewer.Viewport.Width / 2);
if (Math.Abs(horizontalPos - ScrollViewer.Offset.X) >
minimumScrollFraction * ScrollViewer.Viewport.Width)
{
targetX = 0;
}
}
else
{
targetX = 0;
}
}
if (targetX != ScrollViewer.Offset.X || targetY != ScrollViewer.Offset.Y)
ScrollViewer.Offset = new Vector(targetX, targetY);
}
}
}
}
<MSG> Merge pull request #73 from jeffreye/fix-scroll
Fix scroll
<DFF> @@ -47,6 +47,8 @@ namespace AvaloniaEdit
static TextEditor()
{
FocusableProperty.OverrideDefaultValue<TextEditor>(true);
+ HorizontalScrollBarVisibilityProperty.OverrideDefaultValue<TextEditor>(ScrollBarVisibility.Auto);
+ VerticalScrollBarVisibilityProperty.OverrideDefaultValue<TextEditor>(ScrollBarVisibility.Auto);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
@@ -1049,28 +1051,28 @@ namespace AvaloniaEdit
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
- public static readonly AvaloniaProperty HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
+ public static readonly AttachedProperty<ScrollBarVisibility> HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
- get => (ScrollBarVisibility)GetValue(HorizontalScrollBarVisibilityProperty);
+ get => GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
- public static readonly AvaloniaProperty VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
+ public static readonly AttachedProperty<ScrollBarVisibility> VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
- get => (ScrollBarVisibility)GetValue(VerticalScrollBarVisibilityProperty);
+ get => GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
| 6 | Merge pull request #73 from jeffreye/fix-scroll | 4 | .cs | cs | mit | AvaloniaUI/AvaloniaEdit |
10066908 | <NME> TextEditor.cs
<BEF> // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using Avalonia;
using AvaloniaEdit.Document;
using AvaloniaEdit.Editing;
using AvaloniaEdit.Highlighting;
using AvaloniaEdit.Rendering;
using AvaloniaEdit.Utils;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Shapes;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.LogicalTree;
using Avalonia.Media;
using Avalonia.Data;
using AvaloniaEdit.Search;
namespace AvaloniaEdit
{
/// <summary>
/// The text editor control.
/// Contains a scrollable TextArea.
/// </summary>
public class TextEditor : TemplatedControl, ITextEditorComponent
static TextEditor()
{
FocusableProperty.OverrideDefaultValue<TextEditor>(true);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
SyntaxHighlightingProperty.Changed.Subscribe(OnSyntaxHighlightingChanged);
IsReadOnlyProperty.Changed.Subscribe(OnIsReadOnlyChanged);
IsModifiedProperty.Changed.Subscribe(OnIsModifiedChanged);
ShowLineNumbersProperty.Changed.Subscribe(OnShowLineNumbersChanged);
LineNumbersForegroundProperty.Changed.Subscribe(OnLineNumbersForegroundChanged);
FontFamilyProperty.Changed.Subscribe(OnFontFamilyPropertyChanged);
FontSizeProperty.Changed.Subscribe(OnFontSizePropertyChanged);
}
/// <summary>
/// Creates a new TextEditor instance.
/// </summary>
public TextEditor() : this(new TextArea())
{
}
/// <summary>
/// Creates a new TextEditor instance.
/// </summary>
protected TextEditor(TextArea textArea) : this(textArea, new TextDocument())
{
}
protected TextEditor(TextArea textArea, TextDocument document)
{
this.textArea = textArea ?? throw new ArgumentNullException(nameof(textArea));
textArea.TextView.Services.AddService(this);
SetValue(OptionsProperty, textArea.Options);
SetValue(DocumentProperty, document);
textArea[!BackgroundProperty] = this[!BackgroundProperty];
}
#endregion
protected override void OnGotFocus(GotFocusEventArgs e)
{
base.OnGotFocus(e);
TextArea.Focus();
e.Handled = true;
}
#region Document property
/// <summary>
/// Document property.
/// </summary>
public static readonly StyledProperty<TextDocument> DocumentProperty
= TextView.DocumentProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the document displayed by the text editor.
/// This is a dependency property.
/// </summary>
public TextDocument Document
{
get => GetValue(DocumentProperty);
set => SetValue(DocumentProperty, value);
}
/// <summary>
/// Occurs when the document property has changed.
/// </summary>
public event EventHandler DocumentChanged;
/// <summary>
/// Raises the <see cref="DocumentChanged"/> event.
/// </summary>
protected virtual void OnDocumentChanged(EventArgs e)
{
DocumentChanged?.Invoke(this, e);
}
private static void OnDocumentChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnDocumentChanged((TextDocument)e.OldValue, (TextDocument)e.NewValue);
}
private void OnDocumentChanged(TextDocument oldValue, TextDocument newValue)
{
if (oldValue != null)
{
TextDocumentWeakEventManager.TextChanged.RemoveHandler(oldValue, OnTextChanged);
PropertyChangedWeakEventManager.RemoveHandler(oldValue.UndoStack, OnUndoStackPropertyChangedHandler);
}
TextArea.Document = newValue;
if (newValue != null)
{
TextDocumentWeakEventManager.TextChanged.AddHandler(newValue, OnTextChanged);
PropertyChangedWeakEventManager.AddHandler(newValue.UndoStack, OnUndoStackPropertyChangedHandler);
}
OnDocumentChanged(EventArgs.Empty);
OnTextChanged(EventArgs.Empty);
}
#endregion
#region Options property
/// <summary>
/// Options property.
/// </summary>
public static readonly StyledProperty<TextEditorOptions> OptionsProperty
= TextView.OptionsProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the options currently used by the text editor.
/// </summary>
public TextEditorOptions Options
{
get => GetValue(OptionsProperty);
set => SetValue(OptionsProperty, value);
}
/// <summary>
/// Occurs when a text editor option has changed.
/// </summary>
public event PropertyChangedEventHandler OptionChanged;
/// <summary>
/// Raises the <see cref="OptionChanged"/> event.
/// </summary>
protected virtual void OnOptionChanged(PropertyChangedEventArgs e)
{
OptionChanged?.Invoke(this, e);
}
private static void OnOptionsChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnOptionsChanged((TextEditorOptions)e.OldValue, (TextEditorOptions)e.NewValue);
}
private void OnOptionsChanged(TextEditorOptions oldValue, TextEditorOptions newValue)
{
if (oldValue != null)
{
PropertyChangedWeakEventManager.RemoveHandler(oldValue, OnPropertyChangedHandler);
}
TextArea.Options = newValue;
if (newValue != null)
{
PropertyChangedWeakEventManager.AddHandler(newValue, OnPropertyChangedHandler);
}
OnOptionChanged(new PropertyChangedEventArgs(null));
}
private void OnPropertyChangedHandler(object sender, PropertyChangedEventArgs e)
{
OnOptionChanged(e);
}
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
base.OnPropertyChanged(change);
if (change.Property == WordWrapProperty)
{
if (WordWrap)
{
_horizontalScrollBarVisibilityBck = HorizontalScrollBarVisibility;
HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
}
else
{
HorizontalScrollBarVisibility = _horizontalScrollBarVisibilityBck;
}
}
}
private void OnUndoStackPropertyChangedHandler(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsOriginalFile")
{
HandleIsOriginalChanged(e);
}
}
private void OnTextChanged(object sender, EventArgs e)
{
OnTextChanged(e);
}
#endregion
#region Text property
/// <summary>
/// Gets/Sets the text of the current document.
/// </summary>
public string Text
{
get
{
var document = Document;
return document != null ? document.Text : string.Empty;
}
set
{
var document = GetDocument();
document.Text = value ?? string.Empty;
// after replacing the full text, the caret is positioned at the end of the document
// - reset it to the beginning.
CaretOffset = 0;
document.UndoStack.ClearAll();
}
}
private TextDocument GetDocument()
{
var document = Document;
if (document == null)
throw ThrowUtil.NoDocumentAssigned();
return document;
}
/// <summary>
/// Occurs when the Text property changes.
/// </summary>
public event EventHandler TextChanged;
/// <summary>
/// Raises the <see cref="TextChanged"/> event.
/// </summary>
protected virtual void OnTextChanged(EventArgs e)
{
TextChanged?.Invoke(this, e);
}
#endregion
#region TextArea / ScrollViewer properties
private readonly TextArea textArea;
private SearchPanel searchPanel;
private bool wasSearchPanelOpened;
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
ScrollViewer = (ScrollViewer)e.NameScope.Find("PART_ScrollViewer");
ScrollViewer.Content = TextArea;
searchPanel = SearchPanel.Install(this);
}
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnAttachedToLogicalTree(e);
if (searchPanel != null && wasSearchPanelOpened)
{
searchPanel.Open();
}
}
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnDetachedFromLogicalTree(e);
if (searchPanel != null)
{
wasSearchPanelOpened = searchPanel.IsOpened;
if (searchPanel.IsOpened)
searchPanel.Close();
}
}
/// <summary>
/// Gets the text area.
/// </summary>
public TextArea TextArea => textArea;
/// <summary>
/// Gets the search panel.
/// </summary>
public SearchPanel SearchPanel => searchPanel;
/// <summary>
/// Gets the scroll viewer used by the text editor.
/// This property can return null if the template has not been applied / does not contain a scroll viewer.
/// </summary>
internal ScrollViewer ScrollViewer { get; private set; }
#endregion
#region Syntax highlighting
/// <summary>
/// The <see cref="SyntaxHighlighting"/> property.
/// </summary>
public static readonly StyledProperty<IHighlightingDefinition> SyntaxHighlightingProperty =
AvaloniaProperty.Register<TextEditor, IHighlightingDefinition>("SyntaxHighlighting");
/// <summary>
/// Gets/sets the syntax highlighting definition used to colorize the text.
/// </summary>
public IHighlightingDefinition SyntaxHighlighting
{
get => GetValue(SyntaxHighlightingProperty);
set => SetValue(SyntaxHighlightingProperty, value);
}
private IVisualLineTransformer _colorizer;
private static void OnSyntaxHighlightingChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnSyntaxHighlightingChanged(e.NewValue as IHighlightingDefinition);
}
private void OnSyntaxHighlightingChanged(IHighlightingDefinition newValue)
{
if (_colorizer != null)
{
textArea.TextView.LineTransformers.Remove(_colorizer);
_colorizer = null;
}
if (newValue != null)
{
_colorizer = CreateColorizer(newValue);
if (_colorizer != null)
{
textArea.TextView.LineTransformers.Insert(0, _colorizer);
}
}
}
/// <summary>
/// Creates the highlighting colorizer for the specified highlighting definition.
/// Allows derived classes to provide custom colorizer implementations for special highlighting definitions.
/// </summary>
/// <returns></returns>
protected virtual IVisualLineTransformer CreateColorizer(IHighlightingDefinition highlightingDefinition)
{
if (highlightingDefinition == null)
throw new ArgumentNullException(nameof(highlightingDefinition));
return new HighlightingColorizer(highlightingDefinition);
}
#endregion
#region WordWrap
/// <summary>
/// Word wrap dependency property.
/// </summary>
public static readonly StyledProperty<bool> WordWrapProperty =
AvaloniaProperty.Register<TextEditor, bool>("WordWrap");
/// <summary>
/// Specifies whether the text editor uses word wrapping.
/// </summary>
/// <remarks>
/// Setting WordWrap=true has the same effect as setting HorizontalScrollBarVisibility=Disabled and will override the
/// HorizontalScrollBarVisibility setting.
/// </remarks>
public bool WordWrap
{
get => GetValue(WordWrapProperty);
set => SetValue(WordWrapProperty, value);
}
#endregion
#region IsReadOnly
/// <summary>
/// IsReadOnly dependency property.
/// </summary>
public static readonly StyledProperty<bool> IsReadOnlyProperty =
AvaloniaProperty.Register<TextEditor, bool>("IsReadOnly");
/// <summary>
/// Specifies whether the user can change the text editor content.
/// Setting this property will replace the
/// <see cref="Editing.TextArea.ReadOnlySectionProvider">TextArea.ReadOnlySectionProvider</see>.
/// </summary>
public bool IsReadOnly
{
get => GetValue(IsReadOnlyProperty);
set => SetValue(IsReadOnlyProperty, value);
}
private static void OnIsReadOnlyChanged(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is TextEditor editor)
{
if ((bool)e.NewValue)
editor.TextArea.ReadOnlySectionProvider = ReadOnlySectionDocument.Instance;
else
editor.TextArea.ReadOnlySectionProvider = NoReadOnlySections.Instance;
}
}
#endregion
#region IsModified
/// <summary>
/// Dependency property for <see cref="IsModified"/>
/// </summary>
public static readonly StyledProperty<bool> IsModifiedProperty =
AvaloniaProperty.Register<TextEditor, bool>("IsModified");
/// <summary>
/// Gets/Sets the 'modified' flag.
/// </summary>
public bool IsModified
{
get => GetValue(IsModifiedProperty);
set => SetValue(IsModifiedProperty, value);
}
private static void OnIsModifiedChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
var document = editor?.Document;
if (document != null)
{
var undoStack = document.UndoStack;
if ((bool)e.NewValue)
{
if (undoStack.IsOriginalFile)
undoStack.DiscardOriginalFileMarker();
}
else
{
undoStack.MarkAsOriginalFile();
}
}
}
private void HandleIsOriginalChanged(PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsOriginalFile")
{
var document = Document;
if (document != null)
{
SetValue(IsModifiedProperty, (object)!document.UndoStack.IsOriginalFile);
}
}
}
#endregion
#region ShowLineNumbers
/// <summary>
/// ShowLineNumbers dependency property.
/// </summary>
public static readonly StyledProperty<bool> ShowLineNumbersProperty =
AvaloniaProperty.Register<TextEditor, bool>("ShowLineNumbers");
/// <summary>
/// Specifies whether line numbers are shown on the left to the text view.
/// </summary>
public bool ShowLineNumbers
{
get => GetValue(ShowLineNumbersProperty);
set => SetValue(ShowLineNumbersProperty, value);
}
private static void OnShowLineNumbersChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
if (editor == null) return;
var leftMargins = editor.TextArea.LeftMargins;
if ((bool)e.NewValue)
{
var lineNumbers = new LineNumberMargin();
var line = (Line)DottedLineMargin.Create();
leftMargins.Insert(0, lineNumbers);
leftMargins.Insert(1, line);
var lineNumbersForeground = new Binding("LineNumbersForeground") { Source = editor };
line.Bind(Shape.StrokeProperty, lineNumbersForeground);
lineNumbers.Bind(ForegroundProperty, lineNumbersForeground);
}
else
{
for (var i = 0; i < leftMargins.Count; i++)
{
if (leftMargins[i] is LineNumberMargin)
{
leftMargins.RemoveAt(i);
if (i < leftMargins.Count && DottedLineMargin.IsDottedLineMargin(leftMargins[i]))
{
leftMargins.RemoveAt(i);
}
break;
}
}
}
}
#endregion
#region LineNumbersForeground
/// <summary>
/// LineNumbersForeground dependency property.
/// </summary>
public static readonly StyledProperty<IBrush> LineNumbersForegroundProperty =
AvaloniaProperty.Register<TextEditor, IBrush>("LineNumbersForeground", Brushes.Gray);
/// <summary>
/// Gets/sets the Brush used for displaying the foreground color of line numbers.
/// </summary>
public IBrush LineNumbersForeground
{
get => GetValue(LineNumbersForegroundProperty);
set => SetValue(LineNumbersForegroundProperty, value);
}
private static void OnLineNumbersForegroundChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
var lineNumberMargin = editor?.TextArea.LeftMargins.FirstOrDefault(margin => margin is LineNumberMargin) as LineNumberMargin;
lineNumberMargin?.SetValue(ForegroundProperty, e.NewValue);
}
private static void OnFontFamilyPropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
editor?.TextArea.TextView.SetValue(FontFamilyProperty, e.NewValue);
}
private static void OnFontSizePropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
editor?.TextArea.TextView.SetValue(FontSizeProperty, e.NewValue);
}
#endregion
#region TextBoxBase-like methods
/// <summary>
/// Appends text to the end of the document.
/// </summary>
public void AppendText(string textData)
{
var document = GetDocument();
document.Insert(document.TextLength, textData);
}
/// <summary>
/// Begins a group of document changes.
/// </summary>
public void BeginChange()
{
GetDocument().BeginUpdate();
}
/// <summary>
/// Copies the current selection to the clipboard.
/// </summary>
public void Copy()
{
if (CanCopy)
{
ApplicationCommands.Copy.Execute(null, TextArea);
}
}
/// <summary>
/// Removes the current selection and copies it to the clipboard.
/// </summary>
public void Cut()
{
if (CanCut)
{
ApplicationCommands.Cut.Execute(null, TextArea);
}
}
/// <summary>
/// Begins a group of document changes and returns an object that ends the group of document
/// changes when it is disposed.
/// </summary>
public IDisposable DeclareChangeBlock()
{
return GetDocument().RunUpdate();
}
/// <summary>
/// Removes the current selection without copying it to the clipboard.
/// </summary>
public void Delete()
{
if(CanDelete)
{
ApplicationCommands.Delete.Execute(null, TextArea);
}
}
/// <summary>
/// Ends the current group of document changes.
/// </summary>
public void EndChange()
{
GetDocument().EndUpdate();
}
/// <summary>
/// Scrolls one line down.
/// </summary>
public void LineDown()
{
//if (scrollViewer != null)
// scrollViewer.LineDown();
}
/// <summary>
/// Scrolls to the left.
/// </summary>
public void LineLeft()
{
//if (scrollViewer != null)
// scrollViewer.LineLeft();
}
/// <summary>
/// Scrolls to the right.
/// </summary>
public void LineRight()
{
//if (scrollViewer != null)
// scrollViewer.LineRight();
}
/// <summary>
/// Scrolls one line up.
/// </summary>
public void LineUp()
{
//if (scrollViewer != null)
// scrollViewer.LineUp();
}
/// <summary>
/// Scrolls one page down.
/// </summary>
public void PageDown()
{
//if (scrollViewer != null)
// scrollViewer.PageDown();
}
/// <summary>
/// Scrolls one page up.
/// </summary>
public void PageUp()
{
//if (scrollViewer != null)
// scrollViewer.PageUp();
}
/// <summary>
/// Scrolls one page left.
/// </summary>
public void PageLeft()
{
//if (scrollViewer != null)
// scrollViewer.PageLeft();
}
/// <summary>
/// Scrolls one page right.
/// </summary>
public void PageRight()
{
//if (scrollViewer != null)
// scrollViewer.PageRight();
}
/// <summary>
/// Pastes the clipboard content.
/// </summary>
public void Paste()
{
if (CanPaste)
{
ApplicationCommands.Paste.Execute(null, TextArea);
}
}
/// <summary>
/// Redoes the most recent undone command.
/// </summary>
/// <returns>True is the redo operation was successful, false is the redo stack is empty.</returns>
public bool Redo()
{
if (CanRedo)
{
ApplicationCommands.Redo.Execute(null, TextArea);
return true;
}
return false;
}
/// <summary>
/// Scrolls to the end of the document.
/// </summary>
public void ScrollToEnd()
{
ApplyTemplate(); // ensure scrollViewer is created
ScrollViewer?.ScrollToEnd();
}
/// <summary>
/// Scrolls to the start of the document.
/// </summary>
public void ScrollToHome()
{
ApplyTemplate(); // ensure scrollViewer is created
ScrollViewer?.ScrollToHome();
}
/// <summary>
/// Scrolls to the specified position in the document.
/// </summary>
public void ScrollToHorizontalOffset(double offset)
{
ApplyTemplate(); // ensure scrollViewer is created
//if (scrollViewer != null)
// scrollViewer.ScrollToHorizontalOffset(offset);
}
/// <summary>
/// Scrolls to the specified position in the document.
/// </summary>
public void ScrollToVerticalOffset(double offset)
{
ApplyTemplate(); // ensure scrollViewer is created
//if (scrollViewer != null)
// scrollViewer.ScrollToVerticalOffset(offset);
}
/// <summary>
/// Selects the entire text.
/// </summary>
public void SelectAll()
{
if (CanSelectAll)
{
ApplicationCommands.SelectAll.Execute(null, TextArea);
}
}
/// <summary>
/// Undoes the most recent command.
/// </summary>
/// <returns>True is the undo operation was successful, false is the undo stack is empty.</returns>
public bool Undo()
{
if (CanUndo)
{
ApplicationCommands.Undo.Execute(null, TextArea);
return true;
}
return false;
}
/// <summary>
/// Gets if the most recent undone command can be redone.
/// </summary>
public bool CanRedo
{
get { return ApplicationCommands.Redo.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if the most recent command can be undone.
/// </summary>
public bool CanUndo
{
get { return ApplicationCommands.Undo.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be copied
/// </summary>
public bool CanCopy
{
get { return ApplicationCommands.Copy.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be cut
/// </summary>
public bool CanCut
{
get { return ApplicationCommands.Cut.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be pasted
/// </summary>
public bool CanPaste
{
get { return ApplicationCommands.Paste.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if selected text in editor can be deleted
/// </summary>
public bool CanDelete
{
get { return ApplicationCommands.Delete.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text the editor can select all
/// </summary>
public bool CanSelectAll
{
get { return ApplicationCommands.SelectAll.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text editor can activate the search panel
/// </summary>
public bool CanSearch
{
get { return searchPanel != null; }
}
/// <summary>
/// Gets the vertical size of the document.
/// </summary>
public double ExtentHeight => ScrollViewer?.Extent.Height ?? 0;
/// <summary>
/// Gets the horizontal size of the current document region.
/// </summary>
public double ExtentWidth => ScrollViewer?.Extent.Width ?? 0;
/// <summary>
/// Gets the horizontal size of the viewport.
/// </summary>
public double ViewportHeight => ScrollViewer?.Viewport.Height ?? 0;
/// <summary>
/// Gets the horizontal size of the viewport.
/// </summary>
public double ViewportWidth => ScrollViewer?.Viewport.Width ?? 0;
/// <summary>
/// Gets the vertical scroll position.
/// </summary>
public double VerticalOffset => ScrollViewer?.Offset.Y ?? 0;
/// <summary>
/// Gets the horizontal scroll position.
/// </summary>
public double HorizontalOffset => ScrollViewer?.Offset.X ?? 0;
#endregion
#region TextBox methods
/// <summary>
/// Gets/Sets the selected text.
/// </summary>
public string SelectedText
{
get
{
// We'll get the text from the whole surrounding segment.
// This is done to ensure that SelectedText.Length == SelectionLength.
if (textArea.Document != null && !textArea.Selection.IsEmpty)
return textArea.Document.GetText(textArea.Selection.SurroundingSegment);
return string.Empty;
}
set
{
if (value == null)
throw new ArgumentNullException(nameof(value));
var textArea = TextArea;
if (textArea.Document != null)
{
var offset = SelectionStart;
var length = SelectionLength;
textArea.Document.Replace(offset, length, value);
// keep inserted text selected
textArea.Selection = Selection.Create(textArea, offset, offset + value.Length);
}
}
}
/// <summary>
/// Gets/sets the caret position.
/// </summary>
public int CaretOffset
{
get
{
return textArea.Caret.Offset;
}
set
{
textArea.Caret.Offset = value;
}
}
/// <summary>
/// Gets/sets the start position of the selection.
/// </summary>
public int SelectionStart
{
get
{
if (textArea.Selection.IsEmpty)
return textArea.Caret.Offset;
else
return textArea.Selection.SurroundingSegment.Offset;
}
set => Select(value, SelectionLength);
}
/// <summary>
/// Gets/sets the length of the selection.
/// </summary>
public int SelectionLength
{
get
{
if (!textArea.Selection.IsEmpty)
return textArea.Selection.SurroundingSegment.Length;
else
return 0;
}
set => Select(SelectionStart, value);
}
/// <summary>
/// Selects the specified text section.
/// </summary>
public void Select(int start, int length)
{
var documentLength = Document?.TextLength ?? 0;
if (start < 0 || start > documentLength)
throw new ArgumentOutOfRangeException(nameof(start), start, "Value must be between 0 and " + documentLength);
if (length < 0 || start + length > documentLength)
throw new ArgumentOutOfRangeException(nameof(length), length, "Value must be between 0 and " + (documentLength - start));
TextArea.Selection = Selection.Create(TextArea, start, start + length);
TextArea.Caret.Offset = start + length;
}
/// <summary>
/// Gets the number of lines in the document.
/// </summary>
public int LineCount
{
get
{
var document = Document;
if (document != null)
return document.LineCount;
return 1;
}
}
/// <summary>
/// Clears the text.
/// </summary>
public void Clear()
{
Text = string.Empty;
}
#endregion
#region Loading from stream
/// <summary>
/// Loads the text from the stream, auto-detecting the encoding.
/// </summary>
/// <remarks>
/// This method sets <see cref="IsModified"/> to false.
/// </remarks>
public void Load(Stream stream)
{
using (var reader = FileReader.OpenStream(stream, Encoding ?? Encoding.UTF8))
{
Text = reader.ReadToEnd();
SetValue(EncodingProperty, (object)reader.CurrentEncoding);
}
SetValue(IsModifiedProperty, (object)false);
}
/// <summary>
/// Loads the text from the stream, auto-detecting the encoding.
/// </summary>
public void Load(string fileName)
{
if (fileName == null)
throw new ArgumentNullException(nameof(fileName));
// TODO:load
//using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
//{
// Load(fs);
//}
}
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
public static readonly AvaloniaProperty HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
get => (ScrollBarVisibility)GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
public static readonly AvaloniaProperty VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
get => (ScrollBarVisibility)GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
if (stream == null)
throw new ArgumentNullException(nameof(stream));
var encoding = Encoding;
var document = Document;
var writer = encoding != null ? new StreamWriter(stream, encoding) : new StreamWriter(stream);
document?.WriteTextTo(writer);
writer.Flush();
// do not close the stream
SetValue(IsModifiedProperty, (object)false);
}
/// <summary>
/// Saves the text to the file.
/// </summary>
public void Save(string fileName)
{
if (fileName == null)
throw new ArgumentNullException(nameof(fileName));
// TODO: save
//using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
//{
// Save(fs);
//}
}
#endregion
#region PointerHover events
/// <summary>
/// The PreviewPointerHover event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PreviewPointerHoverEvent =
TextView.PreviewPointerHoverEvent;
/// <summary>
/// the pointerHover event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PointerHoverEvent =
TextView.PointerHoverEvent;
/// <summary>
/// The PreviewPointerHoverStopped event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PreviewPointerHoverStoppedEvent =
TextView.PreviewPointerHoverStoppedEvent;
/// <summary>
/// the pointerHoverStopped event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PointerHoverStoppedEvent =
TextView.PointerHoverStoppedEvent;
/// <summary>
/// Occurs when the pointer has hovered over a fixed location for some time.
/// </summary>
public event EventHandler<PointerEventArgs> PreviewPointerHover
{
add => AddHandler(PreviewPointerHoverEvent, value);
remove => RemoveHandler(PreviewPointerHoverEvent, value);
}
/// <summary>
/// Occurs when the pointer has hovered over a fixed location for some time.
/// </summary>
public event EventHandler<PointerEventArgs> PointerHover
{
add => AddHandler(PointerHoverEvent, value);
remove => RemoveHandler(PointerHoverEvent, value);
}
/// <summary>
/// Occurs when the pointer had previously hovered but now started moving again.
/// </summary>
public event EventHandler<PointerEventArgs> PreviewPointerHoverStopped
{
add => AddHandler(PreviewPointerHoverStoppedEvent, value);
remove => RemoveHandler(PreviewPointerHoverStoppedEvent, value);
}
/// <summary>
/// Occurs when the pointer had previously hovered but now started moving again.
/// </summary>
public event EventHandler<PointerEventArgs> PointerHoverStopped
{
add => AddHandler(PointerHoverStoppedEvent, value);
remove => RemoveHandler(PointerHoverStoppedEvent, value);
}
#endregion
#region ScrollBarVisibility
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
public static readonly AttachedProperty<ScrollBarVisibility> HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
get => GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
private ScrollBarVisibility _horizontalScrollBarVisibilityBck = ScrollBarVisibility.Auto;
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
public static readonly AttachedProperty<ScrollBarVisibility> VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
get => GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
object IServiceProvider.GetService(Type serviceType)
{
return TextArea.GetService(serviceType);
}
/// <summary>
/// Gets the text view position from a point inside the editor.
/// </summary>
/// <param name="point">The position, relative to top left
/// corner of TextEditor control</param>
/// <returns>The text view position, or null if the point is outside the document.</returns>
public TextViewPosition? GetPositionFromPoint(Point point)
{
if (Document == null)
return null;
var textView = TextArea.TextView;
Point tpoint = (Point)this.TranslatePoint(point + new Point(textView.ScrollOffset.X, Math.Floor(textView.ScrollOffset.Y)), textView);
return textView.GetPosition(tpoint);
}
/// <summary>
/// Scrolls to the specified line.
/// This method requires that the TextEditor was already assigned a size (layout engine must have run prior).
/// </summary>
public void ScrollToLine(int line)
{
ScrollTo(line, -1);
}
/// <summary>
/// Scrolls to the specified line/column.
/// This method requires that the TextEditor was already assigned a size (layout engine must have run prior).
/// </summary>
public void ScrollTo(int line, int column)
{
const double MinimumScrollFraction = 0.3;
ScrollTo(line, column, VisualYPosition.LineMiddle,
null != ScrollViewer ? ScrollViewer.Viewport.Height / 2 : 0.0, MinimumScrollFraction);
}
/// <summary>
/// Scrolls to the specified line/column.
/// This method requires that the TextEditor was already assigned a size (WPF layout must have run prior).
/// </summary>
/// <param name="line">Line to scroll to.</param>
/// <param name="column">Column to scroll to (important if wrapping is 'on', and for the horizontal scroll position).</param>
/// <param name="yPositionMode">The mode how to reference the Y position of the line.</param>
/// <param name="referencedVerticalViewPortOffset">Offset from the top of the viewport to where the referenced line/column should be positioned.</param>
/// <param name="minimumScrollFraction">The minimum vertical and/or horizontal scroll offset, expressed as fraction of the height or width of the viewport window, respectively.</param>
public void ScrollTo(int line, int column, VisualYPosition yPositionMode,
double referencedVerticalViewPortOffset, double minimumScrollFraction)
{
TextView textView = textArea.TextView;
TextDocument document = textView.Document;
if (ScrollViewer != null && document != null)
{
if (line < 1)
line = 1;
if (line > document.LineCount)
line = document.LineCount;
ILogicalScrollable scrollInfo = textView;
if (!scrollInfo.CanHorizontallyScroll)
{
// Word wrap is enabled. Ensure that we have up-to-date info about line height so that we scroll
// to the correct position.
// This avoids that the user has to repeat the ScrollTo() call several times when there are very long lines.
VisualLine vl = textView.GetOrConstructVisualLine(document.GetLineByNumber(line));
double remainingHeight = referencedVerticalViewPortOffset;
while (remainingHeight > 0)
{
DocumentLine prevLine = vl.FirstDocumentLine.PreviousLine;
if (prevLine == null)
break;
vl = textView.GetOrConstructVisualLine(prevLine);
remainingHeight -= vl.Height;
}
}
Point p = textArea.TextView.GetVisualPosition(
new TextViewPosition(line, Math.Max(1, column)),
yPositionMode);
double targetX = ScrollViewer.Offset.X;
double targetY = ScrollViewer.Offset.Y;
double verticalPos = p.Y - referencedVerticalViewPortOffset;
if (Math.Abs(verticalPos - ScrollViewer.Offset.Y) >
minimumScrollFraction * ScrollViewer.Viewport.Height)
{
targetY = Math.Max(0, verticalPos);
}
if (column > 0)
{
if (p.X > ScrollViewer.Viewport.Width - Caret.MinimumDistanceToViewBorder * 2)
{
double horizontalPos = Math.Max(0, p.X - ScrollViewer.Viewport.Width / 2);
if (Math.Abs(horizontalPos - ScrollViewer.Offset.X) >
minimumScrollFraction * ScrollViewer.Viewport.Width)
{
targetX = 0;
}
}
else
{
targetX = 0;
}
}
if (targetX != ScrollViewer.Offset.X || targetY != ScrollViewer.Offset.Y)
ScrollViewer.Offset = new Vector(targetX, targetY);
}
}
}
}
<MSG> Merge pull request #73 from jeffreye/fix-scroll
Fix scroll
<DFF> @@ -47,6 +47,8 @@ namespace AvaloniaEdit
static TextEditor()
{
FocusableProperty.OverrideDefaultValue<TextEditor>(true);
+ HorizontalScrollBarVisibilityProperty.OverrideDefaultValue<TextEditor>(ScrollBarVisibility.Auto);
+ VerticalScrollBarVisibilityProperty.OverrideDefaultValue<TextEditor>(ScrollBarVisibility.Auto);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
@@ -1049,28 +1051,28 @@ namespace AvaloniaEdit
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
- public static readonly AvaloniaProperty HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
+ public static readonly AttachedProperty<ScrollBarVisibility> HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
- get => (ScrollBarVisibility)GetValue(HorizontalScrollBarVisibilityProperty);
+ get => GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
- public static readonly AvaloniaProperty VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
+ public static readonly AttachedProperty<ScrollBarVisibility> VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
- get => (ScrollBarVisibility)GetValue(VerticalScrollBarVisibilityProperty);
+ get => GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
| 6 | Merge pull request #73 from jeffreye/fix-scroll | 4 | .cs | cs | mit | AvaloniaUI/AvaloniaEdit |
10066909 | <NME> TextEditor.cs
<BEF> // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using Avalonia;
using AvaloniaEdit.Document;
using AvaloniaEdit.Editing;
using AvaloniaEdit.Highlighting;
using AvaloniaEdit.Rendering;
using AvaloniaEdit.Utils;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Shapes;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.LogicalTree;
using Avalonia.Media;
using Avalonia.Data;
using AvaloniaEdit.Search;
namespace AvaloniaEdit
{
/// <summary>
/// The text editor control.
/// Contains a scrollable TextArea.
/// </summary>
public class TextEditor : TemplatedControl, ITextEditorComponent
static TextEditor()
{
FocusableProperty.OverrideDefaultValue<TextEditor>(true);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
SyntaxHighlightingProperty.Changed.Subscribe(OnSyntaxHighlightingChanged);
IsReadOnlyProperty.Changed.Subscribe(OnIsReadOnlyChanged);
IsModifiedProperty.Changed.Subscribe(OnIsModifiedChanged);
ShowLineNumbersProperty.Changed.Subscribe(OnShowLineNumbersChanged);
LineNumbersForegroundProperty.Changed.Subscribe(OnLineNumbersForegroundChanged);
FontFamilyProperty.Changed.Subscribe(OnFontFamilyPropertyChanged);
FontSizeProperty.Changed.Subscribe(OnFontSizePropertyChanged);
}
/// <summary>
/// Creates a new TextEditor instance.
/// </summary>
public TextEditor() : this(new TextArea())
{
}
/// <summary>
/// Creates a new TextEditor instance.
/// </summary>
protected TextEditor(TextArea textArea) : this(textArea, new TextDocument())
{
}
protected TextEditor(TextArea textArea, TextDocument document)
{
this.textArea = textArea ?? throw new ArgumentNullException(nameof(textArea));
textArea.TextView.Services.AddService(this);
SetValue(OptionsProperty, textArea.Options);
SetValue(DocumentProperty, document);
textArea[!BackgroundProperty] = this[!BackgroundProperty];
}
#endregion
protected override void OnGotFocus(GotFocusEventArgs e)
{
base.OnGotFocus(e);
TextArea.Focus();
e.Handled = true;
}
#region Document property
/// <summary>
/// Document property.
/// </summary>
public static readonly StyledProperty<TextDocument> DocumentProperty
= TextView.DocumentProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the document displayed by the text editor.
/// This is a dependency property.
/// </summary>
public TextDocument Document
{
get => GetValue(DocumentProperty);
set => SetValue(DocumentProperty, value);
}
/// <summary>
/// Occurs when the document property has changed.
/// </summary>
public event EventHandler DocumentChanged;
/// <summary>
/// Raises the <see cref="DocumentChanged"/> event.
/// </summary>
protected virtual void OnDocumentChanged(EventArgs e)
{
DocumentChanged?.Invoke(this, e);
}
private static void OnDocumentChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnDocumentChanged((TextDocument)e.OldValue, (TextDocument)e.NewValue);
}
private void OnDocumentChanged(TextDocument oldValue, TextDocument newValue)
{
if (oldValue != null)
{
TextDocumentWeakEventManager.TextChanged.RemoveHandler(oldValue, OnTextChanged);
PropertyChangedWeakEventManager.RemoveHandler(oldValue.UndoStack, OnUndoStackPropertyChangedHandler);
}
TextArea.Document = newValue;
if (newValue != null)
{
TextDocumentWeakEventManager.TextChanged.AddHandler(newValue, OnTextChanged);
PropertyChangedWeakEventManager.AddHandler(newValue.UndoStack, OnUndoStackPropertyChangedHandler);
}
OnDocumentChanged(EventArgs.Empty);
OnTextChanged(EventArgs.Empty);
}
#endregion
#region Options property
/// <summary>
/// Options property.
/// </summary>
public static readonly StyledProperty<TextEditorOptions> OptionsProperty
= TextView.OptionsProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the options currently used by the text editor.
/// </summary>
public TextEditorOptions Options
{
get => GetValue(OptionsProperty);
set => SetValue(OptionsProperty, value);
}
/// <summary>
/// Occurs when a text editor option has changed.
/// </summary>
public event PropertyChangedEventHandler OptionChanged;
/// <summary>
/// Raises the <see cref="OptionChanged"/> event.
/// </summary>
protected virtual void OnOptionChanged(PropertyChangedEventArgs e)
{
OptionChanged?.Invoke(this, e);
}
private static void OnOptionsChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnOptionsChanged((TextEditorOptions)e.OldValue, (TextEditorOptions)e.NewValue);
}
private void OnOptionsChanged(TextEditorOptions oldValue, TextEditorOptions newValue)
{
if (oldValue != null)
{
PropertyChangedWeakEventManager.RemoveHandler(oldValue, OnPropertyChangedHandler);
}
TextArea.Options = newValue;
if (newValue != null)
{
PropertyChangedWeakEventManager.AddHandler(newValue, OnPropertyChangedHandler);
}
OnOptionChanged(new PropertyChangedEventArgs(null));
}
private void OnPropertyChangedHandler(object sender, PropertyChangedEventArgs e)
{
OnOptionChanged(e);
}
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
base.OnPropertyChanged(change);
if (change.Property == WordWrapProperty)
{
if (WordWrap)
{
_horizontalScrollBarVisibilityBck = HorizontalScrollBarVisibility;
HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
}
else
{
HorizontalScrollBarVisibility = _horizontalScrollBarVisibilityBck;
}
}
}
private void OnUndoStackPropertyChangedHandler(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsOriginalFile")
{
HandleIsOriginalChanged(e);
}
}
private void OnTextChanged(object sender, EventArgs e)
{
OnTextChanged(e);
}
#endregion
#region Text property
/// <summary>
/// Gets/Sets the text of the current document.
/// </summary>
public string Text
{
get
{
var document = Document;
return document != null ? document.Text : string.Empty;
}
set
{
var document = GetDocument();
document.Text = value ?? string.Empty;
// after replacing the full text, the caret is positioned at the end of the document
// - reset it to the beginning.
CaretOffset = 0;
document.UndoStack.ClearAll();
}
}
private TextDocument GetDocument()
{
var document = Document;
if (document == null)
throw ThrowUtil.NoDocumentAssigned();
return document;
}
/// <summary>
/// Occurs when the Text property changes.
/// </summary>
public event EventHandler TextChanged;
/// <summary>
/// Raises the <see cref="TextChanged"/> event.
/// </summary>
protected virtual void OnTextChanged(EventArgs e)
{
TextChanged?.Invoke(this, e);
}
#endregion
#region TextArea / ScrollViewer properties
private readonly TextArea textArea;
private SearchPanel searchPanel;
private bool wasSearchPanelOpened;
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
ScrollViewer = (ScrollViewer)e.NameScope.Find("PART_ScrollViewer");
ScrollViewer.Content = TextArea;
searchPanel = SearchPanel.Install(this);
}
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnAttachedToLogicalTree(e);
if (searchPanel != null && wasSearchPanelOpened)
{
searchPanel.Open();
}
}
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnDetachedFromLogicalTree(e);
if (searchPanel != null)
{
wasSearchPanelOpened = searchPanel.IsOpened;
if (searchPanel.IsOpened)
searchPanel.Close();
}
}
/// <summary>
/// Gets the text area.
/// </summary>
public TextArea TextArea => textArea;
/// <summary>
/// Gets the search panel.
/// </summary>
public SearchPanel SearchPanel => searchPanel;
/// <summary>
/// Gets the scroll viewer used by the text editor.
/// This property can return null if the template has not been applied / does not contain a scroll viewer.
/// </summary>
internal ScrollViewer ScrollViewer { get; private set; }
#endregion
#region Syntax highlighting
/// <summary>
/// The <see cref="SyntaxHighlighting"/> property.
/// </summary>
public static readonly StyledProperty<IHighlightingDefinition> SyntaxHighlightingProperty =
AvaloniaProperty.Register<TextEditor, IHighlightingDefinition>("SyntaxHighlighting");
/// <summary>
/// Gets/sets the syntax highlighting definition used to colorize the text.
/// </summary>
public IHighlightingDefinition SyntaxHighlighting
{
get => GetValue(SyntaxHighlightingProperty);
set => SetValue(SyntaxHighlightingProperty, value);
}
private IVisualLineTransformer _colorizer;
private static void OnSyntaxHighlightingChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnSyntaxHighlightingChanged(e.NewValue as IHighlightingDefinition);
}
private void OnSyntaxHighlightingChanged(IHighlightingDefinition newValue)
{
if (_colorizer != null)
{
textArea.TextView.LineTransformers.Remove(_colorizer);
_colorizer = null;
}
if (newValue != null)
{
_colorizer = CreateColorizer(newValue);
if (_colorizer != null)
{
textArea.TextView.LineTransformers.Insert(0, _colorizer);
}
}
}
/// <summary>
/// Creates the highlighting colorizer for the specified highlighting definition.
/// Allows derived classes to provide custom colorizer implementations for special highlighting definitions.
/// </summary>
/// <returns></returns>
protected virtual IVisualLineTransformer CreateColorizer(IHighlightingDefinition highlightingDefinition)
{
if (highlightingDefinition == null)
throw new ArgumentNullException(nameof(highlightingDefinition));
return new HighlightingColorizer(highlightingDefinition);
}
#endregion
#region WordWrap
/// <summary>
/// Word wrap dependency property.
/// </summary>
public static readonly StyledProperty<bool> WordWrapProperty =
AvaloniaProperty.Register<TextEditor, bool>("WordWrap");
/// <summary>
/// Specifies whether the text editor uses word wrapping.
/// </summary>
/// <remarks>
/// Setting WordWrap=true has the same effect as setting HorizontalScrollBarVisibility=Disabled and will override the
/// HorizontalScrollBarVisibility setting.
/// </remarks>
public bool WordWrap
{
get => GetValue(WordWrapProperty);
set => SetValue(WordWrapProperty, value);
}
#endregion
#region IsReadOnly
/// <summary>
/// IsReadOnly dependency property.
/// </summary>
public static readonly StyledProperty<bool> IsReadOnlyProperty =
AvaloniaProperty.Register<TextEditor, bool>("IsReadOnly");
/// <summary>
/// Specifies whether the user can change the text editor content.
/// Setting this property will replace the
/// <see cref="Editing.TextArea.ReadOnlySectionProvider">TextArea.ReadOnlySectionProvider</see>.
/// </summary>
public bool IsReadOnly
{
get => GetValue(IsReadOnlyProperty);
set => SetValue(IsReadOnlyProperty, value);
}
private static void OnIsReadOnlyChanged(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is TextEditor editor)
{
if ((bool)e.NewValue)
editor.TextArea.ReadOnlySectionProvider = ReadOnlySectionDocument.Instance;
else
editor.TextArea.ReadOnlySectionProvider = NoReadOnlySections.Instance;
}
}
#endregion
#region IsModified
/// <summary>
/// Dependency property for <see cref="IsModified"/>
/// </summary>
public static readonly StyledProperty<bool> IsModifiedProperty =
AvaloniaProperty.Register<TextEditor, bool>("IsModified");
/// <summary>
/// Gets/Sets the 'modified' flag.
/// </summary>
public bool IsModified
{
get => GetValue(IsModifiedProperty);
set => SetValue(IsModifiedProperty, value);
}
private static void OnIsModifiedChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
var document = editor?.Document;
if (document != null)
{
var undoStack = document.UndoStack;
if ((bool)e.NewValue)
{
if (undoStack.IsOriginalFile)
undoStack.DiscardOriginalFileMarker();
}
else
{
undoStack.MarkAsOriginalFile();
}
}
}
private void HandleIsOriginalChanged(PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsOriginalFile")
{
var document = Document;
if (document != null)
{
SetValue(IsModifiedProperty, (object)!document.UndoStack.IsOriginalFile);
}
}
}
#endregion
#region ShowLineNumbers
/// <summary>
/// ShowLineNumbers dependency property.
/// </summary>
public static readonly StyledProperty<bool> ShowLineNumbersProperty =
AvaloniaProperty.Register<TextEditor, bool>("ShowLineNumbers");
/// <summary>
/// Specifies whether line numbers are shown on the left to the text view.
/// </summary>
public bool ShowLineNumbers
{
get => GetValue(ShowLineNumbersProperty);
set => SetValue(ShowLineNumbersProperty, value);
}
private static void OnShowLineNumbersChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
if (editor == null) return;
var leftMargins = editor.TextArea.LeftMargins;
if ((bool)e.NewValue)
{
var lineNumbers = new LineNumberMargin();
var line = (Line)DottedLineMargin.Create();
leftMargins.Insert(0, lineNumbers);
leftMargins.Insert(1, line);
var lineNumbersForeground = new Binding("LineNumbersForeground") { Source = editor };
line.Bind(Shape.StrokeProperty, lineNumbersForeground);
lineNumbers.Bind(ForegroundProperty, lineNumbersForeground);
}
else
{
for (var i = 0; i < leftMargins.Count; i++)
{
if (leftMargins[i] is LineNumberMargin)
{
leftMargins.RemoveAt(i);
if (i < leftMargins.Count && DottedLineMargin.IsDottedLineMargin(leftMargins[i]))
{
leftMargins.RemoveAt(i);
}
break;
}
}
}
}
#endregion
#region LineNumbersForeground
/// <summary>
/// LineNumbersForeground dependency property.
/// </summary>
public static readonly StyledProperty<IBrush> LineNumbersForegroundProperty =
AvaloniaProperty.Register<TextEditor, IBrush>("LineNumbersForeground", Brushes.Gray);
/// <summary>
/// Gets/sets the Brush used for displaying the foreground color of line numbers.
/// </summary>
public IBrush LineNumbersForeground
{
get => GetValue(LineNumbersForegroundProperty);
set => SetValue(LineNumbersForegroundProperty, value);
}
private static void OnLineNumbersForegroundChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
var lineNumberMargin = editor?.TextArea.LeftMargins.FirstOrDefault(margin => margin is LineNumberMargin) as LineNumberMargin;
lineNumberMargin?.SetValue(ForegroundProperty, e.NewValue);
}
private static void OnFontFamilyPropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
editor?.TextArea.TextView.SetValue(FontFamilyProperty, e.NewValue);
}
private static void OnFontSizePropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
editor?.TextArea.TextView.SetValue(FontSizeProperty, e.NewValue);
}
#endregion
#region TextBoxBase-like methods
/// <summary>
/// Appends text to the end of the document.
/// </summary>
public void AppendText(string textData)
{
var document = GetDocument();
document.Insert(document.TextLength, textData);
}
/// <summary>
/// Begins a group of document changes.
/// </summary>
public void BeginChange()
{
GetDocument().BeginUpdate();
}
/// <summary>
/// Copies the current selection to the clipboard.
/// </summary>
public void Copy()
{
if (CanCopy)
{
ApplicationCommands.Copy.Execute(null, TextArea);
}
}
/// <summary>
/// Removes the current selection and copies it to the clipboard.
/// </summary>
public void Cut()
{
if (CanCut)
{
ApplicationCommands.Cut.Execute(null, TextArea);
}
}
/// <summary>
/// Begins a group of document changes and returns an object that ends the group of document
/// changes when it is disposed.
/// </summary>
public IDisposable DeclareChangeBlock()
{
return GetDocument().RunUpdate();
}
/// <summary>
/// Removes the current selection without copying it to the clipboard.
/// </summary>
public void Delete()
{
if(CanDelete)
{
ApplicationCommands.Delete.Execute(null, TextArea);
}
}
/// <summary>
/// Ends the current group of document changes.
/// </summary>
public void EndChange()
{
GetDocument().EndUpdate();
}
/// <summary>
/// Scrolls one line down.
/// </summary>
public void LineDown()
{
//if (scrollViewer != null)
// scrollViewer.LineDown();
}
/// <summary>
/// Scrolls to the left.
/// </summary>
public void LineLeft()
{
//if (scrollViewer != null)
// scrollViewer.LineLeft();
}
/// <summary>
/// Scrolls to the right.
/// </summary>
public void LineRight()
{
//if (scrollViewer != null)
// scrollViewer.LineRight();
}
/// <summary>
/// Scrolls one line up.
/// </summary>
public void LineUp()
{
//if (scrollViewer != null)
// scrollViewer.LineUp();
}
/// <summary>
/// Scrolls one page down.
/// </summary>
public void PageDown()
{
//if (scrollViewer != null)
// scrollViewer.PageDown();
}
/// <summary>
/// Scrolls one page up.
/// </summary>
public void PageUp()
{
//if (scrollViewer != null)
// scrollViewer.PageUp();
}
/// <summary>
/// Scrolls one page left.
/// </summary>
public void PageLeft()
{
//if (scrollViewer != null)
// scrollViewer.PageLeft();
}
/// <summary>
/// Scrolls one page right.
/// </summary>
public void PageRight()
{
//if (scrollViewer != null)
// scrollViewer.PageRight();
}
/// <summary>
/// Pastes the clipboard content.
/// </summary>
public void Paste()
{
if (CanPaste)
{
ApplicationCommands.Paste.Execute(null, TextArea);
}
}
/// <summary>
/// Redoes the most recent undone command.
/// </summary>
/// <returns>True is the redo operation was successful, false is the redo stack is empty.</returns>
public bool Redo()
{
if (CanRedo)
{
ApplicationCommands.Redo.Execute(null, TextArea);
return true;
}
return false;
}
/// <summary>
/// Scrolls to the end of the document.
/// </summary>
public void ScrollToEnd()
{
ApplyTemplate(); // ensure scrollViewer is created
ScrollViewer?.ScrollToEnd();
}
/// <summary>
/// Scrolls to the start of the document.
/// </summary>
public void ScrollToHome()
{
ApplyTemplate(); // ensure scrollViewer is created
ScrollViewer?.ScrollToHome();
}
/// <summary>
/// Scrolls to the specified position in the document.
/// </summary>
public void ScrollToHorizontalOffset(double offset)
{
ApplyTemplate(); // ensure scrollViewer is created
//if (scrollViewer != null)
// scrollViewer.ScrollToHorizontalOffset(offset);
}
/// <summary>
/// Scrolls to the specified position in the document.
/// </summary>
public void ScrollToVerticalOffset(double offset)
{
ApplyTemplate(); // ensure scrollViewer is created
//if (scrollViewer != null)
// scrollViewer.ScrollToVerticalOffset(offset);
}
/// <summary>
/// Selects the entire text.
/// </summary>
public void SelectAll()
{
if (CanSelectAll)
{
ApplicationCommands.SelectAll.Execute(null, TextArea);
}
}
/// <summary>
/// Undoes the most recent command.
/// </summary>
/// <returns>True is the undo operation was successful, false is the undo stack is empty.</returns>
public bool Undo()
{
if (CanUndo)
{
ApplicationCommands.Undo.Execute(null, TextArea);
return true;
}
return false;
}
/// <summary>
/// Gets if the most recent undone command can be redone.
/// </summary>
public bool CanRedo
{
get { return ApplicationCommands.Redo.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if the most recent command can be undone.
/// </summary>
public bool CanUndo
{
get { return ApplicationCommands.Undo.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be copied
/// </summary>
public bool CanCopy
{
get { return ApplicationCommands.Copy.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be cut
/// </summary>
public bool CanCut
{
get { return ApplicationCommands.Cut.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be pasted
/// </summary>
public bool CanPaste
{
get { return ApplicationCommands.Paste.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if selected text in editor can be deleted
/// </summary>
public bool CanDelete
{
get { return ApplicationCommands.Delete.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text the editor can select all
/// </summary>
public bool CanSelectAll
{
get { return ApplicationCommands.SelectAll.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text editor can activate the search panel
/// </summary>
public bool CanSearch
{
get { return searchPanel != null; }
}
/// <summary>
/// Gets the vertical size of the document.
/// </summary>
public double ExtentHeight => ScrollViewer?.Extent.Height ?? 0;
/// <summary>
/// Gets the horizontal size of the current document region.
/// </summary>
public double ExtentWidth => ScrollViewer?.Extent.Width ?? 0;
/// <summary>
/// Gets the horizontal size of the viewport.
/// </summary>
public double ViewportHeight => ScrollViewer?.Viewport.Height ?? 0;
/// <summary>
/// Gets the horizontal size of the viewport.
/// </summary>
public double ViewportWidth => ScrollViewer?.Viewport.Width ?? 0;
/// <summary>
/// Gets the vertical scroll position.
/// </summary>
public double VerticalOffset => ScrollViewer?.Offset.Y ?? 0;
/// <summary>
/// Gets the horizontal scroll position.
/// </summary>
public double HorizontalOffset => ScrollViewer?.Offset.X ?? 0;
#endregion
#region TextBox methods
/// <summary>
/// Gets/Sets the selected text.
/// </summary>
public string SelectedText
{
get
{
// We'll get the text from the whole surrounding segment.
// This is done to ensure that SelectedText.Length == SelectionLength.
if (textArea.Document != null && !textArea.Selection.IsEmpty)
return textArea.Document.GetText(textArea.Selection.SurroundingSegment);
return string.Empty;
}
set
{
if (value == null)
throw new ArgumentNullException(nameof(value));
var textArea = TextArea;
if (textArea.Document != null)
{
var offset = SelectionStart;
var length = SelectionLength;
textArea.Document.Replace(offset, length, value);
// keep inserted text selected
textArea.Selection = Selection.Create(textArea, offset, offset + value.Length);
}
}
}
/// <summary>
/// Gets/sets the caret position.
/// </summary>
public int CaretOffset
{
get
{
return textArea.Caret.Offset;
}
set
{
textArea.Caret.Offset = value;
}
}
/// <summary>
/// Gets/sets the start position of the selection.
/// </summary>
public int SelectionStart
{
get
{
if (textArea.Selection.IsEmpty)
return textArea.Caret.Offset;
else
return textArea.Selection.SurroundingSegment.Offset;
}
set => Select(value, SelectionLength);
}
/// <summary>
/// Gets/sets the length of the selection.
/// </summary>
public int SelectionLength
{
get
{
if (!textArea.Selection.IsEmpty)
return textArea.Selection.SurroundingSegment.Length;
else
return 0;
}
set => Select(SelectionStart, value);
}
/// <summary>
/// Selects the specified text section.
/// </summary>
public void Select(int start, int length)
{
var documentLength = Document?.TextLength ?? 0;
if (start < 0 || start > documentLength)
throw new ArgumentOutOfRangeException(nameof(start), start, "Value must be between 0 and " + documentLength);
if (length < 0 || start + length > documentLength)
throw new ArgumentOutOfRangeException(nameof(length), length, "Value must be between 0 and " + (documentLength - start));
TextArea.Selection = Selection.Create(TextArea, start, start + length);
TextArea.Caret.Offset = start + length;
}
/// <summary>
/// Gets the number of lines in the document.
/// </summary>
public int LineCount
{
get
{
var document = Document;
if (document != null)
return document.LineCount;
return 1;
}
}
/// <summary>
/// Clears the text.
/// </summary>
public void Clear()
{
Text = string.Empty;
}
#endregion
#region Loading from stream
/// <summary>
/// Loads the text from the stream, auto-detecting the encoding.
/// </summary>
/// <remarks>
/// This method sets <see cref="IsModified"/> to false.
/// </remarks>
public void Load(Stream stream)
{
using (var reader = FileReader.OpenStream(stream, Encoding ?? Encoding.UTF8))
{
Text = reader.ReadToEnd();
SetValue(EncodingProperty, (object)reader.CurrentEncoding);
}
SetValue(IsModifiedProperty, (object)false);
}
/// <summary>
/// Loads the text from the stream, auto-detecting the encoding.
/// </summary>
public void Load(string fileName)
{
if (fileName == null)
throw new ArgumentNullException(nameof(fileName));
// TODO:load
//using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
//{
// Load(fs);
//}
}
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
public static readonly AvaloniaProperty HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
get => (ScrollBarVisibility)GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
public static readonly AvaloniaProperty VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
get => (ScrollBarVisibility)GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
if (stream == null)
throw new ArgumentNullException(nameof(stream));
var encoding = Encoding;
var document = Document;
var writer = encoding != null ? new StreamWriter(stream, encoding) : new StreamWriter(stream);
document?.WriteTextTo(writer);
writer.Flush();
// do not close the stream
SetValue(IsModifiedProperty, (object)false);
}
/// <summary>
/// Saves the text to the file.
/// </summary>
public void Save(string fileName)
{
if (fileName == null)
throw new ArgumentNullException(nameof(fileName));
// TODO: save
//using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
//{
// Save(fs);
//}
}
#endregion
#region PointerHover events
/// <summary>
/// The PreviewPointerHover event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PreviewPointerHoverEvent =
TextView.PreviewPointerHoverEvent;
/// <summary>
/// the pointerHover event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PointerHoverEvent =
TextView.PointerHoverEvent;
/// <summary>
/// The PreviewPointerHoverStopped event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PreviewPointerHoverStoppedEvent =
TextView.PreviewPointerHoverStoppedEvent;
/// <summary>
/// the pointerHoverStopped event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PointerHoverStoppedEvent =
TextView.PointerHoverStoppedEvent;
/// <summary>
/// Occurs when the pointer has hovered over a fixed location for some time.
/// </summary>
public event EventHandler<PointerEventArgs> PreviewPointerHover
{
add => AddHandler(PreviewPointerHoverEvent, value);
remove => RemoveHandler(PreviewPointerHoverEvent, value);
}
/// <summary>
/// Occurs when the pointer has hovered over a fixed location for some time.
/// </summary>
public event EventHandler<PointerEventArgs> PointerHover
{
add => AddHandler(PointerHoverEvent, value);
remove => RemoveHandler(PointerHoverEvent, value);
}
/// <summary>
/// Occurs when the pointer had previously hovered but now started moving again.
/// </summary>
public event EventHandler<PointerEventArgs> PreviewPointerHoverStopped
{
add => AddHandler(PreviewPointerHoverStoppedEvent, value);
remove => RemoveHandler(PreviewPointerHoverStoppedEvent, value);
}
/// <summary>
/// Occurs when the pointer had previously hovered but now started moving again.
/// </summary>
public event EventHandler<PointerEventArgs> PointerHoverStopped
{
add => AddHandler(PointerHoverStoppedEvent, value);
remove => RemoveHandler(PointerHoverStoppedEvent, value);
}
#endregion
#region ScrollBarVisibility
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
public static readonly AttachedProperty<ScrollBarVisibility> HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
get => GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
private ScrollBarVisibility _horizontalScrollBarVisibilityBck = ScrollBarVisibility.Auto;
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
public static readonly AttachedProperty<ScrollBarVisibility> VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
get => GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
object IServiceProvider.GetService(Type serviceType)
{
return TextArea.GetService(serviceType);
}
/// <summary>
/// Gets the text view position from a point inside the editor.
/// </summary>
/// <param name="point">The position, relative to top left
/// corner of TextEditor control</param>
/// <returns>The text view position, or null if the point is outside the document.</returns>
public TextViewPosition? GetPositionFromPoint(Point point)
{
if (Document == null)
return null;
var textView = TextArea.TextView;
Point tpoint = (Point)this.TranslatePoint(point + new Point(textView.ScrollOffset.X, Math.Floor(textView.ScrollOffset.Y)), textView);
return textView.GetPosition(tpoint);
}
/// <summary>
/// Scrolls to the specified line.
/// This method requires that the TextEditor was already assigned a size (layout engine must have run prior).
/// </summary>
public void ScrollToLine(int line)
{
ScrollTo(line, -1);
}
/// <summary>
/// Scrolls to the specified line/column.
/// This method requires that the TextEditor was already assigned a size (layout engine must have run prior).
/// </summary>
public void ScrollTo(int line, int column)
{
const double MinimumScrollFraction = 0.3;
ScrollTo(line, column, VisualYPosition.LineMiddle,
null != ScrollViewer ? ScrollViewer.Viewport.Height / 2 : 0.0, MinimumScrollFraction);
}
/// <summary>
/// Scrolls to the specified line/column.
/// This method requires that the TextEditor was already assigned a size (WPF layout must have run prior).
/// </summary>
/// <param name="line">Line to scroll to.</param>
/// <param name="column">Column to scroll to (important if wrapping is 'on', and for the horizontal scroll position).</param>
/// <param name="yPositionMode">The mode how to reference the Y position of the line.</param>
/// <param name="referencedVerticalViewPortOffset">Offset from the top of the viewport to where the referenced line/column should be positioned.</param>
/// <param name="minimumScrollFraction">The minimum vertical and/or horizontal scroll offset, expressed as fraction of the height or width of the viewport window, respectively.</param>
public void ScrollTo(int line, int column, VisualYPosition yPositionMode,
double referencedVerticalViewPortOffset, double minimumScrollFraction)
{
TextView textView = textArea.TextView;
TextDocument document = textView.Document;
if (ScrollViewer != null && document != null)
{
if (line < 1)
line = 1;
if (line > document.LineCount)
line = document.LineCount;
ILogicalScrollable scrollInfo = textView;
if (!scrollInfo.CanHorizontallyScroll)
{
// Word wrap is enabled. Ensure that we have up-to-date info about line height so that we scroll
// to the correct position.
// This avoids that the user has to repeat the ScrollTo() call several times when there are very long lines.
VisualLine vl = textView.GetOrConstructVisualLine(document.GetLineByNumber(line));
double remainingHeight = referencedVerticalViewPortOffset;
while (remainingHeight > 0)
{
DocumentLine prevLine = vl.FirstDocumentLine.PreviousLine;
if (prevLine == null)
break;
vl = textView.GetOrConstructVisualLine(prevLine);
remainingHeight -= vl.Height;
}
}
Point p = textArea.TextView.GetVisualPosition(
new TextViewPosition(line, Math.Max(1, column)),
yPositionMode);
double targetX = ScrollViewer.Offset.X;
double targetY = ScrollViewer.Offset.Y;
double verticalPos = p.Y - referencedVerticalViewPortOffset;
if (Math.Abs(verticalPos - ScrollViewer.Offset.Y) >
minimumScrollFraction * ScrollViewer.Viewport.Height)
{
targetY = Math.Max(0, verticalPos);
}
if (column > 0)
{
if (p.X > ScrollViewer.Viewport.Width - Caret.MinimumDistanceToViewBorder * 2)
{
double horizontalPos = Math.Max(0, p.X - ScrollViewer.Viewport.Width / 2);
if (Math.Abs(horizontalPos - ScrollViewer.Offset.X) >
minimumScrollFraction * ScrollViewer.Viewport.Width)
{
targetX = 0;
}
}
else
{
targetX = 0;
}
}
if (targetX != ScrollViewer.Offset.X || targetY != ScrollViewer.Offset.Y)
ScrollViewer.Offset = new Vector(targetX, targetY);
}
}
}
}
<MSG> Merge pull request #73 from jeffreye/fix-scroll
Fix scroll
<DFF> @@ -47,6 +47,8 @@ namespace AvaloniaEdit
static TextEditor()
{
FocusableProperty.OverrideDefaultValue<TextEditor>(true);
+ HorizontalScrollBarVisibilityProperty.OverrideDefaultValue<TextEditor>(ScrollBarVisibility.Auto);
+ VerticalScrollBarVisibilityProperty.OverrideDefaultValue<TextEditor>(ScrollBarVisibility.Auto);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
@@ -1049,28 +1051,28 @@ namespace AvaloniaEdit
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
- public static readonly AvaloniaProperty HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
+ public static readonly AttachedProperty<ScrollBarVisibility> HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
- get => (ScrollBarVisibility)GetValue(HorizontalScrollBarVisibilityProperty);
+ get => GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
- public static readonly AvaloniaProperty VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
+ public static readonly AttachedProperty<ScrollBarVisibility> VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
- get => (ScrollBarVisibility)GetValue(VerticalScrollBarVisibilityProperty);
+ get => GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
| 6 | Merge pull request #73 from jeffreye/fix-scroll | 4 | .cs | cs | mit | AvaloniaUI/AvaloniaEdit |
10066910 | <NME> TextEditor.cs
<BEF> // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using Avalonia;
using AvaloniaEdit.Document;
using AvaloniaEdit.Editing;
using AvaloniaEdit.Highlighting;
using AvaloniaEdit.Rendering;
using AvaloniaEdit.Utils;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Shapes;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.LogicalTree;
using Avalonia.Media;
using Avalonia.Data;
using AvaloniaEdit.Search;
namespace AvaloniaEdit
{
/// <summary>
/// The text editor control.
/// Contains a scrollable TextArea.
/// </summary>
public class TextEditor : TemplatedControl, ITextEditorComponent
static TextEditor()
{
FocusableProperty.OverrideDefaultValue<TextEditor>(true);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
SyntaxHighlightingProperty.Changed.Subscribe(OnSyntaxHighlightingChanged);
IsReadOnlyProperty.Changed.Subscribe(OnIsReadOnlyChanged);
IsModifiedProperty.Changed.Subscribe(OnIsModifiedChanged);
ShowLineNumbersProperty.Changed.Subscribe(OnShowLineNumbersChanged);
LineNumbersForegroundProperty.Changed.Subscribe(OnLineNumbersForegroundChanged);
FontFamilyProperty.Changed.Subscribe(OnFontFamilyPropertyChanged);
FontSizeProperty.Changed.Subscribe(OnFontSizePropertyChanged);
}
/// <summary>
/// Creates a new TextEditor instance.
/// </summary>
public TextEditor() : this(new TextArea())
{
}
/// <summary>
/// Creates a new TextEditor instance.
/// </summary>
protected TextEditor(TextArea textArea) : this(textArea, new TextDocument())
{
}
protected TextEditor(TextArea textArea, TextDocument document)
{
this.textArea = textArea ?? throw new ArgumentNullException(nameof(textArea));
textArea.TextView.Services.AddService(this);
SetValue(OptionsProperty, textArea.Options);
SetValue(DocumentProperty, document);
textArea[!BackgroundProperty] = this[!BackgroundProperty];
}
#endregion
protected override void OnGotFocus(GotFocusEventArgs e)
{
base.OnGotFocus(e);
TextArea.Focus();
e.Handled = true;
}
#region Document property
/// <summary>
/// Document property.
/// </summary>
public static readonly StyledProperty<TextDocument> DocumentProperty
= TextView.DocumentProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the document displayed by the text editor.
/// This is a dependency property.
/// </summary>
public TextDocument Document
{
get => GetValue(DocumentProperty);
set => SetValue(DocumentProperty, value);
}
/// <summary>
/// Occurs when the document property has changed.
/// </summary>
public event EventHandler DocumentChanged;
/// <summary>
/// Raises the <see cref="DocumentChanged"/> event.
/// </summary>
protected virtual void OnDocumentChanged(EventArgs e)
{
DocumentChanged?.Invoke(this, e);
}
private static void OnDocumentChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnDocumentChanged((TextDocument)e.OldValue, (TextDocument)e.NewValue);
}
private void OnDocumentChanged(TextDocument oldValue, TextDocument newValue)
{
if (oldValue != null)
{
TextDocumentWeakEventManager.TextChanged.RemoveHandler(oldValue, OnTextChanged);
PropertyChangedWeakEventManager.RemoveHandler(oldValue.UndoStack, OnUndoStackPropertyChangedHandler);
}
TextArea.Document = newValue;
if (newValue != null)
{
TextDocumentWeakEventManager.TextChanged.AddHandler(newValue, OnTextChanged);
PropertyChangedWeakEventManager.AddHandler(newValue.UndoStack, OnUndoStackPropertyChangedHandler);
}
OnDocumentChanged(EventArgs.Empty);
OnTextChanged(EventArgs.Empty);
}
#endregion
#region Options property
/// <summary>
/// Options property.
/// </summary>
public static readonly StyledProperty<TextEditorOptions> OptionsProperty
= TextView.OptionsProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the options currently used by the text editor.
/// </summary>
public TextEditorOptions Options
{
get => GetValue(OptionsProperty);
set => SetValue(OptionsProperty, value);
}
/// <summary>
/// Occurs when a text editor option has changed.
/// </summary>
public event PropertyChangedEventHandler OptionChanged;
/// <summary>
/// Raises the <see cref="OptionChanged"/> event.
/// </summary>
protected virtual void OnOptionChanged(PropertyChangedEventArgs e)
{
OptionChanged?.Invoke(this, e);
}
private static void OnOptionsChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnOptionsChanged((TextEditorOptions)e.OldValue, (TextEditorOptions)e.NewValue);
}
private void OnOptionsChanged(TextEditorOptions oldValue, TextEditorOptions newValue)
{
if (oldValue != null)
{
PropertyChangedWeakEventManager.RemoveHandler(oldValue, OnPropertyChangedHandler);
}
TextArea.Options = newValue;
if (newValue != null)
{
PropertyChangedWeakEventManager.AddHandler(newValue, OnPropertyChangedHandler);
}
OnOptionChanged(new PropertyChangedEventArgs(null));
}
private void OnPropertyChangedHandler(object sender, PropertyChangedEventArgs e)
{
OnOptionChanged(e);
}
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
base.OnPropertyChanged(change);
if (change.Property == WordWrapProperty)
{
if (WordWrap)
{
_horizontalScrollBarVisibilityBck = HorizontalScrollBarVisibility;
HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
}
else
{
HorizontalScrollBarVisibility = _horizontalScrollBarVisibilityBck;
}
}
}
private void OnUndoStackPropertyChangedHandler(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsOriginalFile")
{
HandleIsOriginalChanged(e);
}
}
private void OnTextChanged(object sender, EventArgs e)
{
OnTextChanged(e);
}
#endregion
#region Text property
/// <summary>
/// Gets/Sets the text of the current document.
/// </summary>
public string Text
{
get
{
var document = Document;
return document != null ? document.Text : string.Empty;
}
set
{
var document = GetDocument();
document.Text = value ?? string.Empty;
// after replacing the full text, the caret is positioned at the end of the document
// - reset it to the beginning.
CaretOffset = 0;
document.UndoStack.ClearAll();
}
}
private TextDocument GetDocument()
{
var document = Document;
if (document == null)
throw ThrowUtil.NoDocumentAssigned();
return document;
}
/// <summary>
/// Occurs when the Text property changes.
/// </summary>
public event EventHandler TextChanged;
/// <summary>
/// Raises the <see cref="TextChanged"/> event.
/// </summary>
protected virtual void OnTextChanged(EventArgs e)
{
TextChanged?.Invoke(this, e);
}
#endregion
#region TextArea / ScrollViewer properties
private readonly TextArea textArea;
private SearchPanel searchPanel;
private bool wasSearchPanelOpened;
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
ScrollViewer = (ScrollViewer)e.NameScope.Find("PART_ScrollViewer");
ScrollViewer.Content = TextArea;
searchPanel = SearchPanel.Install(this);
}
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnAttachedToLogicalTree(e);
if (searchPanel != null && wasSearchPanelOpened)
{
searchPanel.Open();
}
}
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnDetachedFromLogicalTree(e);
if (searchPanel != null)
{
wasSearchPanelOpened = searchPanel.IsOpened;
if (searchPanel.IsOpened)
searchPanel.Close();
}
}
/// <summary>
/// Gets the text area.
/// </summary>
public TextArea TextArea => textArea;
/// <summary>
/// Gets the search panel.
/// </summary>
public SearchPanel SearchPanel => searchPanel;
/// <summary>
/// Gets the scroll viewer used by the text editor.
/// This property can return null if the template has not been applied / does not contain a scroll viewer.
/// </summary>
internal ScrollViewer ScrollViewer { get; private set; }
#endregion
#region Syntax highlighting
/// <summary>
/// The <see cref="SyntaxHighlighting"/> property.
/// </summary>
public static readonly StyledProperty<IHighlightingDefinition> SyntaxHighlightingProperty =
AvaloniaProperty.Register<TextEditor, IHighlightingDefinition>("SyntaxHighlighting");
/// <summary>
/// Gets/sets the syntax highlighting definition used to colorize the text.
/// </summary>
public IHighlightingDefinition SyntaxHighlighting
{
get => GetValue(SyntaxHighlightingProperty);
set => SetValue(SyntaxHighlightingProperty, value);
}
private IVisualLineTransformer _colorizer;
private static void OnSyntaxHighlightingChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnSyntaxHighlightingChanged(e.NewValue as IHighlightingDefinition);
}
private void OnSyntaxHighlightingChanged(IHighlightingDefinition newValue)
{
if (_colorizer != null)
{
textArea.TextView.LineTransformers.Remove(_colorizer);
_colorizer = null;
}
if (newValue != null)
{
_colorizer = CreateColorizer(newValue);
if (_colorizer != null)
{
textArea.TextView.LineTransformers.Insert(0, _colorizer);
}
}
}
/// <summary>
/// Creates the highlighting colorizer for the specified highlighting definition.
/// Allows derived classes to provide custom colorizer implementations for special highlighting definitions.
/// </summary>
/// <returns></returns>
protected virtual IVisualLineTransformer CreateColorizer(IHighlightingDefinition highlightingDefinition)
{
if (highlightingDefinition == null)
throw new ArgumentNullException(nameof(highlightingDefinition));
return new HighlightingColorizer(highlightingDefinition);
}
#endregion
#region WordWrap
/// <summary>
/// Word wrap dependency property.
/// </summary>
public static readonly StyledProperty<bool> WordWrapProperty =
AvaloniaProperty.Register<TextEditor, bool>("WordWrap");
/// <summary>
/// Specifies whether the text editor uses word wrapping.
/// </summary>
/// <remarks>
/// Setting WordWrap=true has the same effect as setting HorizontalScrollBarVisibility=Disabled and will override the
/// HorizontalScrollBarVisibility setting.
/// </remarks>
public bool WordWrap
{
get => GetValue(WordWrapProperty);
set => SetValue(WordWrapProperty, value);
}
#endregion
#region IsReadOnly
/// <summary>
/// IsReadOnly dependency property.
/// </summary>
public static readonly StyledProperty<bool> IsReadOnlyProperty =
AvaloniaProperty.Register<TextEditor, bool>("IsReadOnly");
/// <summary>
/// Specifies whether the user can change the text editor content.
/// Setting this property will replace the
/// <see cref="Editing.TextArea.ReadOnlySectionProvider">TextArea.ReadOnlySectionProvider</see>.
/// </summary>
public bool IsReadOnly
{
get => GetValue(IsReadOnlyProperty);
set => SetValue(IsReadOnlyProperty, value);
}
private static void OnIsReadOnlyChanged(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is TextEditor editor)
{
if ((bool)e.NewValue)
editor.TextArea.ReadOnlySectionProvider = ReadOnlySectionDocument.Instance;
else
editor.TextArea.ReadOnlySectionProvider = NoReadOnlySections.Instance;
}
}
#endregion
#region IsModified
/// <summary>
/// Dependency property for <see cref="IsModified"/>
/// </summary>
public static readonly StyledProperty<bool> IsModifiedProperty =
AvaloniaProperty.Register<TextEditor, bool>("IsModified");
/// <summary>
/// Gets/Sets the 'modified' flag.
/// </summary>
public bool IsModified
{
get => GetValue(IsModifiedProperty);
set => SetValue(IsModifiedProperty, value);
}
private static void OnIsModifiedChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
var document = editor?.Document;
if (document != null)
{
var undoStack = document.UndoStack;
if ((bool)e.NewValue)
{
if (undoStack.IsOriginalFile)
undoStack.DiscardOriginalFileMarker();
}
else
{
undoStack.MarkAsOriginalFile();
}
}
}
private void HandleIsOriginalChanged(PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsOriginalFile")
{
var document = Document;
if (document != null)
{
SetValue(IsModifiedProperty, (object)!document.UndoStack.IsOriginalFile);
}
}
}
#endregion
#region ShowLineNumbers
/// <summary>
/// ShowLineNumbers dependency property.
/// </summary>
public static readonly StyledProperty<bool> ShowLineNumbersProperty =
AvaloniaProperty.Register<TextEditor, bool>("ShowLineNumbers");
/// <summary>
/// Specifies whether line numbers are shown on the left to the text view.
/// </summary>
public bool ShowLineNumbers
{
get => GetValue(ShowLineNumbersProperty);
set => SetValue(ShowLineNumbersProperty, value);
}
private static void OnShowLineNumbersChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
if (editor == null) return;
var leftMargins = editor.TextArea.LeftMargins;
if ((bool)e.NewValue)
{
var lineNumbers = new LineNumberMargin();
var line = (Line)DottedLineMargin.Create();
leftMargins.Insert(0, lineNumbers);
leftMargins.Insert(1, line);
var lineNumbersForeground = new Binding("LineNumbersForeground") { Source = editor };
line.Bind(Shape.StrokeProperty, lineNumbersForeground);
lineNumbers.Bind(ForegroundProperty, lineNumbersForeground);
}
else
{
for (var i = 0; i < leftMargins.Count; i++)
{
if (leftMargins[i] is LineNumberMargin)
{
leftMargins.RemoveAt(i);
if (i < leftMargins.Count && DottedLineMargin.IsDottedLineMargin(leftMargins[i]))
{
leftMargins.RemoveAt(i);
}
break;
}
}
}
}
#endregion
#region LineNumbersForeground
/// <summary>
/// LineNumbersForeground dependency property.
/// </summary>
public static readonly StyledProperty<IBrush> LineNumbersForegroundProperty =
AvaloniaProperty.Register<TextEditor, IBrush>("LineNumbersForeground", Brushes.Gray);
/// <summary>
/// Gets/sets the Brush used for displaying the foreground color of line numbers.
/// </summary>
public IBrush LineNumbersForeground
{
get => GetValue(LineNumbersForegroundProperty);
set => SetValue(LineNumbersForegroundProperty, value);
}
private static void OnLineNumbersForegroundChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
var lineNumberMargin = editor?.TextArea.LeftMargins.FirstOrDefault(margin => margin is LineNumberMargin) as LineNumberMargin;
lineNumberMargin?.SetValue(ForegroundProperty, e.NewValue);
}
private static void OnFontFamilyPropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
editor?.TextArea.TextView.SetValue(FontFamilyProperty, e.NewValue);
}
private static void OnFontSizePropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
editor?.TextArea.TextView.SetValue(FontSizeProperty, e.NewValue);
}
#endregion
#region TextBoxBase-like methods
/// <summary>
/// Appends text to the end of the document.
/// </summary>
public void AppendText(string textData)
{
var document = GetDocument();
document.Insert(document.TextLength, textData);
}
/// <summary>
/// Begins a group of document changes.
/// </summary>
public void BeginChange()
{
GetDocument().BeginUpdate();
}
/// <summary>
/// Copies the current selection to the clipboard.
/// </summary>
public void Copy()
{
if (CanCopy)
{
ApplicationCommands.Copy.Execute(null, TextArea);
}
}
/// <summary>
/// Removes the current selection and copies it to the clipboard.
/// </summary>
public void Cut()
{
if (CanCut)
{
ApplicationCommands.Cut.Execute(null, TextArea);
}
}
/// <summary>
/// Begins a group of document changes and returns an object that ends the group of document
/// changes when it is disposed.
/// </summary>
public IDisposable DeclareChangeBlock()
{
return GetDocument().RunUpdate();
}
/// <summary>
/// Removes the current selection without copying it to the clipboard.
/// </summary>
public void Delete()
{
if(CanDelete)
{
ApplicationCommands.Delete.Execute(null, TextArea);
}
}
/// <summary>
/// Ends the current group of document changes.
/// </summary>
public void EndChange()
{
GetDocument().EndUpdate();
}
/// <summary>
/// Scrolls one line down.
/// </summary>
public void LineDown()
{
//if (scrollViewer != null)
// scrollViewer.LineDown();
}
/// <summary>
/// Scrolls to the left.
/// </summary>
public void LineLeft()
{
//if (scrollViewer != null)
// scrollViewer.LineLeft();
}
/// <summary>
/// Scrolls to the right.
/// </summary>
public void LineRight()
{
//if (scrollViewer != null)
// scrollViewer.LineRight();
}
/// <summary>
/// Scrolls one line up.
/// </summary>
public void LineUp()
{
//if (scrollViewer != null)
// scrollViewer.LineUp();
}
/// <summary>
/// Scrolls one page down.
/// </summary>
public void PageDown()
{
//if (scrollViewer != null)
// scrollViewer.PageDown();
}
/// <summary>
/// Scrolls one page up.
/// </summary>
public void PageUp()
{
//if (scrollViewer != null)
// scrollViewer.PageUp();
}
/// <summary>
/// Scrolls one page left.
/// </summary>
public void PageLeft()
{
//if (scrollViewer != null)
// scrollViewer.PageLeft();
}
/// <summary>
/// Scrolls one page right.
/// </summary>
public void PageRight()
{
//if (scrollViewer != null)
// scrollViewer.PageRight();
}
/// <summary>
/// Pastes the clipboard content.
/// </summary>
public void Paste()
{
if (CanPaste)
{
ApplicationCommands.Paste.Execute(null, TextArea);
}
}
/// <summary>
/// Redoes the most recent undone command.
/// </summary>
/// <returns>True is the redo operation was successful, false is the redo stack is empty.</returns>
public bool Redo()
{
if (CanRedo)
{
ApplicationCommands.Redo.Execute(null, TextArea);
return true;
}
return false;
}
/// <summary>
/// Scrolls to the end of the document.
/// </summary>
public void ScrollToEnd()
{
ApplyTemplate(); // ensure scrollViewer is created
ScrollViewer?.ScrollToEnd();
}
/// <summary>
/// Scrolls to the start of the document.
/// </summary>
public void ScrollToHome()
{
ApplyTemplate(); // ensure scrollViewer is created
ScrollViewer?.ScrollToHome();
}
/// <summary>
/// Scrolls to the specified position in the document.
/// </summary>
public void ScrollToHorizontalOffset(double offset)
{
ApplyTemplate(); // ensure scrollViewer is created
//if (scrollViewer != null)
// scrollViewer.ScrollToHorizontalOffset(offset);
}
/// <summary>
/// Scrolls to the specified position in the document.
/// </summary>
public void ScrollToVerticalOffset(double offset)
{
ApplyTemplate(); // ensure scrollViewer is created
//if (scrollViewer != null)
// scrollViewer.ScrollToVerticalOffset(offset);
}
/// <summary>
/// Selects the entire text.
/// </summary>
public void SelectAll()
{
if (CanSelectAll)
{
ApplicationCommands.SelectAll.Execute(null, TextArea);
}
}
/// <summary>
/// Undoes the most recent command.
/// </summary>
/// <returns>True is the undo operation was successful, false is the undo stack is empty.</returns>
public bool Undo()
{
if (CanUndo)
{
ApplicationCommands.Undo.Execute(null, TextArea);
return true;
}
return false;
}
/// <summary>
/// Gets if the most recent undone command can be redone.
/// </summary>
public bool CanRedo
{
get { return ApplicationCommands.Redo.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if the most recent command can be undone.
/// </summary>
public bool CanUndo
{
get { return ApplicationCommands.Undo.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be copied
/// </summary>
public bool CanCopy
{
get { return ApplicationCommands.Copy.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be cut
/// </summary>
public bool CanCut
{
get { return ApplicationCommands.Cut.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be pasted
/// </summary>
public bool CanPaste
{
get { return ApplicationCommands.Paste.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if selected text in editor can be deleted
/// </summary>
public bool CanDelete
{
get { return ApplicationCommands.Delete.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text the editor can select all
/// </summary>
public bool CanSelectAll
{
get { return ApplicationCommands.SelectAll.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text editor can activate the search panel
/// </summary>
public bool CanSearch
{
get { return searchPanel != null; }
}
/// <summary>
/// Gets the vertical size of the document.
/// </summary>
public double ExtentHeight => ScrollViewer?.Extent.Height ?? 0;
/// <summary>
/// Gets the horizontal size of the current document region.
/// </summary>
public double ExtentWidth => ScrollViewer?.Extent.Width ?? 0;
/// <summary>
/// Gets the horizontal size of the viewport.
/// </summary>
public double ViewportHeight => ScrollViewer?.Viewport.Height ?? 0;
/// <summary>
/// Gets the horizontal size of the viewport.
/// </summary>
public double ViewportWidth => ScrollViewer?.Viewport.Width ?? 0;
/// <summary>
/// Gets the vertical scroll position.
/// </summary>
public double VerticalOffset => ScrollViewer?.Offset.Y ?? 0;
/// <summary>
/// Gets the horizontal scroll position.
/// </summary>
public double HorizontalOffset => ScrollViewer?.Offset.X ?? 0;
#endregion
#region TextBox methods
/// <summary>
/// Gets/Sets the selected text.
/// </summary>
public string SelectedText
{
get
{
// We'll get the text from the whole surrounding segment.
// This is done to ensure that SelectedText.Length == SelectionLength.
if (textArea.Document != null && !textArea.Selection.IsEmpty)
return textArea.Document.GetText(textArea.Selection.SurroundingSegment);
return string.Empty;
}
set
{
if (value == null)
throw new ArgumentNullException(nameof(value));
var textArea = TextArea;
if (textArea.Document != null)
{
var offset = SelectionStart;
var length = SelectionLength;
textArea.Document.Replace(offset, length, value);
// keep inserted text selected
textArea.Selection = Selection.Create(textArea, offset, offset + value.Length);
}
}
}
/// <summary>
/// Gets/sets the caret position.
/// </summary>
public int CaretOffset
{
get
{
return textArea.Caret.Offset;
}
set
{
textArea.Caret.Offset = value;
}
}
/// <summary>
/// Gets/sets the start position of the selection.
/// </summary>
public int SelectionStart
{
get
{
if (textArea.Selection.IsEmpty)
return textArea.Caret.Offset;
else
return textArea.Selection.SurroundingSegment.Offset;
}
set => Select(value, SelectionLength);
}
/// <summary>
/// Gets/sets the length of the selection.
/// </summary>
public int SelectionLength
{
get
{
if (!textArea.Selection.IsEmpty)
return textArea.Selection.SurroundingSegment.Length;
else
return 0;
}
set => Select(SelectionStart, value);
}
/// <summary>
/// Selects the specified text section.
/// </summary>
public void Select(int start, int length)
{
var documentLength = Document?.TextLength ?? 0;
if (start < 0 || start > documentLength)
throw new ArgumentOutOfRangeException(nameof(start), start, "Value must be between 0 and " + documentLength);
if (length < 0 || start + length > documentLength)
throw new ArgumentOutOfRangeException(nameof(length), length, "Value must be between 0 and " + (documentLength - start));
TextArea.Selection = Selection.Create(TextArea, start, start + length);
TextArea.Caret.Offset = start + length;
}
/// <summary>
/// Gets the number of lines in the document.
/// </summary>
public int LineCount
{
get
{
var document = Document;
if (document != null)
return document.LineCount;
return 1;
}
}
/// <summary>
/// Clears the text.
/// </summary>
public void Clear()
{
Text = string.Empty;
}
#endregion
#region Loading from stream
/// <summary>
/// Loads the text from the stream, auto-detecting the encoding.
/// </summary>
/// <remarks>
/// This method sets <see cref="IsModified"/> to false.
/// </remarks>
public void Load(Stream stream)
{
using (var reader = FileReader.OpenStream(stream, Encoding ?? Encoding.UTF8))
{
Text = reader.ReadToEnd();
SetValue(EncodingProperty, (object)reader.CurrentEncoding);
}
SetValue(IsModifiedProperty, (object)false);
}
/// <summary>
/// Loads the text from the stream, auto-detecting the encoding.
/// </summary>
public void Load(string fileName)
{
if (fileName == null)
throw new ArgumentNullException(nameof(fileName));
// TODO:load
//using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
//{
// Load(fs);
//}
}
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
public static readonly AvaloniaProperty HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
get => (ScrollBarVisibility)GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
public static readonly AvaloniaProperty VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
get => (ScrollBarVisibility)GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
if (stream == null)
throw new ArgumentNullException(nameof(stream));
var encoding = Encoding;
var document = Document;
var writer = encoding != null ? new StreamWriter(stream, encoding) : new StreamWriter(stream);
document?.WriteTextTo(writer);
writer.Flush();
// do not close the stream
SetValue(IsModifiedProperty, (object)false);
}
/// <summary>
/// Saves the text to the file.
/// </summary>
public void Save(string fileName)
{
if (fileName == null)
throw new ArgumentNullException(nameof(fileName));
// TODO: save
//using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
//{
// Save(fs);
//}
}
#endregion
#region PointerHover events
/// <summary>
/// The PreviewPointerHover event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PreviewPointerHoverEvent =
TextView.PreviewPointerHoverEvent;
/// <summary>
/// the pointerHover event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PointerHoverEvent =
TextView.PointerHoverEvent;
/// <summary>
/// The PreviewPointerHoverStopped event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PreviewPointerHoverStoppedEvent =
TextView.PreviewPointerHoverStoppedEvent;
/// <summary>
/// the pointerHoverStopped event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PointerHoverStoppedEvent =
TextView.PointerHoverStoppedEvent;
/// <summary>
/// Occurs when the pointer has hovered over a fixed location for some time.
/// </summary>
public event EventHandler<PointerEventArgs> PreviewPointerHover
{
add => AddHandler(PreviewPointerHoverEvent, value);
remove => RemoveHandler(PreviewPointerHoverEvent, value);
}
/// <summary>
/// Occurs when the pointer has hovered over a fixed location for some time.
/// </summary>
public event EventHandler<PointerEventArgs> PointerHover
{
add => AddHandler(PointerHoverEvent, value);
remove => RemoveHandler(PointerHoverEvent, value);
}
/// <summary>
/// Occurs when the pointer had previously hovered but now started moving again.
/// </summary>
public event EventHandler<PointerEventArgs> PreviewPointerHoverStopped
{
add => AddHandler(PreviewPointerHoverStoppedEvent, value);
remove => RemoveHandler(PreviewPointerHoverStoppedEvent, value);
}
/// <summary>
/// Occurs when the pointer had previously hovered but now started moving again.
/// </summary>
public event EventHandler<PointerEventArgs> PointerHoverStopped
{
add => AddHandler(PointerHoverStoppedEvent, value);
remove => RemoveHandler(PointerHoverStoppedEvent, value);
}
#endregion
#region ScrollBarVisibility
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
public static readonly AttachedProperty<ScrollBarVisibility> HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
get => GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
private ScrollBarVisibility _horizontalScrollBarVisibilityBck = ScrollBarVisibility.Auto;
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
public static readonly AttachedProperty<ScrollBarVisibility> VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
get => GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
object IServiceProvider.GetService(Type serviceType)
{
return TextArea.GetService(serviceType);
}
/// <summary>
/// Gets the text view position from a point inside the editor.
/// </summary>
/// <param name="point">The position, relative to top left
/// corner of TextEditor control</param>
/// <returns>The text view position, or null if the point is outside the document.</returns>
public TextViewPosition? GetPositionFromPoint(Point point)
{
if (Document == null)
return null;
var textView = TextArea.TextView;
Point tpoint = (Point)this.TranslatePoint(point + new Point(textView.ScrollOffset.X, Math.Floor(textView.ScrollOffset.Y)), textView);
return textView.GetPosition(tpoint);
}
/// <summary>
/// Scrolls to the specified line.
/// This method requires that the TextEditor was already assigned a size (layout engine must have run prior).
/// </summary>
public void ScrollToLine(int line)
{
ScrollTo(line, -1);
}
/// <summary>
/// Scrolls to the specified line/column.
/// This method requires that the TextEditor was already assigned a size (layout engine must have run prior).
/// </summary>
public void ScrollTo(int line, int column)
{
const double MinimumScrollFraction = 0.3;
ScrollTo(line, column, VisualYPosition.LineMiddle,
null != ScrollViewer ? ScrollViewer.Viewport.Height / 2 : 0.0, MinimumScrollFraction);
}
/// <summary>
/// Scrolls to the specified line/column.
/// This method requires that the TextEditor was already assigned a size (WPF layout must have run prior).
/// </summary>
/// <param name="line">Line to scroll to.</param>
/// <param name="column">Column to scroll to (important if wrapping is 'on', and for the horizontal scroll position).</param>
/// <param name="yPositionMode">The mode how to reference the Y position of the line.</param>
/// <param name="referencedVerticalViewPortOffset">Offset from the top of the viewport to where the referenced line/column should be positioned.</param>
/// <param name="minimumScrollFraction">The minimum vertical and/or horizontal scroll offset, expressed as fraction of the height or width of the viewport window, respectively.</param>
public void ScrollTo(int line, int column, VisualYPosition yPositionMode,
double referencedVerticalViewPortOffset, double minimumScrollFraction)
{
TextView textView = textArea.TextView;
TextDocument document = textView.Document;
if (ScrollViewer != null && document != null)
{
if (line < 1)
line = 1;
if (line > document.LineCount)
line = document.LineCount;
ILogicalScrollable scrollInfo = textView;
if (!scrollInfo.CanHorizontallyScroll)
{
// Word wrap is enabled. Ensure that we have up-to-date info about line height so that we scroll
// to the correct position.
// This avoids that the user has to repeat the ScrollTo() call several times when there are very long lines.
VisualLine vl = textView.GetOrConstructVisualLine(document.GetLineByNumber(line));
double remainingHeight = referencedVerticalViewPortOffset;
while (remainingHeight > 0)
{
DocumentLine prevLine = vl.FirstDocumentLine.PreviousLine;
if (prevLine == null)
break;
vl = textView.GetOrConstructVisualLine(prevLine);
remainingHeight -= vl.Height;
}
}
Point p = textArea.TextView.GetVisualPosition(
new TextViewPosition(line, Math.Max(1, column)),
yPositionMode);
double targetX = ScrollViewer.Offset.X;
double targetY = ScrollViewer.Offset.Y;
double verticalPos = p.Y - referencedVerticalViewPortOffset;
if (Math.Abs(verticalPos - ScrollViewer.Offset.Y) >
minimumScrollFraction * ScrollViewer.Viewport.Height)
{
targetY = Math.Max(0, verticalPos);
}
if (column > 0)
{
if (p.X > ScrollViewer.Viewport.Width - Caret.MinimumDistanceToViewBorder * 2)
{
double horizontalPos = Math.Max(0, p.X - ScrollViewer.Viewport.Width / 2);
if (Math.Abs(horizontalPos - ScrollViewer.Offset.X) >
minimumScrollFraction * ScrollViewer.Viewport.Width)
{
targetX = 0;
}
}
else
{
targetX = 0;
}
}
if (targetX != ScrollViewer.Offset.X || targetY != ScrollViewer.Offset.Y)
ScrollViewer.Offset = new Vector(targetX, targetY);
}
}
}
}
<MSG> Merge pull request #73 from jeffreye/fix-scroll
Fix scroll
<DFF> @@ -47,6 +47,8 @@ namespace AvaloniaEdit
static TextEditor()
{
FocusableProperty.OverrideDefaultValue<TextEditor>(true);
+ HorizontalScrollBarVisibilityProperty.OverrideDefaultValue<TextEditor>(ScrollBarVisibility.Auto);
+ VerticalScrollBarVisibilityProperty.OverrideDefaultValue<TextEditor>(ScrollBarVisibility.Auto);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
@@ -1049,28 +1051,28 @@ namespace AvaloniaEdit
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
- public static readonly AvaloniaProperty HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
+ public static readonly AttachedProperty<ScrollBarVisibility> HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
- get => (ScrollBarVisibility)GetValue(HorizontalScrollBarVisibilityProperty);
+ get => GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
- public static readonly AvaloniaProperty VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
+ public static readonly AttachedProperty<ScrollBarVisibility> VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
- get => (ScrollBarVisibility)GetValue(VerticalScrollBarVisibilityProperty);
+ get => GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
| 6 | Merge pull request #73 from jeffreye/fix-scroll | 4 | .cs | cs | mit | AvaloniaUI/AvaloniaEdit |
10066911 | <NME> TextEditor.cs
<BEF> // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using Avalonia;
using AvaloniaEdit.Document;
using AvaloniaEdit.Editing;
using AvaloniaEdit.Highlighting;
using AvaloniaEdit.Rendering;
using AvaloniaEdit.Utils;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Shapes;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.LogicalTree;
using Avalonia.Media;
using Avalonia.Data;
using AvaloniaEdit.Search;
namespace AvaloniaEdit
{
/// <summary>
/// The text editor control.
/// Contains a scrollable TextArea.
/// </summary>
public class TextEditor : TemplatedControl, ITextEditorComponent
static TextEditor()
{
FocusableProperty.OverrideDefaultValue<TextEditor>(true);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
SyntaxHighlightingProperty.Changed.Subscribe(OnSyntaxHighlightingChanged);
IsReadOnlyProperty.Changed.Subscribe(OnIsReadOnlyChanged);
IsModifiedProperty.Changed.Subscribe(OnIsModifiedChanged);
ShowLineNumbersProperty.Changed.Subscribe(OnShowLineNumbersChanged);
LineNumbersForegroundProperty.Changed.Subscribe(OnLineNumbersForegroundChanged);
FontFamilyProperty.Changed.Subscribe(OnFontFamilyPropertyChanged);
FontSizeProperty.Changed.Subscribe(OnFontSizePropertyChanged);
}
/// <summary>
/// Creates a new TextEditor instance.
/// </summary>
public TextEditor() : this(new TextArea())
{
}
/// <summary>
/// Creates a new TextEditor instance.
/// </summary>
protected TextEditor(TextArea textArea) : this(textArea, new TextDocument())
{
}
protected TextEditor(TextArea textArea, TextDocument document)
{
this.textArea = textArea ?? throw new ArgumentNullException(nameof(textArea));
textArea.TextView.Services.AddService(this);
SetValue(OptionsProperty, textArea.Options);
SetValue(DocumentProperty, document);
textArea[!BackgroundProperty] = this[!BackgroundProperty];
}
#endregion
protected override void OnGotFocus(GotFocusEventArgs e)
{
base.OnGotFocus(e);
TextArea.Focus();
e.Handled = true;
}
#region Document property
/// <summary>
/// Document property.
/// </summary>
public static readonly StyledProperty<TextDocument> DocumentProperty
= TextView.DocumentProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the document displayed by the text editor.
/// This is a dependency property.
/// </summary>
public TextDocument Document
{
get => GetValue(DocumentProperty);
set => SetValue(DocumentProperty, value);
}
/// <summary>
/// Occurs when the document property has changed.
/// </summary>
public event EventHandler DocumentChanged;
/// <summary>
/// Raises the <see cref="DocumentChanged"/> event.
/// </summary>
protected virtual void OnDocumentChanged(EventArgs e)
{
DocumentChanged?.Invoke(this, e);
}
private static void OnDocumentChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnDocumentChanged((TextDocument)e.OldValue, (TextDocument)e.NewValue);
}
private void OnDocumentChanged(TextDocument oldValue, TextDocument newValue)
{
if (oldValue != null)
{
TextDocumentWeakEventManager.TextChanged.RemoveHandler(oldValue, OnTextChanged);
PropertyChangedWeakEventManager.RemoveHandler(oldValue.UndoStack, OnUndoStackPropertyChangedHandler);
}
TextArea.Document = newValue;
if (newValue != null)
{
TextDocumentWeakEventManager.TextChanged.AddHandler(newValue, OnTextChanged);
PropertyChangedWeakEventManager.AddHandler(newValue.UndoStack, OnUndoStackPropertyChangedHandler);
}
OnDocumentChanged(EventArgs.Empty);
OnTextChanged(EventArgs.Empty);
}
#endregion
#region Options property
/// <summary>
/// Options property.
/// </summary>
public static readonly StyledProperty<TextEditorOptions> OptionsProperty
= TextView.OptionsProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the options currently used by the text editor.
/// </summary>
public TextEditorOptions Options
{
get => GetValue(OptionsProperty);
set => SetValue(OptionsProperty, value);
}
/// <summary>
/// Occurs when a text editor option has changed.
/// </summary>
public event PropertyChangedEventHandler OptionChanged;
/// <summary>
/// Raises the <see cref="OptionChanged"/> event.
/// </summary>
protected virtual void OnOptionChanged(PropertyChangedEventArgs e)
{
OptionChanged?.Invoke(this, e);
}
private static void OnOptionsChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnOptionsChanged((TextEditorOptions)e.OldValue, (TextEditorOptions)e.NewValue);
}
private void OnOptionsChanged(TextEditorOptions oldValue, TextEditorOptions newValue)
{
if (oldValue != null)
{
PropertyChangedWeakEventManager.RemoveHandler(oldValue, OnPropertyChangedHandler);
}
TextArea.Options = newValue;
if (newValue != null)
{
PropertyChangedWeakEventManager.AddHandler(newValue, OnPropertyChangedHandler);
}
OnOptionChanged(new PropertyChangedEventArgs(null));
}
private void OnPropertyChangedHandler(object sender, PropertyChangedEventArgs e)
{
OnOptionChanged(e);
}
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
base.OnPropertyChanged(change);
if (change.Property == WordWrapProperty)
{
if (WordWrap)
{
_horizontalScrollBarVisibilityBck = HorizontalScrollBarVisibility;
HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
}
else
{
HorizontalScrollBarVisibility = _horizontalScrollBarVisibilityBck;
}
}
}
private void OnUndoStackPropertyChangedHandler(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsOriginalFile")
{
HandleIsOriginalChanged(e);
}
}
private void OnTextChanged(object sender, EventArgs e)
{
OnTextChanged(e);
}
#endregion
#region Text property
/// <summary>
/// Gets/Sets the text of the current document.
/// </summary>
public string Text
{
get
{
var document = Document;
return document != null ? document.Text : string.Empty;
}
set
{
var document = GetDocument();
document.Text = value ?? string.Empty;
// after replacing the full text, the caret is positioned at the end of the document
// - reset it to the beginning.
CaretOffset = 0;
document.UndoStack.ClearAll();
}
}
private TextDocument GetDocument()
{
var document = Document;
if (document == null)
throw ThrowUtil.NoDocumentAssigned();
return document;
}
/// <summary>
/// Occurs when the Text property changes.
/// </summary>
public event EventHandler TextChanged;
/// <summary>
/// Raises the <see cref="TextChanged"/> event.
/// </summary>
protected virtual void OnTextChanged(EventArgs e)
{
TextChanged?.Invoke(this, e);
}
#endregion
#region TextArea / ScrollViewer properties
private readonly TextArea textArea;
private SearchPanel searchPanel;
private bool wasSearchPanelOpened;
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
ScrollViewer = (ScrollViewer)e.NameScope.Find("PART_ScrollViewer");
ScrollViewer.Content = TextArea;
searchPanel = SearchPanel.Install(this);
}
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnAttachedToLogicalTree(e);
if (searchPanel != null && wasSearchPanelOpened)
{
searchPanel.Open();
}
}
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnDetachedFromLogicalTree(e);
if (searchPanel != null)
{
wasSearchPanelOpened = searchPanel.IsOpened;
if (searchPanel.IsOpened)
searchPanel.Close();
}
}
/// <summary>
/// Gets the text area.
/// </summary>
public TextArea TextArea => textArea;
/// <summary>
/// Gets the search panel.
/// </summary>
public SearchPanel SearchPanel => searchPanel;
/// <summary>
/// Gets the scroll viewer used by the text editor.
/// This property can return null if the template has not been applied / does not contain a scroll viewer.
/// </summary>
internal ScrollViewer ScrollViewer { get; private set; }
#endregion
#region Syntax highlighting
/// <summary>
/// The <see cref="SyntaxHighlighting"/> property.
/// </summary>
public static readonly StyledProperty<IHighlightingDefinition> SyntaxHighlightingProperty =
AvaloniaProperty.Register<TextEditor, IHighlightingDefinition>("SyntaxHighlighting");
/// <summary>
/// Gets/sets the syntax highlighting definition used to colorize the text.
/// </summary>
public IHighlightingDefinition SyntaxHighlighting
{
get => GetValue(SyntaxHighlightingProperty);
set => SetValue(SyntaxHighlightingProperty, value);
}
private IVisualLineTransformer _colorizer;
private static void OnSyntaxHighlightingChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnSyntaxHighlightingChanged(e.NewValue as IHighlightingDefinition);
}
private void OnSyntaxHighlightingChanged(IHighlightingDefinition newValue)
{
if (_colorizer != null)
{
textArea.TextView.LineTransformers.Remove(_colorizer);
_colorizer = null;
}
if (newValue != null)
{
_colorizer = CreateColorizer(newValue);
if (_colorizer != null)
{
textArea.TextView.LineTransformers.Insert(0, _colorizer);
}
}
}
/// <summary>
/// Creates the highlighting colorizer for the specified highlighting definition.
/// Allows derived classes to provide custom colorizer implementations for special highlighting definitions.
/// </summary>
/// <returns></returns>
protected virtual IVisualLineTransformer CreateColorizer(IHighlightingDefinition highlightingDefinition)
{
if (highlightingDefinition == null)
throw new ArgumentNullException(nameof(highlightingDefinition));
return new HighlightingColorizer(highlightingDefinition);
}
#endregion
#region WordWrap
/// <summary>
/// Word wrap dependency property.
/// </summary>
public static readonly StyledProperty<bool> WordWrapProperty =
AvaloniaProperty.Register<TextEditor, bool>("WordWrap");
/// <summary>
/// Specifies whether the text editor uses word wrapping.
/// </summary>
/// <remarks>
/// Setting WordWrap=true has the same effect as setting HorizontalScrollBarVisibility=Disabled and will override the
/// HorizontalScrollBarVisibility setting.
/// </remarks>
public bool WordWrap
{
get => GetValue(WordWrapProperty);
set => SetValue(WordWrapProperty, value);
}
#endregion
#region IsReadOnly
/// <summary>
/// IsReadOnly dependency property.
/// </summary>
public static readonly StyledProperty<bool> IsReadOnlyProperty =
AvaloniaProperty.Register<TextEditor, bool>("IsReadOnly");
/// <summary>
/// Specifies whether the user can change the text editor content.
/// Setting this property will replace the
/// <see cref="Editing.TextArea.ReadOnlySectionProvider">TextArea.ReadOnlySectionProvider</see>.
/// </summary>
public bool IsReadOnly
{
get => GetValue(IsReadOnlyProperty);
set => SetValue(IsReadOnlyProperty, value);
}
private static void OnIsReadOnlyChanged(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is TextEditor editor)
{
if ((bool)e.NewValue)
editor.TextArea.ReadOnlySectionProvider = ReadOnlySectionDocument.Instance;
else
editor.TextArea.ReadOnlySectionProvider = NoReadOnlySections.Instance;
}
}
#endregion
#region IsModified
/// <summary>
/// Dependency property for <see cref="IsModified"/>
/// </summary>
public static readonly StyledProperty<bool> IsModifiedProperty =
AvaloniaProperty.Register<TextEditor, bool>("IsModified");
/// <summary>
/// Gets/Sets the 'modified' flag.
/// </summary>
public bool IsModified
{
get => GetValue(IsModifiedProperty);
set => SetValue(IsModifiedProperty, value);
}
private static void OnIsModifiedChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
var document = editor?.Document;
if (document != null)
{
var undoStack = document.UndoStack;
if ((bool)e.NewValue)
{
if (undoStack.IsOriginalFile)
undoStack.DiscardOriginalFileMarker();
}
else
{
undoStack.MarkAsOriginalFile();
}
}
}
private void HandleIsOriginalChanged(PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsOriginalFile")
{
var document = Document;
if (document != null)
{
SetValue(IsModifiedProperty, (object)!document.UndoStack.IsOriginalFile);
}
}
}
#endregion
#region ShowLineNumbers
/// <summary>
/// ShowLineNumbers dependency property.
/// </summary>
public static readonly StyledProperty<bool> ShowLineNumbersProperty =
AvaloniaProperty.Register<TextEditor, bool>("ShowLineNumbers");
/// <summary>
/// Specifies whether line numbers are shown on the left to the text view.
/// </summary>
public bool ShowLineNumbers
{
get => GetValue(ShowLineNumbersProperty);
set => SetValue(ShowLineNumbersProperty, value);
}
private static void OnShowLineNumbersChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
if (editor == null) return;
var leftMargins = editor.TextArea.LeftMargins;
if ((bool)e.NewValue)
{
var lineNumbers = new LineNumberMargin();
var line = (Line)DottedLineMargin.Create();
leftMargins.Insert(0, lineNumbers);
leftMargins.Insert(1, line);
var lineNumbersForeground = new Binding("LineNumbersForeground") { Source = editor };
line.Bind(Shape.StrokeProperty, lineNumbersForeground);
lineNumbers.Bind(ForegroundProperty, lineNumbersForeground);
}
else
{
for (var i = 0; i < leftMargins.Count; i++)
{
if (leftMargins[i] is LineNumberMargin)
{
leftMargins.RemoveAt(i);
if (i < leftMargins.Count && DottedLineMargin.IsDottedLineMargin(leftMargins[i]))
{
leftMargins.RemoveAt(i);
}
break;
}
}
}
}
#endregion
#region LineNumbersForeground
/// <summary>
/// LineNumbersForeground dependency property.
/// </summary>
public static readonly StyledProperty<IBrush> LineNumbersForegroundProperty =
AvaloniaProperty.Register<TextEditor, IBrush>("LineNumbersForeground", Brushes.Gray);
/// <summary>
/// Gets/sets the Brush used for displaying the foreground color of line numbers.
/// </summary>
public IBrush LineNumbersForeground
{
get => GetValue(LineNumbersForegroundProperty);
set => SetValue(LineNumbersForegroundProperty, value);
}
private static void OnLineNumbersForegroundChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
var lineNumberMargin = editor?.TextArea.LeftMargins.FirstOrDefault(margin => margin is LineNumberMargin) as LineNumberMargin;
lineNumberMargin?.SetValue(ForegroundProperty, e.NewValue);
}
private static void OnFontFamilyPropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
editor?.TextArea.TextView.SetValue(FontFamilyProperty, e.NewValue);
}
private static void OnFontSizePropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
editor?.TextArea.TextView.SetValue(FontSizeProperty, e.NewValue);
}
#endregion
#region TextBoxBase-like methods
/// <summary>
/// Appends text to the end of the document.
/// </summary>
public void AppendText(string textData)
{
var document = GetDocument();
document.Insert(document.TextLength, textData);
}
/// <summary>
/// Begins a group of document changes.
/// </summary>
public void BeginChange()
{
GetDocument().BeginUpdate();
}
/// <summary>
/// Copies the current selection to the clipboard.
/// </summary>
public void Copy()
{
if (CanCopy)
{
ApplicationCommands.Copy.Execute(null, TextArea);
}
}
/// <summary>
/// Removes the current selection and copies it to the clipboard.
/// </summary>
public void Cut()
{
if (CanCut)
{
ApplicationCommands.Cut.Execute(null, TextArea);
}
}
/// <summary>
/// Begins a group of document changes and returns an object that ends the group of document
/// changes when it is disposed.
/// </summary>
public IDisposable DeclareChangeBlock()
{
return GetDocument().RunUpdate();
}
/// <summary>
/// Removes the current selection without copying it to the clipboard.
/// </summary>
public void Delete()
{
if(CanDelete)
{
ApplicationCommands.Delete.Execute(null, TextArea);
}
}
/// <summary>
/// Ends the current group of document changes.
/// </summary>
public void EndChange()
{
GetDocument().EndUpdate();
}
/// <summary>
/// Scrolls one line down.
/// </summary>
public void LineDown()
{
//if (scrollViewer != null)
// scrollViewer.LineDown();
}
/// <summary>
/// Scrolls to the left.
/// </summary>
public void LineLeft()
{
//if (scrollViewer != null)
// scrollViewer.LineLeft();
}
/// <summary>
/// Scrolls to the right.
/// </summary>
public void LineRight()
{
//if (scrollViewer != null)
// scrollViewer.LineRight();
}
/// <summary>
/// Scrolls one line up.
/// </summary>
public void LineUp()
{
//if (scrollViewer != null)
// scrollViewer.LineUp();
}
/// <summary>
/// Scrolls one page down.
/// </summary>
public void PageDown()
{
//if (scrollViewer != null)
// scrollViewer.PageDown();
}
/// <summary>
/// Scrolls one page up.
/// </summary>
public void PageUp()
{
//if (scrollViewer != null)
// scrollViewer.PageUp();
}
/// <summary>
/// Scrolls one page left.
/// </summary>
public void PageLeft()
{
//if (scrollViewer != null)
// scrollViewer.PageLeft();
}
/// <summary>
/// Scrolls one page right.
/// </summary>
public void PageRight()
{
//if (scrollViewer != null)
// scrollViewer.PageRight();
}
/// <summary>
/// Pastes the clipboard content.
/// </summary>
public void Paste()
{
if (CanPaste)
{
ApplicationCommands.Paste.Execute(null, TextArea);
}
}
/// <summary>
/// Redoes the most recent undone command.
/// </summary>
/// <returns>True is the redo operation was successful, false is the redo stack is empty.</returns>
public bool Redo()
{
if (CanRedo)
{
ApplicationCommands.Redo.Execute(null, TextArea);
return true;
}
return false;
}
/// <summary>
/// Scrolls to the end of the document.
/// </summary>
public void ScrollToEnd()
{
ApplyTemplate(); // ensure scrollViewer is created
ScrollViewer?.ScrollToEnd();
}
/// <summary>
/// Scrolls to the start of the document.
/// </summary>
public void ScrollToHome()
{
ApplyTemplate(); // ensure scrollViewer is created
ScrollViewer?.ScrollToHome();
}
/// <summary>
/// Scrolls to the specified position in the document.
/// </summary>
public void ScrollToHorizontalOffset(double offset)
{
ApplyTemplate(); // ensure scrollViewer is created
//if (scrollViewer != null)
// scrollViewer.ScrollToHorizontalOffset(offset);
}
/// <summary>
/// Scrolls to the specified position in the document.
/// </summary>
public void ScrollToVerticalOffset(double offset)
{
ApplyTemplate(); // ensure scrollViewer is created
//if (scrollViewer != null)
// scrollViewer.ScrollToVerticalOffset(offset);
}
/// <summary>
/// Selects the entire text.
/// </summary>
public void SelectAll()
{
if (CanSelectAll)
{
ApplicationCommands.SelectAll.Execute(null, TextArea);
}
}
/// <summary>
/// Undoes the most recent command.
/// </summary>
/// <returns>True is the undo operation was successful, false is the undo stack is empty.</returns>
public bool Undo()
{
if (CanUndo)
{
ApplicationCommands.Undo.Execute(null, TextArea);
return true;
}
return false;
}
/// <summary>
/// Gets if the most recent undone command can be redone.
/// </summary>
public bool CanRedo
{
get { return ApplicationCommands.Redo.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if the most recent command can be undone.
/// </summary>
public bool CanUndo
{
get { return ApplicationCommands.Undo.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be copied
/// </summary>
public bool CanCopy
{
get { return ApplicationCommands.Copy.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be cut
/// </summary>
public bool CanCut
{
get { return ApplicationCommands.Cut.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be pasted
/// </summary>
public bool CanPaste
{
get { return ApplicationCommands.Paste.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if selected text in editor can be deleted
/// </summary>
public bool CanDelete
{
get { return ApplicationCommands.Delete.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text the editor can select all
/// </summary>
public bool CanSelectAll
{
get { return ApplicationCommands.SelectAll.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text editor can activate the search panel
/// </summary>
public bool CanSearch
{
get { return searchPanel != null; }
}
/// <summary>
/// Gets the vertical size of the document.
/// </summary>
public double ExtentHeight => ScrollViewer?.Extent.Height ?? 0;
/// <summary>
/// Gets the horizontal size of the current document region.
/// </summary>
public double ExtentWidth => ScrollViewer?.Extent.Width ?? 0;
/// <summary>
/// Gets the horizontal size of the viewport.
/// </summary>
public double ViewportHeight => ScrollViewer?.Viewport.Height ?? 0;
/// <summary>
/// Gets the horizontal size of the viewport.
/// </summary>
public double ViewportWidth => ScrollViewer?.Viewport.Width ?? 0;
/// <summary>
/// Gets the vertical scroll position.
/// </summary>
public double VerticalOffset => ScrollViewer?.Offset.Y ?? 0;
/// <summary>
/// Gets the horizontal scroll position.
/// </summary>
public double HorizontalOffset => ScrollViewer?.Offset.X ?? 0;
#endregion
#region TextBox methods
/// <summary>
/// Gets/Sets the selected text.
/// </summary>
public string SelectedText
{
get
{
// We'll get the text from the whole surrounding segment.
// This is done to ensure that SelectedText.Length == SelectionLength.
if (textArea.Document != null && !textArea.Selection.IsEmpty)
return textArea.Document.GetText(textArea.Selection.SurroundingSegment);
return string.Empty;
}
set
{
if (value == null)
throw new ArgumentNullException(nameof(value));
var textArea = TextArea;
if (textArea.Document != null)
{
var offset = SelectionStart;
var length = SelectionLength;
textArea.Document.Replace(offset, length, value);
// keep inserted text selected
textArea.Selection = Selection.Create(textArea, offset, offset + value.Length);
}
}
}
/// <summary>
/// Gets/sets the caret position.
/// </summary>
public int CaretOffset
{
get
{
return textArea.Caret.Offset;
}
set
{
textArea.Caret.Offset = value;
}
}
/// <summary>
/// Gets/sets the start position of the selection.
/// </summary>
public int SelectionStart
{
get
{
if (textArea.Selection.IsEmpty)
return textArea.Caret.Offset;
else
return textArea.Selection.SurroundingSegment.Offset;
}
set => Select(value, SelectionLength);
}
/// <summary>
/// Gets/sets the length of the selection.
/// </summary>
public int SelectionLength
{
get
{
if (!textArea.Selection.IsEmpty)
return textArea.Selection.SurroundingSegment.Length;
else
return 0;
}
set => Select(SelectionStart, value);
}
/// <summary>
/// Selects the specified text section.
/// </summary>
public void Select(int start, int length)
{
var documentLength = Document?.TextLength ?? 0;
if (start < 0 || start > documentLength)
throw new ArgumentOutOfRangeException(nameof(start), start, "Value must be between 0 and " + documentLength);
if (length < 0 || start + length > documentLength)
throw new ArgumentOutOfRangeException(nameof(length), length, "Value must be between 0 and " + (documentLength - start));
TextArea.Selection = Selection.Create(TextArea, start, start + length);
TextArea.Caret.Offset = start + length;
}
/// <summary>
/// Gets the number of lines in the document.
/// </summary>
public int LineCount
{
get
{
var document = Document;
if (document != null)
return document.LineCount;
return 1;
}
}
/// <summary>
/// Clears the text.
/// </summary>
public void Clear()
{
Text = string.Empty;
}
#endregion
#region Loading from stream
/// <summary>
/// Loads the text from the stream, auto-detecting the encoding.
/// </summary>
/// <remarks>
/// This method sets <see cref="IsModified"/> to false.
/// </remarks>
public void Load(Stream stream)
{
using (var reader = FileReader.OpenStream(stream, Encoding ?? Encoding.UTF8))
{
Text = reader.ReadToEnd();
SetValue(EncodingProperty, (object)reader.CurrentEncoding);
}
SetValue(IsModifiedProperty, (object)false);
}
/// <summary>
/// Loads the text from the stream, auto-detecting the encoding.
/// </summary>
public void Load(string fileName)
{
if (fileName == null)
throw new ArgumentNullException(nameof(fileName));
// TODO:load
//using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
//{
// Load(fs);
//}
}
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
public static readonly AvaloniaProperty HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
get => (ScrollBarVisibility)GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
public static readonly AvaloniaProperty VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
get => (ScrollBarVisibility)GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
if (stream == null)
throw new ArgumentNullException(nameof(stream));
var encoding = Encoding;
var document = Document;
var writer = encoding != null ? new StreamWriter(stream, encoding) : new StreamWriter(stream);
document?.WriteTextTo(writer);
writer.Flush();
// do not close the stream
SetValue(IsModifiedProperty, (object)false);
}
/// <summary>
/// Saves the text to the file.
/// </summary>
public void Save(string fileName)
{
if (fileName == null)
throw new ArgumentNullException(nameof(fileName));
// TODO: save
//using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
//{
// Save(fs);
//}
}
#endregion
#region PointerHover events
/// <summary>
/// The PreviewPointerHover event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PreviewPointerHoverEvent =
TextView.PreviewPointerHoverEvent;
/// <summary>
/// the pointerHover event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PointerHoverEvent =
TextView.PointerHoverEvent;
/// <summary>
/// The PreviewPointerHoverStopped event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PreviewPointerHoverStoppedEvent =
TextView.PreviewPointerHoverStoppedEvent;
/// <summary>
/// the pointerHoverStopped event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PointerHoverStoppedEvent =
TextView.PointerHoverStoppedEvent;
/// <summary>
/// Occurs when the pointer has hovered over a fixed location for some time.
/// </summary>
public event EventHandler<PointerEventArgs> PreviewPointerHover
{
add => AddHandler(PreviewPointerHoverEvent, value);
remove => RemoveHandler(PreviewPointerHoverEvent, value);
}
/// <summary>
/// Occurs when the pointer has hovered over a fixed location for some time.
/// </summary>
public event EventHandler<PointerEventArgs> PointerHover
{
add => AddHandler(PointerHoverEvent, value);
remove => RemoveHandler(PointerHoverEvent, value);
}
/// <summary>
/// Occurs when the pointer had previously hovered but now started moving again.
/// </summary>
public event EventHandler<PointerEventArgs> PreviewPointerHoverStopped
{
add => AddHandler(PreviewPointerHoverStoppedEvent, value);
remove => RemoveHandler(PreviewPointerHoverStoppedEvent, value);
}
/// <summary>
/// Occurs when the pointer had previously hovered but now started moving again.
/// </summary>
public event EventHandler<PointerEventArgs> PointerHoverStopped
{
add => AddHandler(PointerHoverStoppedEvent, value);
remove => RemoveHandler(PointerHoverStoppedEvent, value);
}
#endregion
#region ScrollBarVisibility
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
public static readonly AttachedProperty<ScrollBarVisibility> HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
get => GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
private ScrollBarVisibility _horizontalScrollBarVisibilityBck = ScrollBarVisibility.Auto;
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
public static readonly AttachedProperty<ScrollBarVisibility> VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
get => GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
object IServiceProvider.GetService(Type serviceType)
{
return TextArea.GetService(serviceType);
}
/// <summary>
/// Gets the text view position from a point inside the editor.
/// </summary>
/// <param name="point">The position, relative to top left
/// corner of TextEditor control</param>
/// <returns>The text view position, or null if the point is outside the document.</returns>
public TextViewPosition? GetPositionFromPoint(Point point)
{
if (Document == null)
return null;
var textView = TextArea.TextView;
Point tpoint = (Point)this.TranslatePoint(point + new Point(textView.ScrollOffset.X, Math.Floor(textView.ScrollOffset.Y)), textView);
return textView.GetPosition(tpoint);
}
/// <summary>
/// Scrolls to the specified line.
/// This method requires that the TextEditor was already assigned a size (layout engine must have run prior).
/// </summary>
public void ScrollToLine(int line)
{
ScrollTo(line, -1);
}
/// <summary>
/// Scrolls to the specified line/column.
/// This method requires that the TextEditor was already assigned a size (layout engine must have run prior).
/// </summary>
public void ScrollTo(int line, int column)
{
const double MinimumScrollFraction = 0.3;
ScrollTo(line, column, VisualYPosition.LineMiddle,
null != ScrollViewer ? ScrollViewer.Viewport.Height / 2 : 0.0, MinimumScrollFraction);
}
/// <summary>
/// Scrolls to the specified line/column.
/// This method requires that the TextEditor was already assigned a size (WPF layout must have run prior).
/// </summary>
/// <param name="line">Line to scroll to.</param>
/// <param name="column">Column to scroll to (important if wrapping is 'on', and for the horizontal scroll position).</param>
/// <param name="yPositionMode">The mode how to reference the Y position of the line.</param>
/// <param name="referencedVerticalViewPortOffset">Offset from the top of the viewport to where the referenced line/column should be positioned.</param>
/// <param name="minimumScrollFraction">The minimum vertical and/or horizontal scroll offset, expressed as fraction of the height or width of the viewport window, respectively.</param>
public void ScrollTo(int line, int column, VisualYPosition yPositionMode,
double referencedVerticalViewPortOffset, double minimumScrollFraction)
{
TextView textView = textArea.TextView;
TextDocument document = textView.Document;
if (ScrollViewer != null && document != null)
{
if (line < 1)
line = 1;
if (line > document.LineCount)
line = document.LineCount;
ILogicalScrollable scrollInfo = textView;
if (!scrollInfo.CanHorizontallyScroll)
{
// Word wrap is enabled. Ensure that we have up-to-date info about line height so that we scroll
// to the correct position.
// This avoids that the user has to repeat the ScrollTo() call several times when there are very long lines.
VisualLine vl = textView.GetOrConstructVisualLine(document.GetLineByNumber(line));
double remainingHeight = referencedVerticalViewPortOffset;
while (remainingHeight > 0)
{
DocumentLine prevLine = vl.FirstDocumentLine.PreviousLine;
if (prevLine == null)
break;
vl = textView.GetOrConstructVisualLine(prevLine);
remainingHeight -= vl.Height;
}
}
Point p = textArea.TextView.GetVisualPosition(
new TextViewPosition(line, Math.Max(1, column)),
yPositionMode);
double targetX = ScrollViewer.Offset.X;
double targetY = ScrollViewer.Offset.Y;
double verticalPos = p.Y - referencedVerticalViewPortOffset;
if (Math.Abs(verticalPos - ScrollViewer.Offset.Y) >
minimumScrollFraction * ScrollViewer.Viewport.Height)
{
targetY = Math.Max(0, verticalPos);
}
if (column > 0)
{
if (p.X > ScrollViewer.Viewport.Width - Caret.MinimumDistanceToViewBorder * 2)
{
double horizontalPos = Math.Max(0, p.X - ScrollViewer.Viewport.Width / 2);
if (Math.Abs(horizontalPos - ScrollViewer.Offset.X) >
minimumScrollFraction * ScrollViewer.Viewport.Width)
{
targetX = 0;
}
}
else
{
targetX = 0;
}
}
if (targetX != ScrollViewer.Offset.X || targetY != ScrollViewer.Offset.Y)
ScrollViewer.Offset = new Vector(targetX, targetY);
}
}
}
}
<MSG> Merge pull request #73 from jeffreye/fix-scroll
Fix scroll
<DFF> @@ -47,6 +47,8 @@ namespace AvaloniaEdit
static TextEditor()
{
FocusableProperty.OverrideDefaultValue<TextEditor>(true);
+ HorizontalScrollBarVisibilityProperty.OverrideDefaultValue<TextEditor>(ScrollBarVisibility.Auto);
+ VerticalScrollBarVisibilityProperty.OverrideDefaultValue<TextEditor>(ScrollBarVisibility.Auto);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
@@ -1049,28 +1051,28 @@ namespace AvaloniaEdit
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
- public static readonly AvaloniaProperty HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
+ public static readonly AttachedProperty<ScrollBarVisibility> HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
- get => (ScrollBarVisibility)GetValue(HorizontalScrollBarVisibilityProperty);
+ get => GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
- public static readonly AvaloniaProperty VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
+ public static readonly AttachedProperty<ScrollBarVisibility> VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
- get => (ScrollBarVisibility)GetValue(VerticalScrollBarVisibilityProperty);
+ get => GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
| 6 | Merge pull request #73 from jeffreye/fix-scroll | 4 | .cs | cs | mit | AvaloniaUI/AvaloniaEdit |
10066912 | <NME> TextEditor.cs
<BEF> // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using Avalonia;
using AvaloniaEdit.Document;
using AvaloniaEdit.Editing;
using AvaloniaEdit.Highlighting;
using AvaloniaEdit.Rendering;
using AvaloniaEdit.Utils;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Shapes;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.LogicalTree;
using Avalonia.Media;
using Avalonia.Data;
using AvaloniaEdit.Search;
namespace AvaloniaEdit
{
/// <summary>
/// The text editor control.
/// Contains a scrollable TextArea.
/// </summary>
public class TextEditor : TemplatedControl, ITextEditorComponent
static TextEditor()
{
FocusableProperty.OverrideDefaultValue<TextEditor>(true);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
SyntaxHighlightingProperty.Changed.Subscribe(OnSyntaxHighlightingChanged);
IsReadOnlyProperty.Changed.Subscribe(OnIsReadOnlyChanged);
IsModifiedProperty.Changed.Subscribe(OnIsModifiedChanged);
ShowLineNumbersProperty.Changed.Subscribe(OnShowLineNumbersChanged);
LineNumbersForegroundProperty.Changed.Subscribe(OnLineNumbersForegroundChanged);
FontFamilyProperty.Changed.Subscribe(OnFontFamilyPropertyChanged);
FontSizeProperty.Changed.Subscribe(OnFontSizePropertyChanged);
}
/// <summary>
/// Creates a new TextEditor instance.
/// </summary>
public TextEditor() : this(new TextArea())
{
}
/// <summary>
/// Creates a new TextEditor instance.
/// </summary>
protected TextEditor(TextArea textArea) : this(textArea, new TextDocument())
{
}
protected TextEditor(TextArea textArea, TextDocument document)
{
this.textArea = textArea ?? throw new ArgumentNullException(nameof(textArea));
textArea.TextView.Services.AddService(this);
SetValue(OptionsProperty, textArea.Options);
SetValue(DocumentProperty, document);
textArea[!BackgroundProperty] = this[!BackgroundProperty];
}
#endregion
protected override void OnGotFocus(GotFocusEventArgs e)
{
base.OnGotFocus(e);
TextArea.Focus();
e.Handled = true;
}
#region Document property
/// <summary>
/// Document property.
/// </summary>
public static readonly StyledProperty<TextDocument> DocumentProperty
= TextView.DocumentProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the document displayed by the text editor.
/// This is a dependency property.
/// </summary>
public TextDocument Document
{
get => GetValue(DocumentProperty);
set => SetValue(DocumentProperty, value);
}
/// <summary>
/// Occurs when the document property has changed.
/// </summary>
public event EventHandler DocumentChanged;
/// <summary>
/// Raises the <see cref="DocumentChanged"/> event.
/// </summary>
protected virtual void OnDocumentChanged(EventArgs e)
{
DocumentChanged?.Invoke(this, e);
}
private static void OnDocumentChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnDocumentChanged((TextDocument)e.OldValue, (TextDocument)e.NewValue);
}
private void OnDocumentChanged(TextDocument oldValue, TextDocument newValue)
{
if (oldValue != null)
{
TextDocumentWeakEventManager.TextChanged.RemoveHandler(oldValue, OnTextChanged);
PropertyChangedWeakEventManager.RemoveHandler(oldValue.UndoStack, OnUndoStackPropertyChangedHandler);
}
TextArea.Document = newValue;
if (newValue != null)
{
TextDocumentWeakEventManager.TextChanged.AddHandler(newValue, OnTextChanged);
PropertyChangedWeakEventManager.AddHandler(newValue.UndoStack, OnUndoStackPropertyChangedHandler);
}
OnDocumentChanged(EventArgs.Empty);
OnTextChanged(EventArgs.Empty);
}
#endregion
#region Options property
/// <summary>
/// Options property.
/// </summary>
public static readonly StyledProperty<TextEditorOptions> OptionsProperty
= TextView.OptionsProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the options currently used by the text editor.
/// </summary>
public TextEditorOptions Options
{
get => GetValue(OptionsProperty);
set => SetValue(OptionsProperty, value);
}
/// <summary>
/// Occurs when a text editor option has changed.
/// </summary>
public event PropertyChangedEventHandler OptionChanged;
/// <summary>
/// Raises the <see cref="OptionChanged"/> event.
/// </summary>
protected virtual void OnOptionChanged(PropertyChangedEventArgs e)
{
OptionChanged?.Invoke(this, e);
}
private static void OnOptionsChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnOptionsChanged((TextEditorOptions)e.OldValue, (TextEditorOptions)e.NewValue);
}
private void OnOptionsChanged(TextEditorOptions oldValue, TextEditorOptions newValue)
{
if (oldValue != null)
{
PropertyChangedWeakEventManager.RemoveHandler(oldValue, OnPropertyChangedHandler);
}
TextArea.Options = newValue;
if (newValue != null)
{
PropertyChangedWeakEventManager.AddHandler(newValue, OnPropertyChangedHandler);
}
OnOptionChanged(new PropertyChangedEventArgs(null));
}
private void OnPropertyChangedHandler(object sender, PropertyChangedEventArgs e)
{
OnOptionChanged(e);
}
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
base.OnPropertyChanged(change);
if (change.Property == WordWrapProperty)
{
if (WordWrap)
{
_horizontalScrollBarVisibilityBck = HorizontalScrollBarVisibility;
HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
}
else
{
HorizontalScrollBarVisibility = _horizontalScrollBarVisibilityBck;
}
}
}
private void OnUndoStackPropertyChangedHandler(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsOriginalFile")
{
HandleIsOriginalChanged(e);
}
}
private void OnTextChanged(object sender, EventArgs e)
{
OnTextChanged(e);
}
#endregion
#region Text property
/// <summary>
/// Gets/Sets the text of the current document.
/// </summary>
public string Text
{
get
{
var document = Document;
return document != null ? document.Text : string.Empty;
}
set
{
var document = GetDocument();
document.Text = value ?? string.Empty;
// after replacing the full text, the caret is positioned at the end of the document
// - reset it to the beginning.
CaretOffset = 0;
document.UndoStack.ClearAll();
}
}
private TextDocument GetDocument()
{
var document = Document;
if (document == null)
throw ThrowUtil.NoDocumentAssigned();
return document;
}
/// <summary>
/// Occurs when the Text property changes.
/// </summary>
public event EventHandler TextChanged;
/// <summary>
/// Raises the <see cref="TextChanged"/> event.
/// </summary>
protected virtual void OnTextChanged(EventArgs e)
{
TextChanged?.Invoke(this, e);
}
#endregion
#region TextArea / ScrollViewer properties
private readonly TextArea textArea;
private SearchPanel searchPanel;
private bool wasSearchPanelOpened;
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
ScrollViewer = (ScrollViewer)e.NameScope.Find("PART_ScrollViewer");
ScrollViewer.Content = TextArea;
searchPanel = SearchPanel.Install(this);
}
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnAttachedToLogicalTree(e);
if (searchPanel != null && wasSearchPanelOpened)
{
searchPanel.Open();
}
}
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnDetachedFromLogicalTree(e);
if (searchPanel != null)
{
wasSearchPanelOpened = searchPanel.IsOpened;
if (searchPanel.IsOpened)
searchPanel.Close();
}
}
/// <summary>
/// Gets the text area.
/// </summary>
public TextArea TextArea => textArea;
/// <summary>
/// Gets the search panel.
/// </summary>
public SearchPanel SearchPanel => searchPanel;
/// <summary>
/// Gets the scroll viewer used by the text editor.
/// This property can return null if the template has not been applied / does not contain a scroll viewer.
/// </summary>
internal ScrollViewer ScrollViewer { get; private set; }
#endregion
#region Syntax highlighting
/// <summary>
/// The <see cref="SyntaxHighlighting"/> property.
/// </summary>
public static readonly StyledProperty<IHighlightingDefinition> SyntaxHighlightingProperty =
AvaloniaProperty.Register<TextEditor, IHighlightingDefinition>("SyntaxHighlighting");
/// <summary>
/// Gets/sets the syntax highlighting definition used to colorize the text.
/// </summary>
public IHighlightingDefinition SyntaxHighlighting
{
get => GetValue(SyntaxHighlightingProperty);
set => SetValue(SyntaxHighlightingProperty, value);
}
private IVisualLineTransformer _colorizer;
private static void OnSyntaxHighlightingChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnSyntaxHighlightingChanged(e.NewValue as IHighlightingDefinition);
}
private void OnSyntaxHighlightingChanged(IHighlightingDefinition newValue)
{
if (_colorizer != null)
{
textArea.TextView.LineTransformers.Remove(_colorizer);
_colorizer = null;
}
if (newValue != null)
{
_colorizer = CreateColorizer(newValue);
if (_colorizer != null)
{
textArea.TextView.LineTransformers.Insert(0, _colorizer);
}
}
}
/// <summary>
/// Creates the highlighting colorizer for the specified highlighting definition.
/// Allows derived classes to provide custom colorizer implementations for special highlighting definitions.
/// </summary>
/// <returns></returns>
protected virtual IVisualLineTransformer CreateColorizer(IHighlightingDefinition highlightingDefinition)
{
if (highlightingDefinition == null)
throw new ArgumentNullException(nameof(highlightingDefinition));
return new HighlightingColorizer(highlightingDefinition);
}
#endregion
#region WordWrap
/// <summary>
/// Word wrap dependency property.
/// </summary>
public static readonly StyledProperty<bool> WordWrapProperty =
AvaloniaProperty.Register<TextEditor, bool>("WordWrap");
/// <summary>
/// Specifies whether the text editor uses word wrapping.
/// </summary>
/// <remarks>
/// Setting WordWrap=true has the same effect as setting HorizontalScrollBarVisibility=Disabled and will override the
/// HorizontalScrollBarVisibility setting.
/// </remarks>
public bool WordWrap
{
get => GetValue(WordWrapProperty);
set => SetValue(WordWrapProperty, value);
}
#endregion
#region IsReadOnly
/// <summary>
/// IsReadOnly dependency property.
/// </summary>
public static readonly StyledProperty<bool> IsReadOnlyProperty =
AvaloniaProperty.Register<TextEditor, bool>("IsReadOnly");
/// <summary>
/// Specifies whether the user can change the text editor content.
/// Setting this property will replace the
/// <see cref="Editing.TextArea.ReadOnlySectionProvider">TextArea.ReadOnlySectionProvider</see>.
/// </summary>
public bool IsReadOnly
{
get => GetValue(IsReadOnlyProperty);
set => SetValue(IsReadOnlyProperty, value);
}
private static void OnIsReadOnlyChanged(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is TextEditor editor)
{
if ((bool)e.NewValue)
editor.TextArea.ReadOnlySectionProvider = ReadOnlySectionDocument.Instance;
else
editor.TextArea.ReadOnlySectionProvider = NoReadOnlySections.Instance;
}
}
#endregion
#region IsModified
/// <summary>
/// Dependency property for <see cref="IsModified"/>
/// </summary>
public static readonly StyledProperty<bool> IsModifiedProperty =
AvaloniaProperty.Register<TextEditor, bool>("IsModified");
/// <summary>
/// Gets/Sets the 'modified' flag.
/// </summary>
public bool IsModified
{
get => GetValue(IsModifiedProperty);
set => SetValue(IsModifiedProperty, value);
}
private static void OnIsModifiedChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
var document = editor?.Document;
if (document != null)
{
var undoStack = document.UndoStack;
if ((bool)e.NewValue)
{
if (undoStack.IsOriginalFile)
undoStack.DiscardOriginalFileMarker();
}
else
{
undoStack.MarkAsOriginalFile();
}
}
}
private void HandleIsOriginalChanged(PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsOriginalFile")
{
var document = Document;
if (document != null)
{
SetValue(IsModifiedProperty, (object)!document.UndoStack.IsOriginalFile);
}
}
}
#endregion
#region ShowLineNumbers
/// <summary>
/// ShowLineNumbers dependency property.
/// </summary>
public static readonly StyledProperty<bool> ShowLineNumbersProperty =
AvaloniaProperty.Register<TextEditor, bool>("ShowLineNumbers");
/// <summary>
/// Specifies whether line numbers are shown on the left to the text view.
/// </summary>
public bool ShowLineNumbers
{
get => GetValue(ShowLineNumbersProperty);
set => SetValue(ShowLineNumbersProperty, value);
}
private static void OnShowLineNumbersChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
if (editor == null) return;
var leftMargins = editor.TextArea.LeftMargins;
if ((bool)e.NewValue)
{
var lineNumbers = new LineNumberMargin();
var line = (Line)DottedLineMargin.Create();
leftMargins.Insert(0, lineNumbers);
leftMargins.Insert(1, line);
var lineNumbersForeground = new Binding("LineNumbersForeground") { Source = editor };
line.Bind(Shape.StrokeProperty, lineNumbersForeground);
lineNumbers.Bind(ForegroundProperty, lineNumbersForeground);
}
else
{
for (var i = 0; i < leftMargins.Count; i++)
{
if (leftMargins[i] is LineNumberMargin)
{
leftMargins.RemoveAt(i);
if (i < leftMargins.Count && DottedLineMargin.IsDottedLineMargin(leftMargins[i]))
{
leftMargins.RemoveAt(i);
}
break;
}
}
}
}
#endregion
#region LineNumbersForeground
/// <summary>
/// LineNumbersForeground dependency property.
/// </summary>
public static readonly StyledProperty<IBrush> LineNumbersForegroundProperty =
AvaloniaProperty.Register<TextEditor, IBrush>("LineNumbersForeground", Brushes.Gray);
/// <summary>
/// Gets/sets the Brush used for displaying the foreground color of line numbers.
/// </summary>
public IBrush LineNumbersForeground
{
get => GetValue(LineNumbersForegroundProperty);
set => SetValue(LineNumbersForegroundProperty, value);
}
private static void OnLineNumbersForegroundChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
var lineNumberMargin = editor?.TextArea.LeftMargins.FirstOrDefault(margin => margin is LineNumberMargin) as LineNumberMargin;
lineNumberMargin?.SetValue(ForegroundProperty, e.NewValue);
}
private static void OnFontFamilyPropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
editor?.TextArea.TextView.SetValue(FontFamilyProperty, e.NewValue);
}
private static void OnFontSizePropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
editor?.TextArea.TextView.SetValue(FontSizeProperty, e.NewValue);
}
#endregion
#region TextBoxBase-like methods
/// <summary>
/// Appends text to the end of the document.
/// </summary>
public void AppendText(string textData)
{
var document = GetDocument();
document.Insert(document.TextLength, textData);
}
/// <summary>
/// Begins a group of document changes.
/// </summary>
public void BeginChange()
{
GetDocument().BeginUpdate();
}
/// <summary>
/// Copies the current selection to the clipboard.
/// </summary>
public void Copy()
{
if (CanCopy)
{
ApplicationCommands.Copy.Execute(null, TextArea);
}
}
/// <summary>
/// Removes the current selection and copies it to the clipboard.
/// </summary>
public void Cut()
{
if (CanCut)
{
ApplicationCommands.Cut.Execute(null, TextArea);
}
}
/// <summary>
/// Begins a group of document changes and returns an object that ends the group of document
/// changes when it is disposed.
/// </summary>
public IDisposable DeclareChangeBlock()
{
return GetDocument().RunUpdate();
}
/// <summary>
/// Removes the current selection without copying it to the clipboard.
/// </summary>
public void Delete()
{
if(CanDelete)
{
ApplicationCommands.Delete.Execute(null, TextArea);
}
}
/// <summary>
/// Ends the current group of document changes.
/// </summary>
public void EndChange()
{
GetDocument().EndUpdate();
}
/// <summary>
/// Scrolls one line down.
/// </summary>
public void LineDown()
{
//if (scrollViewer != null)
// scrollViewer.LineDown();
}
/// <summary>
/// Scrolls to the left.
/// </summary>
public void LineLeft()
{
//if (scrollViewer != null)
// scrollViewer.LineLeft();
}
/// <summary>
/// Scrolls to the right.
/// </summary>
public void LineRight()
{
//if (scrollViewer != null)
// scrollViewer.LineRight();
}
/// <summary>
/// Scrolls one line up.
/// </summary>
public void LineUp()
{
//if (scrollViewer != null)
// scrollViewer.LineUp();
}
/// <summary>
/// Scrolls one page down.
/// </summary>
public void PageDown()
{
//if (scrollViewer != null)
// scrollViewer.PageDown();
}
/// <summary>
/// Scrolls one page up.
/// </summary>
public void PageUp()
{
//if (scrollViewer != null)
// scrollViewer.PageUp();
}
/// <summary>
/// Scrolls one page left.
/// </summary>
public void PageLeft()
{
//if (scrollViewer != null)
// scrollViewer.PageLeft();
}
/// <summary>
/// Scrolls one page right.
/// </summary>
public void PageRight()
{
//if (scrollViewer != null)
// scrollViewer.PageRight();
}
/// <summary>
/// Pastes the clipboard content.
/// </summary>
public void Paste()
{
if (CanPaste)
{
ApplicationCommands.Paste.Execute(null, TextArea);
}
}
/// <summary>
/// Redoes the most recent undone command.
/// </summary>
/// <returns>True is the redo operation was successful, false is the redo stack is empty.</returns>
public bool Redo()
{
if (CanRedo)
{
ApplicationCommands.Redo.Execute(null, TextArea);
return true;
}
return false;
}
/// <summary>
/// Scrolls to the end of the document.
/// </summary>
public void ScrollToEnd()
{
ApplyTemplate(); // ensure scrollViewer is created
ScrollViewer?.ScrollToEnd();
}
/// <summary>
/// Scrolls to the start of the document.
/// </summary>
public void ScrollToHome()
{
ApplyTemplate(); // ensure scrollViewer is created
ScrollViewer?.ScrollToHome();
}
/// <summary>
/// Scrolls to the specified position in the document.
/// </summary>
public void ScrollToHorizontalOffset(double offset)
{
ApplyTemplate(); // ensure scrollViewer is created
//if (scrollViewer != null)
// scrollViewer.ScrollToHorizontalOffset(offset);
}
/// <summary>
/// Scrolls to the specified position in the document.
/// </summary>
public void ScrollToVerticalOffset(double offset)
{
ApplyTemplate(); // ensure scrollViewer is created
//if (scrollViewer != null)
// scrollViewer.ScrollToVerticalOffset(offset);
}
/// <summary>
/// Selects the entire text.
/// </summary>
public void SelectAll()
{
if (CanSelectAll)
{
ApplicationCommands.SelectAll.Execute(null, TextArea);
}
}
/// <summary>
/// Undoes the most recent command.
/// </summary>
/// <returns>True is the undo operation was successful, false is the undo stack is empty.</returns>
public bool Undo()
{
if (CanUndo)
{
ApplicationCommands.Undo.Execute(null, TextArea);
return true;
}
return false;
}
/// <summary>
/// Gets if the most recent undone command can be redone.
/// </summary>
public bool CanRedo
{
get { return ApplicationCommands.Redo.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if the most recent command can be undone.
/// </summary>
public bool CanUndo
{
get { return ApplicationCommands.Undo.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be copied
/// </summary>
public bool CanCopy
{
get { return ApplicationCommands.Copy.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be cut
/// </summary>
public bool CanCut
{
get { return ApplicationCommands.Cut.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be pasted
/// </summary>
public bool CanPaste
{
get { return ApplicationCommands.Paste.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if selected text in editor can be deleted
/// </summary>
public bool CanDelete
{
get { return ApplicationCommands.Delete.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text the editor can select all
/// </summary>
public bool CanSelectAll
{
get { return ApplicationCommands.SelectAll.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text editor can activate the search panel
/// </summary>
public bool CanSearch
{
get { return searchPanel != null; }
}
/// <summary>
/// Gets the vertical size of the document.
/// </summary>
public double ExtentHeight => ScrollViewer?.Extent.Height ?? 0;
/// <summary>
/// Gets the horizontal size of the current document region.
/// </summary>
public double ExtentWidth => ScrollViewer?.Extent.Width ?? 0;
/// <summary>
/// Gets the horizontal size of the viewport.
/// </summary>
public double ViewportHeight => ScrollViewer?.Viewport.Height ?? 0;
/// <summary>
/// Gets the horizontal size of the viewport.
/// </summary>
public double ViewportWidth => ScrollViewer?.Viewport.Width ?? 0;
/// <summary>
/// Gets the vertical scroll position.
/// </summary>
public double VerticalOffset => ScrollViewer?.Offset.Y ?? 0;
/// <summary>
/// Gets the horizontal scroll position.
/// </summary>
public double HorizontalOffset => ScrollViewer?.Offset.X ?? 0;
#endregion
#region TextBox methods
/// <summary>
/// Gets/Sets the selected text.
/// </summary>
public string SelectedText
{
get
{
// We'll get the text from the whole surrounding segment.
// This is done to ensure that SelectedText.Length == SelectionLength.
if (textArea.Document != null && !textArea.Selection.IsEmpty)
return textArea.Document.GetText(textArea.Selection.SurroundingSegment);
return string.Empty;
}
set
{
if (value == null)
throw new ArgumentNullException(nameof(value));
var textArea = TextArea;
if (textArea.Document != null)
{
var offset = SelectionStart;
var length = SelectionLength;
textArea.Document.Replace(offset, length, value);
// keep inserted text selected
textArea.Selection = Selection.Create(textArea, offset, offset + value.Length);
}
}
}
/// <summary>
/// Gets/sets the caret position.
/// </summary>
public int CaretOffset
{
get
{
return textArea.Caret.Offset;
}
set
{
textArea.Caret.Offset = value;
}
}
/// <summary>
/// Gets/sets the start position of the selection.
/// </summary>
public int SelectionStart
{
get
{
if (textArea.Selection.IsEmpty)
return textArea.Caret.Offset;
else
return textArea.Selection.SurroundingSegment.Offset;
}
set => Select(value, SelectionLength);
}
/// <summary>
/// Gets/sets the length of the selection.
/// </summary>
public int SelectionLength
{
get
{
if (!textArea.Selection.IsEmpty)
return textArea.Selection.SurroundingSegment.Length;
else
return 0;
}
set => Select(SelectionStart, value);
}
/// <summary>
/// Selects the specified text section.
/// </summary>
public void Select(int start, int length)
{
var documentLength = Document?.TextLength ?? 0;
if (start < 0 || start > documentLength)
throw new ArgumentOutOfRangeException(nameof(start), start, "Value must be between 0 and " + documentLength);
if (length < 0 || start + length > documentLength)
throw new ArgumentOutOfRangeException(nameof(length), length, "Value must be between 0 and " + (documentLength - start));
TextArea.Selection = Selection.Create(TextArea, start, start + length);
TextArea.Caret.Offset = start + length;
}
/// <summary>
/// Gets the number of lines in the document.
/// </summary>
public int LineCount
{
get
{
var document = Document;
if (document != null)
return document.LineCount;
return 1;
}
}
/// <summary>
/// Clears the text.
/// </summary>
public void Clear()
{
Text = string.Empty;
}
#endregion
#region Loading from stream
/// <summary>
/// Loads the text from the stream, auto-detecting the encoding.
/// </summary>
/// <remarks>
/// This method sets <see cref="IsModified"/> to false.
/// </remarks>
public void Load(Stream stream)
{
using (var reader = FileReader.OpenStream(stream, Encoding ?? Encoding.UTF8))
{
Text = reader.ReadToEnd();
SetValue(EncodingProperty, (object)reader.CurrentEncoding);
}
SetValue(IsModifiedProperty, (object)false);
}
/// <summary>
/// Loads the text from the stream, auto-detecting the encoding.
/// </summary>
public void Load(string fileName)
{
if (fileName == null)
throw new ArgumentNullException(nameof(fileName));
// TODO:load
//using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
//{
// Load(fs);
//}
}
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
public static readonly AvaloniaProperty HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
get => (ScrollBarVisibility)GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
public static readonly AvaloniaProperty VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
get => (ScrollBarVisibility)GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
if (stream == null)
throw new ArgumentNullException(nameof(stream));
var encoding = Encoding;
var document = Document;
var writer = encoding != null ? new StreamWriter(stream, encoding) : new StreamWriter(stream);
document?.WriteTextTo(writer);
writer.Flush();
// do not close the stream
SetValue(IsModifiedProperty, (object)false);
}
/// <summary>
/// Saves the text to the file.
/// </summary>
public void Save(string fileName)
{
if (fileName == null)
throw new ArgumentNullException(nameof(fileName));
// TODO: save
//using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
//{
// Save(fs);
//}
}
#endregion
#region PointerHover events
/// <summary>
/// The PreviewPointerHover event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PreviewPointerHoverEvent =
TextView.PreviewPointerHoverEvent;
/// <summary>
/// the pointerHover event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PointerHoverEvent =
TextView.PointerHoverEvent;
/// <summary>
/// The PreviewPointerHoverStopped event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PreviewPointerHoverStoppedEvent =
TextView.PreviewPointerHoverStoppedEvent;
/// <summary>
/// the pointerHoverStopped event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PointerHoverStoppedEvent =
TextView.PointerHoverStoppedEvent;
/// <summary>
/// Occurs when the pointer has hovered over a fixed location for some time.
/// </summary>
public event EventHandler<PointerEventArgs> PreviewPointerHover
{
add => AddHandler(PreviewPointerHoverEvent, value);
remove => RemoveHandler(PreviewPointerHoverEvent, value);
}
/// <summary>
/// Occurs when the pointer has hovered over a fixed location for some time.
/// </summary>
public event EventHandler<PointerEventArgs> PointerHover
{
add => AddHandler(PointerHoverEvent, value);
remove => RemoveHandler(PointerHoverEvent, value);
}
/// <summary>
/// Occurs when the pointer had previously hovered but now started moving again.
/// </summary>
public event EventHandler<PointerEventArgs> PreviewPointerHoverStopped
{
add => AddHandler(PreviewPointerHoverStoppedEvent, value);
remove => RemoveHandler(PreviewPointerHoverStoppedEvent, value);
}
/// <summary>
/// Occurs when the pointer had previously hovered but now started moving again.
/// </summary>
public event EventHandler<PointerEventArgs> PointerHoverStopped
{
add => AddHandler(PointerHoverStoppedEvent, value);
remove => RemoveHandler(PointerHoverStoppedEvent, value);
}
#endregion
#region ScrollBarVisibility
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
public static readonly AttachedProperty<ScrollBarVisibility> HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
get => GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
private ScrollBarVisibility _horizontalScrollBarVisibilityBck = ScrollBarVisibility.Auto;
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
public static readonly AttachedProperty<ScrollBarVisibility> VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
get => GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
object IServiceProvider.GetService(Type serviceType)
{
return TextArea.GetService(serviceType);
}
/// <summary>
/// Gets the text view position from a point inside the editor.
/// </summary>
/// <param name="point">The position, relative to top left
/// corner of TextEditor control</param>
/// <returns>The text view position, or null if the point is outside the document.</returns>
public TextViewPosition? GetPositionFromPoint(Point point)
{
if (Document == null)
return null;
var textView = TextArea.TextView;
Point tpoint = (Point)this.TranslatePoint(point + new Point(textView.ScrollOffset.X, Math.Floor(textView.ScrollOffset.Y)), textView);
return textView.GetPosition(tpoint);
}
/// <summary>
/// Scrolls to the specified line.
/// This method requires that the TextEditor was already assigned a size (layout engine must have run prior).
/// </summary>
public void ScrollToLine(int line)
{
ScrollTo(line, -1);
}
/// <summary>
/// Scrolls to the specified line/column.
/// This method requires that the TextEditor was already assigned a size (layout engine must have run prior).
/// </summary>
public void ScrollTo(int line, int column)
{
const double MinimumScrollFraction = 0.3;
ScrollTo(line, column, VisualYPosition.LineMiddle,
null != ScrollViewer ? ScrollViewer.Viewport.Height / 2 : 0.0, MinimumScrollFraction);
}
/// <summary>
/// Scrolls to the specified line/column.
/// This method requires that the TextEditor was already assigned a size (WPF layout must have run prior).
/// </summary>
/// <param name="line">Line to scroll to.</param>
/// <param name="column">Column to scroll to (important if wrapping is 'on', and for the horizontal scroll position).</param>
/// <param name="yPositionMode">The mode how to reference the Y position of the line.</param>
/// <param name="referencedVerticalViewPortOffset">Offset from the top of the viewport to where the referenced line/column should be positioned.</param>
/// <param name="minimumScrollFraction">The minimum vertical and/or horizontal scroll offset, expressed as fraction of the height or width of the viewport window, respectively.</param>
public void ScrollTo(int line, int column, VisualYPosition yPositionMode,
double referencedVerticalViewPortOffset, double minimumScrollFraction)
{
TextView textView = textArea.TextView;
TextDocument document = textView.Document;
if (ScrollViewer != null && document != null)
{
if (line < 1)
line = 1;
if (line > document.LineCount)
line = document.LineCount;
ILogicalScrollable scrollInfo = textView;
if (!scrollInfo.CanHorizontallyScroll)
{
// Word wrap is enabled. Ensure that we have up-to-date info about line height so that we scroll
// to the correct position.
// This avoids that the user has to repeat the ScrollTo() call several times when there are very long lines.
VisualLine vl = textView.GetOrConstructVisualLine(document.GetLineByNumber(line));
double remainingHeight = referencedVerticalViewPortOffset;
while (remainingHeight > 0)
{
DocumentLine prevLine = vl.FirstDocumentLine.PreviousLine;
if (prevLine == null)
break;
vl = textView.GetOrConstructVisualLine(prevLine);
remainingHeight -= vl.Height;
}
}
Point p = textArea.TextView.GetVisualPosition(
new TextViewPosition(line, Math.Max(1, column)),
yPositionMode);
double targetX = ScrollViewer.Offset.X;
double targetY = ScrollViewer.Offset.Y;
double verticalPos = p.Y - referencedVerticalViewPortOffset;
if (Math.Abs(verticalPos - ScrollViewer.Offset.Y) >
minimumScrollFraction * ScrollViewer.Viewport.Height)
{
targetY = Math.Max(0, verticalPos);
}
if (column > 0)
{
if (p.X > ScrollViewer.Viewport.Width - Caret.MinimumDistanceToViewBorder * 2)
{
double horizontalPos = Math.Max(0, p.X - ScrollViewer.Viewport.Width / 2);
if (Math.Abs(horizontalPos - ScrollViewer.Offset.X) >
minimumScrollFraction * ScrollViewer.Viewport.Width)
{
targetX = 0;
}
}
else
{
targetX = 0;
}
}
if (targetX != ScrollViewer.Offset.X || targetY != ScrollViewer.Offset.Y)
ScrollViewer.Offset = new Vector(targetX, targetY);
}
}
}
}
<MSG> Merge pull request #73 from jeffreye/fix-scroll
Fix scroll
<DFF> @@ -47,6 +47,8 @@ namespace AvaloniaEdit
static TextEditor()
{
FocusableProperty.OverrideDefaultValue<TextEditor>(true);
+ HorizontalScrollBarVisibilityProperty.OverrideDefaultValue<TextEditor>(ScrollBarVisibility.Auto);
+ VerticalScrollBarVisibilityProperty.OverrideDefaultValue<TextEditor>(ScrollBarVisibility.Auto);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
@@ -1049,28 +1051,28 @@ namespace AvaloniaEdit
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
- public static readonly AvaloniaProperty HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
+ public static readonly AttachedProperty<ScrollBarVisibility> HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
- get => (ScrollBarVisibility)GetValue(HorizontalScrollBarVisibilityProperty);
+ get => GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
- public static readonly AvaloniaProperty VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
+ public static readonly AttachedProperty<ScrollBarVisibility> VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
- get => (ScrollBarVisibility)GetValue(VerticalScrollBarVisibilityProperty);
+ get => GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
| 6 | Merge pull request #73 from jeffreye/fix-scroll | 4 | .cs | cs | mit | AvaloniaUI/AvaloniaEdit |
10066913 | <NME> TextEditor.cs
<BEF> // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using Avalonia;
using AvaloniaEdit.Document;
using AvaloniaEdit.Editing;
using AvaloniaEdit.Highlighting;
using AvaloniaEdit.Rendering;
using AvaloniaEdit.Utils;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Shapes;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.LogicalTree;
using Avalonia.Media;
using Avalonia.Data;
using AvaloniaEdit.Search;
namespace AvaloniaEdit
{
/// <summary>
/// The text editor control.
/// Contains a scrollable TextArea.
/// </summary>
public class TextEditor : TemplatedControl, ITextEditorComponent
static TextEditor()
{
FocusableProperty.OverrideDefaultValue<TextEditor>(true);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
SyntaxHighlightingProperty.Changed.Subscribe(OnSyntaxHighlightingChanged);
IsReadOnlyProperty.Changed.Subscribe(OnIsReadOnlyChanged);
IsModifiedProperty.Changed.Subscribe(OnIsModifiedChanged);
ShowLineNumbersProperty.Changed.Subscribe(OnShowLineNumbersChanged);
LineNumbersForegroundProperty.Changed.Subscribe(OnLineNumbersForegroundChanged);
FontFamilyProperty.Changed.Subscribe(OnFontFamilyPropertyChanged);
FontSizeProperty.Changed.Subscribe(OnFontSizePropertyChanged);
}
/// <summary>
/// Creates a new TextEditor instance.
/// </summary>
public TextEditor() : this(new TextArea())
{
}
/// <summary>
/// Creates a new TextEditor instance.
/// </summary>
protected TextEditor(TextArea textArea) : this(textArea, new TextDocument())
{
}
protected TextEditor(TextArea textArea, TextDocument document)
{
this.textArea = textArea ?? throw new ArgumentNullException(nameof(textArea));
textArea.TextView.Services.AddService(this);
SetValue(OptionsProperty, textArea.Options);
SetValue(DocumentProperty, document);
textArea[!BackgroundProperty] = this[!BackgroundProperty];
}
#endregion
protected override void OnGotFocus(GotFocusEventArgs e)
{
base.OnGotFocus(e);
TextArea.Focus();
e.Handled = true;
}
#region Document property
/// <summary>
/// Document property.
/// </summary>
public static readonly StyledProperty<TextDocument> DocumentProperty
= TextView.DocumentProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the document displayed by the text editor.
/// This is a dependency property.
/// </summary>
public TextDocument Document
{
get => GetValue(DocumentProperty);
set => SetValue(DocumentProperty, value);
}
/// <summary>
/// Occurs when the document property has changed.
/// </summary>
public event EventHandler DocumentChanged;
/// <summary>
/// Raises the <see cref="DocumentChanged"/> event.
/// </summary>
protected virtual void OnDocumentChanged(EventArgs e)
{
DocumentChanged?.Invoke(this, e);
}
private static void OnDocumentChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnDocumentChanged((TextDocument)e.OldValue, (TextDocument)e.NewValue);
}
private void OnDocumentChanged(TextDocument oldValue, TextDocument newValue)
{
if (oldValue != null)
{
TextDocumentWeakEventManager.TextChanged.RemoveHandler(oldValue, OnTextChanged);
PropertyChangedWeakEventManager.RemoveHandler(oldValue.UndoStack, OnUndoStackPropertyChangedHandler);
}
TextArea.Document = newValue;
if (newValue != null)
{
TextDocumentWeakEventManager.TextChanged.AddHandler(newValue, OnTextChanged);
PropertyChangedWeakEventManager.AddHandler(newValue.UndoStack, OnUndoStackPropertyChangedHandler);
}
OnDocumentChanged(EventArgs.Empty);
OnTextChanged(EventArgs.Empty);
}
#endregion
#region Options property
/// <summary>
/// Options property.
/// </summary>
public static readonly StyledProperty<TextEditorOptions> OptionsProperty
= TextView.OptionsProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the options currently used by the text editor.
/// </summary>
public TextEditorOptions Options
{
get => GetValue(OptionsProperty);
set => SetValue(OptionsProperty, value);
}
/// <summary>
/// Occurs when a text editor option has changed.
/// </summary>
public event PropertyChangedEventHandler OptionChanged;
/// <summary>
/// Raises the <see cref="OptionChanged"/> event.
/// </summary>
protected virtual void OnOptionChanged(PropertyChangedEventArgs e)
{
OptionChanged?.Invoke(this, e);
}
private static void OnOptionsChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnOptionsChanged((TextEditorOptions)e.OldValue, (TextEditorOptions)e.NewValue);
}
private void OnOptionsChanged(TextEditorOptions oldValue, TextEditorOptions newValue)
{
if (oldValue != null)
{
PropertyChangedWeakEventManager.RemoveHandler(oldValue, OnPropertyChangedHandler);
}
TextArea.Options = newValue;
if (newValue != null)
{
PropertyChangedWeakEventManager.AddHandler(newValue, OnPropertyChangedHandler);
}
OnOptionChanged(new PropertyChangedEventArgs(null));
}
private void OnPropertyChangedHandler(object sender, PropertyChangedEventArgs e)
{
OnOptionChanged(e);
}
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
base.OnPropertyChanged(change);
if (change.Property == WordWrapProperty)
{
if (WordWrap)
{
_horizontalScrollBarVisibilityBck = HorizontalScrollBarVisibility;
HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
}
else
{
HorizontalScrollBarVisibility = _horizontalScrollBarVisibilityBck;
}
}
}
private void OnUndoStackPropertyChangedHandler(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsOriginalFile")
{
HandleIsOriginalChanged(e);
}
}
private void OnTextChanged(object sender, EventArgs e)
{
OnTextChanged(e);
}
#endregion
#region Text property
/// <summary>
/// Gets/Sets the text of the current document.
/// </summary>
public string Text
{
get
{
var document = Document;
return document != null ? document.Text : string.Empty;
}
set
{
var document = GetDocument();
document.Text = value ?? string.Empty;
// after replacing the full text, the caret is positioned at the end of the document
// - reset it to the beginning.
CaretOffset = 0;
document.UndoStack.ClearAll();
}
}
private TextDocument GetDocument()
{
var document = Document;
if (document == null)
throw ThrowUtil.NoDocumentAssigned();
return document;
}
/// <summary>
/// Occurs when the Text property changes.
/// </summary>
public event EventHandler TextChanged;
/// <summary>
/// Raises the <see cref="TextChanged"/> event.
/// </summary>
protected virtual void OnTextChanged(EventArgs e)
{
TextChanged?.Invoke(this, e);
}
#endregion
#region TextArea / ScrollViewer properties
private readonly TextArea textArea;
private SearchPanel searchPanel;
private bool wasSearchPanelOpened;
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
ScrollViewer = (ScrollViewer)e.NameScope.Find("PART_ScrollViewer");
ScrollViewer.Content = TextArea;
searchPanel = SearchPanel.Install(this);
}
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnAttachedToLogicalTree(e);
if (searchPanel != null && wasSearchPanelOpened)
{
searchPanel.Open();
}
}
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnDetachedFromLogicalTree(e);
if (searchPanel != null)
{
wasSearchPanelOpened = searchPanel.IsOpened;
if (searchPanel.IsOpened)
searchPanel.Close();
}
}
/// <summary>
/// Gets the text area.
/// </summary>
public TextArea TextArea => textArea;
/// <summary>
/// Gets the search panel.
/// </summary>
public SearchPanel SearchPanel => searchPanel;
/// <summary>
/// Gets the scroll viewer used by the text editor.
/// This property can return null if the template has not been applied / does not contain a scroll viewer.
/// </summary>
internal ScrollViewer ScrollViewer { get; private set; }
#endregion
#region Syntax highlighting
/// <summary>
/// The <see cref="SyntaxHighlighting"/> property.
/// </summary>
public static readonly StyledProperty<IHighlightingDefinition> SyntaxHighlightingProperty =
AvaloniaProperty.Register<TextEditor, IHighlightingDefinition>("SyntaxHighlighting");
/// <summary>
/// Gets/sets the syntax highlighting definition used to colorize the text.
/// </summary>
public IHighlightingDefinition SyntaxHighlighting
{
get => GetValue(SyntaxHighlightingProperty);
set => SetValue(SyntaxHighlightingProperty, value);
}
private IVisualLineTransformer _colorizer;
private static void OnSyntaxHighlightingChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnSyntaxHighlightingChanged(e.NewValue as IHighlightingDefinition);
}
private void OnSyntaxHighlightingChanged(IHighlightingDefinition newValue)
{
if (_colorizer != null)
{
textArea.TextView.LineTransformers.Remove(_colorizer);
_colorizer = null;
}
if (newValue != null)
{
_colorizer = CreateColorizer(newValue);
if (_colorizer != null)
{
textArea.TextView.LineTransformers.Insert(0, _colorizer);
}
}
}
/// <summary>
/// Creates the highlighting colorizer for the specified highlighting definition.
/// Allows derived classes to provide custom colorizer implementations for special highlighting definitions.
/// </summary>
/// <returns></returns>
protected virtual IVisualLineTransformer CreateColorizer(IHighlightingDefinition highlightingDefinition)
{
if (highlightingDefinition == null)
throw new ArgumentNullException(nameof(highlightingDefinition));
return new HighlightingColorizer(highlightingDefinition);
}
#endregion
#region WordWrap
/// <summary>
/// Word wrap dependency property.
/// </summary>
public static readonly StyledProperty<bool> WordWrapProperty =
AvaloniaProperty.Register<TextEditor, bool>("WordWrap");
/// <summary>
/// Specifies whether the text editor uses word wrapping.
/// </summary>
/// <remarks>
/// Setting WordWrap=true has the same effect as setting HorizontalScrollBarVisibility=Disabled and will override the
/// HorizontalScrollBarVisibility setting.
/// </remarks>
public bool WordWrap
{
get => GetValue(WordWrapProperty);
set => SetValue(WordWrapProperty, value);
}
#endregion
#region IsReadOnly
/// <summary>
/// IsReadOnly dependency property.
/// </summary>
public static readonly StyledProperty<bool> IsReadOnlyProperty =
AvaloniaProperty.Register<TextEditor, bool>("IsReadOnly");
/// <summary>
/// Specifies whether the user can change the text editor content.
/// Setting this property will replace the
/// <see cref="Editing.TextArea.ReadOnlySectionProvider">TextArea.ReadOnlySectionProvider</see>.
/// </summary>
public bool IsReadOnly
{
get => GetValue(IsReadOnlyProperty);
set => SetValue(IsReadOnlyProperty, value);
}
private static void OnIsReadOnlyChanged(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is TextEditor editor)
{
if ((bool)e.NewValue)
editor.TextArea.ReadOnlySectionProvider = ReadOnlySectionDocument.Instance;
else
editor.TextArea.ReadOnlySectionProvider = NoReadOnlySections.Instance;
}
}
#endregion
#region IsModified
/// <summary>
/// Dependency property for <see cref="IsModified"/>
/// </summary>
public static readonly StyledProperty<bool> IsModifiedProperty =
AvaloniaProperty.Register<TextEditor, bool>("IsModified");
/// <summary>
/// Gets/Sets the 'modified' flag.
/// </summary>
public bool IsModified
{
get => GetValue(IsModifiedProperty);
set => SetValue(IsModifiedProperty, value);
}
private static void OnIsModifiedChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
var document = editor?.Document;
if (document != null)
{
var undoStack = document.UndoStack;
if ((bool)e.NewValue)
{
if (undoStack.IsOriginalFile)
undoStack.DiscardOriginalFileMarker();
}
else
{
undoStack.MarkAsOriginalFile();
}
}
}
private void HandleIsOriginalChanged(PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsOriginalFile")
{
var document = Document;
if (document != null)
{
SetValue(IsModifiedProperty, (object)!document.UndoStack.IsOriginalFile);
}
}
}
#endregion
#region ShowLineNumbers
/// <summary>
/// ShowLineNumbers dependency property.
/// </summary>
public static readonly StyledProperty<bool> ShowLineNumbersProperty =
AvaloniaProperty.Register<TextEditor, bool>("ShowLineNumbers");
/// <summary>
/// Specifies whether line numbers are shown on the left to the text view.
/// </summary>
public bool ShowLineNumbers
{
get => GetValue(ShowLineNumbersProperty);
set => SetValue(ShowLineNumbersProperty, value);
}
private static void OnShowLineNumbersChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
if (editor == null) return;
var leftMargins = editor.TextArea.LeftMargins;
if ((bool)e.NewValue)
{
var lineNumbers = new LineNumberMargin();
var line = (Line)DottedLineMargin.Create();
leftMargins.Insert(0, lineNumbers);
leftMargins.Insert(1, line);
var lineNumbersForeground = new Binding("LineNumbersForeground") { Source = editor };
line.Bind(Shape.StrokeProperty, lineNumbersForeground);
lineNumbers.Bind(ForegroundProperty, lineNumbersForeground);
}
else
{
for (var i = 0; i < leftMargins.Count; i++)
{
if (leftMargins[i] is LineNumberMargin)
{
leftMargins.RemoveAt(i);
if (i < leftMargins.Count && DottedLineMargin.IsDottedLineMargin(leftMargins[i]))
{
leftMargins.RemoveAt(i);
}
break;
}
}
}
}
#endregion
#region LineNumbersForeground
/// <summary>
/// LineNumbersForeground dependency property.
/// </summary>
public static readonly StyledProperty<IBrush> LineNumbersForegroundProperty =
AvaloniaProperty.Register<TextEditor, IBrush>("LineNumbersForeground", Brushes.Gray);
/// <summary>
/// Gets/sets the Brush used for displaying the foreground color of line numbers.
/// </summary>
public IBrush LineNumbersForeground
{
get => GetValue(LineNumbersForegroundProperty);
set => SetValue(LineNumbersForegroundProperty, value);
}
private static void OnLineNumbersForegroundChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
var lineNumberMargin = editor?.TextArea.LeftMargins.FirstOrDefault(margin => margin is LineNumberMargin) as LineNumberMargin;
lineNumberMargin?.SetValue(ForegroundProperty, e.NewValue);
}
private static void OnFontFamilyPropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
editor?.TextArea.TextView.SetValue(FontFamilyProperty, e.NewValue);
}
private static void OnFontSizePropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
editor?.TextArea.TextView.SetValue(FontSizeProperty, e.NewValue);
}
#endregion
#region TextBoxBase-like methods
/// <summary>
/// Appends text to the end of the document.
/// </summary>
public void AppendText(string textData)
{
var document = GetDocument();
document.Insert(document.TextLength, textData);
}
/// <summary>
/// Begins a group of document changes.
/// </summary>
public void BeginChange()
{
GetDocument().BeginUpdate();
}
/// <summary>
/// Copies the current selection to the clipboard.
/// </summary>
public void Copy()
{
if (CanCopy)
{
ApplicationCommands.Copy.Execute(null, TextArea);
}
}
/// <summary>
/// Removes the current selection and copies it to the clipboard.
/// </summary>
public void Cut()
{
if (CanCut)
{
ApplicationCommands.Cut.Execute(null, TextArea);
}
}
/// <summary>
/// Begins a group of document changes and returns an object that ends the group of document
/// changes when it is disposed.
/// </summary>
public IDisposable DeclareChangeBlock()
{
return GetDocument().RunUpdate();
}
/// <summary>
/// Removes the current selection without copying it to the clipboard.
/// </summary>
public void Delete()
{
if(CanDelete)
{
ApplicationCommands.Delete.Execute(null, TextArea);
}
}
/// <summary>
/// Ends the current group of document changes.
/// </summary>
public void EndChange()
{
GetDocument().EndUpdate();
}
/// <summary>
/// Scrolls one line down.
/// </summary>
public void LineDown()
{
//if (scrollViewer != null)
// scrollViewer.LineDown();
}
/// <summary>
/// Scrolls to the left.
/// </summary>
public void LineLeft()
{
//if (scrollViewer != null)
// scrollViewer.LineLeft();
}
/// <summary>
/// Scrolls to the right.
/// </summary>
public void LineRight()
{
//if (scrollViewer != null)
// scrollViewer.LineRight();
}
/// <summary>
/// Scrolls one line up.
/// </summary>
public void LineUp()
{
//if (scrollViewer != null)
// scrollViewer.LineUp();
}
/// <summary>
/// Scrolls one page down.
/// </summary>
public void PageDown()
{
//if (scrollViewer != null)
// scrollViewer.PageDown();
}
/// <summary>
/// Scrolls one page up.
/// </summary>
public void PageUp()
{
//if (scrollViewer != null)
// scrollViewer.PageUp();
}
/// <summary>
/// Scrolls one page left.
/// </summary>
public void PageLeft()
{
//if (scrollViewer != null)
// scrollViewer.PageLeft();
}
/// <summary>
/// Scrolls one page right.
/// </summary>
public void PageRight()
{
//if (scrollViewer != null)
// scrollViewer.PageRight();
}
/// <summary>
/// Pastes the clipboard content.
/// </summary>
public void Paste()
{
if (CanPaste)
{
ApplicationCommands.Paste.Execute(null, TextArea);
}
}
/// <summary>
/// Redoes the most recent undone command.
/// </summary>
/// <returns>True is the redo operation was successful, false is the redo stack is empty.</returns>
public bool Redo()
{
if (CanRedo)
{
ApplicationCommands.Redo.Execute(null, TextArea);
return true;
}
return false;
}
/// <summary>
/// Scrolls to the end of the document.
/// </summary>
public void ScrollToEnd()
{
ApplyTemplate(); // ensure scrollViewer is created
ScrollViewer?.ScrollToEnd();
}
/// <summary>
/// Scrolls to the start of the document.
/// </summary>
public void ScrollToHome()
{
ApplyTemplate(); // ensure scrollViewer is created
ScrollViewer?.ScrollToHome();
}
/// <summary>
/// Scrolls to the specified position in the document.
/// </summary>
public void ScrollToHorizontalOffset(double offset)
{
ApplyTemplate(); // ensure scrollViewer is created
//if (scrollViewer != null)
// scrollViewer.ScrollToHorizontalOffset(offset);
}
/// <summary>
/// Scrolls to the specified position in the document.
/// </summary>
public void ScrollToVerticalOffset(double offset)
{
ApplyTemplate(); // ensure scrollViewer is created
//if (scrollViewer != null)
// scrollViewer.ScrollToVerticalOffset(offset);
}
/// <summary>
/// Selects the entire text.
/// </summary>
public void SelectAll()
{
if (CanSelectAll)
{
ApplicationCommands.SelectAll.Execute(null, TextArea);
}
}
/// <summary>
/// Undoes the most recent command.
/// </summary>
/// <returns>True is the undo operation was successful, false is the undo stack is empty.</returns>
public bool Undo()
{
if (CanUndo)
{
ApplicationCommands.Undo.Execute(null, TextArea);
return true;
}
return false;
}
/// <summary>
/// Gets if the most recent undone command can be redone.
/// </summary>
public bool CanRedo
{
get { return ApplicationCommands.Redo.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if the most recent command can be undone.
/// </summary>
public bool CanUndo
{
get { return ApplicationCommands.Undo.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be copied
/// </summary>
public bool CanCopy
{
get { return ApplicationCommands.Copy.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be cut
/// </summary>
public bool CanCut
{
get { return ApplicationCommands.Cut.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be pasted
/// </summary>
public bool CanPaste
{
get { return ApplicationCommands.Paste.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if selected text in editor can be deleted
/// </summary>
public bool CanDelete
{
get { return ApplicationCommands.Delete.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text the editor can select all
/// </summary>
public bool CanSelectAll
{
get { return ApplicationCommands.SelectAll.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text editor can activate the search panel
/// </summary>
public bool CanSearch
{
get { return searchPanel != null; }
}
/// <summary>
/// Gets the vertical size of the document.
/// </summary>
public double ExtentHeight => ScrollViewer?.Extent.Height ?? 0;
/// <summary>
/// Gets the horizontal size of the current document region.
/// </summary>
public double ExtentWidth => ScrollViewer?.Extent.Width ?? 0;
/// <summary>
/// Gets the horizontal size of the viewport.
/// </summary>
public double ViewportHeight => ScrollViewer?.Viewport.Height ?? 0;
/// <summary>
/// Gets the horizontal size of the viewport.
/// </summary>
public double ViewportWidth => ScrollViewer?.Viewport.Width ?? 0;
/// <summary>
/// Gets the vertical scroll position.
/// </summary>
public double VerticalOffset => ScrollViewer?.Offset.Y ?? 0;
/// <summary>
/// Gets the horizontal scroll position.
/// </summary>
public double HorizontalOffset => ScrollViewer?.Offset.X ?? 0;
#endregion
#region TextBox methods
/// <summary>
/// Gets/Sets the selected text.
/// </summary>
public string SelectedText
{
get
{
// We'll get the text from the whole surrounding segment.
// This is done to ensure that SelectedText.Length == SelectionLength.
if (textArea.Document != null && !textArea.Selection.IsEmpty)
return textArea.Document.GetText(textArea.Selection.SurroundingSegment);
return string.Empty;
}
set
{
if (value == null)
throw new ArgumentNullException(nameof(value));
var textArea = TextArea;
if (textArea.Document != null)
{
var offset = SelectionStart;
var length = SelectionLength;
textArea.Document.Replace(offset, length, value);
// keep inserted text selected
textArea.Selection = Selection.Create(textArea, offset, offset + value.Length);
}
}
}
/// <summary>
/// Gets/sets the caret position.
/// </summary>
public int CaretOffset
{
get
{
return textArea.Caret.Offset;
}
set
{
textArea.Caret.Offset = value;
}
}
/// <summary>
/// Gets/sets the start position of the selection.
/// </summary>
public int SelectionStart
{
get
{
if (textArea.Selection.IsEmpty)
return textArea.Caret.Offset;
else
return textArea.Selection.SurroundingSegment.Offset;
}
set => Select(value, SelectionLength);
}
/// <summary>
/// Gets/sets the length of the selection.
/// </summary>
public int SelectionLength
{
get
{
if (!textArea.Selection.IsEmpty)
return textArea.Selection.SurroundingSegment.Length;
else
return 0;
}
set => Select(SelectionStart, value);
}
/// <summary>
/// Selects the specified text section.
/// </summary>
public void Select(int start, int length)
{
var documentLength = Document?.TextLength ?? 0;
if (start < 0 || start > documentLength)
throw new ArgumentOutOfRangeException(nameof(start), start, "Value must be between 0 and " + documentLength);
if (length < 0 || start + length > documentLength)
throw new ArgumentOutOfRangeException(nameof(length), length, "Value must be between 0 and " + (documentLength - start));
TextArea.Selection = Selection.Create(TextArea, start, start + length);
TextArea.Caret.Offset = start + length;
}
/// <summary>
/// Gets the number of lines in the document.
/// </summary>
public int LineCount
{
get
{
var document = Document;
if (document != null)
return document.LineCount;
return 1;
}
}
/// <summary>
/// Clears the text.
/// </summary>
public void Clear()
{
Text = string.Empty;
}
#endregion
#region Loading from stream
/// <summary>
/// Loads the text from the stream, auto-detecting the encoding.
/// </summary>
/// <remarks>
/// This method sets <see cref="IsModified"/> to false.
/// </remarks>
public void Load(Stream stream)
{
using (var reader = FileReader.OpenStream(stream, Encoding ?? Encoding.UTF8))
{
Text = reader.ReadToEnd();
SetValue(EncodingProperty, (object)reader.CurrentEncoding);
}
SetValue(IsModifiedProperty, (object)false);
}
/// <summary>
/// Loads the text from the stream, auto-detecting the encoding.
/// </summary>
public void Load(string fileName)
{
if (fileName == null)
throw new ArgumentNullException(nameof(fileName));
// TODO:load
//using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
//{
// Load(fs);
//}
}
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
public static readonly AvaloniaProperty HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
get => (ScrollBarVisibility)GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
public static readonly AvaloniaProperty VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
get => (ScrollBarVisibility)GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
if (stream == null)
throw new ArgumentNullException(nameof(stream));
var encoding = Encoding;
var document = Document;
var writer = encoding != null ? new StreamWriter(stream, encoding) : new StreamWriter(stream);
document?.WriteTextTo(writer);
writer.Flush();
// do not close the stream
SetValue(IsModifiedProperty, (object)false);
}
/// <summary>
/// Saves the text to the file.
/// </summary>
public void Save(string fileName)
{
if (fileName == null)
throw new ArgumentNullException(nameof(fileName));
// TODO: save
//using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
//{
// Save(fs);
//}
}
#endregion
#region PointerHover events
/// <summary>
/// The PreviewPointerHover event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PreviewPointerHoverEvent =
TextView.PreviewPointerHoverEvent;
/// <summary>
/// the pointerHover event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PointerHoverEvent =
TextView.PointerHoverEvent;
/// <summary>
/// The PreviewPointerHoverStopped event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PreviewPointerHoverStoppedEvent =
TextView.PreviewPointerHoverStoppedEvent;
/// <summary>
/// the pointerHoverStopped event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PointerHoverStoppedEvent =
TextView.PointerHoverStoppedEvent;
/// <summary>
/// Occurs when the pointer has hovered over a fixed location for some time.
/// </summary>
public event EventHandler<PointerEventArgs> PreviewPointerHover
{
add => AddHandler(PreviewPointerHoverEvent, value);
remove => RemoveHandler(PreviewPointerHoverEvent, value);
}
/// <summary>
/// Occurs when the pointer has hovered over a fixed location for some time.
/// </summary>
public event EventHandler<PointerEventArgs> PointerHover
{
add => AddHandler(PointerHoverEvent, value);
remove => RemoveHandler(PointerHoverEvent, value);
}
/// <summary>
/// Occurs when the pointer had previously hovered but now started moving again.
/// </summary>
public event EventHandler<PointerEventArgs> PreviewPointerHoverStopped
{
add => AddHandler(PreviewPointerHoverStoppedEvent, value);
remove => RemoveHandler(PreviewPointerHoverStoppedEvent, value);
}
/// <summary>
/// Occurs when the pointer had previously hovered but now started moving again.
/// </summary>
public event EventHandler<PointerEventArgs> PointerHoverStopped
{
add => AddHandler(PointerHoverStoppedEvent, value);
remove => RemoveHandler(PointerHoverStoppedEvent, value);
}
#endregion
#region ScrollBarVisibility
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
public static readonly AttachedProperty<ScrollBarVisibility> HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
get => GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
private ScrollBarVisibility _horizontalScrollBarVisibilityBck = ScrollBarVisibility.Auto;
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
public static readonly AttachedProperty<ScrollBarVisibility> VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
get => GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
object IServiceProvider.GetService(Type serviceType)
{
return TextArea.GetService(serviceType);
}
/// <summary>
/// Gets the text view position from a point inside the editor.
/// </summary>
/// <param name="point">The position, relative to top left
/// corner of TextEditor control</param>
/// <returns>The text view position, or null if the point is outside the document.</returns>
public TextViewPosition? GetPositionFromPoint(Point point)
{
if (Document == null)
return null;
var textView = TextArea.TextView;
Point tpoint = (Point)this.TranslatePoint(point + new Point(textView.ScrollOffset.X, Math.Floor(textView.ScrollOffset.Y)), textView);
return textView.GetPosition(tpoint);
}
/// <summary>
/// Scrolls to the specified line.
/// This method requires that the TextEditor was already assigned a size (layout engine must have run prior).
/// </summary>
public void ScrollToLine(int line)
{
ScrollTo(line, -1);
}
/// <summary>
/// Scrolls to the specified line/column.
/// This method requires that the TextEditor was already assigned a size (layout engine must have run prior).
/// </summary>
public void ScrollTo(int line, int column)
{
const double MinimumScrollFraction = 0.3;
ScrollTo(line, column, VisualYPosition.LineMiddle,
null != ScrollViewer ? ScrollViewer.Viewport.Height / 2 : 0.0, MinimumScrollFraction);
}
/// <summary>
/// Scrolls to the specified line/column.
/// This method requires that the TextEditor was already assigned a size (WPF layout must have run prior).
/// </summary>
/// <param name="line">Line to scroll to.</param>
/// <param name="column">Column to scroll to (important if wrapping is 'on', and for the horizontal scroll position).</param>
/// <param name="yPositionMode">The mode how to reference the Y position of the line.</param>
/// <param name="referencedVerticalViewPortOffset">Offset from the top of the viewport to where the referenced line/column should be positioned.</param>
/// <param name="minimumScrollFraction">The minimum vertical and/or horizontal scroll offset, expressed as fraction of the height or width of the viewport window, respectively.</param>
public void ScrollTo(int line, int column, VisualYPosition yPositionMode,
double referencedVerticalViewPortOffset, double minimumScrollFraction)
{
TextView textView = textArea.TextView;
TextDocument document = textView.Document;
if (ScrollViewer != null && document != null)
{
if (line < 1)
line = 1;
if (line > document.LineCount)
line = document.LineCount;
ILogicalScrollable scrollInfo = textView;
if (!scrollInfo.CanHorizontallyScroll)
{
// Word wrap is enabled. Ensure that we have up-to-date info about line height so that we scroll
// to the correct position.
// This avoids that the user has to repeat the ScrollTo() call several times when there are very long lines.
VisualLine vl = textView.GetOrConstructVisualLine(document.GetLineByNumber(line));
double remainingHeight = referencedVerticalViewPortOffset;
while (remainingHeight > 0)
{
DocumentLine prevLine = vl.FirstDocumentLine.PreviousLine;
if (prevLine == null)
break;
vl = textView.GetOrConstructVisualLine(prevLine);
remainingHeight -= vl.Height;
}
}
Point p = textArea.TextView.GetVisualPosition(
new TextViewPosition(line, Math.Max(1, column)),
yPositionMode);
double targetX = ScrollViewer.Offset.X;
double targetY = ScrollViewer.Offset.Y;
double verticalPos = p.Y - referencedVerticalViewPortOffset;
if (Math.Abs(verticalPos - ScrollViewer.Offset.Y) >
minimumScrollFraction * ScrollViewer.Viewport.Height)
{
targetY = Math.Max(0, verticalPos);
}
if (column > 0)
{
if (p.X > ScrollViewer.Viewport.Width - Caret.MinimumDistanceToViewBorder * 2)
{
double horizontalPos = Math.Max(0, p.X - ScrollViewer.Viewport.Width / 2);
if (Math.Abs(horizontalPos - ScrollViewer.Offset.X) >
minimumScrollFraction * ScrollViewer.Viewport.Width)
{
targetX = 0;
}
}
else
{
targetX = 0;
}
}
if (targetX != ScrollViewer.Offset.X || targetY != ScrollViewer.Offset.Y)
ScrollViewer.Offset = new Vector(targetX, targetY);
}
}
}
}
<MSG> Merge pull request #73 from jeffreye/fix-scroll
Fix scroll
<DFF> @@ -47,6 +47,8 @@ namespace AvaloniaEdit
static TextEditor()
{
FocusableProperty.OverrideDefaultValue<TextEditor>(true);
+ HorizontalScrollBarVisibilityProperty.OverrideDefaultValue<TextEditor>(ScrollBarVisibility.Auto);
+ VerticalScrollBarVisibilityProperty.OverrideDefaultValue<TextEditor>(ScrollBarVisibility.Auto);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
@@ -1049,28 +1051,28 @@ namespace AvaloniaEdit
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
- public static readonly AvaloniaProperty HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
+ public static readonly AttachedProperty<ScrollBarVisibility> HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
- get => (ScrollBarVisibility)GetValue(HorizontalScrollBarVisibilityProperty);
+ get => GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
- public static readonly AvaloniaProperty VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
+ public static readonly AttachedProperty<ScrollBarVisibility> VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
- get => (ScrollBarVisibility)GetValue(VerticalScrollBarVisibilityProperty);
+ get => GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
| 6 | Merge pull request #73 from jeffreye/fix-scroll | 4 | .cs | cs | mit | AvaloniaUI/AvaloniaEdit |
10066914 | <NME> TextEditor.cs
<BEF> // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using Avalonia;
using AvaloniaEdit.Document;
using AvaloniaEdit.Editing;
using AvaloniaEdit.Highlighting;
using AvaloniaEdit.Rendering;
using AvaloniaEdit.Utils;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Shapes;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.LogicalTree;
using Avalonia.Media;
using Avalonia.Data;
using AvaloniaEdit.Search;
namespace AvaloniaEdit
{
/// <summary>
/// The text editor control.
/// Contains a scrollable TextArea.
/// </summary>
public class TextEditor : TemplatedControl, ITextEditorComponent
static TextEditor()
{
FocusableProperty.OverrideDefaultValue<TextEditor>(true);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
SyntaxHighlightingProperty.Changed.Subscribe(OnSyntaxHighlightingChanged);
IsReadOnlyProperty.Changed.Subscribe(OnIsReadOnlyChanged);
IsModifiedProperty.Changed.Subscribe(OnIsModifiedChanged);
ShowLineNumbersProperty.Changed.Subscribe(OnShowLineNumbersChanged);
LineNumbersForegroundProperty.Changed.Subscribe(OnLineNumbersForegroundChanged);
FontFamilyProperty.Changed.Subscribe(OnFontFamilyPropertyChanged);
FontSizeProperty.Changed.Subscribe(OnFontSizePropertyChanged);
}
/// <summary>
/// Creates a new TextEditor instance.
/// </summary>
public TextEditor() : this(new TextArea())
{
}
/// <summary>
/// Creates a new TextEditor instance.
/// </summary>
protected TextEditor(TextArea textArea) : this(textArea, new TextDocument())
{
}
protected TextEditor(TextArea textArea, TextDocument document)
{
this.textArea = textArea ?? throw new ArgumentNullException(nameof(textArea));
textArea.TextView.Services.AddService(this);
SetValue(OptionsProperty, textArea.Options);
SetValue(DocumentProperty, document);
textArea[!BackgroundProperty] = this[!BackgroundProperty];
}
#endregion
protected override void OnGotFocus(GotFocusEventArgs e)
{
base.OnGotFocus(e);
TextArea.Focus();
e.Handled = true;
}
#region Document property
/// <summary>
/// Document property.
/// </summary>
public static readonly StyledProperty<TextDocument> DocumentProperty
= TextView.DocumentProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the document displayed by the text editor.
/// This is a dependency property.
/// </summary>
public TextDocument Document
{
get => GetValue(DocumentProperty);
set => SetValue(DocumentProperty, value);
}
/// <summary>
/// Occurs when the document property has changed.
/// </summary>
public event EventHandler DocumentChanged;
/// <summary>
/// Raises the <see cref="DocumentChanged"/> event.
/// </summary>
protected virtual void OnDocumentChanged(EventArgs e)
{
DocumentChanged?.Invoke(this, e);
}
private static void OnDocumentChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnDocumentChanged((TextDocument)e.OldValue, (TextDocument)e.NewValue);
}
private void OnDocumentChanged(TextDocument oldValue, TextDocument newValue)
{
if (oldValue != null)
{
TextDocumentWeakEventManager.TextChanged.RemoveHandler(oldValue, OnTextChanged);
PropertyChangedWeakEventManager.RemoveHandler(oldValue.UndoStack, OnUndoStackPropertyChangedHandler);
}
TextArea.Document = newValue;
if (newValue != null)
{
TextDocumentWeakEventManager.TextChanged.AddHandler(newValue, OnTextChanged);
PropertyChangedWeakEventManager.AddHandler(newValue.UndoStack, OnUndoStackPropertyChangedHandler);
}
OnDocumentChanged(EventArgs.Empty);
OnTextChanged(EventArgs.Empty);
}
#endregion
#region Options property
/// <summary>
/// Options property.
/// </summary>
public static readonly StyledProperty<TextEditorOptions> OptionsProperty
= TextView.OptionsProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the options currently used by the text editor.
/// </summary>
public TextEditorOptions Options
{
get => GetValue(OptionsProperty);
set => SetValue(OptionsProperty, value);
}
/// <summary>
/// Occurs when a text editor option has changed.
/// </summary>
public event PropertyChangedEventHandler OptionChanged;
/// <summary>
/// Raises the <see cref="OptionChanged"/> event.
/// </summary>
protected virtual void OnOptionChanged(PropertyChangedEventArgs e)
{
OptionChanged?.Invoke(this, e);
}
private static void OnOptionsChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnOptionsChanged((TextEditorOptions)e.OldValue, (TextEditorOptions)e.NewValue);
}
private void OnOptionsChanged(TextEditorOptions oldValue, TextEditorOptions newValue)
{
if (oldValue != null)
{
PropertyChangedWeakEventManager.RemoveHandler(oldValue, OnPropertyChangedHandler);
}
TextArea.Options = newValue;
if (newValue != null)
{
PropertyChangedWeakEventManager.AddHandler(newValue, OnPropertyChangedHandler);
}
OnOptionChanged(new PropertyChangedEventArgs(null));
}
private void OnPropertyChangedHandler(object sender, PropertyChangedEventArgs e)
{
OnOptionChanged(e);
}
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
base.OnPropertyChanged(change);
if (change.Property == WordWrapProperty)
{
if (WordWrap)
{
_horizontalScrollBarVisibilityBck = HorizontalScrollBarVisibility;
HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
}
else
{
HorizontalScrollBarVisibility = _horizontalScrollBarVisibilityBck;
}
}
}
private void OnUndoStackPropertyChangedHandler(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsOriginalFile")
{
HandleIsOriginalChanged(e);
}
}
private void OnTextChanged(object sender, EventArgs e)
{
OnTextChanged(e);
}
#endregion
#region Text property
/// <summary>
/// Gets/Sets the text of the current document.
/// </summary>
public string Text
{
get
{
var document = Document;
return document != null ? document.Text : string.Empty;
}
set
{
var document = GetDocument();
document.Text = value ?? string.Empty;
// after replacing the full text, the caret is positioned at the end of the document
// - reset it to the beginning.
CaretOffset = 0;
document.UndoStack.ClearAll();
}
}
private TextDocument GetDocument()
{
var document = Document;
if (document == null)
throw ThrowUtil.NoDocumentAssigned();
return document;
}
/// <summary>
/// Occurs when the Text property changes.
/// </summary>
public event EventHandler TextChanged;
/// <summary>
/// Raises the <see cref="TextChanged"/> event.
/// </summary>
protected virtual void OnTextChanged(EventArgs e)
{
TextChanged?.Invoke(this, e);
}
#endregion
#region TextArea / ScrollViewer properties
private readonly TextArea textArea;
private SearchPanel searchPanel;
private bool wasSearchPanelOpened;
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
ScrollViewer = (ScrollViewer)e.NameScope.Find("PART_ScrollViewer");
ScrollViewer.Content = TextArea;
searchPanel = SearchPanel.Install(this);
}
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnAttachedToLogicalTree(e);
if (searchPanel != null && wasSearchPanelOpened)
{
searchPanel.Open();
}
}
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnDetachedFromLogicalTree(e);
if (searchPanel != null)
{
wasSearchPanelOpened = searchPanel.IsOpened;
if (searchPanel.IsOpened)
searchPanel.Close();
}
}
/// <summary>
/// Gets the text area.
/// </summary>
public TextArea TextArea => textArea;
/// <summary>
/// Gets the search panel.
/// </summary>
public SearchPanel SearchPanel => searchPanel;
/// <summary>
/// Gets the scroll viewer used by the text editor.
/// This property can return null if the template has not been applied / does not contain a scroll viewer.
/// </summary>
internal ScrollViewer ScrollViewer { get; private set; }
#endregion
#region Syntax highlighting
/// <summary>
/// The <see cref="SyntaxHighlighting"/> property.
/// </summary>
public static readonly StyledProperty<IHighlightingDefinition> SyntaxHighlightingProperty =
AvaloniaProperty.Register<TextEditor, IHighlightingDefinition>("SyntaxHighlighting");
/// <summary>
/// Gets/sets the syntax highlighting definition used to colorize the text.
/// </summary>
public IHighlightingDefinition SyntaxHighlighting
{
get => GetValue(SyntaxHighlightingProperty);
set => SetValue(SyntaxHighlightingProperty, value);
}
private IVisualLineTransformer _colorizer;
private static void OnSyntaxHighlightingChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnSyntaxHighlightingChanged(e.NewValue as IHighlightingDefinition);
}
private void OnSyntaxHighlightingChanged(IHighlightingDefinition newValue)
{
if (_colorizer != null)
{
textArea.TextView.LineTransformers.Remove(_colorizer);
_colorizer = null;
}
if (newValue != null)
{
_colorizer = CreateColorizer(newValue);
if (_colorizer != null)
{
textArea.TextView.LineTransformers.Insert(0, _colorizer);
}
}
}
/// <summary>
/// Creates the highlighting colorizer for the specified highlighting definition.
/// Allows derived classes to provide custom colorizer implementations for special highlighting definitions.
/// </summary>
/// <returns></returns>
protected virtual IVisualLineTransformer CreateColorizer(IHighlightingDefinition highlightingDefinition)
{
if (highlightingDefinition == null)
throw new ArgumentNullException(nameof(highlightingDefinition));
return new HighlightingColorizer(highlightingDefinition);
}
#endregion
#region WordWrap
/// <summary>
/// Word wrap dependency property.
/// </summary>
public static readonly StyledProperty<bool> WordWrapProperty =
AvaloniaProperty.Register<TextEditor, bool>("WordWrap");
/// <summary>
/// Specifies whether the text editor uses word wrapping.
/// </summary>
/// <remarks>
/// Setting WordWrap=true has the same effect as setting HorizontalScrollBarVisibility=Disabled and will override the
/// HorizontalScrollBarVisibility setting.
/// </remarks>
public bool WordWrap
{
get => GetValue(WordWrapProperty);
set => SetValue(WordWrapProperty, value);
}
#endregion
#region IsReadOnly
/// <summary>
/// IsReadOnly dependency property.
/// </summary>
public static readonly StyledProperty<bool> IsReadOnlyProperty =
AvaloniaProperty.Register<TextEditor, bool>("IsReadOnly");
/// <summary>
/// Specifies whether the user can change the text editor content.
/// Setting this property will replace the
/// <see cref="Editing.TextArea.ReadOnlySectionProvider">TextArea.ReadOnlySectionProvider</see>.
/// </summary>
public bool IsReadOnly
{
get => GetValue(IsReadOnlyProperty);
set => SetValue(IsReadOnlyProperty, value);
}
private static void OnIsReadOnlyChanged(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is TextEditor editor)
{
if ((bool)e.NewValue)
editor.TextArea.ReadOnlySectionProvider = ReadOnlySectionDocument.Instance;
else
editor.TextArea.ReadOnlySectionProvider = NoReadOnlySections.Instance;
}
}
#endregion
#region IsModified
/// <summary>
/// Dependency property for <see cref="IsModified"/>
/// </summary>
public static readonly StyledProperty<bool> IsModifiedProperty =
AvaloniaProperty.Register<TextEditor, bool>("IsModified");
/// <summary>
/// Gets/Sets the 'modified' flag.
/// </summary>
public bool IsModified
{
get => GetValue(IsModifiedProperty);
set => SetValue(IsModifiedProperty, value);
}
private static void OnIsModifiedChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
var document = editor?.Document;
if (document != null)
{
var undoStack = document.UndoStack;
if ((bool)e.NewValue)
{
if (undoStack.IsOriginalFile)
undoStack.DiscardOriginalFileMarker();
}
else
{
undoStack.MarkAsOriginalFile();
}
}
}
private void HandleIsOriginalChanged(PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsOriginalFile")
{
var document = Document;
if (document != null)
{
SetValue(IsModifiedProperty, (object)!document.UndoStack.IsOriginalFile);
}
}
}
#endregion
#region ShowLineNumbers
/// <summary>
/// ShowLineNumbers dependency property.
/// </summary>
public static readonly StyledProperty<bool> ShowLineNumbersProperty =
AvaloniaProperty.Register<TextEditor, bool>("ShowLineNumbers");
/// <summary>
/// Specifies whether line numbers are shown on the left to the text view.
/// </summary>
public bool ShowLineNumbers
{
get => GetValue(ShowLineNumbersProperty);
set => SetValue(ShowLineNumbersProperty, value);
}
private static void OnShowLineNumbersChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
if (editor == null) return;
var leftMargins = editor.TextArea.LeftMargins;
if ((bool)e.NewValue)
{
var lineNumbers = new LineNumberMargin();
var line = (Line)DottedLineMargin.Create();
leftMargins.Insert(0, lineNumbers);
leftMargins.Insert(1, line);
var lineNumbersForeground = new Binding("LineNumbersForeground") { Source = editor };
line.Bind(Shape.StrokeProperty, lineNumbersForeground);
lineNumbers.Bind(ForegroundProperty, lineNumbersForeground);
}
else
{
for (var i = 0; i < leftMargins.Count; i++)
{
if (leftMargins[i] is LineNumberMargin)
{
leftMargins.RemoveAt(i);
if (i < leftMargins.Count && DottedLineMargin.IsDottedLineMargin(leftMargins[i]))
{
leftMargins.RemoveAt(i);
}
break;
}
}
}
}
#endregion
#region LineNumbersForeground
/// <summary>
/// LineNumbersForeground dependency property.
/// </summary>
public static readonly StyledProperty<IBrush> LineNumbersForegroundProperty =
AvaloniaProperty.Register<TextEditor, IBrush>("LineNumbersForeground", Brushes.Gray);
/// <summary>
/// Gets/sets the Brush used for displaying the foreground color of line numbers.
/// </summary>
public IBrush LineNumbersForeground
{
get => GetValue(LineNumbersForegroundProperty);
set => SetValue(LineNumbersForegroundProperty, value);
}
private static void OnLineNumbersForegroundChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
var lineNumberMargin = editor?.TextArea.LeftMargins.FirstOrDefault(margin => margin is LineNumberMargin) as LineNumberMargin;
lineNumberMargin?.SetValue(ForegroundProperty, e.NewValue);
}
private static void OnFontFamilyPropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
editor?.TextArea.TextView.SetValue(FontFamilyProperty, e.NewValue);
}
private static void OnFontSizePropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
editor?.TextArea.TextView.SetValue(FontSizeProperty, e.NewValue);
}
#endregion
#region TextBoxBase-like methods
/// <summary>
/// Appends text to the end of the document.
/// </summary>
public void AppendText(string textData)
{
var document = GetDocument();
document.Insert(document.TextLength, textData);
}
/// <summary>
/// Begins a group of document changes.
/// </summary>
public void BeginChange()
{
GetDocument().BeginUpdate();
}
/// <summary>
/// Copies the current selection to the clipboard.
/// </summary>
public void Copy()
{
if (CanCopy)
{
ApplicationCommands.Copy.Execute(null, TextArea);
}
}
/// <summary>
/// Removes the current selection and copies it to the clipboard.
/// </summary>
public void Cut()
{
if (CanCut)
{
ApplicationCommands.Cut.Execute(null, TextArea);
}
}
/// <summary>
/// Begins a group of document changes and returns an object that ends the group of document
/// changes when it is disposed.
/// </summary>
public IDisposable DeclareChangeBlock()
{
return GetDocument().RunUpdate();
}
/// <summary>
/// Removes the current selection without copying it to the clipboard.
/// </summary>
public void Delete()
{
if(CanDelete)
{
ApplicationCommands.Delete.Execute(null, TextArea);
}
}
/// <summary>
/// Ends the current group of document changes.
/// </summary>
public void EndChange()
{
GetDocument().EndUpdate();
}
/// <summary>
/// Scrolls one line down.
/// </summary>
public void LineDown()
{
//if (scrollViewer != null)
// scrollViewer.LineDown();
}
/// <summary>
/// Scrolls to the left.
/// </summary>
public void LineLeft()
{
//if (scrollViewer != null)
// scrollViewer.LineLeft();
}
/// <summary>
/// Scrolls to the right.
/// </summary>
public void LineRight()
{
//if (scrollViewer != null)
// scrollViewer.LineRight();
}
/// <summary>
/// Scrolls one line up.
/// </summary>
public void LineUp()
{
//if (scrollViewer != null)
// scrollViewer.LineUp();
}
/// <summary>
/// Scrolls one page down.
/// </summary>
public void PageDown()
{
//if (scrollViewer != null)
// scrollViewer.PageDown();
}
/// <summary>
/// Scrolls one page up.
/// </summary>
public void PageUp()
{
//if (scrollViewer != null)
// scrollViewer.PageUp();
}
/// <summary>
/// Scrolls one page left.
/// </summary>
public void PageLeft()
{
//if (scrollViewer != null)
// scrollViewer.PageLeft();
}
/// <summary>
/// Scrolls one page right.
/// </summary>
public void PageRight()
{
//if (scrollViewer != null)
// scrollViewer.PageRight();
}
/// <summary>
/// Pastes the clipboard content.
/// </summary>
public void Paste()
{
if (CanPaste)
{
ApplicationCommands.Paste.Execute(null, TextArea);
}
}
/// <summary>
/// Redoes the most recent undone command.
/// </summary>
/// <returns>True is the redo operation was successful, false is the redo stack is empty.</returns>
public bool Redo()
{
if (CanRedo)
{
ApplicationCommands.Redo.Execute(null, TextArea);
return true;
}
return false;
}
/// <summary>
/// Scrolls to the end of the document.
/// </summary>
public void ScrollToEnd()
{
ApplyTemplate(); // ensure scrollViewer is created
ScrollViewer?.ScrollToEnd();
}
/// <summary>
/// Scrolls to the start of the document.
/// </summary>
public void ScrollToHome()
{
ApplyTemplate(); // ensure scrollViewer is created
ScrollViewer?.ScrollToHome();
}
/// <summary>
/// Scrolls to the specified position in the document.
/// </summary>
public void ScrollToHorizontalOffset(double offset)
{
ApplyTemplate(); // ensure scrollViewer is created
//if (scrollViewer != null)
// scrollViewer.ScrollToHorizontalOffset(offset);
}
/// <summary>
/// Scrolls to the specified position in the document.
/// </summary>
public void ScrollToVerticalOffset(double offset)
{
ApplyTemplate(); // ensure scrollViewer is created
//if (scrollViewer != null)
// scrollViewer.ScrollToVerticalOffset(offset);
}
/// <summary>
/// Selects the entire text.
/// </summary>
public void SelectAll()
{
if (CanSelectAll)
{
ApplicationCommands.SelectAll.Execute(null, TextArea);
}
}
/// <summary>
/// Undoes the most recent command.
/// </summary>
/// <returns>True is the undo operation was successful, false is the undo stack is empty.</returns>
public bool Undo()
{
if (CanUndo)
{
ApplicationCommands.Undo.Execute(null, TextArea);
return true;
}
return false;
}
/// <summary>
/// Gets if the most recent undone command can be redone.
/// </summary>
public bool CanRedo
{
get { return ApplicationCommands.Redo.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if the most recent command can be undone.
/// </summary>
public bool CanUndo
{
get { return ApplicationCommands.Undo.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be copied
/// </summary>
public bool CanCopy
{
get { return ApplicationCommands.Copy.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be cut
/// </summary>
public bool CanCut
{
get { return ApplicationCommands.Cut.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be pasted
/// </summary>
public bool CanPaste
{
get { return ApplicationCommands.Paste.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if selected text in editor can be deleted
/// </summary>
public bool CanDelete
{
get { return ApplicationCommands.Delete.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text the editor can select all
/// </summary>
public bool CanSelectAll
{
get { return ApplicationCommands.SelectAll.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text editor can activate the search panel
/// </summary>
public bool CanSearch
{
get { return searchPanel != null; }
}
/// <summary>
/// Gets the vertical size of the document.
/// </summary>
public double ExtentHeight => ScrollViewer?.Extent.Height ?? 0;
/// <summary>
/// Gets the horizontal size of the current document region.
/// </summary>
public double ExtentWidth => ScrollViewer?.Extent.Width ?? 0;
/// <summary>
/// Gets the horizontal size of the viewport.
/// </summary>
public double ViewportHeight => ScrollViewer?.Viewport.Height ?? 0;
/// <summary>
/// Gets the horizontal size of the viewport.
/// </summary>
public double ViewportWidth => ScrollViewer?.Viewport.Width ?? 0;
/// <summary>
/// Gets the vertical scroll position.
/// </summary>
public double VerticalOffset => ScrollViewer?.Offset.Y ?? 0;
/// <summary>
/// Gets the horizontal scroll position.
/// </summary>
public double HorizontalOffset => ScrollViewer?.Offset.X ?? 0;
#endregion
#region TextBox methods
/// <summary>
/// Gets/Sets the selected text.
/// </summary>
public string SelectedText
{
get
{
// We'll get the text from the whole surrounding segment.
// This is done to ensure that SelectedText.Length == SelectionLength.
if (textArea.Document != null && !textArea.Selection.IsEmpty)
return textArea.Document.GetText(textArea.Selection.SurroundingSegment);
return string.Empty;
}
set
{
if (value == null)
throw new ArgumentNullException(nameof(value));
var textArea = TextArea;
if (textArea.Document != null)
{
var offset = SelectionStart;
var length = SelectionLength;
textArea.Document.Replace(offset, length, value);
// keep inserted text selected
textArea.Selection = Selection.Create(textArea, offset, offset + value.Length);
}
}
}
/// <summary>
/// Gets/sets the caret position.
/// </summary>
public int CaretOffset
{
get
{
return textArea.Caret.Offset;
}
set
{
textArea.Caret.Offset = value;
}
}
/// <summary>
/// Gets/sets the start position of the selection.
/// </summary>
public int SelectionStart
{
get
{
if (textArea.Selection.IsEmpty)
return textArea.Caret.Offset;
else
return textArea.Selection.SurroundingSegment.Offset;
}
set => Select(value, SelectionLength);
}
/// <summary>
/// Gets/sets the length of the selection.
/// </summary>
public int SelectionLength
{
get
{
if (!textArea.Selection.IsEmpty)
return textArea.Selection.SurroundingSegment.Length;
else
return 0;
}
set => Select(SelectionStart, value);
}
/// <summary>
/// Selects the specified text section.
/// </summary>
public void Select(int start, int length)
{
var documentLength = Document?.TextLength ?? 0;
if (start < 0 || start > documentLength)
throw new ArgumentOutOfRangeException(nameof(start), start, "Value must be between 0 and " + documentLength);
if (length < 0 || start + length > documentLength)
throw new ArgumentOutOfRangeException(nameof(length), length, "Value must be between 0 and " + (documentLength - start));
TextArea.Selection = Selection.Create(TextArea, start, start + length);
TextArea.Caret.Offset = start + length;
}
/// <summary>
/// Gets the number of lines in the document.
/// </summary>
public int LineCount
{
get
{
var document = Document;
if (document != null)
return document.LineCount;
return 1;
}
}
/// <summary>
/// Clears the text.
/// </summary>
public void Clear()
{
Text = string.Empty;
}
#endregion
#region Loading from stream
/// <summary>
/// Loads the text from the stream, auto-detecting the encoding.
/// </summary>
/// <remarks>
/// This method sets <see cref="IsModified"/> to false.
/// </remarks>
public void Load(Stream stream)
{
using (var reader = FileReader.OpenStream(stream, Encoding ?? Encoding.UTF8))
{
Text = reader.ReadToEnd();
SetValue(EncodingProperty, (object)reader.CurrentEncoding);
}
SetValue(IsModifiedProperty, (object)false);
}
/// <summary>
/// Loads the text from the stream, auto-detecting the encoding.
/// </summary>
public void Load(string fileName)
{
if (fileName == null)
throw new ArgumentNullException(nameof(fileName));
// TODO:load
//using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
//{
// Load(fs);
//}
}
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
public static readonly AvaloniaProperty HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
get => (ScrollBarVisibility)GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
public static readonly AvaloniaProperty VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
get => (ScrollBarVisibility)GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
if (stream == null)
throw new ArgumentNullException(nameof(stream));
var encoding = Encoding;
var document = Document;
var writer = encoding != null ? new StreamWriter(stream, encoding) : new StreamWriter(stream);
document?.WriteTextTo(writer);
writer.Flush();
// do not close the stream
SetValue(IsModifiedProperty, (object)false);
}
/// <summary>
/// Saves the text to the file.
/// </summary>
public void Save(string fileName)
{
if (fileName == null)
throw new ArgumentNullException(nameof(fileName));
// TODO: save
//using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
//{
// Save(fs);
//}
}
#endregion
#region PointerHover events
/// <summary>
/// The PreviewPointerHover event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PreviewPointerHoverEvent =
TextView.PreviewPointerHoverEvent;
/// <summary>
/// the pointerHover event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PointerHoverEvent =
TextView.PointerHoverEvent;
/// <summary>
/// The PreviewPointerHoverStopped event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PreviewPointerHoverStoppedEvent =
TextView.PreviewPointerHoverStoppedEvent;
/// <summary>
/// the pointerHoverStopped event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PointerHoverStoppedEvent =
TextView.PointerHoverStoppedEvent;
/// <summary>
/// Occurs when the pointer has hovered over a fixed location for some time.
/// </summary>
public event EventHandler<PointerEventArgs> PreviewPointerHover
{
add => AddHandler(PreviewPointerHoverEvent, value);
remove => RemoveHandler(PreviewPointerHoverEvent, value);
}
/// <summary>
/// Occurs when the pointer has hovered over a fixed location for some time.
/// </summary>
public event EventHandler<PointerEventArgs> PointerHover
{
add => AddHandler(PointerHoverEvent, value);
remove => RemoveHandler(PointerHoverEvent, value);
}
/// <summary>
/// Occurs when the pointer had previously hovered but now started moving again.
/// </summary>
public event EventHandler<PointerEventArgs> PreviewPointerHoverStopped
{
add => AddHandler(PreviewPointerHoverStoppedEvent, value);
remove => RemoveHandler(PreviewPointerHoverStoppedEvent, value);
}
/// <summary>
/// Occurs when the pointer had previously hovered but now started moving again.
/// </summary>
public event EventHandler<PointerEventArgs> PointerHoverStopped
{
add => AddHandler(PointerHoverStoppedEvent, value);
remove => RemoveHandler(PointerHoverStoppedEvent, value);
}
#endregion
#region ScrollBarVisibility
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
public static readonly AttachedProperty<ScrollBarVisibility> HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
get => GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
private ScrollBarVisibility _horizontalScrollBarVisibilityBck = ScrollBarVisibility.Auto;
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
public static readonly AttachedProperty<ScrollBarVisibility> VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
get => GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
object IServiceProvider.GetService(Type serviceType)
{
return TextArea.GetService(serviceType);
}
/// <summary>
/// Gets the text view position from a point inside the editor.
/// </summary>
/// <param name="point">The position, relative to top left
/// corner of TextEditor control</param>
/// <returns>The text view position, or null if the point is outside the document.</returns>
public TextViewPosition? GetPositionFromPoint(Point point)
{
if (Document == null)
return null;
var textView = TextArea.TextView;
Point tpoint = (Point)this.TranslatePoint(point + new Point(textView.ScrollOffset.X, Math.Floor(textView.ScrollOffset.Y)), textView);
return textView.GetPosition(tpoint);
}
/// <summary>
/// Scrolls to the specified line.
/// This method requires that the TextEditor was already assigned a size (layout engine must have run prior).
/// </summary>
public void ScrollToLine(int line)
{
ScrollTo(line, -1);
}
/// <summary>
/// Scrolls to the specified line/column.
/// This method requires that the TextEditor was already assigned a size (layout engine must have run prior).
/// </summary>
public void ScrollTo(int line, int column)
{
const double MinimumScrollFraction = 0.3;
ScrollTo(line, column, VisualYPosition.LineMiddle,
null != ScrollViewer ? ScrollViewer.Viewport.Height / 2 : 0.0, MinimumScrollFraction);
}
/// <summary>
/// Scrolls to the specified line/column.
/// This method requires that the TextEditor was already assigned a size (WPF layout must have run prior).
/// </summary>
/// <param name="line">Line to scroll to.</param>
/// <param name="column">Column to scroll to (important if wrapping is 'on', and for the horizontal scroll position).</param>
/// <param name="yPositionMode">The mode how to reference the Y position of the line.</param>
/// <param name="referencedVerticalViewPortOffset">Offset from the top of the viewport to where the referenced line/column should be positioned.</param>
/// <param name="minimumScrollFraction">The minimum vertical and/or horizontal scroll offset, expressed as fraction of the height or width of the viewport window, respectively.</param>
public void ScrollTo(int line, int column, VisualYPosition yPositionMode,
double referencedVerticalViewPortOffset, double minimumScrollFraction)
{
TextView textView = textArea.TextView;
TextDocument document = textView.Document;
if (ScrollViewer != null && document != null)
{
if (line < 1)
line = 1;
if (line > document.LineCount)
line = document.LineCount;
ILogicalScrollable scrollInfo = textView;
if (!scrollInfo.CanHorizontallyScroll)
{
// Word wrap is enabled. Ensure that we have up-to-date info about line height so that we scroll
// to the correct position.
// This avoids that the user has to repeat the ScrollTo() call several times when there are very long lines.
VisualLine vl = textView.GetOrConstructVisualLine(document.GetLineByNumber(line));
double remainingHeight = referencedVerticalViewPortOffset;
while (remainingHeight > 0)
{
DocumentLine prevLine = vl.FirstDocumentLine.PreviousLine;
if (prevLine == null)
break;
vl = textView.GetOrConstructVisualLine(prevLine);
remainingHeight -= vl.Height;
}
}
Point p = textArea.TextView.GetVisualPosition(
new TextViewPosition(line, Math.Max(1, column)),
yPositionMode);
double targetX = ScrollViewer.Offset.X;
double targetY = ScrollViewer.Offset.Y;
double verticalPos = p.Y - referencedVerticalViewPortOffset;
if (Math.Abs(verticalPos - ScrollViewer.Offset.Y) >
minimumScrollFraction * ScrollViewer.Viewport.Height)
{
targetY = Math.Max(0, verticalPos);
}
if (column > 0)
{
if (p.X > ScrollViewer.Viewport.Width - Caret.MinimumDistanceToViewBorder * 2)
{
double horizontalPos = Math.Max(0, p.X - ScrollViewer.Viewport.Width / 2);
if (Math.Abs(horizontalPos - ScrollViewer.Offset.X) >
minimumScrollFraction * ScrollViewer.Viewport.Width)
{
targetX = 0;
}
}
else
{
targetX = 0;
}
}
if (targetX != ScrollViewer.Offset.X || targetY != ScrollViewer.Offset.Y)
ScrollViewer.Offset = new Vector(targetX, targetY);
}
}
}
}
<MSG> Merge pull request #73 from jeffreye/fix-scroll
Fix scroll
<DFF> @@ -47,6 +47,8 @@ namespace AvaloniaEdit
static TextEditor()
{
FocusableProperty.OverrideDefaultValue<TextEditor>(true);
+ HorizontalScrollBarVisibilityProperty.OverrideDefaultValue<TextEditor>(ScrollBarVisibility.Auto);
+ VerticalScrollBarVisibilityProperty.OverrideDefaultValue<TextEditor>(ScrollBarVisibility.Auto);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
@@ -1049,28 +1051,28 @@ namespace AvaloniaEdit
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
- public static readonly AvaloniaProperty HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
+ public static readonly AttachedProperty<ScrollBarVisibility> HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
- get => (ScrollBarVisibility)GetValue(HorizontalScrollBarVisibilityProperty);
+ get => GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
- public static readonly AvaloniaProperty VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
+ public static readonly AttachedProperty<ScrollBarVisibility> VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
- get => (ScrollBarVisibility)GetValue(VerticalScrollBarVisibilityProperty);
+ get => GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
| 6 | Merge pull request #73 from jeffreye/fix-scroll | 4 | .cs | cs | mit | AvaloniaUI/AvaloniaEdit |
10066915 | <NME> TextEditor.cs
<BEF> // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using Avalonia;
using AvaloniaEdit.Document;
using AvaloniaEdit.Editing;
using AvaloniaEdit.Highlighting;
using AvaloniaEdit.Rendering;
using AvaloniaEdit.Utils;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Shapes;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.LogicalTree;
using Avalonia.Media;
using Avalonia.Data;
using AvaloniaEdit.Search;
namespace AvaloniaEdit
{
/// <summary>
/// The text editor control.
/// Contains a scrollable TextArea.
/// </summary>
public class TextEditor : TemplatedControl, ITextEditorComponent
static TextEditor()
{
FocusableProperty.OverrideDefaultValue<TextEditor>(true);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
SyntaxHighlightingProperty.Changed.Subscribe(OnSyntaxHighlightingChanged);
IsReadOnlyProperty.Changed.Subscribe(OnIsReadOnlyChanged);
IsModifiedProperty.Changed.Subscribe(OnIsModifiedChanged);
ShowLineNumbersProperty.Changed.Subscribe(OnShowLineNumbersChanged);
LineNumbersForegroundProperty.Changed.Subscribe(OnLineNumbersForegroundChanged);
FontFamilyProperty.Changed.Subscribe(OnFontFamilyPropertyChanged);
FontSizeProperty.Changed.Subscribe(OnFontSizePropertyChanged);
}
/// <summary>
/// Creates a new TextEditor instance.
/// </summary>
public TextEditor() : this(new TextArea())
{
}
/// <summary>
/// Creates a new TextEditor instance.
/// </summary>
protected TextEditor(TextArea textArea) : this(textArea, new TextDocument())
{
}
protected TextEditor(TextArea textArea, TextDocument document)
{
this.textArea = textArea ?? throw new ArgumentNullException(nameof(textArea));
textArea.TextView.Services.AddService(this);
SetValue(OptionsProperty, textArea.Options);
SetValue(DocumentProperty, document);
textArea[!BackgroundProperty] = this[!BackgroundProperty];
}
#endregion
protected override void OnGotFocus(GotFocusEventArgs e)
{
base.OnGotFocus(e);
TextArea.Focus();
e.Handled = true;
}
#region Document property
/// <summary>
/// Document property.
/// </summary>
public static readonly StyledProperty<TextDocument> DocumentProperty
= TextView.DocumentProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the document displayed by the text editor.
/// This is a dependency property.
/// </summary>
public TextDocument Document
{
get => GetValue(DocumentProperty);
set => SetValue(DocumentProperty, value);
}
/// <summary>
/// Occurs when the document property has changed.
/// </summary>
public event EventHandler DocumentChanged;
/// <summary>
/// Raises the <see cref="DocumentChanged"/> event.
/// </summary>
protected virtual void OnDocumentChanged(EventArgs e)
{
DocumentChanged?.Invoke(this, e);
}
private static void OnDocumentChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnDocumentChanged((TextDocument)e.OldValue, (TextDocument)e.NewValue);
}
private void OnDocumentChanged(TextDocument oldValue, TextDocument newValue)
{
if (oldValue != null)
{
TextDocumentWeakEventManager.TextChanged.RemoveHandler(oldValue, OnTextChanged);
PropertyChangedWeakEventManager.RemoveHandler(oldValue.UndoStack, OnUndoStackPropertyChangedHandler);
}
TextArea.Document = newValue;
if (newValue != null)
{
TextDocumentWeakEventManager.TextChanged.AddHandler(newValue, OnTextChanged);
PropertyChangedWeakEventManager.AddHandler(newValue.UndoStack, OnUndoStackPropertyChangedHandler);
}
OnDocumentChanged(EventArgs.Empty);
OnTextChanged(EventArgs.Empty);
}
#endregion
#region Options property
/// <summary>
/// Options property.
/// </summary>
public static readonly StyledProperty<TextEditorOptions> OptionsProperty
= TextView.OptionsProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the options currently used by the text editor.
/// </summary>
public TextEditorOptions Options
{
get => GetValue(OptionsProperty);
set => SetValue(OptionsProperty, value);
}
/// <summary>
/// Occurs when a text editor option has changed.
/// </summary>
public event PropertyChangedEventHandler OptionChanged;
/// <summary>
/// Raises the <see cref="OptionChanged"/> event.
/// </summary>
protected virtual void OnOptionChanged(PropertyChangedEventArgs e)
{
OptionChanged?.Invoke(this, e);
}
private static void OnOptionsChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnOptionsChanged((TextEditorOptions)e.OldValue, (TextEditorOptions)e.NewValue);
}
private void OnOptionsChanged(TextEditorOptions oldValue, TextEditorOptions newValue)
{
if (oldValue != null)
{
PropertyChangedWeakEventManager.RemoveHandler(oldValue, OnPropertyChangedHandler);
}
TextArea.Options = newValue;
if (newValue != null)
{
PropertyChangedWeakEventManager.AddHandler(newValue, OnPropertyChangedHandler);
}
OnOptionChanged(new PropertyChangedEventArgs(null));
}
private void OnPropertyChangedHandler(object sender, PropertyChangedEventArgs e)
{
OnOptionChanged(e);
}
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
base.OnPropertyChanged(change);
if (change.Property == WordWrapProperty)
{
if (WordWrap)
{
_horizontalScrollBarVisibilityBck = HorizontalScrollBarVisibility;
HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
}
else
{
HorizontalScrollBarVisibility = _horizontalScrollBarVisibilityBck;
}
}
}
private void OnUndoStackPropertyChangedHandler(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsOriginalFile")
{
HandleIsOriginalChanged(e);
}
}
private void OnTextChanged(object sender, EventArgs e)
{
OnTextChanged(e);
}
#endregion
#region Text property
/// <summary>
/// Gets/Sets the text of the current document.
/// </summary>
public string Text
{
get
{
var document = Document;
return document != null ? document.Text : string.Empty;
}
set
{
var document = GetDocument();
document.Text = value ?? string.Empty;
// after replacing the full text, the caret is positioned at the end of the document
// - reset it to the beginning.
CaretOffset = 0;
document.UndoStack.ClearAll();
}
}
private TextDocument GetDocument()
{
var document = Document;
if (document == null)
throw ThrowUtil.NoDocumentAssigned();
return document;
}
/// <summary>
/// Occurs when the Text property changes.
/// </summary>
public event EventHandler TextChanged;
/// <summary>
/// Raises the <see cref="TextChanged"/> event.
/// </summary>
protected virtual void OnTextChanged(EventArgs e)
{
TextChanged?.Invoke(this, e);
}
#endregion
#region TextArea / ScrollViewer properties
private readonly TextArea textArea;
private SearchPanel searchPanel;
private bool wasSearchPanelOpened;
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
ScrollViewer = (ScrollViewer)e.NameScope.Find("PART_ScrollViewer");
ScrollViewer.Content = TextArea;
searchPanel = SearchPanel.Install(this);
}
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnAttachedToLogicalTree(e);
if (searchPanel != null && wasSearchPanelOpened)
{
searchPanel.Open();
}
}
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnDetachedFromLogicalTree(e);
if (searchPanel != null)
{
wasSearchPanelOpened = searchPanel.IsOpened;
if (searchPanel.IsOpened)
searchPanel.Close();
}
}
/// <summary>
/// Gets the text area.
/// </summary>
public TextArea TextArea => textArea;
/// <summary>
/// Gets the search panel.
/// </summary>
public SearchPanel SearchPanel => searchPanel;
/// <summary>
/// Gets the scroll viewer used by the text editor.
/// This property can return null if the template has not been applied / does not contain a scroll viewer.
/// </summary>
internal ScrollViewer ScrollViewer { get; private set; }
#endregion
#region Syntax highlighting
/// <summary>
/// The <see cref="SyntaxHighlighting"/> property.
/// </summary>
public static readonly StyledProperty<IHighlightingDefinition> SyntaxHighlightingProperty =
AvaloniaProperty.Register<TextEditor, IHighlightingDefinition>("SyntaxHighlighting");
/// <summary>
/// Gets/sets the syntax highlighting definition used to colorize the text.
/// </summary>
public IHighlightingDefinition SyntaxHighlighting
{
get => GetValue(SyntaxHighlightingProperty);
set => SetValue(SyntaxHighlightingProperty, value);
}
private IVisualLineTransformer _colorizer;
private static void OnSyntaxHighlightingChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnSyntaxHighlightingChanged(e.NewValue as IHighlightingDefinition);
}
private void OnSyntaxHighlightingChanged(IHighlightingDefinition newValue)
{
if (_colorizer != null)
{
textArea.TextView.LineTransformers.Remove(_colorizer);
_colorizer = null;
}
if (newValue != null)
{
_colorizer = CreateColorizer(newValue);
if (_colorizer != null)
{
textArea.TextView.LineTransformers.Insert(0, _colorizer);
}
}
}
/// <summary>
/// Creates the highlighting colorizer for the specified highlighting definition.
/// Allows derived classes to provide custom colorizer implementations for special highlighting definitions.
/// </summary>
/// <returns></returns>
protected virtual IVisualLineTransformer CreateColorizer(IHighlightingDefinition highlightingDefinition)
{
if (highlightingDefinition == null)
throw new ArgumentNullException(nameof(highlightingDefinition));
return new HighlightingColorizer(highlightingDefinition);
}
#endregion
#region WordWrap
/// <summary>
/// Word wrap dependency property.
/// </summary>
public static readonly StyledProperty<bool> WordWrapProperty =
AvaloniaProperty.Register<TextEditor, bool>("WordWrap");
/// <summary>
/// Specifies whether the text editor uses word wrapping.
/// </summary>
/// <remarks>
/// Setting WordWrap=true has the same effect as setting HorizontalScrollBarVisibility=Disabled and will override the
/// HorizontalScrollBarVisibility setting.
/// </remarks>
public bool WordWrap
{
get => GetValue(WordWrapProperty);
set => SetValue(WordWrapProperty, value);
}
#endregion
#region IsReadOnly
/// <summary>
/// IsReadOnly dependency property.
/// </summary>
public static readonly StyledProperty<bool> IsReadOnlyProperty =
AvaloniaProperty.Register<TextEditor, bool>("IsReadOnly");
/// <summary>
/// Specifies whether the user can change the text editor content.
/// Setting this property will replace the
/// <see cref="Editing.TextArea.ReadOnlySectionProvider">TextArea.ReadOnlySectionProvider</see>.
/// </summary>
public bool IsReadOnly
{
get => GetValue(IsReadOnlyProperty);
set => SetValue(IsReadOnlyProperty, value);
}
private static void OnIsReadOnlyChanged(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is TextEditor editor)
{
if ((bool)e.NewValue)
editor.TextArea.ReadOnlySectionProvider = ReadOnlySectionDocument.Instance;
else
editor.TextArea.ReadOnlySectionProvider = NoReadOnlySections.Instance;
}
}
#endregion
#region IsModified
/// <summary>
/// Dependency property for <see cref="IsModified"/>
/// </summary>
public static readonly StyledProperty<bool> IsModifiedProperty =
AvaloniaProperty.Register<TextEditor, bool>("IsModified");
/// <summary>
/// Gets/Sets the 'modified' flag.
/// </summary>
public bool IsModified
{
get => GetValue(IsModifiedProperty);
set => SetValue(IsModifiedProperty, value);
}
private static void OnIsModifiedChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
var document = editor?.Document;
if (document != null)
{
var undoStack = document.UndoStack;
if ((bool)e.NewValue)
{
if (undoStack.IsOriginalFile)
undoStack.DiscardOriginalFileMarker();
}
else
{
undoStack.MarkAsOriginalFile();
}
}
}
private void HandleIsOriginalChanged(PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsOriginalFile")
{
var document = Document;
if (document != null)
{
SetValue(IsModifiedProperty, (object)!document.UndoStack.IsOriginalFile);
}
}
}
#endregion
#region ShowLineNumbers
/// <summary>
/// ShowLineNumbers dependency property.
/// </summary>
public static readonly StyledProperty<bool> ShowLineNumbersProperty =
AvaloniaProperty.Register<TextEditor, bool>("ShowLineNumbers");
/// <summary>
/// Specifies whether line numbers are shown on the left to the text view.
/// </summary>
public bool ShowLineNumbers
{
get => GetValue(ShowLineNumbersProperty);
set => SetValue(ShowLineNumbersProperty, value);
}
private static void OnShowLineNumbersChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
if (editor == null) return;
var leftMargins = editor.TextArea.LeftMargins;
if ((bool)e.NewValue)
{
var lineNumbers = new LineNumberMargin();
var line = (Line)DottedLineMargin.Create();
leftMargins.Insert(0, lineNumbers);
leftMargins.Insert(1, line);
var lineNumbersForeground = new Binding("LineNumbersForeground") { Source = editor };
line.Bind(Shape.StrokeProperty, lineNumbersForeground);
lineNumbers.Bind(ForegroundProperty, lineNumbersForeground);
}
else
{
for (var i = 0; i < leftMargins.Count; i++)
{
if (leftMargins[i] is LineNumberMargin)
{
leftMargins.RemoveAt(i);
if (i < leftMargins.Count && DottedLineMargin.IsDottedLineMargin(leftMargins[i]))
{
leftMargins.RemoveAt(i);
}
break;
}
}
}
}
#endregion
#region LineNumbersForeground
/// <summary>
/// LineNumbersForeground dependency property.
/// </summary>
public static readonly StyledProperty<IBrush> LineNumbersForegroundProperty =
AvaloniaProperty.Register<TextEditor, IBrush>("LineNumbersForeground", Brushes.Gray);
/// <summary>
/// Gets/sets the Brush used for displaying the foreground color of line numbers.
/// </summary>
public IBrush LineNumbersForeground
{
get => GetValue(LineNumbersForegroundProperty);
set => SetValue(LineNumbersForegroundProperty, value);
}
private static void OnLineNumbersForegroundChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
var lineNumberMargin = editor?.TextArea.LeftMargins.FirstOrDefault(margin => margin is LineNumberMargin) as LineNumberMargin;
lineNumberMargin?.SetValue(ForegroundProperty, e.NewValue);
}
private static void OnFontFamilyPropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
editor?.TextArea.TextView.SetValue(FontFamilyProperty, e.NewValue);
}
private static void OnFontSizePropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
editor?.TextArea.TextView.SetValue(FontSizeProperty, e.NewValue);
}
#endregion
#region TextBoxBase-like methods
/// <summary>
/// Appends text to the end of the document.
/// </summary>
public void AppendText(string textData)
{
var document = GetDocument();
document.Insert(document.TextLength, textData);
}
/// <summary>
/// Begins a group of document changes.
/// </summary>
public void BeginChange()
{
GetDocument().BeginUpdate();
}
/// <summary>
/// Copies the current selection to the clipboard.
/// </summary>
public void Copy()
{
if (CanCopy)
{
ApplicationCommands.Copy.Execute(null, TextArea);
}
}
/// <summary>
/// Removes the current selection and copies it to the clipboard.
/// </summary>
public void Cut()
{
if (CanCut)
{
ApplicationCommands.Cut.Execute(null, TextArea);
}
}
/// <summary>
/// Begins a group of document changes and returns an object that ends the group of document
/// changes when it is disposed.
/// </summary>
public IDisposable DeclareChangeBlock()
{
return GetDocument().RunUpdate();
}
/// <summary>
/// Removes the current selection without copying it to the clipboard.
/// </summary>
public void Delete()
{
if(CanDelete)
{
ApplicationCommands.Delete.Execute(null, TextArea);
}
}
/// <summary>
/// Ends the current group of document changes.
/// </summary>
public void EndChange()
{
GetDocument().EndUpdate();
}
/// <summary>
/// Scrolls one line down.
/// </summary>
public void LineDown()
{
//if (scrollViewer != null)
// scrollViewer.LineDown();
}
/// <summary>
/// Scrolls to the left.
/// </summary>
public void LineLeft()
{
//if (scrollViewer != null)
// scrollViewer.LineLeft();
}
/// <summary>
/// Scrolls to the right.
/// </summary>
public void LineRight()
{
//if (scrollViewer != null)
// scrollViewer.LineRight();
}
/// <summary>
/// Scrolls one line up.
/// </summary>
public void LineUp()
{
//if (scrollViewer != null)
// scrollViewer.LineUp();
}
/// <summary>
/// Scrolls one page down.
/// </summary>
public void PageDown()
{
//if (scrollViewer != null)
// scrollViewer.PageDown();
}
/// <summary>
/// Scrolls one page up.
/// </summary>
public void PageUp()
{
//if (scrollViewer != null)
// scrollViewer.PageUp();
}
/// <summary>
/// Scrolls one page left.
/// </summary>
public void PageLeft()
{
//if (scrollViewer != null)
// scrollViewer.PageLeft();
}
/// <summary>
/// Scrolls one page right.
/// </summary>
public void PageRight()
{
//if (scrollViewer != null)
// scrollViewer.PageRight();
}
/// <summary>
/// Pastes the clipboard content.
/// </summary>
public void Paste()
{
if (CanPaste)
{
ApplicationCommands.Paste.Execute(null, TextArea);
}
}
/// <summary>
/// Redoes the most recent undone command.
/// </summary>
/// <returns>True is the redo operation was successful, false is the redo stack is empty.</returns>
public bool Redo()
{
if (CanRedo)
{
ApplicationCommands.Redo.Execute(null, TextArea);
return true;
}
return false;
}
/// <summary>
/// Scrolls to the end of the document.
/// </summary>
public void ScrollToEnd()
{
ApplyTemplate(); // ensure scrollViewer is created
ScrollViewer?.ScrollToEnd();
}
/// <summary>
/// Scrolls to the start of the document.
/// </summary>
public void ScrollToHome()
{
ApplyTemplate(); // ensure scrollViewer is created
ScrollViewer?.ScrollToHome();
}
/// <summary>
/// Scrolls to the specified position in the document.
/// </summary>
public void ScrollToHorizontalOffset(double offset)
{
ApplyTemplate(); // ensure scrollViewer is created
//if (scrollViewer != null)
// scrollViewer.ScrollToHorizontalOffset(offset);
}
/// <summary>
/// Scrolls to the specified position in the document.
/// </summary>
public void ScrollToVerticalOffset(double offset)
{
ApplyTemplate(); // ensure scrollViewer is created
//if (scrollViewer != null)
// scrollViewer.ScrollToVerticalOffset(offset);
}
/// <summary>
/// Selects the entire text.
/// </summary>
public void SelectAll()
{
if (CanSelectAll)
{
ApplicationCommands.SelectAll.Execute(null, TextArea);
}
}
/// <summary>
/// Undoes the most recent command.
/// </summary>
/// <returns>True is the undo operation was successful, false is the undo stack is empty.</returns>
public bool Undo()
{
if (CanUndo)
{
ApplicationCommands.Undo.Execute(null, TextArea);
return true;
}
return false;
}
/// <summary>
/// Gets if the most recent undone command can be redone.
/// </summary>
public bool CanRedo
{
get { return ApplicationCommands.Redo.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if the most recent command can be undone.
/// </summary>
public bool CanUndo
{
get { return ApplicationCommands.Undo.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be copied
/// </summary>
public bool CanCopy
{
get { return ApplicationCommands.Copy.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be cut
/// </summary>
public bool CanCut
{
get { return ApplicationCommands.Cut.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be pasted
/// </summary>
public bool CanPaste
{
get { return ApplicationCommands.Paste.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if selected text in editor can be deleted
/// </summary>
public bool CanDelete
{
get { return ApplicationCommands.Delete.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text the editor can select all
/// </summary>
public bool CanSelectAll
{
get { return ApplicationCommands.SelectAll.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text editor can activate the search panel
/// </summary>
public bool CanSearch
{
get { return searchPanel != null; }
}
/// <summary>
/// Gets the vertical size of the document.
/// </summary>
public double ExtentHeight => ScrollViewer?.Extent.Height ?? 0;
/// <summary>
/// Gets the horizontal size of the current document region.
/// </summary>
public double ExtentWidth => ScrollViewer?.Extent.Width ?? 0;
/// <summary>
/// Gets the horizontal size of the viewport.
/// </summary>
public double ViewportHeight => ScrollViewer?.Viewport.Height ?? 0;
/// <summary>
/// Gets the horizontal size of the viewport.
/// </summary>
public double ViewportWidth => ScrollViewer?.Viewport.Width ?? 0;
/// <summary>
/// Gets the vertical scroll position.
/// </summary>
public double VerticalOffset => ScrollViewer?.Offset.Y ?? 0;
/// <summary>
/// Gets the horizontal scroll position.
/// </summary>
public double HorizontalOffset => ScrollViewer?.Offset.X ?? 0;
#endregion
#region TextBox methods
/// <summary>
/// Gets/Sets the selected text.
/// </summary>
public string SelectedText
{
get
{
// We'll get the text from the whole surrounding segment.
// This is done to ensure that SelectedText.Length == SelectionLength.
if (textArea.Document != null && !textArea.Selection.IsEmpty)
return textArea.Document.GetText(textArea.Selection.SurroundingSegment);
return string.Empty;
}
set
{
if (value == null)
throw new ArgumentNullException(nameof(value));
var textArea = TextArea;
if (textArea.Document != null)
{
var offset = SelectionStart;
var length = SelectionLength;
textArea.Document.Replace(offset, length, value);
// keep inserted text selected
textArea.Selection = Selection.Create(textArea, offset, offset + value.Length);
}
}
}
/// <summary>
/// Gets/sets the caret position.
/// </summary>
public int CaretOffset
{
get
{
return textArea.Caret.Offset;
}
set
{
textArea.Caret.Offset = value;
}
}
/// <summary>
/// Gets/sets the start position of the selection.
/// </summary>
public int SelectionStart
{
get
{
if (textArea.Selection.IsEmpty)
return textArea.Caret.Offset;
else
return textArea.Selection.SurroundingSegment.Offset;
}
set => Select(value, SelectionLength);
}
/// <summary>
/// Gets/sets the length of the selection.
/// </summary>
public int SelectionLength
{
get
{
if (!textArea.Selection.IsEmpty)
return textArea.Selection.SurroundingSegment.Length;
else
return 0;
}
set => Select(SelectionStart, value);
}
/// <summary>
/// Selects the specified text section.
/// </summary>
public void Select(int start, int length)
{
var documentLength = Document?.TextLength ?? 0;
if (start < 0 || start > documentLength)
throw new ArgumentOutOfRangeException(nameof(start), start, "Value must be between 0 and " + documentLength);
if (length < 0 || start + length > documentLength)
throw new ArgumentOutOfRangeException(nameof(length), length, "Value must be between 0 and " + (documentLength - start));
TextArea.Selection = Selection.Create(TextArea, start, start + length);
TextArea.Caret.Offset = start + length;
}
/// <summary>
/// Gets the number of lines in the document.
/// </summary>
public int LineCount
{
get
{
var document = Document;
if (document != null)
return document.LineCount;
return 1;
}
}
/// <summary>
/// Clears the text.
/// </summary>
public void Clear()
{
Text = string.Empty;
}
#endregion
#region Loading from stream
/// <summary>
/// Loads the text from the stream, auto-detecting the encoding.
/// </summary>
/// <remarks>
/// This method sets <see cref="IsModified"/> to false.
/// </remarks>
public void Load(Stream stream)
{
using (var reader = FileReader.OpenStream(stream, Encoding ?? Encoding.UTF8))
{
Text = reader.ReadToEnd();
SetValue(EncodingProperty, (object)reader.CurrentEncoding);
}
SetValue(IsModifiedProperty, (object)false);
}
/// <summary>
/// Loads the text from the stream, auto-detecting the encoding.
/// </summary>
public void Load(string fileName)
{
if (fileName == null)
throw new ArgumentNullException(nameof(fileName));
// TODO:load
//using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
//{
// Load(fs);
//}
}
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
public static readonly AvaloniaProperty HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
get => (ScrollBarVisibility)GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
public static readonly AvaloniaProperty VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
get => (ScrollBarVisibility)GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
if (stream == null)
throw new ArgumentNullException(nameof(stream));
var encoding = Encoding;
var document = Document;
var writer = encoding != null ? new StreamWriter(stream, encoding) : new StreamWriter(stream);
document?.WriteTextTo(writer);
writer.Flush();
// do not close the stream
SetValue(IsModifiedProperty, (object)false);
}
/// <summary>
/// Saves the text to the file.
/// </summary>
public void Save(string fileName)
{
if (fileName == null)
throw new ArgumentNullException(nameof(fileName));
// TODO: save
//using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
//{
// Save(fs);
//}
}
#endregion
#region PointerHover events
/// <summary>
/// The PreviewPointerHover event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PreviewPointerHoverEvent =
TextView.PreviewPointerHoverEvent;
/// <summary>
/// the pointerHover event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PointerHoverEvent =
TextView.PointerHoverEvent;
/// <summary>
/// The PreviewPointerHoverStopped event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PreviewPointerHoverStoppedEvent =
TextView.PreviewPointerHoverStoppedEvent;
/// <summary>
/// the pointerHoverStopped event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PointerHoverStoppedEvent =
TextView.PointerHoverStoppedEvent;
/// <summary>
/// Occurs when the pointer has hovered over a fixed location for some time.
/// </summary>
public event EventHandler<PointerEventArgs> PreviewPointerHover
{
add => AddHandler(PreviewPointerHoverEvent, value);
remove => RemoveHandler(PreviewPointerHoverEvent, value);
}
/// <summary>
/// Occurs when the pointer has hovered over a fixed location for some time.
/// </summary>
public event EventHandler<PointerEventArgs> PointerHover
{
add => AddHandler(PointerHoverEvent, value);
remove => RemoveHandler(PointerHoverEvent, value);
}
/// <summary>
/// Occurs when the pointer had previously hovered but now started moving again.
/// </summary>
public event EventHandler<PointerEventArgs> PreviewPointerHoverStopped
{
add => AddHandler(PreviewPointerHoverStoppedEvent, value);
remove => RemoveHandler(PreviewPointerHoverStoppedEvent, value);
}
/// <summary>
/// Occurs when the pointer had previously hovered but now started moving again.
/// </summary>
public event EventHandler<PointerEventArgs> PointerHoverStopped
{
add => AddHandler(PointerHoverStoppedEvent, value);
remove => RemoveHandler(PointerHoverStoppedEvent, value);
}
#endregion
#region ScrollBarVisibility
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
public static readonly AttachedProperty<ScrollBarVisibility> HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
get => GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
private ScrollBarVisibility _horizontalScrollBarVisibilityBck = ScrollBarVisibility.Auto;
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
public static readonly AttachedProperty<ScrollBarVisibility> VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
get => GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
object IServiceProvider.GetService(Type serviceType)
{
return TextArea.GetService(serviceType);
}
/// <summary>
/// Gets the text view position from a point inside the editor.
/// </summary>
/// <param name="point">The position, relative to top left
/// corner of TextEditor control</param>
/// <returns>The text view position, or null if the point is outside the document.</returns>
public TextViewPosition? GetPositionFromPoint(Point point)
{
if (Document == null)
return null;
var textView = TextArea.TextView;
Point tpoint = (Point)this.TranslatePoint(point + new Point(textView.ScrollOffset.X, Math.Floor(textView.ScrollOffset.Y)), textView);
return textView.GetPosition(tpoint);
}
/// <summary>
/// Scrolls to the specified line.
/// This method requires that the TextEditor was already assigned a size (layout engine must have run prior).
/// </summary>
public void ScrollToLine(int line)
{
ScrollTo(line, -1);
}
/// <summary>
/// Scrolls to the specified line/column.
/// This method requires that the TextEditor was already assigned a size (layout engine must have run prior).
/// </summary>
public void ScrollTo(int line, int column)
{
const double MinimumScrollFraction = 0.3;
ScrollTo(line, column, VisualYPosition.LineMiddle,
null != ScrollViewer ? ScrollViewer.Viewport.Height / 2 : 0.0, MinimumScrollFraction);
}
/// <summary>
/// Scrolls to the specified line/column.
/// This method requires that the TextEditor was already assigned a size (WPF layout must have run prior).
/// </summary>
/// <param name="line">Line to scroll to.</param>
/// <param name="column">Column to scroll to (important if wrapping is 'on', and for the horizontal scroll position).</param>
/// <param name="yPositionMode">The mode how to reference the Y position of the line.</param>
/// <param name="referencedVerticalViewPortOffset">Offset from the top of the viewport to where the referenced line/column should be positioned.</param>
/// <param name="minimumScrollFraction">The minimum vertical and/or horizontal scroll offset, expressed as fraction of the height or width of the viewport window, respectively.</param>
public void ScrollTo(int line, int column, VisualYPosition yPositionMode,
double referencedVerticalViewPortOffset, double minimumScrollFraction)
{
TextView textView = textArea.TextView;
TextDocument document = textView.Document;
if (ScrollViewer != null && document != null)
{
if (line < 1)
line = 1;
if (line > document.LineCount)
line = document.LineCount;
ILogicalScrollable scrollInfo = textView;
if (!scrollInfo.CanHorizontallyScroll)
{
// Word wrap is enabled. Ensure that we have up-to-date info about line height so that we scroll
// to the correct position.
// This avoids that the user has to repeat the ScrollTo() call several times when there are very long lines.
VisualLine vl = textView.GetOrConstructVisualLine(document.GetLineByNumber(line));
double remainingHeight = referencedVerticalViewPortOffset;
while (remainingHeight > 0)
{
DocumentLine prevLine = vl.FirstDocumentLine.PreviousLine;
if (prevLine == null)
break;
vl = textView.GetOrConstructVisualLine(prevLine);
remainingHeight -= vl.Height;
}
}
Point p = textArea.TextView.GetVisualPosition(
new TextViewPosition(line, Math.Max(1, column)),
yPositionMode);
double targetX = ScrollViewer.Offset.X;
double targetY = ScrollViewer.Offset.Y;
double verticalPos = p.Y - referencedVerticalViewPortOffset;
if (Math.Abs(verticalPos - ScrollViewer.Offset.Y) >
minimumScrollFraction * ScrollViewer.Viewport.Height)
{
targetY = Math.Max(0, verticalPos);
}
if (column > 0)
{
if (p.X > ScrollViewer.Viewport.Width - Caret.MinimumDistanceToViewBorder * 2)
{
double horizontalPos = Math.Max(0, p.X - ScrollViewer.Viewport.Width / 2);
if (Math.Abs(horizontalPos - ScrollViewer.Offset.X) >
minimumScrollFraction * ScrollViewer.Viewport.Width)
{
targetX = 0;
}
}
else
{
targetX = 0;
}
}
if (targetX != ScrollViewer.Offset.X || targetY != ScrollViewer.Offset.Y)
ScrollViewer.Offset = new Vector(targetX, targetY);
}
}
}
}
<MSG> Merge pull request #73 from jeffreye/fix-scroll
Fix scroll
<DFF> @@ -47,6 +47,8 @@ namespace AvaloniaEdit
static TextEditor()
{
FocusableProperty.OverrideDefaultValue<TextEditor>(true);
+ HorizontalScrollBarVisibilityProperty.OverrideDefaultValue<TextEditor>(ScrollBarVisibility.Auto);
+ VerticalScrollBarVisibilityProperty.OverrideDefaultValue<TextEditor>(ScrollBarVisibility.Auto);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
@@ -1049,28 +1051,28 @@ namespace AvaloniaEdit
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
- public static readonly AvaloniaProperty HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
+ public static readonly AttachedProperty<ScrollBarVisibility> HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
- get => (ScrollBarVisibility)GetValue(HorizontalScrollBarVisibilityProperty);
+ get => GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
- public static readonly AvaloniaProperty VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
+ public static readonly AttachedProperty<ScrollBarVisibility> VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
- get => (ScrollBarVisibility)GetValue(VerticalScrollBarVisibilityProperty);
+ get => GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
| 6 | Merge pull request #73 from jeffreye/fix-scroll | 4 | .cs | cs | mit | AvaloniaUI/AvaloniaEdit |
10066916 | <NME> TextEditor.cs
<BEF> // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using Avalonia;
using AvaloniaEdit.Document;
using AvaloniaEdit.Editing;
using AvaloniaEdit.Highlighting;
using AvaloniaEdit.Rendering;
using AvaloniaEdit.Utils;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Shapes;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.LogicalTree;
using Avalonia.Media;
using Avalonia.Data;
using AvaloniaEdit.Search;
namespace AvaloniaEdit
{
/// <summary>
/// The text editor control.
/// Contains a scrollable TextArea.
/// </summary>
public class TextEditor : TemplatedControl, ITextEditorComponent
static TextEditor()
{
FocusableProperty.OverrideDefaultValue<TextEditor>(true);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
SyntaxHighlightingProperty.Changed.Subscribe(OnSyntaxHighlightingChanged);
IsReadOnlyProperty.Changed.Subscribe(OnIsReadOnlyChanged);
IsModifiedProperty.Changed.Subscribe(OnIsModifiedChanged);
ShowLineNumbersProperty.Changed.Subscribe(OnShowLineNumbersChanged);
LineNumbersForegroundProperty.Changed.Subscribe(OnLineNumbersForegroundChanged);
FontFamilyProperty.Changed.Subscribe(OnFontFamilyPropertyChanged);
FontSizeProperty.Changed.Subscribe(OnFontSizePropertyChanged);
}
/// <summary>
/// Creates a new TextEditor instance.
/// </summary>
public TextEditor() : this(new TextArea())
{
}
/// <summary>
/// Creates a new TextEditor instance.
/// </summary>
protected TextEditor(TextArea textArea) : this(textArea, new TextDocument())
{
}
protected TextEditor(TextArea textArea, TextDocument document)
{
this.textArea = textArea ?? throw new ArgumentNullException(nameof(textArea));
textArea.TextView.Services.AddService(this);
SetValue(OptionsProperty, textArea.Options);
SetValue(DocumentProperty, document);
textArea[!BackgroundProperty] = this[!BackgroundProperty];
}
#endregion
protected override void OnGotFocus(GotFocusEventArgs e)
{
base.OnGotFocus(e);
TextArea.Focus();
e.Handled = true;
}
#region Document property
/// <summary>
/// Document property.
/// </summary>
public static readonly StyledProperty<TextDocument> DocumentProperty
= TextView.DocumentProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the document displayed by the text editor.
/// This is a dependency property.
/// </summary>
public TextDocument Document
{
get => GetValue(DocumentProperty);
set => SetValue(DocumentProperty, value);
}
/// <summary>
/// Occurs when the document property has changed.
/// </summary>
public event EventHandler DocumentChanged;
/// <summary>
/// Raises the <see cref="DocumentChanged"/> event.
/// </summary>
protected virtual void OnDocumentChanged(EventArgs e)
{
DocumentChanged?.Invoke(this, e);
}
private static void OnDocumentChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnDocumentChanged((TextDocument)e.OldValue, (TextDocument)e.NewValue);
}
private void OnDocumentChanged(TextDocument oldValue, TextDocument newValue)
{
if (oldValue != null)
{
TextDocumentWeakEventManager.TextChanged.RemoveHandler(oldValue, OnTextChanged);
PropertyChangedWeakEventManager.RemoveHandler(oldValue.UndoStack, OnUndoStackPropertyChangedHandler);
}
TextArea.Document = newValue;
if (newValue != null)
{
TextDocumentWeakEventManager.TextChanged.AddHandler(newValue, OnTextChanged);
PropertyChangedWeakEventManager.AddHandler(newValue.UndoStack, OnUndoStackPropertyChangedHandler);
}
OnDocumentChanged(EventArgs.Empty);
OnTextChanged(EventArgs.Empty);
}
#endregion
#region Options property
/// <summary>
/// Options property.
/// </summary>
public static readonly StyledProperty<TextEditorOptions> OptionsProperty
= TextView.OptionsProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the options currently used by the text editor.
/// </summary>
public TextEditorOptions Options
{
get => GetValue(OptionsProperty);
set => SetValue(OptionsProperty, value);
}
/// <summary>
/// Occurs when a text editor option has changed.
/// </summary>
public event PropertyChangedEventHandler OptionChanged;
/// <summary>
/// Raises the <see cref="OptionChanged"/> event.
/// </summary>
protected virtual void OnOptionChanged(PropertyChangedEventArgs e)
{
OptionChanged?.Invoke(this, e);
}
private static void OnOptionsChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnOptionsChanged((TextEditorOptions)e.OldValue, (TextEditorOptions)e.NewValue);
}
private void OnOptionsChanged(TextEditorOptions oldValue, TextEditorOptions newValue)
{
if (oldValue != null)
{
PropertyChangedWeakEventManager.RemoveHandler(oldValue, OnPropertyChangedHandler);
}
TextArea.Options = newValue;
if (newValue != null)
{
PropertyChangedWeakEventManager.AddHandler(newValue, OnPropertyChangedHandler);
}
OnOptionChanged(new PropertyChangedEventArgs(null));
}
private void OnPropertyChangedHandler(object sender, PropertyChangedEventArgs e)
{
OnOptionChanged(e);
}
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
base.OnPropertyChanged(change);
if (change.Property == WordWrapProperty)
{
if (WordWrap)
{
_horizontalScrollBarVisibilityBck = HorizontalScrollBarVisibility;
HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
}
else
{
HorizontalScrollBarVisibility = _horizontalScrollBarVisibilityBck;
}
}
}
private void OnUndoStackPropertyChangedHandler(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsOriginalFile")
{
HandleIsOriginalChanged(e);
}
}
private void OnTextChanged(object sender, EventArgs e)
{
OnTextChanged(e);
}
#endregion
#region Text property
/// <summary>
/// Gets/Sets the text of the current document.
/// </summary>
public string Text
{
get
{
var document = Document;
return document != null ? document.Text : string.Empty;
}
set
{
var document = GetDocument();
document.Text = value ?? string.Empty;
// after replacing the full text, the caret is positioned at the end of the document
// - reset it to the beginning.
CaretOffset = 0;
document.UndoStack.ClearAll();
}
}
private TextDocument GetDocument()
{
var document = Document;
if (document == null)
throw ThrowUtil.NoDocumentAssigned();
return document;
}
/// <summary>
/// Occurs when the Text property changes.
/// </summary>
public event EventHandler TextChanged;
/// <summary>
/// Raises the <see cref="TextChanged"/> event.
/// </summary>
protected virtual void OnTextChanged(EventArgs e)
{
TextChanged?.Invoke(this, e);
}
#endregion
#region TextArea / ScrollViewer properties
private readonly TextArea textArea;
private SearchPanel searchPanel;
private bool wasSearchPanelOpened;
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
ScrollViewer = (ScrollViewer)e.NameScope.Find("PART_ScrollViewer");
ScrollViewer.Content = TextArea;
searchPanel = SearchPanel.Install(this);
}
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnAttachedToLogicalTree(e);
if (searchPanel != null && wasSearchPanelOpened)
{
searchPanel.Open();
}
}
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnDetachedFromLogicalTree(e);
if (searchPanel != null)
{
wasSearchPanelOpened = searchPanel.IsOpened;
if (searchPanel.IsOpened)
searchPanel.Close();
}
}
/// <summary>
/// Gets the text area.
/// </summary>
public TextArea TextArea => textArea;
/// <summary>
/// Gets the search panel.
/// </summary>
public SearchPanel SearchPanel => searchPanel;
/// <summary>
/// Gets the scroll viewer used by the text editor.
/// This property can return null if the template has not been applied / does not contain a scroll viewer.
/// </summary>
internal ScrollViewer ScrollViewer { get; private set; }
#endregion
#region Syntax highlighting
/// <summary>
/// The <see cref="SyntaxHighlighting"/> property.
/// </summary>
public static readonly StyledProperty<IHighlightingDefinition> SyntaxHighlightingProperty =
AvaloniaProperty.Register<TextEditor, IHighlightingDefinition>("SyntaxHighlighting");
/// <summary>
/// Gets/sets the syntax highlighting definition used to colorize the text.
/// </summary>
public IHighlightingDefinition SyntaxHighlighting
{
get => GetValue(SyntaxHighlightingProperty);
set => SetValue(SyntaxHighlightingProperty, value);
}
private IVisualLineTransformer _colorizer;
private static void OnSyntaxHighlightingChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnSyntaxHighlightingChanged(e.NewValue as IHighlightingDefinition);
}
private void OnSyntaxHighlightingChanged(IHighlightingDefinition newValue)
{
if (_colorizer != null)
{
textArea.TextView.LineTransformers.Remove(_colorizer);
_colorizer = null;
}
if (newValue != null)
{
_colorizer = CreateColorizer(newValue);
if (_colorizer != null)
{
textArea.TextView.LineTransformers.Insert(0, _colorizer);
}
}
}
/// <summary>
/// Creates the highlighting colorizer for the specified highlighting definition.
/// Allows derived classes to provide custom colorizer implementations for special highlighting definitions.
/// </summary>
/// <returns></returns>
protected virtual IVisualLineTransformer CreateColorizer(IHighlightingDefinition highlightingDefinition)
{
if (highlightingDefinition == null)
throw new ArgumentNullException(nameof(highlightingDefinition));
return new HighlightingColorizer(highlightingDefinition);
}
#endregion
#region WordWrap
/// <summary>
/// Word wrap dependency property.
/// </summary>
public static readonly StyledProperty<bool> WordWrapProperty =
AvaloniaProperty.Register<TextEditor, bool>("WordWrap");
/// <summary>
/// Specifies whether the text editor uses word wrapping.
/// </summary>
/// <remarks>
/// Setting WordWrap=true has the same effect as setting HorizontalScrollBarVisibility=Disabled and will override the
/// HorizontalScrollBarVisibility setting.
/// </remarks>
public bool WordWrap
{
get => GetValue(WordWrapProperty);
set => SetValue(WordWrapProperty, value);
}
#endregion
#region IsReadOnly
/// <summary>
/// IsReadOnly dependency property.
/// </summary>
public static readonly StyledProperty<bool> IsReadOnlyProperty =
AvaloniaProperty.Register<TextEditor, bool>("IsReadOnly");
/// <summary>
/// Specifies whether the user can change the text editor content.
/// Setting this property will replace the
/// <see cref="Editing.TextArea.ReadOnlySectionProvider">TextArea.ReadOnlySectionProvider</see>.
/// </summary>
public bool IsReadOnly
{
get => GetValue(IsReadOnlyProperty);
set => SetValue(IsReadOnlyProperty, value);
}
private static void OnIsReadOnlyChanged(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is TextEditor editor)
{
if ((bool)e.NewValue)
editor.TextArea.ReadOnlySectionProvider = ReadOnlySectionDocument.Instance;
else
editor.TextArea.ReadOnlySectionProvider = NoReadOnlySections.Instance;
}
}
#endregion
#region IsModified
/// <summary>
/// Dependency property for <see cref="IsModified"/>
/// </summary>
public static readonly StyledProperty<bool> IsModifiedProperty =
AvaloniaProperty.Register<TextEditor, bool>("IsModified");
/// <summary>
/// Gets/Sets the 'modified' flag.
/// </summary>
public bool IsModified
{
get => GetValue(IsModifiedProperty);
set => SetValue(IsModifiedProperty, value);
}
private static void OnIsModifiedChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
var document = editor?.Document;
if (document != null)
{
var undoStack = document.UndoStack;
if ((bool)e.NewValue)
{
if (undoStack.IsOriginalFile)
undoStack.DiscardOriginalFileMarker();
}
else
{
undoStack.MarkAsOriginalFile();
}
}
}
private void HandleIsOriginalChanged(PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsOriginalFile")
{
var document = Document;
if (document != null)
{
SetValue(IsModifiedProperty, (object)!document.UndoStack.IsOriginalFile);
}
}
}
#endregion
#region ShowLineNumbers
/// <summary>
/// ShowLineNumbers dependency property.
/// </summary>
public static readonly StyledProperty<bool> ShowLineNumbersProperty =
AvaloniaProperty.Register<TextEditor, bool>("ShowLineNumbers");
/// <summary>
/// Specifies whether line numbers are shown on the left to the text view.
/// </summary>
public bool ShowLineNumbers
{
get => GetValue(ShowLineNumbersProperty);
set => SetValue(ShowLineNumbersProperty, value);
}
private static void OnShowLineNumbersChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
if (editor == null) return;
var leftMargins = editor.TextArea.LeftMargins;
if ((bool)e.NewValue)
{
var lineNumbers = new LineNumberMargin();
var line = (Line)DottedLineMargin.Create();
leftMargins.Insert(0, lineNumbers);
leftMargins.Insert(1, line);
var lineNumbersForeground = new Binding("LineNumbersForeground") { Source = editor };
line.Bind(Shape.StrokeProperty, lineNumbersForeground);
lineNumbers.Bind(ForegroundProperty, lineNumbersForeground);
}
else
{
for (var i = 0; i < leftMargins.Count; i++)
{
if (leftMargins[i] is LineNumberMargin)
{
leftMargins.RemoveAt(i);
if (i < leftMargins.Count && DottedLineMargin.IsDottedLineMargin(leftMargins[i]))
{
leftMargins.RemoveAt(i);
}
break;
}
}
}
}
#endregion
#region LineNumbersForeground
/// <summary>
/// LineNumbersForeground dependency property.
/// </summary>
public static readonly StyledProperty<IBrush> LineNumbersForegroundProperty =
AvaloniaProperty.Register<TextEditor, IBrush>("LineNumbersForeground", Brushes.Gray);
/// <summary>
/// Gets/sets the Brush used for displaying the foreground color of line numbers.
/// </summary>
public IBrush LineNumbersForeground
{
get => GetValue(LineNumbersForegroundProperty);
set => SetValue(LineNumbersForegroundProperty, value);
}
private static void OnLineNumbersForegroundChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
var lineNumberMargin = editor?.TextArea.LeftMargins.FirstOrDefault(margin => margin is LineNumberMargin) as LineNumberMargin;
lineNumberMargin?.SetValue(ForegroundProperty, e.NewValue);
}
private static void OnFontFamilyPropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
editor?.TextArea.TextView.SetValue(FontFamilyProperty, e.NewValue);
}
private static void OnFontSizePropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
editor?.TextArea.TextView.SetValue(FontSizeProperty, e.NewValue);
}
#endregion
#region TextBoxBase-like methods
/// <summary>
/// Appends text to the end of the document.
/// </summary>
public void AppendText(string textData)
{
var document = GetDocument();
document.Insert(document.TextLength, textData);
}
/// <summary>
/// Begins a group of document changes.
/// </summary>
public void BeginChange()
{
GetDocument().BeginUpdate();
}
/// <summary>
/// Copies the current selection to the clipboard.
/// </summary>
public void Copy()
{
if (CanCopy)
{
ApplicationCommands.Copy.Execute(null, TextArea);
}
}
/// <summary>
/// Removes the current selection and copies it to the clipboard.
/// </summary>
public void Cut()
{
if (CanCut)
{
ApplicationCommands.Cut.Execute(null, TextArea);
}
}
/// <summary>
/// Begins a group of document changes and returns an object that ends the group of document
/// changes when it is disposed.
/// </summary>
public IDisposable DeclareChangeBlock()
{
return GetDocument().RunUpdate();
}
/// <summary>
/// Removes the current selection without copying it to the clipboard.
/// </summary>
public void Delete()
{
if(CanDelete)
{
ApplicationCommands.Delete.Execute(null, TextArea);
}
}
/// <summary>
/// Ends the current group of document changes.
/// </summary>
public void EndChange()
{
GetDocument().EndUpdate();
}
/// <summary>
/// Scrolls one line down.
/// </summary>
public void LineDown()
{
//if (scrollViewer != null)
// scrollViewer.LineDown();
}
/// <summary>
/// Scrolls to the left.
/// </summary>
public void LineLeft()
{
//if (scrollViewer != null)
// scrollViewer.LineLeft();
}
/// <summary>
/// Scrolls to the right.
/// </summary>
public void LineRight()
{
//if (scrollViewer != null)
// scrollViewer.LineRight();
}
/// <summary>
/// Scrolls one line up.
/// </summary>
public void LineUp()
{
//if (scrollViewer != null)
// scrollViewer.LineUp();
}
/// <summary>
/// Scrolls one page down.
/// </summary>
public void PageDown()
{
//if (scrollViewer != null)
// scrollViewer.PageDown();
}
/// <summary>
/// Scrolls one page up.
/// </summary>
public void PageUp()
{
//if (scrollViewer != null)
// scrollViewer.PageUp();
}
/// <summary>
/// Scrolls one page left.
/// </summary>
public void PageLeft()
{
//if (scrollViewer != null)
// scrollViewer.PageLeft();
}
/// <summary>
/// Scrolls one page right.
/// </summary>
public void PageRight()
{
//if (scrollViewer != null)
// scrollViewer.PageRight();
}
/// <summary>
/// Pastes the clipboard content.
/// </summary>
public void Paste()
{
if (CanPaste)
{
ApplicationCommands.Paste.Execute(null, TextArea);
}
}
/// <summary>
/// Redoes the most recent undone command.
/// </summary>
/// <returns>True is the redo operation was successful, false is the redo stack is empty.</returns>
public bool Redo()
{
if (CanRedo)
{
ApplicationCommands.Redo.Execute(null, TextArea);
return true;
}
return false;
}
/// <summary>
/// Scrolls to the end of the document.
/// </summary>
public void ScrollToEnd()
{
ApplyTemplate(); // ensure scrollViewer is created
ScrollViewer?.ScrollToEnd();
}
/// <summary>
/// Scrolls to the start of the document.
/// </summary>
public void ScrollToHome()
{
ApplyTemplate(); // ensure scrollViewer is created
ScrollViewer?.ScrollToHome();
}
/// <summary>
/// Scrolls to the specified position in the document.
/// </summary>
public void ScrollToHorizontalOffset(double offset)
{
ApplyTemplate(); // ensure scrollViewer is created
//if (scrollViewer != null)
// scrollViewer.ScrollToHorizontalOffset(offset);
}
/// <summary>
/// Scrolls to the specified position in the document.
/// </summary>
public void ScrollToVerticalOffset(double offset)
{
ApplyTemplate(); // ensure scrollViewer is created
//if (scrollViewer != null)
// scrollViewer.ScrollToVerticalOffset(offset);
}
/// <summary>
/// Selects the entire text.
/// </summary>
public void SelectAll()
{
if (CanSelectAll)
{
ApplicationCommands.SelectAll.Execute(null, TextArea);
}
}
/// <summary>
/// Undoes the most recent command.
/// </summary>
/// <returns>True is the undo operation was successful, false is the undo stack is empty.</returns>
public bool Undo()
{
if (CanUndo)
{
ApplicationCommands.Undo.Execute(null, TextArea);
return true;
}
return false;
}
/// <summary>
/// Gets if the most recent undone command can be redone.
/// </summary>
public bool CanRedo
{
get { return ApplicationCommands.Redo.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if the most recent command can be undone.
/// </summary>
public bool CanUndo
{
get { return ApplicationCommands.Undo.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be copied
/// </summary>
public bool CanCopy
{
get { return ApplicationCommands.Copy.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be cut
/// </summary>
public bool CanCut
{
get { return ApplicationCommands.Cut.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be pasted
/// </summary>
public bool CanPaste
{
get { return ApplicationCommands.Paste.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if selected text in editor can be deleted
/// </summary>
public bool CanDelete
{
get { return ApplicationCommands.Delete.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text the editor can select all
/// </summary>
public bool CanSelectAll
{
get { return ApplicationCommands.SelectAll.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text editor can activate the search panel
/// </summary>
public bool CanSearch
{
get { return searchPanel != null; }
}
/// <summary>
/// Gets the vertical size of the document.
/// </summary>
public double ExtentHeight => ScrollViewer?.Extent.Height ?? 0;
/// <summary>
/// Gets the horizontal size of the current document region.
/// </summary>
public double ExtentWidth => ScrollViewer?.Extent.Width ?? 0;
/// <summary>
/// Gets the horizontal size of the viewport.
/// </summary>
public double ViewportHeight => ScrollViewer?.Viewport.Height ?? 0;
/// <summary>
/// Gets the horizontal size of the viewport.
/// </summary>
public double ViewportWidth => ScrollViewer?.Viewport.Width ?? 0;
/// <summary>
/// Gets the vertical scroll position.
/// </summary>
public double VerticalOffset => ScrollViewer?.Offset.Y ?? 0;
/// <summary>
/// Gets the horizontal scroll position.
/// </summary>
public double HorizontalOffset => ScrollViewer?.Offset.X ?? 0;
#endregion
#region TextBox methods
/// <summary>
/// Gets/Sets the selected text.
/// </summary>
public string SelectedText
{
get
{
// We'll get the text from the whole surrounding segment.
// This is done to ensure that SelectedText.Length == SelectionLength.
if (textArea.Document != null && !textArea.Selection.IsEmpty)
return textArea.Document.GetText(textArea.Selection.SurroundingSegment);
return string.Empty;
}
set
{
if (value == null)
throw new ArgumentNullException(nameof(value));
var textArea = TextArea;
if (textArea.Document != null)
{
var offset = SelectionStart;
var length = SelectionLength;
textArea.Document.Replace(offset, length, value);
// keep inserted text selected
textArea.Selection = Selection.Create(textArea, offset, offset + value.Length);
}
}
}
/// <summary>
/// Gets/sets the caret position.
/// </summary>
public int CaretOffset
{
get
{
return textArea.Caret.Offset;
}
set
{
textArea.Caret.Offset = value;
}
}
/// <summary>
/// Gets/sets the start position of the selection.
/// </summary>
public int SelectionStart
{
get
{
if (textArea.Selection.IsEmpty)
return textArea.Caret.Offset;
else
return textArea.Selection.SurroundingSegment.Offset;
}
set => Select(value, SelectionLength);
}
/// <summary>
/// Gets/sets the length of the selection.
/// </summary>
public int SelectionLength
{
get
{
if (!textArea.Selection.IsEmpty)
return textArea.Selection.SurroundingSegment.Length;
else
return 0;
}
set => Select(SelectionStart, value);
}
/// <summary>
/// Selects the specified text section.
/// </summary>
public void Select(int start, int length)
{
var documentLength = Document?.TextLength ?? 0;
if (start < 0 || start > documentLength)
throw new ArgumentOutOfRangeException(nameof(start), start, "Value must be between 0 and " + documentLength);
if (length < 0 || start + length > documentLength)
throw new ArgumentOutOfRangeException(nameof(length), length, "Value must be between 0 and " + (documentLength - start));
TextArea.Selection = Selection.Create(TextArea, start, start + length);
TextArea.Caret.Offset = start + length;
}
/// <summary>
/// Gets the number of lines in the document.
/// </summary>
public int LineCount
{
get
{
var document = Document;
if (document != null)
return document.LineCount;
return 1;
}
}
/// <summary>
/// Clears the text.
/// </summary>
public void Clear()
{
Text = string.Empty;
}
#endregion
#region Loading from stream
/// <summary>
/// Loads the text from the stream, auto-detecting the encoding.
/// </summary>
/// <remarks>
/// This method sets <see cref="IsModified"/> to false.
/// </remarks>
public void Load(Stream stream)
{
using (var reader = FileReader.OpenStream(stream, Encoding ?? Encoding.UTF8))
{
Text = reader.ReadToEnd();
SetValue(EncodingProperty, (object)reader.CurrentEncoding);
}
SetValue(IsModifiedProperty, (object)false);
}
/// <summary>
/// Loads the text from the stream, auto-detecting the encoding.
/// </summary>
public void Load(string fileName)
{
if (fileName == null)
throw new ArgumentNullException(nameof(fileName));
// TODO:load
//using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
//{
// Load(fs);
//}
}
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
public static readonly AvaloniaProperty HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
get => (ScrollBarVisibility)GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
public static readonly AvaloniaProperty VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
get => (ScrollBarVisibility)GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
if (stream == null)
throw new ArgumentNullException(nameof(stream));
var encoding = Encoding;
var document = Document;
var writer = encoding != null ? new StreamWriter(stream, encoding) : new StreamWriter(stream);
document?.WriteTextTo(writer);
writer.Flush();
// do not close the stream
SetValue(IsModifiedProperty, (object)false);
}
/// <summary>
/// Saves the text to the file.
/// </summary>
public void Save(string fileName)
{
if (fileName == null)
throw new ArgumentNullException(nameof(fileName));
// TODO: save
//using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
//{
// Save(fs);
//}
}
#endregion
#region PointerHover events
/// <summary>
/// The PreviewPointerHover event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PreviewPointerHoverEvent =
TextView.PreviewPointerHoverEvent;
/// <summary>
/// the pointerHover event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PointerHoverEvent =
TextView.PointerHoverEvent;
/// <summary>
/// The PreviewPointerHoverStopped event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PreviewPointerHoverStoppedEvent =
TextView.PreviewPointerHoverStoppedEvent;
/// <summary>
/// the pointerHoverStopped event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PointerHoverStoppedEvent =
TextView.PointerHoverStoppedEvent;
/// <summary>
/// Occurs when the pointer has hovered over a fixed location for some time.
/// </summary>
public event EventHandler<PointerEventArgs> PreviewPointerHover
{
add => AddHandler(PreviewPointerHoverEvent, value);
remove => RemoveHandler(PreviewPointerHoverEvent, value);
}
/// <summary>
/// Occurs when the pointer has hovered over a fixed location for some time.
/// </summary>
public event EventHandler<PointerEventArgs> PointerHover
{
add => AddHandler(PointerHoverEvent, value);
remove => RemoveHandler(PointerHoverEvent, value);
}
/// <summary>
/// Occurs when the pointer had previously hovered but now started moving again.
/// </summary>
public event EventHandler<PointerEventArgs> PreviewPointerHoverStopped
{
add => AddHandler(PreviewPointerHoverStoppedEvent, value);
remove => RemoveHandler(PreviewPointerHoverStoppedEvent, value);
}
/// <summary>
/// Occurs when the pointer had previously hovered but now started moving again.
/// </summary>
public event EventHandler<PointerEventArgs> PointerHoverStopped
{
add => AddHandler(PointerHoverStoppedEvent, value);
remove => RemoveHandler(PointerHoverStoppedEvent, value);
}
#endregion
#region ScrollBarVisibility
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
public static readonly AttachedProperty<ScrollBarVisibility> HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
get => GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
private ScrollBarVisibility _horizontalScrollBarVisibilityBck = ScrollBarVisibility.Auto;
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
public static readonly AttachedProperty<ScrollBarVisibility> VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
get => GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
object IServiceProvider.GetService(Type serviceType)
{
return TextArea.GetService(serviceType);
}
/// <summary>
/// Gets the text view position from a point inside the editor.
/// </summary>
/// <param name="point">The position, relative to top left
/// corner of TextEditor control</param>
/// <returns>The text view position, or null if the point is outside the document.</returns>
public TextViewPosition? GetPositionFromPoint(Point point)
{
if (Document == null)
return null;
var textView = TextArea.TextView;
Point tpoint = (Point)this.TranslatePoint(point + new Point(textView.ScrollOffset.X, Math.Floor(textView.ScrollOffset.Y)), textView);
return textView.GetPosition(tpoint);
}
/// <summary>
/// Scrolls to the specified line.
/// This method requires that the TextEditor was already assigned a size (layout engine must have run prior).
/// </summary>
public void ScrollToLine(int line)
{
ScrollTo(line, -1);
}
/// <summary>
/// Scrolls to the specified line/column.
/// This method requires that the TextEditor was already assigned a size (layout engine must have run prior).
/// </summary>
public void ScrollTo(int line, int column)
{
const double MinimumScrollFraction = 0.3;
ScrollTo(line, column, VisualYPosition.LineMiddle,
null != ScrollViewer ? ScrollViewer.Viewport.Height / 2 : 0.0, MinimumScrollFraction);
}
/// <summary>
/// Scrolls to the specified line/column.
/// This method requires that the TextEditor was already assigned a size (WPF layout must have run prior).
/// </summary>
/// <param name="line">Line to scroll to.</param>
/// <param name="column">Column to scroll to (important if wrapping is 'on', and for the horizontal scroll position).</param>
/// <param name="yPositionMode">The mode how to reference the Y position of the line.</param>
/// <param name="referencedVerticalViewPortOffset">Offset from the top of the viewport to where the referenced line/column should be positioned.</param>
/// <param name="minimumScrollFraction">The minimum vertical and/or horizontal scroll offset, expressed as fraction of the height or width of the viewport window, respectively.</param>
public void ScrollTo(int line, int column, VisualYPosition yPositionMode,
double referencedVerticalViewPortOffset, double minimumScrollFraction)
{
TextView textView = textArea.TextView;
TextDocument document = textView.Document;
if (ScrollViewer != null && document != null)
{
if (line < 1)
line = 1;
if (line > document.LineCount)
line = document.LineCount;
ILogicalScrollable scrollInfo = textView;
if (!scrollInfo.CanHorizontallyScroll)
{
// Word wrap is enabled. Ensure that we have up-to-date info about line height so that we scroll
// to the correct position.
// This avoids that the user has to repeat the ScrollTo() call several times when there are very long lines.
VisualLine vl = textView.GetOrConstructVisualLine(document.GetLineByNumber(line));
double remainingHeight = referencedVerticalViewPortOffset;
while (remainingHeight > 0)
{
DocumentLine prevLine = vl.FirstDocumentLine.PreviousLine;
if (prevLine == null)
break;
vl = textView.GetOrConstructVisualLine(prevLine);
remainingHeight -= vl.Height;
}
}
Point p = textArea.TextView.GetVisualPosition(
new TextViewPosition(line, Math.Max(1, column)),
yPositionMode);
double targetX = ScrollViewer.Offset.X;
double targetY = ScrollViewer.Offset.Y;
double verticalPos = p.Y - referencedVerticalViewPortOffset;
if (Math.Abs(verticalPos - ScrollViewer.Offset.Y) >
minimumScrollFraction * ScrollViewer.Viewport.Height)
{
targetY = Math.Max(0, verticalPos);
}
if (column > 0)
{
if (p.X > ScrollViewer.Viewport.Width - Caret.MinimumDistanceToViewBorder * 2)
{
double horizontalPos = Math.Max(0, p.X - ScrollViewer.Viewport.Width / 2);
if (Math.Abs(horizontalPos - ScrollViewer.Offset.X) >
minimumScrollFraction * ScrollViewer.Viewport.Width)
{
targetX = 0;
}
}
else
{
targetX = 0;
}
}
if (targetX != ScrollViewer.Offset.X || targetY != ScrollViewer.Offset.Y)
ScrollViewer.Offset = new Vector(targetX, targetY);
}
}
}
}
<MSG> Merge pull request #73 from jeffreye/fix-scroll
Fix scroll
<DFF> @@ -47,6 +47,8 @@ namespace AvaloniaEdit
static TextEditor()
{
FocusableProperty.OverrideDefaultValue<TextEditor>(true);
+ HorizontalScrollBarVisibilityProperty.OverrideDefaultValue<TextEditor>(ScrollBarVisibility.Auto);
+ VerticalScrollBarVisibilityProperty.OverrideDefaultValue<TextEditor>(ScrollBarVisibility.Auto);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
@@ -1049,28 +1051,28 @@ namespace AvaloniaEdit
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
- public static readonly AvaloniaProperty HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
+ public static readonly AttachedProperty<ScrollBarVisibility> HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
- get => (ScrollBarVisibility)GetValue(HorizontalScrollBarVisibilityProperty);
+ get => GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
- public static readonly AvaloniaProperty VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
+ public static readonly AttachedProperty<ScrollBarVisibility> VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
- get => (ScrollBarVisibility)GetValue(VerticalScrollBarVisibilityProperty);
+ get => GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
| 6 | Merge pull request #73 from jeffreye/fix-scroll | 4 | .cs | cs | mit | AvaloniaUI/AvaloniaEdit |
10066917 | <NME> TextEditor.cs
<BEF> // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using Avalonia;
using AvaloniaEdit.Document;
using AvaloniaEdit.Editing;
using AvaloniaEdit.Highlighting;
using AvaloniaEdit.Rendering;
using AvaloniaEdit.Utils;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Shapes;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.LogicalTree;
using Avalonia.Media;
using Avalonia.Data;
using AvaloniaEdit.Search;
namespace AvaloniaEdit
{
/// <summary>
/// The text editor control.
/// Contains a scrollable TextArea.
/// </summary>
public class TextEditor : TemplatedControl, ITextEditorComponent
static TextEditor()
{
FocusableProperty.OverrideDefaultValue<TextEditor>(true);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
SyntaxHighlightingProperty.Changed.Subscribe(OnSyntaxHighlightingChanged);
IsReadOnlyProperty.Changed.Subscribe(OnIsReadOnlyChanged);
IsModifiedProperty.Changed.Subscribe(OnIsModifiedChanged);
ShowLineNumbersProperty.Changed.Subscribe(OnShowLineNumbersChanged);
LineNumbersForegroundProperty.Changed.Subscribe(OnLineNumbersForegroundChanged);
FontFamilyProperty.Changed.Subscribe(OnFontFamilyPropertyChanged);
FontSizeProperty.Changed.Subscribe(OnFontSizePropertyChanged);
}
/// <summary>
/// Creates a new TextEditor instance.
/// </summary>
public TextEditor() : this(new TextArea())
{
}
/// <summary>
/// Creates a new TextEditor instance.
/// </summary>
protected TextEditor(TextArea textArea) : this(textArea, new TextDocument())
{
}
protected TextEditor(TextArea textArea, TextDocument document)
{
this.textArea = textArea ?? throw new ArgumentNullException(nameof(textArea));
textArea.TextView.Services.AddService(this);
SetValue(OptionsProperty, textArea.Options);
SetValue(DocumentProperty, document);
textArea[!BackgroundProperty] = this[!BackgroundProperty];
}
#endregion
protected override void OnGotFocus(GotFocusEventArgs e)
{
base.OnGotFocus(e);
TextArea.Focus();
e.Handled = true;
}
#region Document property
/// <summary>
/// Document property.
/// </summary>
public static readonly StyledProperty<TextDocument> DocumentProperty
= TextView.DocumentProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the document displayed by the text editor.
/// This is a dependency property.
/// </summary>
public TextDocument Document
{
get => GetValue(DocumentProperty);
set => SetValue(DocumentProperty, value);
}
/// <summary>
/// Occurs when the document property has changed.
/// </summary>
public event EventHandler DocumentChanged;
/// <summary>
/// Raises the <see cref="DocumentChanged"/> event.
/// </summary>
protected virtual void OnDocumentChanged(EventArgs e)
{
DocumentChanged?.Invoke(this, e);
}
private static void OnDocumentChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnDocumentChanged((TextDocument)e.OldValue, (TextDocument)e.NewValue);
}
private void OnDocumentChanged(TextDocument oldValue, TextDocument newValue)
{
if (oldValue != null)
{
TextDocumentWeakEventManager.TextChanged.RemoveHandler(oldValue, OnTextChanged);
PropertyChangedWeakEventManager.RemoveHandler(oldValue.UndoStack, OnUndoStackPropertyChangedHandler);
}
TextArea.Document = newValue;
if (newValue != null)
{
TextDocumentWeakEventManager.TextChanged.AddHandler(newValue, OnTextChanged);
PropertyChangedWeakEventManager.AddHandler(newValue.UndoStack, OnUndoStackPropertyChangedHandler);
}
OnDocumentChanged(EventArgs.Empty);
OnTextChanged(EventArgs.Empty);
}
#endregion
#region Options property
/// <summary>
/// Options property.
/// </summary>
public static readonly StyledProperty<TextEditorOptions> OptionsProperty
= TextView.OptionsProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the options currently used by the text editor.
/// </summary>
public TextEditorOptions Options
{
get => GetValue(OptionsProperty);
set => SetValue(OptionsProperty, value);
}
/// <summary>
/// Occurs when a text editor option has changed.
/// </summary>
public event PropertyChangedEventHandler OptionChanged;
/// <summary>
/// Raises the <see cref="OptionChanged"/> event.
/// </summary>
protected virtual void OnOptionChanged(PropertyChangedEventArgs e)
{
OptionChanged?.Invoke(this, e);
}
private static void OnOptionsChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnOptionsChanged((TextEditorOptions)e.OldValue, (TextEditorOptions)e.NewValue);
}
private void OnOptionsChanged(TextEditorOptions oldValue, TextEditorOptions newValue)
{
if (oldValue != null)
{
PropertyChangedWeakEventManager.RemoveHandler(oldValue, OnPropertyChangedHandler);
}
TextArea.Options = newValue;
if (newValue != null)
{
PropertyChangedWeakEventManager.AddHandler(newValue, OnPropertyChangedHandler);
}
OnOptionChanged(new PropertyChangedEventArgs(null));
}
private void OnPropertyChangedHandler(object sender, PropertyChangedEventArgs e)
{
OnOptionChanged(e);
}
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
base.OnPropertyChanged(change);
if (change.Property == WordWrapProperty)
{
if (WordWrap)
{
_horizontalScrollBarVisibilityBck = HorizontalScrollBarVisibility;
HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
}
else
{
HorizontalScrollBarVisibility = _horizontalScrollBarVisibilityBck;
}
}
}
private void OnUndoStackPropertyChangedHandler(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsOriginalFile")
{
HandleIsOriginalChanged(e);
}
}
private void OnTextChanged(object sender, EventArgs e)
{
OnTextChanged(e);
}
#endregion
#region Text property
/// <summary>
/// Gets/Sets the text of the current document.
/// </summary>
public string Text
{
get
{
var document = Document;
return document != null ? document.Text : string.Empty;
}
set
{
var document = GetDocument();
document.Text = value ?? string.Empty;
// after replacing the full text, the caret is positioned at the end of the document
// - reset it to the beginning.
CaretOffset = 0;
document.UndoStack.ClearAll();
}
}
private TextDocument GetDocument()
{
var document = Document;
if (document == null)
throw ThrowUtil.NoDocumentAssigned();
return document;
}
/// <summary>
/// Occurs when the Text property changes.
/// </summary>
public event EventHandler TextChanged;
/// <summary>
/// Raises the <see cref="TextChanged"/> event.
/// </summary>
protected virtual void OnTextChanged(EventArgs e)
{
TextChanged?.Invoke(this, e);
}
#endregion
#region TextArea / ScrollViewer properties
private readonly TextArea textArea;
private SearchPanel searchPanel;
private bool wasSearchPanelOpened;
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
ScrollViewer = (ScrollViewer)e.NameScope.Find("PART_ScrollViewer");
ScrollViewer.Content = TextArea;
searchPanel = SearchPanel.Install(this);
}
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnAttachedToLogicalTree(e);
if (searchPanel != null && wasSearchPanelOpened)
{
searchPanel.Open();
}
}
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnDetachedFromLogicalTree(e);
if (searchPanel != null)
{
wasSearchPanelOpened = searchPanel.IsOpened;
if (searchPanel.IsOpened)
searchPanel.Close();
}
}
/// <summary>
/// Gets the text area.
/// </summary>
public TextArea TextArea => textArea;
/// <summary>
/// Gets the search panel.
/// </summary>
public SearchPanel SearchPanel => searchPanel;
/// <summary>
/// Gets the scroll viewer used by the text editor.
/// This property can return null if the template has not been applied / does not contain a scroll viewer.
/// </summary>
internal ScrollViewer ScrollViewer { get; private set; }
#endregion
#region Syntax highlighting
/// <summary>
/// The <see cref="SyntaxHighlighting"/> property.
/// </summary>
public static readonly StyledProperty<IHighlightingDefinition> SyntaxHighlightingProperty =
AvaloniaProperty.Register<TextEditor, IHighlightingDefinition>("SyntaxHighlighting");
/// <summary>
/// Gets/sets the syntax highlighting definition used to colorize the text.
/// </summary>
public IHighlightingDefinition SyntaxHighlighting
{
get => GetValue(SyntaxHighlightingProperty);
set => SetValue(SyntaxHighlightingProperty, value);
}
private IVisualLineTransformer _colorizer;
private static void OnSyntaxHighlightingChanged(AvaloniaPropertyChangedEventArgs e)
{
(e.Sender as TextEditor)?.OnSyntaxHighlightingChanged(e.NewValue as IHighlightingDefinition);
}
private void OnSyntaxHighlightingChanged(IHighlightingDefinition newValue)
{
if (_colorizer != null)
{
textArea.TextView.LineTransformers.Remove(_colorizer);
_colorizer = null;
}
if (newValue != null)
{
_colorizer = CreateColorizer(newValue);
if (_colorizer != null)
{
textArea.TextView.LineTransformers.Insert(0, _colorizer);
}
}
}
/// <summary>
/// Creates the highlighting colorizer for the specified highlighting definition.
/// Allows derived classes to provide custom colorizer implementations for special highlighting definitions.
/// </summary>
/// <returns></returns>
protected virtual IVisualLineTransformer CreateColorizer(IHighlightingDefinition highlightingDefinition)
{
if (highlightingDefinition == null)
throw new ArgumentNullException(nameof(highlightingDefinition));
return new HighlightingColorizer(highlightingDefinition);
}
#endregion
#region WordWrap
/// <summary>
/// Word wrap dependency property.
/// </summary>
public static readonly StyledProperty<bool> WordWrapProperty =
AvaloniaProperty.Register<TextEditor, bool>("WordWrap");
/// <summary>
/// Specifies whether the text editor uses word wrapping.
/// </summary>
/// <remarks>
/// Setting WordWrap=true has the same effect as setting HorizontalScrollBarVisibility=Disabled and will override the
/// HorizontalScrollBarVisibility setting.
/// </remarks>
public bool WordWrap
{
get => GetValue(WordWrapProperty);
set => SetValue(WordWrapProperty, value);
}
#endregion
#region IsReadOnly
/// <summary>
/// IsReadOnly dependency property.
/// </summary>
public static readonly StyledProperty<bool> IsReadOnlyProperty =
AvaloniaProperty.Register<TextEditor, bool>("IsReadOnly");
/// <summary>
/// Specifies whether the user can change the text editor content.
/// Setting this property will replace the
/// <see cref="Editing.TextArea.ReadOnlySectionProvider">TextArea.ReadOnlySectionProvider</see>.
/// </summary>
public bool IsReadOnly
{
get => GetValue(IsReadOnlyProperty);
set => SetValue(IsReadOnlyProperty, value);
}
private static void OnIsReadOnlyChanged(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is TextEditor editor)
{
if ((bool)e.NewValue)
editor.TextArea.ReadOnlySectionProvider = ReadOnlySectionDocument.Instance;
else
editor.TextArea.ReadOnlySectionProvider = NoReadOnlySections.Instance;
}
}
#endregion
#region IsModified
/// <summary>
/// Dependency property for <see cref="IsModified"/>
/// </summary>
public static readonly StyledProperty<bool> IsModifiedProperty =
AvaloniaProperty.Register<TextEditor, bool>("IsModified");
/// <summary>
/// Gets/Sets the 'modified' flag.
/// </summary>
public bool IsModified
{
get => GetValue(IsModifiedProperty);
set => SetValue(IsModifiedProperty, value);
}
private static void OnIsModifiedChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
var document = editor?.Document;
if (document != null)
{
var undoStack = document.UndoStack;
if ((bool)e.NewValue)
{
if (undoStack.IsOriginalFile)
undoStack.DiscardOriginalFileMarker();
}
else
{
undoStack.MarkAsOriginalFile();
}
}
}
private void HandleIsOriginalChanged(PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsOriginalFile")
{
var document = Document;
if (document != null)
{
SetValue(IsModifiedProperty, (object)!document.UndoStack.IsOriginalFile);
}
}
}
#endregion
#region ShowLineNumbers
/// <summary>
/// ShowLineNumbers dependency property.
/// </summary>
public static readonly StyledProperty<bool> ShowLineNumbersProperty =
AvaloniaProperty.Register<TextEditor, bool>("ShowLineNumbers");
/// <summary>
/// Specifies whether line numbers are shown on the left to the text view.
/// </summary>
public bool ShowLineNumbers
{
get => GetValue(ShowLineNumbersProperty);
set => SetValue(ShowLineNumbersProperty, value);
}
private static void OnShowLineNumbersChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
if (editor == null) return;
var leftMargins = editor.TextArea.LeftMargins;
if ((bool)e.NewValue)
{
var lineNumbers = new LineNumberMargin();
var line = (Line)DottedLineMargin.Create();
leftMargins.Insert(0, lineNumbers);
leftMargins.Insert(1, line);
var lineNumbersForeground = new Binding("LineNumbersForeground") { Source = editor };
line.Bind(Shape.StrokeProperty, lineNumbersForeground);
lineNumbers.Bind(ForegroundProperty, lineNumbersForeground);
}
else
{
for (var i = 0; i < leftMargins.Count; i++)
{
if (leftMargins[i] is LineNumberMargin)
{
leftMargins.RemoveAt(i);
if (i < leftMargins.Count && DottedLineMargin.IsDottedLineMargin(leftMargins[i]))
{
leftMargins.RemoveAt(i);
}
break;
}
}
}
}
#endregion
#region LineNumbersForeground
/// <summary>
/// LineNumbersForeground dependency property.
/// </summary>
public static readonly StyledProperty<IBrush> LineNumbersForegroundProperty =
AvaloniaProperty.Register<TextEditor, IBrush>("LineNumbersForeground", Brushes.Gray);
/// <summary>
/// Gets/sets the Brush used for displaying the foreground color of line numbers.
/// </summary>
public IBrush LineNumbersForeground
{
get => GetValue(LineNumbersForegroundProperty);
set => SetValue(LineNumbersForegroundProperty, value);
}
private static void OnLineNumbersForegroundChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
var lineNumberMargin = editor?.TextArea.LeftMargins.FirstOrDefault(margin => margin is LineNumberMargin) as LineNumberMargin;
lineNumberMargin?.SetValue(ForegroundProperty, e.NewValue);
}
private static void OnFontFamilyPropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
editor?.TextArea.TextView.SetValue(FontFamilyProperty, e.NewValue);
}
private static void OnFontSizePropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
var editor = e.Sender as TextEditor;
editor?.TextArea.TextView.SetValue(FontSizeProperty, e.NewValue);
}
#endregion
#region TextBoxBase-like methods
/// <summary>
/// Appends text to the end of the document.
/// </summary>
public void AppendText(string textData)
{
var document = GetDocument();
document.Insert(document.TextLength, textData);
}
/// <summary>
/// Begins a group of document changes.
/// </summary>
public void BeginChange()
{
GetDocument().BeginUpdate();
}
/// <summary>
/// Copies the current selection to the clipboard.
/// </summary>
public void Copy()
{
if (CanCopy)
{
ApplicationCommands.Copy.Execute(null, TextArea);
}
}
/// <summary>
/// Removes the current selection and copies it to the clipboard.
/// </summary>
public void Cut()
{
if (CanCut)
{
ApplicationCommands.Cut.Execute(null, TextArea);
}
}
/// <summary>
/// Begins a group of document changes and returns an object that ends the group of document
/// changes when it is disposed.
/// </summary>
public IDisposable DeclareChangeBlock()
{
return GetDocument().RunUpdate();
}
/// <summary>
/// Removes the current selection without copying it to the clipboard.
/// </summary>
public void Delete()
{
if(CanDelete)
{
ApplicationCommands.Delete.Execute(null, TextArea);
}
}
/// <summary>
/// Ends the current group of document changes.
/// </summary>
public void EndChange()
{
GetDocument().EndUpdate();
}
/// <summary>
/// Scrolls one line down.
/// </summary>
public void LineDown()
{
//if (scrollViewer != null)
// scrollViewer.LineDown();
}
/// <summary>
/// Scrolls to the left.
/// </summary>
public void LineLeft()
{
//if (scrollViewer != null)
// scrollViewer.LineLeft();
}
/// <summary>
/// Scrolls to the right.
/// </summary>
public void LineRight()
{
//if (scrollViewer != null)
// scrollViewer.LineRight();
}
/// <summary>
/// Scrolls one line up.
/// </summary>
public void LineUp()
{
//if (scrollViewer != null)
// scrollViewer.LineUp();
}
/// <summary>
/// Scrolls one page down.
/// </summary>
public void PageDown()
{
//if (scrollViewer != null)
// scrollViewer.PageDown();
}
/// <summary>
/// Scrolls one page up.
/// </summary>
public void PageUp()
{
//if (scrollViewer != null)
// scrollViewer.PageUp();
}
/// <summary>
/// Scrolls one page left.
/// </summary>
public void PageLeft()
{
//if (scrollViewer != null)
// scrollViewer.PageLeft();
}
/// <summary>
/// Scrolls one page right.
/// </summary>
public void PageRight()
{
//if (scrollViewer != null)
// scrollViewer.PageRight();
}
/// <summary>
/// Pastes the clipboard content.
/// </summary>
public void Paste()
{
if (CanPaste)
{
ApplicationCommands.Paste.Execute(null, TextArea);
}
}
/// <summary>
/// Redoes the most recent undone command.
/// </summary>
/// <returns>True is the redo operation was successful, false is the redo stack is empty.</returns>
public bool Redo()
{
if (CanRedo)
{
ApplicationCommands.Redo.Execute(null, TextArea);
return true;
}
return false;
}
/// <summary>
/// Scrolls to the end of the document.
/// </summary>
public void ScrollToEnd()
{
ApplyTemplate(); // ensure scrollViewer is created
ScrollViewer?.ScrollToEnd();
}
/// <summary>
/// Scrolls to the start of the document.
/// </summary>
public void ScrollToHome()
{
ApplyTemplate(); // ensure scrollViewer is created
ScrollViewer?.ScrollToHome();
}
/// <summary>
/// Scrolls to the specified position in the document.
/// </summary>
public void ScrollToHorizontalOffset(double offset)
{
ApplyTemplate(); // ensure scrollViewer is created
//if (scrollViewer != null)
// scrollViewer.ScrollToHorizontalOffset(offset);
}
/// <summary>
/// Scrolls to the specified position in the document.
/// </summary>
public void ScrollToVerticalOffset(double offset)
{
ApplyTemplate(); // ensure scrollViewer is created
//if (scrollViewer != null)
// scrollViewer.ScrollToVerticalOffset(offset);
}
/// <summary>
/// Selects the entire text.
/// </summary>
public void SelectAll()
{
if (CanSelectAll)
{
ApplicationCommands.SelectAll.Execute(null, TextArea);
}
}
/// <summary>
/// Undoes the most recent command.
/// </summary>
/// <returns>True is the undo operation was successful, false is the undo stack is empty.</returns>
public bool Undo()
{
if (CanUndo)
{
ApplicationCommands.Undo.Execute(null, TextArea);
return true;
}
return false;
}
/// <summary>
/// Gets if the most recent undone command can be redone.
/// </summary>
public bool CanRedo
{
get { return ApplicationCommands.Redo.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if the most recent command can be undone.
/// </summary>
public bool CanUndo
{
get { return ApplicationCommands.Undo.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be copied
/// </summary>
public bool CanCopy
{
get { return ApplicationCommands.Copy.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be cut
/// </summary>
public bool CanCut
{
get { return ApplicationCommands.Cut.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text in editor can be pasted
/// </summary>
public bool CanPaste
{
get { return ApplicationCommands.Paste.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if selected text in editor can be deleted
/// </summary>
public bool CanDelete
{
get { return ApplicationCommands.Delete.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text the editor can select all
/// </summary>
public bool CanSelectAll
{
get { return ApplicationCommands.SelectAll.CanExecute(null, TextArea); }
}
/// <summary>
/// Gets if text editor can activate the search panel
/// </summary>
public bool CanSearch
{
get { return searchPanel != null; }
}
/// <summary>
/// Gets the vertical size of the document.
/// </summary>
public double ExtentHeight => ScrollViewer?.Extent.Height ?? 0;
/// <summary>
/// Gets the horizontal size of the current document region.
/// </summary>
public double ExtentWidth => ScrollViewer?.Extent.Width ?? 0;
/// <summary>
/// Gets the horizontal size of the viewport.
/// </summary>
public double ViewportHeight => ScrollViewer?.Viewport.Height ?? 0;
/// <summary>
/// Gets the horizontal size of the viewport.
/// </summary>
public double ViewportWidth => ScrollViewer?.Viewport.Width ?? 0;
/// <summary>
/// Gets the vertical scroll position.
/// </summary>
public double VerticalOffset => ScrollViewer?.Offset.Y ?? 0;
/// <summary>
/// Gets the horizontal scroll position.
/// </summary>
public double HorizontalOffset => ScrollViewer?.Offset.X ?? 0;
#endregion
#region TextBox methods
/// <summary>
/// Gets/Sets the selected text.
/// </summary>
public string SelectedText
{
get
{
// We'll get the text from the whole surrounding segment.
// This is done to ensure that SelectedText.Length == SelectionLength.
if (textArea.Document != null && !textArea.Selection.IsEmpty)
return textArea.Document.GetText(textArea.Selection.SurroundingSegment);
return string.Empty;
}
set
{
if (value == null)
throw new ArgumentNullException(nameof(value));
var textArea = TextArea;
if (textArea.Document != null)
{
var offset = SelectionStart;
var length = SelectionLength;
textArea.Document.Replace(offset, length, value);
// keep inserted text selected
textArea.Selection = Selection.Create(textArea, offset, offset + value.Length);
}
}
}
/// <summary>
/// Gets/sets the caret position.
/// </summary>
public int CaretOffset
{
get
{
return textArea.Caret.Offset;
}
set
{
textArea.Caret.Offset = value;
}
}
/// <summary>
/// Gets/sets the start position of the selection.
/// </summary>
public int SelectionStart
{
get
{
if (textArea.Selection.IsEmpty)
return textArea.Caret.Offset;
else
return textArea.Selection.SurroundingSegment.Offset;
}
set => Select(value, SelectionLength);
}
/// <summary>
/// Gets/sets the length of the selection.
/// </summary>
public int SelectionLength
{
get
{
if (!textArea.Selection.IsEmpty)
return textArea.Selection.SurroundingSegment.Length;
else
return 0;
}
set => Select(SelectionStart, value);
}
/// <summary>
/// Selects the specified text section.
/// </summary>
public void Select(int start, int length)
{
var documentLength = Document?.TextLength ?? 0;
if (start < 0 || start > documentLength)
throw new ArgumentOutOfRangeException(nameof(start), start, "Value must be between 0 and " + documentLength);
if (length < 0 || start + length > documentLength)
throw new ArgumentOutOfRangeException(nameof(length), length, "Value must be between 0 and " + (documentLength - start));
TextArea.Selection = Selection.Create(TextArea, start, start + length);
TextArea.Caret.Offset = start + length;
}
/// <summary>
/// Gets the number of lines in the document.
/// </summary>
public int LineCount
{
get
{
var document = Document;
if (document != null)
return document.LineCount;
return 1;
}
}
/// <summary>
/// Clears the text.
/// </summary>
public void Clear()
{
Text = string.Empty;
}
#endregion
#region Loading from stream
/// <summary>
/// Loads the text from the stream, auto-detecting the encoding.
/// </summary>
/// <remarks>
/// This method sets <see cref="IsModified"/> to false.
/// </remarks>
public void Load(Stream stream)
{
using (var reader = FileReader.OpenStream(stream, Encoding ?? Encoding.UTF8))
{
Text = reader.ReadToEnd();
SetValue(EncodingProperty, (object)reader.CurrentEncoding);
}
SetValue(IsModifiedProperty, (object)false);
}
/// <summary>
/// Loads the text from the stream, auto-detecting the encoding.
/// </summary>
public void Load(string fileName)
{
if (fileName == null)
throw new ArgumentNullException(nameof(fileName));
// TODO:load
//using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
//{
// Load(fs);
//}
}
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
public static readonly AvaloniaProperty HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
get => (ScrollBarVisibility)GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
public static readonly AvaloniaProperty VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
get => (ScrollBarVisibility)GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
if (stream == null)
throw new ArgumentNullException(nameof(stream));
var encoding = Encoding;
var document = Document;
var writer = encoding != null ? new StreamWriter(stream, encoding) : new StreamWriter(stream);
document?.WriteTextTo(writer);
writer.Flush();
// do not close the stream
SetValue(IsModifiedProperty, (object)false);
}
/// <summary>
/// Saves the text to the file.
/// </summary>
public void Save(string fileName)
{
if (fileName == null)
throw new ArgumentNullException(nameof(fileName));
// TODO: save
//using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
//{
// Save(fs);
//}
}
#endregion
#region PointerHover events
/// <summary>
/// The PreviewPointerHover event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PreviewPointerHoverEvent =
TextView.PreviewPointerHoverEvent;
/// <summary>
/// the pointerHover event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PointerHoverEvent =
TextView.PointerHoverEvent;
/// <summary>
/// The PreviewPointerHoverStopped event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PreviewPointerHoverStoppedEvent =
TextView.PreviewPointerHoverStoppedEvent;
/// <summary>
/// the pointerHoverStopped event.
/// </summary>
public static readonly RoutedEvent<PointerEventArgs> PointerHoverStoppedEvent =
TextView.PointerHoverStoppedEvent;
/// <summary>
/// Occurs when the pointer has hovered over a fixed location for some time.
/// </summary>
public event EventHandler<PointerEventArgs> PreviewPointerHover
{
add => AddHandler(PreviewPointerHoverEvent, value);
remove => RemoveHandler(PreviewPointerHoverEvent, value);
}
/// <summary>
/// Occurs when the pointer has hovered over a fixed location for some time.
/// </summary>
public event EventHandler<PointerEventArgs> PointerHover
{
add => AddHandler(PointerHoverEvent, value);
remove => RemoveHandler(PointerHoverEvent, value);
}
/// <summary>
/// Occurs when the pointer had previously hovered but now started moving again.
/// </summary>
public event EventHandler<PointerEventArgs> PreviewPointerHoverStopped
{
add => AddHandler(PreviewPointerHoverStoppedEvent, value);
remove => RemoveHandler(PreviewPointerHoverStoppedEvent, value);
}
/// <summary>
/// Occurs when the pointer had previously hovered but now started moving again.
/// </summary>
public event EventHandler<PointerEventArgs> PointerHoverStopped
{
add => AddHandler(PointerHoverStoppedEvent, value);
remove => RemoveHandler(PointerHoverStoppedEvent, value);
}
#endregion
#region ScrollBarVisibility
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
public static readonly AttachedProperty<ScrollBarVisibility> HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
get => GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
private ScrollBarVisibility _horizontalScrollBarVisibilityBck = ScrollBarVisibility.Auto;
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
public static readonly AttachedProperty<ScrollBarVisibility> VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
get => GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
object IServiceProvider.GetService(Type serviceType)
{
return TextArea.GetService(serviceType);
}
/// <summary>
/// Gets the text view position from a point inside the editor.
/// </summary>
/// <param name="point">The position, relative to top left
/// corner of TextEditor control</param>
/// <returns>The text view position, or null if the point is outside the document.</returns>
public TextViewPosition? GetPositionFromPoint(Point point)
{
if (Document == null)
return null;
var textView = TextArea.TextView;
Point tpoint = (Point)this.TranslatePoint(point + new Point(textView.ScrollOffset.X, Math.Floor(textView.ScrollOffset.Y)), textView);
return textView.GetPosition(tpoint);
}
/// <summary>
/// Scrolls to the specified line.
/// This method requires that the TextEditor was already assigned a size (layout engine must have run prior).
/// </summary>
public void ScrollToLine(int line)
{
ScrollTo(line, -1);
}
/// <summary>
/// Scrolls to the specified line/column.
/// This method requires that the TextEditor was already assigned a size (layout engine must have run prior).
/// </summary>
public void ScrollTo(int line, int column)
{
const double MinimumScrollFraction = 0.3;
ScrollTo(line, column, VisualYPosition.LineMiddle,
null != ScrollViewer ? ScrollViewer.Viewport.Height / 2 : 0.0, MinimumScrollFraction);
}
/// <summary>
/// Scrolls to the specified line/column.
/// This method requires that the TextEditor was already assigned a size (WPF layout must have run prior).
/// </summary>
/// <param name="line">Line to scroll to.</param>
/// <param name="column">Column to scroll to (important if wrapping is 'on', and for the horizontal scroll position).</param>
/// <param name="yPositionMode">The mode how to reference the Y position of the line.</param>
/// <param name="referencedVerticalViewPortOffset">Offset from the top of the viewport to where the referenced line/column should be positioned.</param>
/// <param name="minimumScrollFraction">The minimum vertical and/or horizontal scroll offset, expressed as fraction of the height or width of the viewport window, respectively.</param>
public void ScrollTo(int line, int column, VisualYPosition yPositionMode,
double referencedVerticalViewPortOffset, double minimumScrollFraction)
{
TextView textView = textArea.TextView;
TextDocument document = textView.Document;
if (ScrollViewer != null && document != null)
{
if (line < 1)
line = 1;
if (line > document.LineCount)
line = document.LineCount;
ILogicalScrollable scrollInfo = textView;
if (!scrollInfo.CanHorizontallyScroll)
{
// Word wrap is enabled. Ensure that we have up-to-date info about line height so that we scroll
// to the correct position.
// This avoids that the user has to repeat the ScrollTo() call several times when there are very long lines.
VisualLine vl = textView.GetOrConstructVisualLine(document.GetLineByNumber(line));
double remainingHeight = referencedVerticalViewPortOffset;
while (remainingHeight > 0)
{
DocumentLine prevLine = vl.FirstDocumentLine.PreviousLine;
if (prevLine == null)
break;
vl = textView.GetOrConstructVisualLine(prevLine);
remainingHeight -= vl.Height;
}
}
Point p = textArea.TextView.GetVisualPosition(
new TextViewPosition(line, Math.Max(1, column)),
yPositionMode);
double targetX = ScrollViewer.Offset.X;
double targetY = ScrollViewer.Offset.Y;
double verticalPos = p.Y - referencedVerticalViewPortOffset;
if (Math.Abs(verticalPos - ScrollViewer.Offset.Y) >
minimumScrollFraction * ScrollViewer.Viewport.Height)
{
targetY = Math.Max(0, verticalPos);
}
if (column > 0)
{
if (p.X > ScrollViewer.Viewport.Width - Caret.MinimumDistanceToViewBorder * 2)
{
double horizontalPos = Math.Max(0, p.X - ScrollViewer.Viewport.Width / 2);
if (Math.Abs(horizontalPos - ScrollViewer.Offset.X) >
minimumScrollFraction * ScrollViewer.Viewport.Width)
{
targetX = 0;
}
}
else
{
targetX = 0;
}
}
if (targetX != ScrollViewer.Offset.X || targetY != ScrollViewer.Offset.Y)
ScrollViewer.Offset = new Vector(targetX, targetY);
}
}
}
}
<MSG> Merge pull request #73 from jeffreye/fix-scroll
Fix scroll
<DFF> @@ -47,6 +47,8 @@ namespace AvaloniaEdit
static TextEditor()
{
FocusableProperty.OverrideDefaultValue<TextEditor>(true);
+ HorizontalScrollBarVisibilityProperty.OverrideDefaultValue<TextEditor>(ScrollBarVisibility.Auto);
+ VerticalScrollBarVisibilityProperty.OverrideDefaultValue<TextEditor>(ScrollBarVisibility.Auto);
OptionsProperty.Changed.Subscribe(OnOptionsChanged);
DocumentProperty.Changed.Subscribe(OnDocumentChanged);
@@ -1049,28 +1051,28 @@ namespace AvaloniaEdit
/// <summary>
/// Dependency property for <see cref="HorizontalScrollBarVisibility"/>
/// </summary>
- public static readonly AvaloniaProperty HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
+ public static readonly AttachedProperty<ScrollBarVisibility> HorizontalScrollBarVisibilityProperty = ScrollViewer.HorizontalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the horizontal scroll bar visibility.
/// </summary>
public ScrollBarVisibility HorizontalScrollBarVisibility
{
- get => (ScrollBarVisibility)GetValue(HorizontalScrollBarVisibilityProperty);
+ get => GetValue(HorizontalScrollBarVisibilityProperty);
set => SetValue(HorizontalScrollBarVisibilityProperty, value);
}
/// <summary>
/// Dependency property for <see cref="VerticalScrollBarVisibility"/>
/// </summary>
- public static readonly AvaloniaProperty VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
+ public static readonly AttachedProperty<ScrollBarVisibility> VerticalScrollBarVisibilityProperty = ScrollViewer.VerticalScrollBarVisibilityProperty.AddOwner<TextEditor>();
/// <summary>
/// Gets/Sets the vertical scroll bar visibility.
/// </summary>
public ScrollBarVisibility VerticalScrollBarVisibility
{
- get => (ScrollBarVisibility)GetValue(VerticalScrollBarVisibilityProperty);
+ get => GetValue(VerticalScrollBarVisibilityProperty);
set => SetValue(VerticalScrollBarVisibilityProperty, value);
}
#endregion
| 6 | Merge pull request #73 from jeffreye/fix-scroll | 4 | .cs | cs | mit | AvaloniaUI/AvaloniaEdit |
10066918 | <NME> module.js
<BEF> ADDFILE
<MSG> Ammend all tests to work with new APIs
<DFF> @@ -0,0 +1,13 @@
+
+buster.testCase('FruitMachine.module()', {
+ setUp: function() {},
+
+ "Should store the module in FruitMachine.store under module type": function() {
+ FruitMachine.module({ module: 'my-module' });
+ assert.defined(FruitMachine.store.modules['my-module']);
+ },
+
+ tearDown: function() {
+ FruitMachine.module.clear();
+ }
+});
\ No newline at end of file
| 13 | Ammend all tests to work with new APIs | 0 | .js | js | mit | ftlabs/fruitmachine |
10066919 | <NME> loadjs.js
<BEF> /**
* Global dependencies.
* @global {Object} document - DOM
*/
var devnull = function() {},
bundleIdCache = {},
bundleResultCache = {},
bundleCallbackQueue = {};
/**
* Subscribe to bundle load event.
* @param {string[]} bundleIds - Bundle ids
* @param {Function} callbackFn - The callback function
*/
function subscribe(bundleIds, callbackFn) {
// listify
bundleIds = bundleIds.push ? bundleIds : [bundleIds];
var depsNotFound = [],
i = bundleIds.length,
numWaiting = i,
fn,
bundleId,
r,
q;
// define callback function
numWaiting -= 1;
if (numWaiting === 0) callbackFn(depsNotFound);
};
// register callback
while (i--) {
bundleId = bundleIds[i];
// execute callback if in result cache
r = bundleResultCache[bundleId];
if (r) {
fn(bundleId, r);
continue;
}
// add to callback queue
q = bundleCallbackQueue[bundleId] = bundleCallbackQueue[bundleId] || [];
q.push(fn);
// add to callback queue
q = bundleCallbackQueue[bundleId] = bundleCallbackQueue[bundleId] || [];
q.push(fn);
}
}
/**
* Publish bundle load event.
function publish(bundleId, pathsNotFound) {
// exit if id isn't defined
if (!bundleId) return;
var q = bundleCallbackQueue[bundleId];
// cache result
bundleResultCache[bundleId] = pathsNotFound;
// exit if queue is empty
if (!q) return;
// empty callback queue
while (q.length) {
q[0](bundleId, pathsNotFound);
// empty callback queue
while (q.length) {
q[0](bundleId, pathsNotFound);
q.splice(0, 1);
}
}
/**
* Execute callbacks.
function loadScript(path, callbackFn) {
var doc = document,
s = doc.createElement('script');
s.src = path;
s.onload = s.onerror = function(ev) {
// execute callback
callbackFn(path, ev.type);
};
// add to document
doc.head.appendChild(s);
}
* Load individual file.
* @param {string} path - The file path
* @param {Function} callbackFn - The callback function
*/
function loadFile(path, callbackFn, args, numTries) {
var doc = document,
async = args.async,
function loadScripts(paths, callbackFn) {
// listify paths
paths = paths.push ? paths : [paths];
var i = paths.length, numWaiting = i, pathsNotFound = [], fn;
// define callback function
fn = function(path, result) {
if (result === 'error') pathsNotFound.push(path);
numWaiting -= 1;
if (numWaiting === 0) callbackFn(pathsNotFound);
};
// load scripts
while (i--) loadScript(paths[i], fn);
}
// use preload in IE Edge (to detect load errors)
if (isLegacyIECss && e.relList) {
isLegacyIECss = 0;
e.rel = 'preload';
e.as = 'style';
}
} else if (/(^img!|\.(png|gif|jpg|svg|webp)$)/.test(pathname)) {
*/
function loadjs(paths, arg1, arg2, arg3) {
var bundleId, successFn, failFn;
// bundleId
if (arg1 && !arg1.call) bundleId = arg1;
// successFn, failFn
successFn = bundleId ? arg2 : arg1;
failFn = bundleId ? arg3 : arg2;
// throw error if bundle is already defined
if (bundleId) {
if (bundleId in bundleIdCache) {
// support in IE9-11
if (isLegacyIECss) {
bundleIdCache[bundleId] = true;
}
}
// load scripts
loadScripts(paths, function(pathsNotFound) {
if (pathsNotFound.length) (failFn || devnull)(pathsNotFound);
else (successFn || devnull)();
// publish bundle load event
publish(bundleId, pathsNotFound);
});
numTries += 1;
// exit function and try again
if (numTries < maxTries) {
return loadFile(path, callbackFn, args, numTries);
}
} else if (e.rel == 'preload' && e.as == 'style') {
// activate preloaded stylesheets
return e.rel = 'stylesheet'; // jshint ignore:line
}
// execute callback
callbackFn(path, result, ev.defaultPrevented);
if (depsNotFound.length) (failFn || devnull)(depsNotFound);
else (successFn || devnull)();
});
return loadjs;
};
/**
* Load multiple files.
* @param {string[]} paths - The file paths
* @param {Function} callbackFn - The callback function
*/
function loadFiles(paths, callbackFn, args) {
// listify paths
paths = paths.push ? paths : [paths];
var numWaiting = paths.length,
x = numWaiting,
pathsNotFound = [],
fn,
i;
// define callback function
fn = function(path, result, defaultPrevented) {
// handle error
if (result == 'e') pathsNotFound.push(path);
// handle beforeload event. If defaultPrevented then that means the load
// will be blocked (ex. Ghostery/ABP on Safari)
if (result == 'b') {
if (defaultPrevented) pathsNotFound.push(path);
else return;
}
numWaiting--;
if (!numWaiting) callbackFn(pathsNotFound);
};
// load scripts
for (i=0; i < x; i++) loadFile(paths[i], fn, args);
}
/**
* Initiate script load and register bundle.
* @param {(string|string[])} paths - The file paths
* @param {(string|Function|Object)} [arg1] - The (1) bundleId or (2) success
* callback or (3) object literal with success/error arguments, numRetries,
* etc.
* @param {(Function|Object)} [arg2] - The (1) success callback or (2) object
* literal with success/error arguments, numRetries, etc.
*/
function loadjs(paths, arg1, arg2) {
var bundleId,
args;
// bundleId (if string)
if (arg1 && arg1.trim) bundleId = arg1;
// args (default is {})
args = (bundleId ? arg2 : arg1) || {};
// throw error if bundle is already defined
if (bundleId) {
if (bundleId in bundleIdCache) {
throw "LoadJS";
} else {
bundleIdCache[bundleId] = true;
}
}
function loadFn(resolve, reject) {
loadFiles(paths, function (pathsNotFound) {
// execute callbacks
executeCallbacks(args, pathsNotFound);
// resolve Promise
if (resolve) {
executeCallbacks({success: resolve, error: reject}, pathsNotFound);
}
// publish bundle load event
publish(bundleId, pathsNotFound);
}, args);
}
if (args.returnPromise) return new Promise(loadFn);
else loadFn();
}
/**
* Execute callbacks when dependencies have been satisfied.
* @param {(string|string[])} deps - List of bundle ids
* @param {Object} args - success/error arguments
*/
loadjs.ready = function ready(deps, args) {
// subscribe to bundle load event
subscribe(deps, function (depsNotFound) {
// execute callbacks
executeCallbacks(args, depsNotFound);
});
return loadjs;
};
/**
* Manually satisfy bundle dependencies.
* @param {string} bundleId - The bundle id
*/
loadjs.done = function done(bundleId) {
publish(bundleId, []);
};
/**
* Reset loadjs dependencies statuses
*/
loadjs.reset = function reset() {
bundleIdCache = {};
bundleResultCache = {};
bundleCallbackQueue = {};
};
/**
* Determine if bundle has already been defined
* @param String} bundleId - The bundle id
*/
loadjs.isDefined = function isDefined(bundleId) {
return bundleId in bundleIdCache;
};
// export
return loadjs;
<MSG> fixed spacing issues in source code
<DFF> @@ -17,7 +17,7 @@ var devnull = function() {},
function subscribe(bundleIds, callbackFn) {
// listify
bundleIds = bundleIds.push ? bundleIds : [bundleIds];
-
+
var depsNotFound = [],
i = bundleIds.length,
numWaiting = i,
@@ -30,18 +30,18 @@ function subscribe(bundleIds, callbackFn) {
numWaiting -= 1;
if (numWaiting === 0) callbackFn(depsNotFound);
};
-
+
// register callback
while (i--) {
bundleId = bundleIds[i];
-
+
// execute callback if in result cache
r = bundleResultCache[bundleId];
if (r) {
fn(bundleId, r);
continue;
}
-
+
// add to callback queue
q = bundleCallbackQueue[bundleId] = bundleCallbackQueue[bundleId] || [];
q.push(fn);
@@ -57,15 +57,15 @@ function subscribe(bundleIds, callbackFn) {
function publish(bundleId, pathsNotFound) {
// exit if id isn't defined
if (!bundleId) return;
-
+
var q = bundleCallbackQueue[bundleId];
-
+
// cache result
bundleResultCache[bundleId] = pathsNotFound;
-
+
// exit if queue is empty
if (!q) return;
-
+
// empty callback queue
while (q.length) {
q[0](bundleId, pathsNotFound);
@@ -82,13 +82,14 @@ function publish(bundleId, pathsNotFound) {
function loadScript(path, callbackFn) {
var doc = document,
s = doc.createElement('script');
- s.src = path;
+ s.src = path;
+
s.onload = s.onerror = function(ev) {
// execute callback
callbackFn(path, ev.type);
};
-
+
// add to document
doc.head.appendChild(s);
}
@@ -102,17 +103,17 @@ function loadScript(path, callbackFn) {
function loadScripts(paths, callbackFn) {
// listify paths
paths = paths.push ? paths : [paths];
-
+
var i = paths.length, numWaiting = i, pathsNotFound = [], fn;
-
+
// define callback function
fn = function(path, result) {
if (result === 'error') pathsNotFound.push(path);
-
+
numWaiting -= 1;
if (numWaiting === 0) callbackFn(pathsNotFound);
};
-
+
// load scripts
while (i--) loadScript(paths[i], fn);
}
@@ -127,14 +128,14 @@ function loadScripts(paths, callbackFn) {
*/
function loadjs(paths, arg1, arg2, arg3) {
var bundleId, successFn, failFn;
-
+
// bundleId
if (arg1 && !arg1.call) bundleId = arg1;
-
+
// successFn, failFn
successFn = bundleId ? arg2 : arg1;
failFn = bundleId ? arg3 : arg2;
-
+
// throw error if bundle is already defined
if (bundleId) {
if (bundleId in bundleIdCache) {
@@ -143,12 +144,12 @@ function loadjs(paths, arg1, arg2, arg3) {
bundleIdCache[bundleId] = true;
}
}
-
+
// load scripts
loadScripts(paths, function(pathsNotFound) {
if (pathsNotFound.length) (failFn || devnull)(pathsNotFound);
else (successFn || devnull)();
-
+
// publish bundle load event
publish(bundleId, pathsNotFound);
});
@@ -168,7 +169,7 @@ loadjs.ready = function (deps, successFn, failFn) {
if (depsNotFound.length) (failFn || devnull)(depsNotFound);
else (successFn || devnull)();
});
-
+
return loadjs;
};
| 21 | fixed spacing issues in source code | 20 | .js | js | mit | muicss/loadjs |
10066920 | <NME> loadjs.js
<BEF> /**
* Global dependencies.
* @global {Object} document - DOM
*/
var devnull = function() {},
bundleIdCache = {},
bundleResultCache = {},
bundleCallbackQueue = {};
/**
* Subscribe to bundle load event.
* @param {string[]} bundleIds - Bundle ids
* @param {Function} callbackFn - The callback function
*/
function subscribe(bundleIds, callbackFn) {
// listify
bundleIds = bundleIds.push ? bundleIds : [bundleIds];
var depsNotFound = [],
i = bundleIds.length,
numWaiting = i,
fn,
bundleId,
r,
q;
// define callback function
numWaiting -= 1;
if (numWaiting === 0) callbackFn(depsNotFound);
};
// register callback
while (i--) {
bundleId = bundleIds[i];
// execute callback if in result cache
r = bundleResultCache[bundleId];
if (r) {
fn(bundleId, r);
continue;
}
// add to callback queue
q = bundleCallbackQueue[bundleId] = bundleCallbackQueue[bundleId] || [];
q.push(fn);
// add to callback queue
q = bundleCallbackQueue[bundleId] = bundleCallbackQueue[bundleId] || [];
q.push(fn);
}
}
/**
* Publish bundle load event.
function publish(bundleId, pathsNotFound) {
// exit if id isn't defined
if (!bundleId) return;
var q = bundleCallbackQueue[bundleId];
// cache result
bundleResultCache[bundleId] = pathsNotFound;
// exit if queue is empty
if (!q) return;
// empty callback queue
while (q.length) {
q[0](bundleId, pathsNotFound);
// empty callback queue
while (q.length) {
q[0](bundleId, pathsNotFound);
q.splice(0, 1);
}
}
/**
* Execute callbacks.
function loadScript(path, callbackFn) {
var doc = document,
s = doc.createElement('script');
s.src = path;
s.onload = s.onerror = function(ev) {
// execute callback
callbackFn(path, ev.type);
};
// add to document
doc.head.appendChild(s);
}
* Load individual file.
* @param {string} path - The file path
* @param {Function} callbackFn - The callback function
*/
function loadFile(path, callbackFn, args, numTries) {
var doc = document,
async = args.async,
function loadScripts(paths, callbackFn) {
// listify paths
paths = paths.push ? paths : [paths];
var i = paths.length, numWaiting = i, pathsNotFound = [], fn;
// define callback function
fn = function(path, result) {
if (result === 'error') pathsNotFound.push(path);
numWaiting -= 1;
if (numWaiting === 0) callbackFn(pathsNotFound);
};
// load scripts
while (i--) loadScript(paths[i], fn);
}
// use preload in IE Edge (to detect load errors)
if (isLegacyIECss && e.relList) {
isLegacyIECss = 0;
e.rel = 'preload';
e.as = 'style';
}
} else if (/(^img!|\.(png|gif|jpg|svg|webp)$)/.test(pathname)) {
*/
function loadjs(paths, arg1, arg2, arg3) {
var bundleId, successFn, failFn;
// bundleId
if (arg1 && !arg1.call) bundleId = arg1;
// successFn, failFn
successFn = bundleId ? arg2 : arg1;
failFn = bundleId ? arg3 : arg2;
// throw error if bundle is already defined
if (bundleId) {
if (bundleId in bundleIdCache) {
// support in IE9-11
if (isLegacyIECss) {
bundleIdCache[bundleId] = true;
}
}
// load scripts
loadScripts(paths, function(pathsNotFound) {
if (pathsNotFound.length) (failFn || devnull)(pathsNotFound);
else (successFn || devnull)();
// publish bundle load event
publish(bundleId, pathsNotFound);
});
numTries += 1;
// exit function and try again
if (numTries < maxTries) {
return loadFile(path, callbackFn, args, numTries);
}
} else if (e.rel == 'preload' && e.as == 'style') {
// activate preloaded stylesheets
return e.rel = 'stylesheet'; // jshint ignore:line
}
// execute callback
callbackFn(path, result, ev.defaultPrevented);
if (depsNotFound.length) (failFn || devnull)(depsNotFound);
else (successFn || devnull)();
});
return loadjs;
};
/**
* Load multiple files.
* @param {string[]} paths - The file paths
* @param {Function} callbackFn - The callback function
*/
function loadFiles(paths, callbackFn, args) {
// listify paths
paths = paths.push ? paths : [paths];
var numWaiting = paths.length,
x = numWaiting,
pathsNotFound = [],
fn,
i;
// define callback function
fn = function(path, result, defaultPrevented) {
// handle error
if (result == 'e') pathsNotFound.push(path);
// handle beforeload event. If defaultPrevented then that means the load
// will be blocked (ex. Ghostery/ABP on Safari)
if (result == 'b') {
if (defaultPrevented) pathsNotFound.push(path);
else return;
}
numWaiting--;
if (!numWaiting) callbackFn(pathsNotFound);
};
// load scripts
for (i=0; i < x; i++) loadFile(paths[i], fn, args);
}
/**
* Initiate script load and register bundle.
* @param {(string|string[])} paths - The file paths
* @param {(string|Function|Object)} [arg1] - The (1) bundleId or (2) success
* callback or (3) object literal with success/error arguments, numRetries,
* etc.
* @param {(Function|Object)} [arg2] - The (1) success callback or (2) object
* literal with success/error arguments, numRetries, etc.
*/
function loadjs(paths, arg1, arg2) {
var bundleId,
args;
// bundleId (if string)
if (arg1 && arg1.trim) bundleId = arg1;
// args (default is {})
args = (bundleId ? arg2 : arg1) || {};
// throw error if bundle is already defined
if (bundleId) {
if (bundleId in bundleIdCache) {
throw "LoadJS";
} else {
bundleIdCache[bundleId] = true;
}
}
function loadFn(resolve, reject) {
loadFiles(paths, function (pathsNotFound) {
// execute callbacks
executeCallbacks(args, pathsNotFound);
// resolve Promise
if (resolve) {
executeCallbacks({success: resolve, error: reject}, pathsNotFound);
}
// publish bundle load event
publish(bundleId, pathsNotFound);
}, args);
}
if (args.returnPromise) return new Promise(loadFn);
else loadFn();
}
/**
* Execute callbacks when dependencies have been satisfied.
* @param {(string|string[])} deps - List of bundle ids
* @param {Object} args - success/error arguments
*/
loadjs.ready = function ready(deps, args) {
// subscribe to bundle load event
subscribe(deps, function (depsNotFound) {
// execute callbacks
executeCallbacks(args, depsNotFound);
});
return loadjs;
};
/**
* Manually satisfy bundle dependencies.
* @param {string} bundleId - The bundle id
*/
loadjs.done = function done(bundleId) {
publish(bundleId, []);
};
/**
* Reset loadjs dependencies statuses
*/
loadjs.reset = function reset() {
bundleIdCache = {};
bundleResultCache = {};
bundleCallbackQueue = {};
};
/**
* Determine if bundle has already been defined
* @param String} bundleId - The bundle id
*/
loadjs.isDefined = function isDefined(bundleId) {
return bundleId in bundleIdCache;
};
// export
return loadjs;
<MSG> fixed spacing issues in source code
<DFF> @@ -17,7 +17,7 @@ var devnull = function() {},
function subscribe(bundleIds, callbackFn) {
// listify
bundleIds = bundleIds.push ? bundleIds : [bundleIds];
-
+
var depsNotFound = [],
i = bundleIds.length,
numWaiting = i,
@@ -30,18 +30,18 @@ function subscribe(bundleIds, callbackFn) {
numWaiting -= 1;
if (numWaiting === 0) callbackFn(depsNotFound);
};
-
+
// register callback
while (i--) {
bundleId = bundleIds[i];
-
+
// execute callback if in result cache
r = bundleResultCache[bundleId];
if (r) {
fn(bundleId, r);
continue;
}
-
+
// add to callback queue
q = bundleCallbackQueue[bundleId] = bundleCallbackQueue[bundleId] || [];
q.push(fn);
@@ -57,15 +57,15 @@ function subscribe(bundleIds, callbackFn) {
function publish(bundleId, pathsNotFound) {
// exit if id isn't defined
if (!bundleId) return;
-
+
var q = bundleCallbackQueue[bundleId];
-
+
// cache result
bundleResultCache[bundleId] = pathsNotFound;
-
+
// exit if queue is empty
if (!q) return;
-
+
// empty callback queue
while (q.length) {
q[0](bundleId, pathsNotFound);
@@ -82,13 +82,14 @@ function publish(bundleId, pathsNotFound) {
function loadScript(path, callbackFn) {
var doc = document,
s = doc.createElement('script');
- s.src = path;
+ s.src = path;
+
s.onload = s.onerror = function(ev) {
// execute callback
callbackFn(path, ev.type);
};
-
+
// add to document
doc.head.appendChild(s);
}
@@ -102,17 +103,17 @@ function loadScript(path, callbackFn) {
function loadScripts(paths, callbackFn) {
// listify paths
paths = paths.push ? paths : [paths];
-
+
var i = paths.length, numWaiting = i, pathsNotFound = [], fn;
-
+
// define callback function
fn = function(path, result) {
if (result === 'error') pathsNotFound.push(path);
-
+
numWaiting -= 1;
if (numWaiting === 0) callbackFn(pathsNotFound);
};
-
+
// load scripts
while (i--) loadScript(paths[i], fn);
}
@@ -127,14 +128,14 @@ function loadScripts(paths, callbackFn) {
*/
function loadjs(paths, arg1, arg2, arg3) {
var bundleId, successFn, failFn;
-
+
// bundleId
if (arg1 && !arg1.call) bundleId = arg1;
-
+
// successFn, failFn
successFn = bundleId ? arg2 : arg1;
failFn = bundleId ? arg3 : arg2;
-
+
// throw error if bundle is already defined
if (bundleId) {
if (bundleId in bundleIdCache) {
@@ -143,12 +144,12 @@ function loadjs(paths, arg1, arg2, arg3) {
bundleIdCache[bundleId] = true;
}
}
-
+
// load scripts
loadScripts(paths, function(pathsNotFound) {
if (pathsNotFound.length) (failFn || devnull)(pathsNotFound);
else (successFn || devnull)();
-
+
// publish bundle load event
publish(bundleId, pathsNotFound);
});
@@ -168,7 +169,7 @@ loadjs.ready = function (deps, successFn, failFn) {
if (depsNotFound.length) (failFn || devnull)(depsNotFound);
else (successFn || devnull)();
});
-
+
return loadjs;
};
| 21 | fixed spacing issues in source code | 20 | .js | js | mit | muicss/loadjs |
10066921 | <NME> TSQL-Mode.xshd
<BEF> <?xml version="1.0"?>
<SyntaxDefinition name="TSQL" extensions=".sql" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
<Color name="Comment" foreground="Green" exampleText="-- comment" />
<Color name="Char" foreground="Red" exampleText="name = 'abc'"/>
<Color name="Keywords" fontWeight="bold" foreground="Blue" exampleText="SELECT FROM"/>
<Property name="DocCommentMarker" value="///" />
<RuleSet name="CommentMarkerSet">
<Keywords fontWeight="bold" foreground="Red">
<Word>TODO</Word>
<Word>FIXME</Word>
</Keywords>
<Keywords fontWeight="bold" foreground="#E0E000">
<Word>HACK</Word>
<Word>UNDONE</Word>
</Keywords>
</RuleSet>
<RuleSet ignoreCase="true">
<Span color="Comment" ruleSet="CommentMarkerSet">
<Begin>--</Begin>
</Span>
<Span color="Comment" ruleSet="CommentMarkerSet" multiline="true">
<Begin>/\*</Begin>
<End>\*/</End>
</Span>
<Span color="Char">
<Begin>'</Begin>
<End>'</End>
<RuleSet>
<Span begin="\\" end="."/>
</RuleSet>
</Span>
<Keywords color="Keywords">
<Word>abs</Word>
<Word>absolute</Word>
<Word>access</Word>
<Word>acos</Word>
<Word>add</Word>
<Word>add_months</Word>
<Word>adddate</Word>
<Word>admin</Word>
<Word>after</Word>
<Word>aggregate</Word>
<Word>all</Word>
<Word>allocate</Word>
<Word>alter</Word>
<Word>and</Word>
<Word>any</Word>
<Word>app_name</Word>
<Word>are</Word>
<Word>array</Word>
<Word>as</Word>
<Word>asc</Word>
<Word>ascii</Word>
<Word>asin</Word>
<Word>assertion</Word>
<Word>at</Word>
<Word>atan</Word>
<Word>atn2</Word>
<Word>audit</Word>
<Word>authid</Word>
<Word>authorization</Word>
<Word>autonomous_transaction</Word>
<Word>avg</Word>
<Word>before</Word>
<Word>begin</Word>
<Word>benchmark</Word>
<Word>between</Word>
<Word>bfilename</Word>
<Word>bigint</Word>
<Word>bin</Word>
<Word>binary</Word>
<Word>binary_checksum</Word>
<Word>binary_integer</Word>
<Word>bit</Word>
<Word>bit_count</Word>
<Word>bit_and</Word>
<Word>bit_or</Word>
<Word>blob</Word>
<Word>body</Word>
<Word>boolean</Word>
<Word>both</Word>
<Word>breadth</Word>
<Word>bulk</Word>
<Word>by</Word>
<Word>call</Word>
<Word>cascade</Word>
<Word>cascaded</Word>
<Word>case</Word>
<Word>cast</Word>
<Word>catalog</Word>
<Word>ceil</Word>
<Word>ceiling</Word>
<Word>char</Word>
<Word>char_base</Word>
<Word>character</Word>
<Word>charindex</Word>
<Word>chartorowid</Word>
<Word>check</Word>
<Word>checksum</Word>
<Word>checksum_agg</Word>
<Word>chr</Word>
<Word>class</Word>
<Word>clob</Word>
<Word>close</Word>
<Word>cluster</Word>
<Word>coalesce</Word>
<Word>col_length</Word>
<Word>col_name</Word>
<Word>collate</Word>
<Word>collation</Word>
<Word>collect</Word>
<Word>column</Word>
<Word>comment</Word>
<Word>commit</Word>
<Word>completion</Word>
<Word>compress</Word>
<Word>concat</Word>
<Word>concat_ws</Word>
<Word>connect</Word>
<Word>connection</Word>
<Word>constant</Word>
<Word>constraint</Word>
<Word>constraints</Word>
<Word>constructorcreate</Word>
<Word>contains</Word>
<Word>containsable</Word>
<Word>continue</Word>
<Word>conv</Word>
<Word>convert</Word>
<Word>corr</Word>
<Word>corresponding</Word>
<Word>cos</Word>
<Word>cot</Word>
<Word>count</Word>
<Word>count_big</Word>
<Word>covar_pop</Word>
<Word>covar_samp</Word>
<Word>create</Word>
<Word>cross</Word>
<Word>cube</Word>
<Word>cume_dist</Word>
<Word>current</Word>
<Word>current_date</Word>
<Word>current_path</Word>
<Word>current_role</Word>
<Word>current_time</Word>
<Word>current_timestamp</Word>
<Word>current_user</Word>
<Word>currval</Word>
<Word>cursor</Word>
<Word>cycle</Word>
<Word>data</Word>
<Word>datalength</Word>
<Word>databasepropertyex</Word>
<Word>date</Word>
<Word>date_add</Word>
<Word>date_format</Word>
<Word>date_sub</Word>
<Word>dateadd</Word>
<Word>datediff</Word>
<Word>datename</Word>
<Word>datepart</Word>
<Word>datetime</Word>
<Word>day</Word>
<Word>db_id</Word>
<Word>db_name</Word>
<Word>deallocate</Word>
<Word>dec</Word>
<Word>declare</Word>
<Word>decimal</Word>
<Word>decode</Word>
<Word>default</Word>
<Word>deferrable</Word>
<Word>deferred</Word>
<Word>degrees</Word>
<Word>delete</Word>
<Word>dense_rank</Word>
<Word>depth</Word>
<Word>deref</Word>
<Word>desc</Word>
<Word>describe</Word>
<Word>descriptor</Word>
<Word>destroy</Word>
<Word>destructor</Word>
<Word>deterministic</Word>
<Word>diagnostics</Word>
<Word>dictionary</Word>
<Word>disconnect</Word>
<Word>difference</Word>
<Word>distinct</Word>
<Word>do</Word>
<Word>domain</Word>
<Word>double</Word>
<Word>drop</Word>
<Word>dump</Word>
<Word>dynamic</Word>
<Word>each</Word>
<Word>else</Word>
<Word>elsif</Word>
<Word>empth</Word>
<Word>encode</Word>
<Word>encrypt</Word>
<Word>end</Word>
<Word>end-exec</Word>
<Word>equals</Word>
<Word>escape</Word>
<Word>every</Word>
<Word>except</Word>
<Word>exception</Word>
<Word>exclusive</Word>
<Word>exec</Word>
<Word>execute</Word>
<Word>exists</Word>
<Word>exit</Word>
<Word>exp</Word>
<Word>export_set</Word>
<Word>extends</Word>
<Word>external</Word>
<Word>extract</Word>
<Word>false</Word>
<Word>fetch</Word>
<Word>first</Word>
<Word>first_value</Word>
<Word>file</Word>
<Word>float</Word>
<Word>floor</Word>
<Word>file_id</Word>
<Word>file_name</Word>
<Word>filegroup_id</Word>
<Word>filegroup_name</Word>
<Word>filegroupproperty</Word>
<Word>fileproperty</Word>
<Word>for</Word>
<Word>forall</Word>
<Word>foreign</Word>
<Word>format</Word>
<Word>formatmessage</Word>
<Word>found</Word>
<Word>freetexttable</Word>
<Word>from</Word>
<Word>from_days</Word>
<Word>fulltextcatalog</Word>
<Word>fulltextservice</Word>
<Word>function</Word>
<Word>general</Word>
<Word>get</Word>
<Word>get_lock</Word>
<Word>getdate</Word>
<Word>getansinull</Word>
<Word>getutcdate</Word>
<Word>global</Word>
<Word>go</Word>
<Word>goto</Word>
<Word>grant</Word>
<Word>greatest</Word>
<Word>group</Word>
<Word>grouping</Word>
<Word>having</Word>
<Word>heap</Word>
<Word>hex</Word>
<Word>hextoraw</Word>
<Word>host</Word>
<Word>host_id</Word>
<Word>host_name</Word>
<Word>hour</Word>
<Word>ident_incr</Word>
<Word>ident_seed</Word>
<Word>ident_current</Word>
<Word>identified</Word>
<Word>identity</Word>
<Word>if</Word>
<Word>ifnull</Word>
<Word>ignore</Word>
<Word>immediate</Word>
<Word>in</Word>
<Word>increment</Word>
<Word>index</Word>
<Word>index_col</Word>
<Word>indexproperty</Word>
<Word>indicator</Word>
<Word>initcap</Word>
<Word>initial</Word>
<Word>initialize</Word>
<Word>initially</Word>
<Word>inner</Word>
<Word>inout</Word>
<Word>input</Word>
<Word>insert</Word>
<Word>instr</Word>
<Word>instrb</Word>
<Word>int</Word>
<Word>integer</Word>
<Word>interface</Word>
<Word>intersect</Word>
<Word>interval</Word>
<Word>into</Word>
<Word>is</Word>
<Word>is_member</Word>
<Word>is_srvrolemember</Word>
<Word>is_null</Word>
<Word>is_numeric</Word>
<Word>isdate</Word>
<Word>isnull</Word>
<Word>isolation</Word>
<Word>iterate</Word>
<Word>java</Word>
<Word>join</Word>
<Word>key</Word>
<Word>lag</Word>
<Word>language</Word>
<Word>large</Word>
<Word>last</Word>
<Word>last_day</Word>
<Word>last_value</Word>
<Word>lateral</Word>
<Word>lcase</Word>
<Word>lead</Word>
<Word>leading</Word>
<Word>least</Word>
<Word>left</Word>
<Word>len</Word>
<Word>length</Word>
<Word>lengthb</Word>
<Word>less</Word>
<Word>level</Word>
<Word>like</Word>
<Word>limit</Word>
<Word>limited</Word>
<Word>ln</Word>
<Word>lpad</Word>
<Word>local</Word>
<Word>localtime</Word>
<Word>localtimestamp</Word>
<Word>locator</Word>
<Word>lock</Word>
<Word>log</Word>
<Word>log10</Word>
<Word>long</Word>
<Word>loop</Word>
<Word>lower</Word>
<Word>ltrim</Word>
<Word>make_ref</Word>
<Word>map</Word>
<Word>match</Word>
<Word>max</Word>
<Word>maxextents</Word>
<Word>mid</Word>
<Word>min</Word>
<Word>minus</Word>
<Word>minute</Word>
<Word>mlslabel</Word>
<Word>mod</Word>
<Word>mode</Word>
<Word>modifies</Word>
<Word>modify</Word>
<Word>module</Word>
<Word>month</Word>
<Word>months_between</Word>
<Word>names</Word>
<Word>national</Word>
<Word>natural</Word>
<Word>naturaln</Word>
<Word>nchar</Word>
<Word>nclob</Word>
<Word>new</Word>
<Word>new_time</Word>
<Word>newid</Word>
<Word>next</Word>
<Word>next_day</Word>
<Word>nextval</Word>
<Word>no</Word>
<Word>noaudit</Word>
<Word>nocompress</Word>
<Word>nocopy</Word>
<Word>nolock</Word>
<Word>none</Word>
<Word>not</Word>
<Word>nowait</Word>
<Word>null</Word>
<Word>nullif</Word>
<Word>number</Word>
<Word>number_base</Word>
<Word>numeric</Word>
<Word>nvl</Word>
<Word>nvl2</Word>
<Word>object</Word>
<Word>object_id</Word>
<Word>object_name</Word>
<Word>object_property</Word>
<Word>ocirowid</Word>
<Word>oct</Word>
<Word>of</Word>
<Word>off</Word>
<Word>offline</Word>
<Word>old</Word>
<Word>on</Word>
<Word>online</Word>
<Word>only</Word>
<Word>opaque</Word>
<Word>open</Word>
<Word>operator</Word>
<Word>operation</Word>
<Word>option</Word>
<Word>or</Word>
<Word>ord</Word>
<Word>order</Word>
<Word>ordinalityorganization</Word>
<Word>others</Word>
<Word>out</Word>
<Word>outer</Word>
<Word>output</Word>
<Word>package</Word>
<Word>pad</Word>
<Word>parameter</Word>
<Word>parameters</Word>
<Word>partial</Word>
<Word>partition</Word>
<Word>path</Word>
<Word>pctfree</Word>
<Word>percent_rank</Word>
<Word>pi</Word>
<Word>pls_integer</Word>
<Word>positive</Word>
<Word>positiven</Word>
<Word>postfix</Word>
<Word>pow</Word>
<Word>power</Word>
<Word>pragma</Word>
<Word>precision</Word>
<Word>prefix</Word>
<Word>preorder</Word>
<Word>prepare</Word>
<Word>preserve</Word>
<Word>primary</Word>
<Word>prior</Word>
<Word>private</Word>
<Word>privileges</Word>
<Word>procedure</Word>
<Word>public</Word>
<Word>radians</Word>
<Word>raise</Word>
<Word>rand</Word>
<Word>range</Word>
<Word>rank</Word>
<Word>ratio_to_export</Word>
<Word>raw</Word>
<Word>rawtohex</Word>
<Word>read</Word>
<Word>reads</Word>
<Word>real</Word>
<Word>record</Word>
<Word>recursive</Word>
<Word>ref</Word>
<Word>references</Word>
<Word>referencing</Word>
<Word>reftohex</Word>
<Word>relative</Word>
<Word>release</Word>
<Word>release_lock</Word>
<Word>rename</Word>
<Word>repeat</Word>
<Word>replace</Word>
<Word>resource</Word>
<Word>restrict</Word>
<Word>result</Word>
<Word>return</Word>
<Word>returns</Word>
<Word>reverse</Word>
<Word>revoke</Word>
<Word>right</Word>
<Word>rollback</Word>
<Word>rollup</Word>
<Word>round</Word>
<Word>routine</Word>
<Word>row</Word>
<Word>row_number</Word>
<Word>rowid</Word>
<Word>rowidtochar</Word>
<Word>rowlabel</Word>
<Word>rowlock</Word>
<Word>rownum</Word>
<Word>rows</Word>
<Word>rowtype</Word>
<Word>rpad</Word>
<Word>rtrim</Word>
<Word>savepoint</Word>
<Word>schema</Word>
<Word>scroll</Word>
<Word>scope</Word>
<Word>search</Word>
<Word>second</Word>
<Word>section</Word>
<Word>seddev_samp</Word>
<Word>select</Word>
<Word>separate</Word>
<Word>sequence</Word>
<Word>session</Word>
<Word>session_user</Word>
<Word>set</Word>
<Word>sets</Word>
<Word>share</Word>
<Word>sign</Word>
<Word>sin</Word>
<Word>sinh</Word>
<Word>size</Word>
<Word>smallint</Word>
<Word>some</Word>
<Word>soundex</Word>
<Word>space</Word>
<Word>specific</Word>
<Word>specifictype</Word>
<Word>sql</Word>
<Word>sqlcode</Word>
<Word>sqlerrm</Word>
<Word>sqlexception</Word>
<Word>sqlstate</Word>
<Word>sqlwarning</Word>
<Word>sqrt</Word>
<Word>start</Word>
<Word>state</Word>
<Word>statement</Word>
<Word>static</Word>
<Word>std</Word>
<Word>stddev</Word>
<Word>stdev_pop</Word>
<Word>strcmp</Word>
<Word>structure</Word>
<Word>subdate</Word>
<Word>substr</Word>
<Word>substrb</Word>
<Word>substring</Word>
<Word>substring_index</Word>
<Word>subtype</Word>
<Word>successful</Word>
<Word>sum</Word>
<Word>synonym</Word>
<Word>sys_context</Word>
<Word>sys_guid</Word>
<Word>sysdate</Word>
<Word>system_user</Word>
<Word>table</Word>
<Word>tan</Word>
<Word>tanh</Word>
<Word>temporary</Word>
<Word>terminate</Word>
<Word>than</Word>
<Word>then</Word>
<Word>time</Word>
<Word>timestamp</Word>
<Word>timezone_abbr</Word>
<Word>timezone_minute</Word>
<Word>timezone_hour</Word>
<Word>timezone_region</Word>
<Word>tinyint</Word>
<Word>to</Word>
<Word>to_char</Word>
<Word>to_date</Word>
<Word>to_days</Word>
<Word>to_number</Word>
<Word>to_single_byte</Word>
<Word>trailing</Word>
<Word>transaction</Word>
<Word>translate</Word>
<Word>translation</Word>
<Word>treat</Word>
<Word>trigger</Word>
<Word>trim</Word>
<Word>true</Word>
<Word>trunc</Word>
<Word>truncate</Word>
<Word>type</Word>
<Word>ucase</Word>
<Word>uid</Word>
<Word>under</Word>
<Word>union</Word>
<Word>unique</Word>
<Word>unknown</Word>
<Word>unnest</Word>
<Word>update</Word>
<Word>upper</Word>
<Word>usage</Word>
<Word>use</Word>
<Word>user</Word>
<Word>userenv</Word>
<Word>using</Word>
<Word>validate</Word>
<Word>value</Word>
<Word>values</Word>
<Word>var_pop</Word>
<Word>var_samp</Word>
<Word>varbinary</Word>
<Word>varchar</Word>
<Word>varchar2</Word>
<Word>variable</Word>
<Word>variance</Word>
<Word>varying</Word>
<Word>view</Word>
<Word>vsize</Word>
<Word>when</Word>
<Word>whenever</Word>
<Word>where</Word>
<Word>with</Word>
<Word>without</Word>
<Word>while</Word>
<Word>work</Word>
<Word>write</Word>
<Word>year</Word>
<Word>zone</Word>
</Keywords>
</RuleSet>
</SyntaxDefinition>
<MSG> Update TSQL file #125
https://github.com/icsharpcode/AvalonEdit/pull/125
<DFF> @@ -559,6 +559,7 @@
<Word>timezone_region</Word>
<Word>tinyint</Word>
<Word>to</Word>
+ <Word>top</Word>
<Word>to_char</Word>
<Word>to_date</Word>
<Word>to_days</Word>
| 1 | Update TSQL file #125 | 0 | .xshd | xshd | mit | AvaloniaUI/AvaloniaEdit |
10066922 | <NME> TSQL-Mode.xshd
<BEF> <?xml version="1.0"?>
<SyntaxDefinition name="TSQL" extensions=".sql" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
<Color name="Comment" foreground="Green" exampleText="-- comment" />
<Color name="Char" foreground="Red" exampleText="name = 'abc'"/>
<Color name="Keywords" fontWeight="bold" foreground="Blue" exampleText="SELECT FROM"/>
<Property name="DocCommentMarker" value="///" />
<RuleSet name="CommentMarkerSet">
<Keywords fontWeight="bold" foreground="Red">
<Word>TODO</Word>
<Word>FIXME</Word>
</Keywords>
<Keywords fontWeight="bold" foreground="#E0E000">
<Word>HACK</Word>
<Word>UNDONE</Word>
</Keywords>
</RuleSet>
<RuleSet ignoreCase="true">
<Span color="Comment" ruleSet="CommentMarkerSet">
<Begin>--</Begin>
</Span>
<Span color="Comment" ruleSet="CommentMarkerSet" multiline="true">
<Begin>/\*</Begin>
<End>\*/</End>
</Span>
<Span color="Char">
<Begin>'</Begin>
<End>'</End>
<RuleSet>
<Span begin="\\" end="."/>
</RuleSet>
</Span>
<Keywords color="Keywords">
<Word>abs</Word>
<Word>absolute</Word>
<Word>access</Word>
<Word>acos</Word>
<Word>add</Word>
<Word>add_months</Word>
<Word>adddate</Word>
<Word>admin</Word>
<Word>after</Word>
<Word>aggregate</Word>
<Word>all</Word>
<Word>allocate</Word>
<Word>alter</Word>
<Word>and</Word>
<Word>any</Word>
<Word>app_name</Word>
<Word>are</Word>
<Word>array</Word>
<Word>as</Word>
<Word>asc</Word>
<Word>ascii</Word>
<Word>asin</Word>
<Word>assertion</Word>
<Word>at</Word>
<Word>atan</Word>
<Word>atn2</Word>
<Word>audit</Word>
<Word>authid</Word>
<Word>authorization</Word>
<Word>autonomous_transaction</Word>
<Word>avg</Word>
<Word>before</Word>
<Word>begin</Word>
<Word>benchmark</Word>
<Word>between</Word>
<Word>bfilename</Word>
<Word>bigint</Word>
<Word>bin</Word>
<Word>binary</Word>
<Word>binary_checksum</Word>
<Word>binary_integer</Word>
<Word>bit</Word>
<Word>bit_count</Word>
<Word>bit_and</Word>
<Word>bit_or</Word>
<Word>blob</Word>
<Word>body</Word>
<Word>boolean</Word>
<Word>both</Word>
<Word>breadth</Word>
<Word>bulk</Word>
<Word>by</Word>
<Word>call</Word>
<Word>cascade</Word>
<Word>cascaded</Word>
<Word>case</Word>
<Word>cast</Word>
<Word>catalog</Word>
<Word>ceil</Word>
<Word>ceiling</Word>
<Word>char</Word>
<Word>char_base</Word>
<Word>character</Word>
<Word>charindex</Word>
<Word>chartorowid</Word>
<Word>check</Word>
<Word>checksum</Word>
<Word>checksum_agg</Word>
<Word>chr</Word>
<Word>class</Word>
<Word>clob</Word>
<Word>close</Word>
<Word>cluster</Word>
<Word>coalesce</Word>
<Word>col_length</Word>
<Word>col_name</Word>
<Word>collate</Word>
<Word>collation</Word>
<Word>collect</Word>
<Word>column</Word>
<Word>comment</Word>
<Word>commit</Word>
<Word>completion</Word>
<Word>compress</Word>
<Word>concat</Word>
<Word>concat_ws</Word>
<Word>connect</Word>
<Word>connection</Word>
<Word>constant</Word>
<Word>constraint</Word>
<Word>constraints</Word>
<Word>constructorcreate</Word>
<Word>contains</Word>
<Word>containsable</Word>
<Word>continue</Word>
<Word>conv</Word>
<Word>convert</Word>
<Word>corr</Word>
<Word>corresponding</Word>
<Word>cos</Word>
<Word>cot</Word>
<Word>count</Word>
<Word>count_big</Word>
<Word>covar_pop</Word>
<Word>covar_samp</Word>
<Word>create</Word>
<Word>cross</Word>
<Word>cube</Word>
<Word>cume_dist</Word>
<Word>current</Word>
<Word>current_date</Word>
<Word>current_path</Word>
<Word>current_role</Word>
<Word>current_time</Word>
<Word>current_timestamp</Word>
<Word>current_user</Word>
<Word>currval</Word>
<Word>cursor</Word>
<Word>cycle</Word>
<Word>data</Word>
<Word>datalength</Word>
<Word>databasepropertyex</Word>
<Word>date</Word>
<Word>date_add</Word>
<Word>date_format</Word>
<Word>date_sub</Word>
<Word>dateadd</Word>
<Word>datediff</Word>
<Word>datename</Word>
<Word>datepart</Word>
<Word>datetime</Word>
<Word>day</Word>
<Word>db_id</Word>
<Word>db_name</Word>
<Word>deallocate</Word>
<Word>dec</Word>
<Word>declare</Word>
<Word>decimal</Word>
<Word>decode</Word>
<Word>default</Word>
<Word>deferrable</Word>
<Word>deferred</Word>
<Word>degrees</Word>
<Word>delete</Word>
<Word>dense_rank</Word>
<Word>depth</Word>
<Word>deref</Word>
<Word>desc</Word>
<Word>describe</Word>
<Word>descriptor</Word>
<Word>destroy</Word>
<Word>destructor</Word>
<Word>deterministic</Word>
<Word>diagnostics</Word>
<Word>dictionary</Word>
<Word>disconnect</Word>
<Word>difference</Word>
<Word>distinct</Word>
<Word>do</Word>
<Word>domain</Word>
<Word>double</Word>
<Word>drop</Word>
<Word>dump</Word>
<Word>dynamic</Word>
<Word>each</Word>
<Word>else</Word>
<Word>elsif</Word>
<Word>empth</Word>
<Word>encode</Word>
<Word>encrypt</Word>
<Word>end</Word>
<Word>end-exec</Word>
<Word>equals</Word>
<Word>escape</Word>
<Word>every</Word>
<Word>except</Word>
<Word>exception</Word>
<Word>exclusive</Word>
<Word>exec</Word>
<Word>execute</Word>
<Word>exists</Word>
<Word>exit</Word>
<Word>exp</Word>
<Word>export_set</Word>
<Word>extends</Word>
<Word>external</Word>
<Word>extract</Word>
<Word>false</Word>
<Word>fetch</Word>
<Word>first</Word>
<Word>first_value</Word>
<Word>file</Word>
<Word>float</Word>
<Word>floor</Word>
<Word>file_id</Word>
<Word>file_name</Word>
<Word>filegroup_id</Word>
<Word>filegroup_name</Word>
<Word>filegroupproperty</Word>
<Word>fileproperty</Word>
<Word>for</Word>
<Word>forall</Word>
<Word>foreign</Word>
<Word>format</Word>
<Word>formatmessage</Word>
<Word>found</Word>
<Word>freetexttable</Word>
<Word>from</Word>
<Word>from_days</Word>
<Word>fulltextcatalog</Word>
<Word>fulltextservice</Word>
<Word>function</Word>
<Word>general</Word>
<Word>get</Word>
<Word>get_lock</Word>
<Word>getdate</Word>
<Word>getansinull</Word>
<Word>getutcdate</Word>
<Word>global</Word>
<Word>go</Word>
<Word>goto</Word>
<Word>grant</Word>
<Word>greatest</Word>
<Word>group</Word>
<Word>grouping</Word>
<Word>having</Word>
<Word>heap</Word>
<Word>hex</Word>
<Word>hextoraw</Word>
<Word>host</Word>
<Word>host_id</Word>
<Word>host_name</Word>
<Word>hour</Word>
<Word>ident_incr</Word>
<Word>ident_seed</Word>
<Word>ident_current</Word>
<Word>identified</Word>
<Word>identity</Word>
<Word>if</Word>
<Word>ifnull</Word>
<Word>ignore</Word>
<Word>immediate</Word>
<Word>in</Word>
<Word>increment</Word>
<Word>index</Word>
<Word>index_col</Word>
<Word>indexproperty</Word>
<Word>indicator</Word>
<Word>initcap</Word>
<Word>initial</Word>
<Word>initialize</Word>
<Word>initially</Word>
<Word>inner</Word>
<Word>inout</Word>
<Word>input</Word>
<Word>insert</Word>
<Word>instr</Word>
<Word>instrb</Word>
<Word>int</Word>
<Word>integer</Word>
<Word>interface</Word>
<Word>intersect</Word>
<Word>interval</Word>
<Word>into</Word>
<Word>is</Word>
<Word>is_member</Word>
<Word>is_srvrolemember</Word>
<Word>is_null</Word>
<Word>is_numeric</Word>
<Word>isdate</Word>
<Word>isnull</Word>
<Word>isolation</Word>
<Word>iterate</Word>
<Word>java</Word>
<Word>join</Word>
<Word>key</Word>
<Word>lag</Word>
<Word>language</Word>
<Word>large</Word>
<Word>last</Word>
<Word>last_day</Word>
<Word>last_value</Word>
<Word>lateral</Word>
<Word>lcase</Word>
<Word>lead</Word>
<Word>leading</Word>
<Word>least</Word>
<Word>left</Word>
<Word>len</Word>
<Word>length</Word>
<Word>lengthb</Word>
<Word>less</Word>
<Word>level</Word>
<Word>like</Word>
<Word>limit</Word>
<Word>limited</Word>
<Word>ln</Word>
<Word>lpad</Word>
<Word>local</Word>
<Word>localtime</Word>
<Word>localtimestamp</Word>
<Word>locator</Word>
<Word>lock</Word>
<Word>log</Word>
<Word>log10</Word>
<Word>long</Word>
<Word>loop</Word>
<Word>lower</Word>
<Word>ltrim</Word>
<Word>make_ref</Word>
<Word>map</Word>
<Word>match</Word>
<Word>max</Word>
<Word>maxextents</Word>
<Word>mid</Word>
<Word>min</Word>
<Word>minus</Word>
<Word>minute</Word>
<Word>mlslabel</Word>
<Word>mod</Word>
<Word>mode</Word>
<Word>modifies</Word>
<Word>modify</Word>
<Word>module</Word>
<Word>month</Word>
<Word>months_between</Word>
<Word>names</Word>
<Word>national</Word>
<Word>natural</Word>
<Word>naturaln</Word>
<Word>nchar</Word>
<Word>nclob</Word>
<Word>new</Word>
<Word>new_time</Word>
<Word>newid</Word>
<Word>next</Word>
<Word>next_day</Word>
<Word>nextval</Word>
<Word>no</Word>
<Word>noaudit</Word>
<Word>nocompress</Word>
<Word>nocopy</Word>
<Word>nolock</Word>
<Word>none</Word>
<Word>not</Word>
<Word>nowait</Word>
<Word>null</Word>
<Word>nullif</Word>
<Word>number</Word>
<Word>number_base</Word>
<Word>numeric</Word>
<Word>nvl</Word>
<Word>nvl2</Word>
<Word>object</Word>
<Word>object_id</Word>
<Word>object_name</Word>
<Word>object_property</Word>
<Word>ocirowid</Word>
<Word>oct</Word>
<Word>of</Word>
<Word>off</Word>
<Word>offline</Word>
<Word>old</Word>
<Word>on</Word>
<Word>online</Word>
<Word>only</Word>
<Word>opaque</Word>
<Word>open</Word>
<Word>operator</Word>
<Word>operation</Word>
<Word>option</Word>
<Word>or</Word>
<Word>ord</Word>
<Word>order</Word>
<Word>ordinalityorganization</Word>
<Word>others</Word>
<Word>out</Word>
<Word>outer</Word>
<Word>output</Word>
<Word>package</Word>
<Word>pad</Word>
<Word>parameter</Word>
<Word>parameters</Word>
<Word>partial</Word>
<Word>partition</Word>
<Word>path</Word>
<Word>pctfree</Word>
<Word>percent_rank</Word>
<Word>pi</Word>
<Word>pls_integer</Word>
<Word>positive</Word>
<Word>positiven</Word>
<Word>postfix</Word>
<Word>pow</Word>
<Word>power</Word>
<Word>pragma</Word>
<Word>precision</Word>
<Word>prefix</Word>
<Word>preorder</Word>
<Word>prepare</Word>
<Word>preserve</Word>
<Word>primary</Word>
<Word>prior</Word>
<Word>private</Word>
<Word>privileges</Word>
<Word>procedure</Word>
<Word>public</Word>
<Word>radians</Word>
<Word>raise</Word>
<Word>rand</Word>
<Word>range</Word>
<Word>rank</Word>
<Word>ratio_to_export</Word>
<Word>raw</Word>
<Word>rawtohex</Word>
<Word>read</Word>
<Word>reads</Word>
<Word>real</Word>
<Word>record</Word>
<Word>recursive</Word>
<Word>ref</Word>
<Word>references</Word>
<Word>referencing</Word>
<Word>reftohex</Word>
<Word>relative</Word>
<Word>release</Word>
<Word>release_lock</Word>
<Word>rename</Word>
<Word>repeat</Word>
<Word>replace</Word>
<Word>resource</Word>
<Word>restrict</Word>
<Word>result</Word>
<Word>return</Word>
<Word>returns</Word>
<Word>reverse</Word>
<Word>revoke</Word>
<Word>right</Word>
<Word>rollback</Word>
<Word>rollup</Word>
<Word>round</Word>
<Word>routine</Word>
<Word>row</Word>
<Word>row_number</Word>
<Word>rowid</Word>
<Word>rowidtochar</Word>
<Word>rowlabel</Word>
<Word>rowlock</Word>
<Word>rownum</Word>
<Word>rows</Word>
<Word>rowtype</Word>
<Word>rpad</Word>
<Word>rtrim</Word>
<Word>savepoint</Word>
<Word>schema</Word>
<Word>scroll</Word>
<Word>scope</Word>
<Word>search</Word>
<Word>second</Word>
<Word>section</Word>
<Word>seddev_samp</Word>
<Word>select</Word>
<Word>separate</Word>
<Word>sequence</Word>
<Word>session</Word>
<Word>session_user</Word>
<Word>set</Word>
<Word>sets</Word>
<Word>share</Word>
<Word>sign</Word>
<Word>sin</Word>
<Word>sinh</Word>
<Word>size</Word>
<Word>smallint</Word>
<Word>some</Word>
<Word>soundex</Word>
<Word>space</Word>
<Word>specific</Word>
<Word>specifictype</Word>
<Word>sql</Word>
<Word>sqlcode</Word>
<Word>sqlerrm</Word>
<Word>sqlexception</Word>
<Word>sqlstate</Word>
<Word>sqlwarning</Word>
<Word>sqrt</Word>
<Word>start</Word>
<Word>state</Word>
<Word>statement</Word>
<Word>static</Word>
<Word>std</Word>
<Word>stddev</Word>
<Word>stdev_pop</Word>
<Word>strcmp</Word>
<Word>structure</Word>
<Word>subdate</Word>
<Word>substr</Word>
<Word>substrb</Word>
<Word>substring</Word>
<Word>substring_index</Word>
<Word>subtype</Word>
<Word>successful</Word>
<Word>sum</Word>
<Word>synonym</Word>
<Word>sys_context</Word>
<Word>sys_guid</Word>
<Word>sysdate</Word>
<Word>system_user</Word>
<Word>table</Word>
<Word>tan</Word>
<Word>tanh</Word>
<Word>temporary</Word>
<Word>terminate</Word>
<Word>than</Word>
<Word>then</Word>
<Word>time</Word>
<Word>timestamp</Word>
<Word>timezone_abbr</Word>
<Word>timezone_minute</Word>
<Word>timezone_hour</Word>
<Word>timezone_region</Word>
<Word>tinyint</Word>
<Word>to</Word>
<Word>to_char</Word>
<Word>to_date</Word>
<Word>to_days</Word>
<Word>to_number</Word>
<Word>to_single_byte</Word>
<Word>trailing</Word>
<Word>transaction</Word>
<Word>translate</Word>
<Word>translation</Word>
<Word>treat</Word>
<Word>trigger</Word>
<Word>trim</Word>
<Word>true</Word>
<Word>trunc</Word>
<Word>truncate</Word>
<Word>type</Word>
<Word>ucase</Word>
<Word>uid</Word>
<Word>under</Word>
<Word>union</Word>
<Word>unique</Word>
<Word>unknown</Word>
<Word>unnest</Word>
<Word>update</Word>
<Word>upper</Word>
<Word>usage</Word>
<Word>use</Word>
<Word>user</Word>
<Word>userenv</Word>
<Word>using</Word>
<Word>validate</Word>
<Word>value</Word>
<Word>values</Word>
<Word>var_pop</Word>
<Word>var_samp</Word>
<Word>varbinary</Word>
<Word>varchar</Word>
<Word>varchar2</Word>
<Word>variable</Word>
<Word>variance</Word>
<Word>varying</Word>
<Word>view</Word>
<Word>vsize</Word>
<Word>when</Word>
<Word>whenever</Word>
<Word>where</Word>
<Word>with</Word>
<Word>without</Word>
<Word>while</Word>
<Word>work</Word>
<Word>write</Word>
<Word>year</Word>
<Word>zone</Word>
</Keywords>
</RuleSet>
</SyntaxDefinition>
<MSG> Update TSQL file #125
https://github.com/icsharpcode/AvalonEdit/pull/125
<DFF> @@ -559,6 +559,7 @@
<Word>timezone_region</Word>
<Word>tinyint</Word>
<Word>to</Word>
+ <Word>top</Word>
<Word>to_char</Word>
<Word>to_date</Word>
<Word>to_days</Word>
| 1 | Update TSQL file #125 | 0 | .xshd | xshd | mit | AvaloniaUI/AvaloniaEdit |
10066923 | <NME> TSQL-Mode.xshd
<BEF> <?xml version="1.0"?>
<SyntaxDefinition name="TSQL" extensions=".sql" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
<Color name="Comment" foreground="Green" exampleText="-- comment" />
<Color name="Char" foreground="Red" exampleText="name = 'abc'"/>
<Color name="Keywords" fontWeight="bold" foreground="Blue" exampleText="SELECT FROM"/>
<Property name="DocCommentMarker" value="///" />
<RuleSet name="CommentMarkerSet">
<Keywords fontWeight="bold" foreground="Red">
<Word>TODO</Word>
<Word>FIXME</Word>
</Keywords>
<Keywords fontWeight="bold" foreground="#E0E000">
<Word>HACK</Word>
<Word>UNDONE</Word>
</Keywords>
</RuleSet>
<RuleSet ignoreCase="true">
<Span color="Comment" ruleSet="CommentMarkerSet">
<Begin>--</Begin>
</Span>
<Span color="Comment" ruleSet="CommentMarkerSet" multiline="true">
<Begin>/\*</Begin>
<End>\*/</End>
</Span>
<Span color="Char">
<Begin>'</Begin>
<End>'</End>
<RuleSet>
<Span begin="\\" end="."/>
</RuleSet>
</Span>
<Keywords color="Keywords">
<Word>abs</Word>
<Word>absolute</Word>
<Word>access</Word>
<Word>acos</Word>
<Word>add</Word>
<Word>add_months</Word>
<Word>adddate</Word>
<Word>admin</Word>
<Word>after</Word>
<Word>aggregate</Word>
<Word>all</Word>
<Word>allocate</Word>
<Word>alter</Word>
<Word>and</Word>
<Word>any</Word>
<Word>app_name</Word>
<Word>are</Word>
<Word>array</Word>
<Word>as</Word>
<Word>asc</Word>
<Word>ascii</Word>
<Word>asin</Word>
<Word>assertion</Word>
<Word>at</Word>
<Word>atan</Word>
<Word>atn2</Word>
<Word>audit</Word>
<Word>authid</Word>
<Word>authorization</Word>
<Word>autonomous_transaction</Word>
<Word>avg</Word>
<Word>before</Word>
<Word>begin</Word>
<Word>benchmark</Word>
<Word>between</Word>
<Word>bfilename</Word>
<Word>bigint</Word>
<Word>bin</Word>
<Word>binary</Word>
<Word>binary_checksum</Word>
<Word>binary_integer</Word>
<Word>bit</Word>
<Word>bit_count</Word>
<Word>bit_and</Word>
<Word>bit_or</Word>
<Word>blob</Word>
<Word>body</Word>
<Word>boolean</Word>
<Word>both</Word>
<Word>breadth</Word>
<Word>bulk</Word>
<Word>by</Word>
<Word>call</Word>
<Word>cascade</Word>
<Word>cascaded</Word>
<Word>case</Word>
<Word>cast</Word>
<Word>catalog</Word>
<Word>ceil</Word>
<Word>ceiling</Word>
<Word>char</Word>
<Word>char_base</Word>
<Word>character</Word>
<Word>charindex</Word>
<Word>chartorowid</Word>
<Word>check</Word>
<Word>checksum</Word>
<Word>checksum_agg</Word>
<Word>chr</Word>
<Word>class</Word>
<Word>clob</Word>
<Word>close</Word>
<Word>cluster</Word>
<Word>coalesce</Word>
<Word>col_length</Word>
<Word>col_name</Word>
<Word>collate</Word>
<Word>collation</Word>
<Word>collect</Word>
<Word>column</Word>
<Word>comment</Word>
<Word>commit</Word>
<Word>completion</Word>
<Word>compress</Word>
<Word>concat</Word>
<Word>concat_ws</Word>
<Word>connect</Word>
<Word>connection</Word>
<Word>constant</Word>
<Word>constraint</Word>
<Word>constraints</Word>
<Word>constructorcreate</Word>
<Word>contains</Word>
<Word>containsable</Word>
<Word>continue</Word>
<Word>conv</Word>
<Word>convert</Word>
<Word>corr</Word>
<Word>corresponding</Word>
<Word>cos</Word>
<Word>cot</Word>
<Word>count</Word>
<Word>count_big</Word>
<Word>covar_pop</Word>
<Word>covar_samp</Word>
<Word>create</Word>
<Word>cross</Word>
<Word>cube</Word>
<Word>cume_dist</Word>
<Word>current</Word>
<Word>current_date</Word>
<Word>current_path</Word>
<Word>current_role</Word>
<Word>current_time</Word>
<Word>current_timestamp</Word>
<Word>current_user</Word>
<Word>currval</Word>
<Word>cursor</Word>
<Word>cycle</Word>
<Word>data</Word>
<Word>datalength</Word>
<Word>databasepropertyex</Word>
<Word>date</Word>
<Word>date_add</Word>
<Word>date_format</Word>
<Word>date_sub</Word>
<Word>dateadd</Word>
<Word>datediff</Word>
<Word>datename</Word>
<Word>datepart</Word>
<Word>datetime</Word>
<Word>day</Word>
<Word>db_id</Word>
<Word>db_name</Word>
<Word>deallocate</Word>
<Word>dec</Word>
<Word>declare</Word>
<Word>decimal</Word>
<Word>decode</Word>
<Word>default</Word>
<Word>deferrable</Word>
<Word>deferred</Word>
<Word>degrees</Word>
<Word>delete</Word>
<Word>dense_rank</Word>
<Word>depth</Word>
<Word>deref</Word>
<Word>desc</Word>
<Word>describe</Word>
<Word>descriptor</Word>
<Word>destroy</Word>
<Word>destructor</Word>
<Word>deterministic</Word>
<Word>diagnostics</Word>
<Word>dictionary</Word>
<Word>disconnect</Word>
<Word>difference</Word>
<Word>distinct</Word>
<Word>do</Word>
<Word>domain</Word>
<Word>double</Word>
<Word>drop</Word>
<Word>dump</Word>
<Word>dynamic</Word>
<Word>each</Word>
<Word>else</Word>
<Word>elsif</Word>
<Word>empth</Word>
<Word>encode</Word>
<Word>encrypt</Word>
<Word>end</Word>
<Word>end-exec</Word>
<Word>equals</Word>
<Word>escape</Word>
<Word>every</Word>
<Word>except</Word>
<Word>exception</Word>
<Word>exclusive</Word>
<Word>exec</Word>
<Word>execute</Word>
<Word>exists</Word>
<Word>exit</Word>
<Word>exp</Word>
<Word>export_set</Word>
<Word>extends</Word>
<Word>external</Word>
<Word>extract</Word>
<Word>false</Word>
<Word>fetch</Word>
<Word>first</Word>
<Word>first_value</Word>
<Word>file</Word>
<Word>float</Word>
<Word>floor</Word>
<Word>file_id</Word>
<Word>file_name</Word>
<Word>filegroup_id</Word>
<Word>filegroup_name</Word>
<Word>filegroupproperty</Word>
<Word>fileproperty</Word>
<Word>for</Word>
<Word>forall</Word>
<Word>foreign</Word>
<Word>format</Word>
<Word>formatmessage</Word>
<Word>found</Word>
<Word>freetexttable</Word>
<Word>from</Word>
<Word>from_days</Word>
<Word>fulltextcatalog</Word>
<Word>fulltextservice</Word>
<Word>function</Word>
<Word>general</Word>
<Word>get</Word>
<Word>get_lock</Word>
<Word>getdate</Word>
<Word>getansinull</Word>
<Word>getutcdate</Word>
<Word>global</Word>
<Word>go</Word>
<Word>goto</Word>
<Word>grant</Word>
<Word>greatest</Word>
<Word>group</Word>
<Word>grouping</Word>
<Word>having</Word>
<Word>heap</Word>
<Word>hex</Word>
<Word>hextoraw</Word>
<Word>host</Word>
<Word>host_id</Word>
<Word>host_name</Word>
<Word>hour</Word>
<Word>ident_incr</Word>
<Word>ident_seed</Word>
<Word>ident_current</Word>
<Word>identified</Word>
<Word>identity</Word>
<Word>if</Word>
<Word>ifnull</Word>
<Word>ignore</Word>
<Word>immediate</Word>
<Word>in</Word>
<Word>increment</Word>
<Word>index</Word>
<Word>index_col</Word>
<Word>indexproperty</Word>
<Word>indicator</Word>
<Word>initcap</Word>
<Word>initial</Word>
<Word>initialize</Word>
<Word>initially</Word>
<Word>inner</Word>
<Word>inout</Word>
<Word>input</Word>
<Word>insert</Word>
<Word>instr</Word>
<Word>instrb</Word>
<Word>int</Word>
<Word>integer</Word>
<Word>interface</Word>
<Word>intersect</Word>
<Word>interval</Word>
<Word>into</Word>
<Word>is</Word>
<Word>is_member</Word>
<Word>is_srvrolemember</Word>
<Word>is_null</Word>
<Word>is_numeric</Word>
<Word>isdate</Word>
<Word>isnull</Word>
<Word>isolation</Word>
<Word>iterate</Word>
<Word>java</Word>
<Word>join</Word>
<Word>key</Word>
<Word>lag</Word>
<Word>language</Word>
<Word>large</Word>
<Word>last</Word>
<Word>last_day</Word>
<Word>last_value</Word>
<Word>lateral</Word>
<Word>lcase</Word>
<Word>lead</Word>
<Word>leading</Word>
<Word>least</Word>
<Word>left</Word>
<Word>len</Word>
<Word>length</Word>
<Word>lengthb</Word>
<Word>less</Word>
<Word>level</Word>
<Word>like</Word>
<Word>limit</Word>
<Word>limited</Word>
<Word>ln</Word>
<Word>lpad</Word>
<Word>local</Word>
<Word>localtime</Word>
<Word>localtimestamp</Word>
<Word>locator</Word>
<Word>lock</Word>
<Word>log</Word>
<Word>log10</Word>
<Word>long</Word>
<Word>loop</Word>
<Word>lower</Word>
<Word>ltrim</Word>
<Word>make_ref</Word>
<Word>map</Word>
<Word>match</Word>
<Word>max</Word>
<Word>maxextents</Word>
<Word>mid</Word>
<Word>min</Word>
<Word>minus</Word>
<Word>minute</Word>
<Word>mlslabel</Word>
<Word>mod</Word>
<Word>mode</Word>
<Word>modifies</Word>
<Word>modify</Word>
<Word>module</Word>
<Word>month</Word>
<Word>months_between</Word>
<Word>names</Word>
<Word>national</Word>
<Word>natural</Word>
<Word>naturaln</Word>
<Word>nchar</Word>
<Word>nclob</Word>
<Word>new</Word>
<Word>new_time</Word>
<Word>newid</Word>
<Word>next</Word>
<Word>next_day</Word>
<Word>nextval</Word>
<Word>no</Word>
<Word>noaudit</Word>
<Word>nocompress</Word>
<Word>nocopy</Word>
<Word>nolock</Word>
<Word>none</Word>
<Word>not</Word>
<Word>nowait</Word>
<Word>null</Word>
<Word>nullif</Word>
<Word>number</Word>
<Word>number_base</Word>
<Word>numeric</Word>
<Word>nvl</Word>
<Word>nvl2</Word>
<Word>object</Word>
<Word>object_id</Word>
<Word>object_name</Word>
<Word>object_property</Word>
<Word>ocirowid</Word>
<Word>oct</Word>
<Word>of</Word>
<Word>off</Word>
<Word>offline</Word>
<Word>old</Word>
<Word>on</Word>
<Word>online</Word>
<Word>only</Word>
<Word>opaque</Word>
<Word>open</Word>
<Word>operator</Word>
<Word>operation</Word>
<Word>option</Word>
<Word>or</Word>
<Word>ord</Word>
<Word>order</Word>
<Word>ordinalityorganization</Word>
<Word>others</Word>
<Word>out</Word>
<Word>outer</Word>
<Word>output</Word>
<Word>package</Word>
<Word>pad</Word>
<Word>parameter</Word>
<Word>parameters</Word>
<Word>partial</Word>
<Word>partition</Word>
<Word>path</Word>
<Word>pctfree</Word>
<Word>percent_rank</Word>
<Word>pi</Word>
<Word>pls_integer</Word>
<Word>positive</Word>
<Word>positiven</Word>
<Word>postfix</Word>
<Word>pow</Word>
<Word>power</Word>
<Word>pragma</Word>
<Word>precision</Word>
<Word>prefix</Word>
<Word>preorder</Word>
<Word>prepare</Word>
<Word>preserve</Word>
<Word>primary</Word>
<Word>prior</Word>
<Word>private</Word>
<Word>privileges</Word>
<Word>procedure</Word>
<Word>public</Word>
<Word>radians</Word>
<Word>raise</Word>
<Word>rand</Word>
<Word>range</Word>
<Word>rank</Word>
<Word>ratio_to_export</Word>
<Word>raw</Word>
<Word>rawtohex</Word>
<Word>read</Word>
<Word>reads</Word>
<Word>real</Word>
<Word>record</Word>
<Word>recursive</Word>
<Word>ref</Word>
<Word>references</Word>
<Word>referencing</Word>
<Word>reftohex</Word>
<Word>relative</Word>
<Word>release</Word>
<Word>release_lock</Word>
<Word>rename</Word>
<Word>repeat</Word>
<Word>replace</Word>
<Word>resource</Word>
<Word>restrict</Word>
<Word>result</Word>
<Word>return</Word>
<Word>returns</Word>
<Word>reverse</Word>
<Word>revoke</Word>
<Word>right</Word>
<Word>rollback</Word>
<Word>rollup</Word>
<Word>round</Word>
<Word>routine</Word>
<Word>row</Word>
<Word>row_number</Word>
<Word>rowid</Word>
<Word>rowidtochar</Word>
<Word>rowlabel</Word>
<Word>rowlock</Word>
<Word>rownum</Word>
<Word>rows</Word>
<Word>rowtype</Word>
<Word>rpad</Word>
<Word>rtrim</Word>
<Word>savepoint</Word>
<Word>schema</Word>
<Word>scroll</Word>
<Word>scope</Word>
<Word>search</Word>
<Word>second</Word>
<Word>section</Word>
<Word>seddev_samp</Word>
<Word>select</Word>
<Word>separate</Word>
<Word>sequence</Word>
<Word>session</Word>
<Word>session_user</Word>
<Word>set</Word>
<Word>sets</Word>
<Word>share</Word>
<Word>sign</Word>
<Word>sin</Word>
<Word>sinh</Word>
<Word>size</Word>
<Word>smallint</Word>
<Word>some</Word>
<Word>soundex</Word>
<Word>space</Word>
<Word>specific</Word>
<Word>specifictype</Word>
<Word>sql</Word>
<Word>sqlcode</Word>
<Word>sqlerrm</Word>
<Word>sqlexception</Word>
<Word>sqlstate</Word>
<Word>sqlwarning</Word>
<Word>sqrt</Word>
<Word>start</Word>
<Word>state</Word>
<Word>statement</Word>
<Word>static</Word>
<Word>std</Word>
<Word>stddev</Word>
<Word>stdev_pop</Word>
<Word>strcmp</Word>
<Word>structure</Word>
<Word>subdate</Word>
<Word>substr</Word>
<Word>substrb</Word>
<Word>substring</Word>
<Word>substring_index</Word>
<Word>subtype</Word>
<Word>successful</Word>
<Word>sum</Word>
<Word>synonym</Word>
<Word>sys_context</Word>
<Word>sys_guid</Word>
<Word>sysdate</Word>
<Word>system_user</Word>
<Word>table</Word>
<Word>tan</Word>
<Word>tanh</Word>
<Word>temporary</Word>
<Word>terminate</Word>
<Word>than</Word>
<Word>then</Word>
<Word>time</Word>
<Word>timestamp</Word>
<Word>timezone_abbr</Word>
<Word>timezone_minute</Word>
<Word>timezone_hour</Word>
<Word>timezone_region</Word>
<Word>tinyint</Word>
<Word>to</Word>
<Word>to_char</Word>
<Word>to_date</Word>
<Word>to_days</Word>
<Word>to_number</Word>
<Word>to_single_byte</Word>
<Word>trailing</Word>
<Word>transaction</Word>
<Word>translate</Word>
<Word>translation</Word>
<Word>treat</Word>
<Word>trigger</Word>
<Word>trim</Word>
<Word>true</Word>
<Word>trunc</Word>
<Word>truncate</Word>
<Word>type</Word>
<Word>ucase</Word>
<Word>uid</Word>
<Word>under</Word>
<Word>union</Word>
<Word>unique</Word>
<Word>unknown</Word>
<Word>unnest</Word>
<Word>update</Word>
<Word>upper</Word>
<Word>usage</Word>
<Word>use</Word>
<Word>user</Word>
<Word>userenv</Word>
<Word>using</Word>
<Word>validate</Word>
<Word>value</Word>
<Word>values</Word>
<Word>var_pop</Word>
<Word>var_samp</Word>
<Word>varbinary</Word>
<Word>varchar</Word>
<Word>varchar2</Word>
<Word>variable</Word>
<Word>variance</Word>
<Word>varying</Word>
<Word>view</Word>
<Word>vsize</Word>
<Word>when</Word>
<Word>whenever</Word>
<Word>where</Word>
<Word>with</Word>
<Word>without</Word>
<Word>while</Word>
<Word>work</Word>
<Word>write</Word>
<Word>year</Word>
<Word>zone</Word>
</Keywords>
</RuleSet>
</SyntaxDefinition>
<MSG> Update TSQL file #125
https://github.com/icsharpcode/AvalonEdit/pull/125
<DFF> @@ -559,6 +559,7 @@
<Word>timezone_region</Word>
<Word>tinyint</Word>
<Word>to</Word>
+ <Word>top</Word>
<Word>to_char</Word>
<Word>to_date</Word>
<Word>to_days</Word>
| 1 | Update TSQL file #125 | 0 | .xshd | xshd | mit | AvaloniaUI/AvaloniaEdit |
10066924 | <NME> TSQL-Mode.xshd
<BEF> <?xml version="1.0"?>
<SyntaxDefinition name="TSQL" extensions=".sql" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
<Color name="Comment" foreground="Green" exampleText="-- comment" />
<Color name="Char" foreground="Red" exampleText="name = 'abc'"/>
<Color name="Keywords" fontWeight="bold" foreground="Blue" exampleText="SELECT FROM"/>
<Property name="DocCommentMarker" value="///" />
<RuleSet name="CommentMarkerSet">
<Keywords fontWeight="bold" foreground="Red">
<Word>TODO</Word>
<Word>FIXME</Word>
</Keywords>
<Keywords fontWeight="bold" foreground="#E0E000">
<Word>HACK</Word>
<Word>UNDONE</Word>
</Keywords>
</RuleSet>
<RuleSet ignoreCase="true">
<Span color="Comment" ruleSet="CommentMarkerSet">
<Begin>--</Begin>
</Span>
<Span color="Comment" ruleSet="CommentMarkerSet" multiline="true">
<Begin>/\*</Begin>
<End>\*/</End>
</Span>
<Span color="Char">
<Begin>'</Begin>
<End>'</End>
<RuleSet>
<Span begin="\\" end="."/>
</RuleSet>
</Span>
<Keywords color="Keywords">
<Word>abs</Word>
<Word>absolute</Word>
<Word>access</Word>
<Word>acos</Word>
<Word>add</Word>
<Word>add_months</Word>
<Word>adddate</Word>
<Word>admin</Word>
<Word>after</Word>
<Word>aggregate</Word>
<Word>all</Word>
<Word>allocate</Word>
<Word>alter</Word>
<Word>and</Word>
<Word>any</Word>
<Word>app_name</Word>
<Word>are</Word>
<Word>array</Word>
<Word>as</Word>
<Word>asc</Word>
<Word>ascii</Word>
<Word>asin</Word>
<Word>assertion</Word>
<Word>at</Word>
<Word>atan</Word>
<Word>atn2</Word>
<Word>audit</Word>
<Word>authid</Word>
<Word>authorization</Word>
<Word>autonomous_transaction</Word>
<Word>avg</Word>
<Word>before</Word>
<Word>begin</Word>
<Word>benchmark</Word>
<Word>between</Word>
<Word>bfilename</Word>
<Word>bigint</Word>
<Word>bin</Word>
<Word>binary</Word>
<Word>binary_checksum</Word>
<Word>binary_integer</Word>
<Word>bit</Word>
<Word>bit_count</Word>
<Word>bit_and</Word>
<Word>bit_or</Word>
<Word>blob</Word>
<Word>body</Word>
<Word>boolean</Word>
<Word>both</Word>
<Word>breadth</Word>
<Word>bulk</Word>
<Word>by</Word>
<Word>call</Word>
<Word>cascade</Word>
<Word>cascaded</Word>
<Word>case</Word>
<Word>cast</Word>
<Word>catalog</Word>
<Word>ceil</Word>
<Word>ceiling</Word>
<Word>char</Word>
<Word>char_base</Word>
<Word>character</Word>
<Word>charindex</Word>
<Word>chartorowid</Word>
<Word>check</Word>
<Word>checksum</Word>
<Word>checksum_agg</Word>
<Word>chr</Word>
<Word>class</Word>
<Word>clob</Word>
<Word>close</Word>
<Word>cluster</Word>
<Word>coalesce</Word>
<Word>col_length</Word>
<Word>col_name</Word>
<Word>collate</Word>
<Word>collation</Word>
<Word>collect</Word>
<Word>column</Word>
<Word>comment</Word>
<Word>commit</Word>
<Word>completion</Word>
<Word>compress</Word>
<Word>concat</Word>
<Word>concat_ws</Word>
<Word>connect</Word>
<Word>connection</Word>
<Word>constant</Word>
<Word>constraint</Word>
<Word>constraints</Word>
<Word>constructorcreate</Word>
<Word>contains</Word>
<Word>containsable</Word>
<Word>continue</Word>
<Word>conv</Word>
<Word>convert</Word>
<Word>corr</Word>
<Word>corresponding</Word>
<Word>cos</Word>
<Word>cot</Word>
<Word>count</Word>
<Word>count_big</Word>
<Word>covar_pop</Word>
<Word>covar_samp</Word>
<Word>create</Word>
<Word>cross</Word>
<Word>cube</Word>
<Word>cume_dist</Word>
<Word>current</Word>
<Word>current_date</Word>
<Word>current_path</Word>
<Word>current_role</Word>
<Word>current_time</Word>
<Word>current_timestamp</Word>
<Word>current_user</Word>
<Word>currval</Word>
<Word>cursor</Word>
<Word>cycle</Word>
<Word>data</Word>
<Word>datalength</Word>
<Word>databasepropertyex</Word>
<Word>date</Word>
<Word>date_add</Word>
<Word>date_format</Word>
<Word>date_sub</Word>
<Word>dateadd</Word>
<Word>datediff</Word>
<Word>datename</Word>
<Word>datepart</Word>
<Word>datetime</Word>
<Word>day</Word>
<Word>db_id</Word>
<Word>db_name</Word>
<Word>deallocate</Word>
<Word>dec</Word>
<Word>declare</Word>
<Word>decimal</Word>
<Word>decode</Word>
<Word>default</Word>
<Word>deferrable</Word>
<Word>deferred</Word>
<Word>degrees</Word>
<Word>delete</Word>
<Word>dense_rank</Word>
<Word>depth</Word>
<Word>deref</Word>
<Word>desc</Word>
<Word>describe</Word>
<Word>descriptor</Word>
<Word>destroy</Word>
<Word>destructor</Word>
<Word>deterministic</Word>
<Word>diagnostics</Word>
<Word>dictionary</Word>
<Word>disconnect</Word>
<Word>difference</Word>
<Word>distinct</Word>
<Word>do</Word>
<Word>domain</Word>
<Word>double</Word>
<Word>drop</Word>
<Word>dump</Word>
<Word>dynamic</Word>
<Word>each</Word>
<Word>else</Word>
<Word>elsif</Word>
<Word>empth</Word>
<Word>encode</Word>
<Word>encrypt</Word>
<Word>end</Word>
<Word>end-exec</Word>
<Word>equals</Word>
<Word>escape</Word>
<Word>every</Word>
<Word>except</Word>
<Word>exception</Word>
<Word>exclusive</Word>
<Word>exec</Word>
<Word>execute</Word>
<Word>exists</Word>
<Word>exit</Word>
<Word>exp</Word>
<Word>export_set</Word>
<Word>extends</Word>
<Word>external</Word>
<Word>extract</Word>
<Word>false</Word>
<Word>fetch</Word>
<Word>first</Word>
<Word>first_value</Word>
<Word>file</Word>
<Word>float</Word>
<Word>floor</Word>
<Word>file_id</Word>
<Word>file_name</Word>
<Word>filegroup_id</Word>
<Word>filegroup_name</Word>
<Word>filegroupproperty</Word>
<Word>fileproperty</Word>
<Word>for</Word>
<Word>forall</Word>
<Word>foreign</Word>
<Word>format</Word>
<Word>formatmessage</Word>
<Word>found</Word>
<Word>freetexttable</Word>
<Word>from</Word>
<Word>from_days</Word>
<Word>fulltextcatalog</Word>
<Word>fulltextservice</Word>
<Word>function</Word>
<Word>general</Word>
<Word>get</Word>
<Word>get_lock</Word>
<Word>getdate</Word>
<Word>getansinull</Word>
<Word>getutcdate</Word>
<Word>global</Word>
<Word>go</Word>
<Word>goto</Word>
<Word>grant</Word>
<Word>greatest</Word>
<Word>group</Word>
<Word>grouping</Word>
<Word>having</Word>
<Word>heap</Word>
<Word>hex</Word>
<Word>hextoraw</Word>
<Word>host</Word>
<Word>host_id</Word>
<Word>host_name</Word>
<Word>hour</Word>
<Word>ident_incr</Word>
<Word>ident_seed</Word>
<Word>ident_current</Word>
<Word>identified</Word>
<Word>identity</Word>
<Word>if</Word>
<Word>ifnull</Word>
<Word>ignore</Word>
<Word>immediate</Word>
<Word>in</Word>
<Word>increment</Word>
<Word>index</Word>
<Word>index_col</Word>
<Word>indexproperty</Word>
<Word>indicator</Word>
<Word>initcap</Word>
<Word>initial</Word>
<Word>initialize</Word>
<Word>initially</Word>
<Word>inner</Word>
<Word>inout</Word>
<Word>input</Word>
<Word>insert</Word>
<Word>instr</Word>
<Word>instrb</Word>
<Word>int</Word>
<Word>integer</Word>
<Word>interface</Word>
<Word>intersect</Word>
<Word>interval</Word>
<Word>into</Word>
<Word>is</Word>
<Word>is_member</Word>
<Word>is_srvrolemember</Word>
<Word>is_null</Word>
<Word>is_numeric</Word>
<Word>isdate</Word>
<Word>isnull</Word>
<Word>isolation</Word>
<Word>iterate</Word>
<Word>java</Word>
<Word>join</Word>
<Word>key</Word>
<Word>lag</Word>
<Word>language</Word>
<Word>large</Word>
<Word>last</Word>
<Word>last_day</Word>
<Word>last_value</Word>
<Word>lateral</Word>
<Word>lcase</Word>
<Word>lead</Word>
<Word>leading</Word>
<Word>least</Word>
<Word>left</Word>
<Word>len</Word>
<Word>length</Word>
<Word>lengthb</Word>
<Word>less</Word>
<Word>level</Word>
<Word>like</Word>
<Word>limit</Word>
<Word>limited</Word>
<Word>ln</Word>
<Word>lpad</Word>
<Word>local</Word>
<Word>localtime</Word>
<Word>localtimestamp</Word>
<Word>locator</Word>
<Word>lock</Word>
<Word>log</Word>
<Word>log10</Word>
<Word>long</Word>
<Word>loop</Word>
<Word>lower</Word>
<Word>ltrim</Word>
<Word>make_ref</Word>
<Word>map</Word>
<Word>match</Word>
<Word>max</Word>
<Word>maxextents</Word>
<Word>mid</Word>
<Word>min</Word>
<Word>minus</Word>
<Word>minute</Word>
<Word>mlslabel</Word>
<Word>mod</Word>
<Word>mode</Word>
<Word>modifies</Word>
<Word>modify</Word>
<Word>module</Word>
<Word>month</Word>
<Word>months_between</Word>
<Word>names</Word>
<Word>national</Word>
<Word>natural</Word>
<Word>naturaln</Word>
<Word>nchar</Word>
<Word>nclob</Word>
<Word>new</Word>
<Word>new_time</Word>
<Word>newid</Word>
<Word>next</Word>
<Word>next_day</Word>
<Word>nextval</Word>
<Word>no</Word>
<Word>noaudit</Word>
<Word>nocompress</Word>
<Word>nocopy</Word>
<Word>nolock</Word>
<Word>none</Word>
<Word>not</Word>
<Word>nowait</Word>
<Word>null</Word>
<Word>nullif</Word>
<Word>number</Word>
<Word>number_base</Word>
<Word>numeric</Word>
<Word>nvl</Word>
<Word>nvl2</Word>
<Word>object</Word>
<Word>object_id</Word>
<Word>object_name</Word>
<Word>object_property</Word>
<Word>ocirowid</Word>
<Word>oct</Word>
<Word>of</Word>
<Word>off</Word>
<Word>offline</Word>
<Word>old</Word>
<Word>on</Word>
<Word>online</Word>
<Word>only</Word>
<Word>opaque</Word>
<Word>open</Word>
<Word>operator</Word>
<Word>operation</Word>
<Word>option</Word>
<Word>or</Word>
<Word>ord</Word>
<Word>order</Word>
<Word>ordinalityorganization</Word>
<Word>others</Word>
<Word>out</Word>
<Word>outer</Word>
<Word>output</Word>
<Word>package</Word>
<Word>pad</Word>
<Word>parameter</Word>
<Word>parameters</Word>
<Word>partial</Word>
<Word>partition</Word>
<Word>path</Word>
<Word>pctfree</Word>
<Word>percent_rank</Word>
<Word>pi</Word>
<Word>pls_integer</Word>
<Word>positive</Word>
<Word>positiven</Word>
<Word>postfix</Word>
<Word>pow</Word>
<Word>power</Word>
<Word>pragma</Word>
<Word>precision</Word>
<Word>prefix</Word>
<Word>preorder</Word>
<Word>prepare</Word>
<Word>preserve</Word>
<Word>primary</Word>
<Word>prior</Word>
<Word>private</Word>
<Word>privileges</Word>
<Word>procedure</Word>
<Word>public</Word>
<Word>radians</Word>
<Word>raise</Word>
<Word>rand</Word>
<Word>range</Word>
<Word>rank</Word>
<Word>ratio_to_export</Word>
<Word>raw</Word>
<Word>rawtohex</Word>
<Word>read</Word>
<Word>reads</Word>
<Word>real</Word>
<Word>record</Word>
<Word>recursive</Word>
<Word>ref</Word>
<Word>references</Word>
<Word>referencing</Word>
<Word>reftohex</Word>
<Word>relative</Word>
<Word>release</Word>
<Word>release_lock</Word>
<Word>rename</Word>
<Word>repeat</Word>
<Word>replace</Word>
<Word>resource</Word>
<Word>restrict</Word>
<Word>result</Word>
<Word>return</Word>
<Word>returns</Word>
<Word>reverse</Word>
<Word>revoke</Word>
<Word>right</Word>
<Word>rollback</Word>
<Word>rollup</Word>
<Word>round</Word>
<Word>routine</Word>
<Word>row</Word>
<Word>row_number</Word>
<Word>rowid</Word>
<Word>rowidtochar</Word>
<Word>rowlabel</Word>
<Word>rowlock</Word>
<Word>rownum</Word>
<Word>rows</Word>
<Word>rowtype</Word>
<Word>rpad</Word>
<Word>rtrim</Word>
<Word>savepoint</Word>
<Word>schema</Word>
<Word>scroll</Word>
<Word>scope</Word>
<Word>search</Word>
<Word>second</Word>
<Word>section</Word>
<Word>seddev_samp</Word>
<Word>select</Word>
<Word>separate</Word>
<Word>sequence</Word>
<Word>session</Word>
<Word>session_user</Word>
<Word>set</Word>
<Word>sets</Word>
<Word>share</Word>
<Word>sign</Word>
<Word>sin</Word>
<Word>sinh</Word>
<Word>size</Word>
<Word>smallint</Word>
<Word>some</Word>
<Word>soundex</Word>
<Word>space</Word>
<Word>specific</Word>
<Word>specifictype</Word>
<Word>sql</Word>
<Word>sqlcode</Word>
<Word>sqlerrm</Word>
<Word>sqlexception</Word>
<Word>sqlstate</Word>
<Word>sqlwarning</Word>
<Word>sqrt</Word>
<Word>start</Word>
<Word>state</Word>
<Word>statement</Word>
<Word>static</Word>
<Word>std</Word>
<Word>stddev</Word>
<Word>stdev_pop</Word>
<Word>strcmp</Word>
<Word>structure</Word>
<Word>subdate</Word>
<Word>substr</Word>
<Word>substrb</Word>
<Word>substring</Word>
<Word>substring_index</Word>
<Word>subtype</Word>
<Word>successful</Word>
<Word>sum</Word>
<Word>synonym</Word>
<Word>sys_context</Word>
<Word>sys_guid</Word>
<Word>sysdate</Word>
<Word>system_user</Word>
<Word>table</Word>
<Word>tan</Word>
<Word>tanh</Word>
<Word>temporary</Word>
<Word>terminate</Word>
<Word>than</Word>
<Word>then</Word>
<Word>time</Word>
<Word>timestamp</Word>
<Word>timezone_abbr</Word>
<Word>timezone_minute</Word>
<Word>timezone_hour</Word>
<Word>timezone_region</Word>
<Word>tinyint</Word>
<Word>to</Word>
<Word>to_char</Word>
<Word>to_date</Word>
<Word>to_days</Word>
<Word>to_number</Word>
<Word>to_single_byte</Word>
<Word>trailing</Word>
<Word>transaction</Word>
<Word>translate</Word>
<Word>translation</Word>
<Word>treat</Word>
<Word>trigger</Word>
<Word>trim</Word>
<Word>true</Word>
<Word>trunc</Word>
<Word>truncate</Word>
<Word>type</Word>
<Word>ucase</Word>
<Word>uid</Word>
<Word>under</Word>
<Word>union</Word>
<Word>unique</Word>
<Word>unknown</Word>
<Word>unnest</Word>
<Word>update</Word>
<Word>upper</Word>
<Word>usage</Word>
<Word>use</Word>
<Word>user</Word>
<Word>userenv</Word>
<Word>using</Word>
<Word>validate</Word>
<Word>value</Word>
<Word>values</Word>
<Word>var_pop</Word>
<Word>var_samp</Word>
<Word>varbinary</Word>
<Word>varchar</Word>
<Word>varchar2</Word>
<Word>variable</Word>
<Word>variance</Word>
<Word>varying</Word>
<Word>view</Word>
<Word>vsize</Word>
<Word>when</Word>
<Word>whenever</Word>
<Word>where</Word>
<Word>with</Word>
<Word>without</Word>
<Word>while</Word>
<Word>work</Word>
<Word>write</Word>
<Word>year</Word>
<Word>zone</Word>
</Keywords>
</RuleSet>
</SyntaxDefinition>
<MSG> Update TSQL file #125
https://github.com/icsharpcode/AvalonEdit/pull/125
<DFF> @@ -559,6 +559,7 @@
<Word>timezone_region</Word>
<Word>tinyint</Word>
<Word>to</Word>
+ <Word>top</Word>
<Word>to_char</Word>
<Word>to_date</Word>
<Word>to_days</Word>
| 1 | Update TSQL file #125 | 0 | .xshd | xshd | mit | AvaloniaUI/AvaloniaEdit |
10066925 | <NME> TSQL-Mode.xshd
<BEF> <?xml version="1.0"?>
<SyntaxDefinition name="TSQL" extensions=".sql" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
<Color name="Comment" foreground="Green" exampleText="-- comment" />
<Color name="Char" foreground="Red" exampleText="name = 'abc'"/>
<Color name="Keywords" fontWeight="bold" foreground="Blue" exampleText="SELECT FROM"/>
<Property name="DocCommentMarker" value="///" />
<RuleSet name="CommentMarkerSet">
<Keywords fontWeight="bold" foreground="Red">
<Word>TODO</Word>
<Word>FIXME</Word>
</Keywords>
<Keywords fontWeight="bold" foreground="#E0E000">
<Word>HACK</Word>
<Word>UNDONE</Word>
</Keywords>
</RuleSet>
<RuleSet ignoreCase="true">
<Span color="Comment" ruleSet="CommentMarkerSet">
<Begin>--</Begin>
</Span>
<Span color="Comment" ruleSet="CommentMarkerSet" multiline="true">
<Begin>/\*</Begin>
<End>\*/</End>
</Span>
<Span color="Char">
<Begin>'</Begin>
<End>'</End>
<RuleSet>
<Span begin="\\" end="."/>
</RuleSet>
</Span>
<Keywords color="Keywords">
<Word>abs</Word>
<Word>absolute</Word>
<Word>access</Word>
<Word>acos</Word>
<Word>add</Word>
<Word>add_months</Word>
<Word>adddate</Word>
<Word>admin</Word>
<Word>after</Word>
<Word>aggregate</Word>
<Word>all</Word>
<Word>allocate</Word>
<Word>alter</Word>
<Word>and</Word>
<Word>any</Word>
<Word>app_name</Word>
<Word>are</Word>
<Word>array</Word>
<Word>as</Word>
<Word>asc</Word>
<Word>ascii</Word>
<Word>asin</Word>
<Word>assertion</Word>
<Word>at</Word>
<Word>atan</Word>
<Word>atn2</Word>
<Word>audit</Word>
<Word>authid</Word>
<Word>authorization</Word>
<Word>autonomous_transaction</Word>
<Word>avg</Word>
<Word>before</Word>
<Word>begin</Word>
<Word>benchmark</Word>
<Word>between</Word>
<Word>bfilename</Word>
<Word>bigint</Word>
<Word>bin</Word>
<Word>binary</Word>
<Word>binary_checksum</Word>
<Word>binary_integer</Word>
<Word>bit</Word>
<Word>bit_count</Word>
<Word>bit_and</Word>
<Word>bit_or</Word>
<Word>blob</Word>
<Word>body</Word>
<Word>boolean</Word>
<Word>both</Word>
<Word>breadth</Word>
<Word>bulk</Word>
<Word>by</Word>
<Word>call</Word>
<Word>cascade</Word>
<Word>cascaded</Word>
<Word>case</Word>
<Word>cast</Word>
<Word>catalog</Word>
<Word>ceil</Word>
<Word>ceiling</Word>
<Word>char</Word>
<Word>char_base</Word>
<Word>character</Word>
<Word>charindex</Word>
<Word>chartorowid</Word>
<Word>check</Word>
<Word>checksum</Word>
<Word>checksum_agg</Word>
<Word>chr</Word>
<Word>class</Word>
<Word>clob</Word>
<Word>close</Word>
<Word>cluster</Word>
<Word>coalesce</Word>
<Word>col_length</Word>
<Word>col_name</Word>
<Word>collate</Word>
<Word>collation</Word>
<Word>collect</Word>
<Word>column</Word>
<Word>comment</Word>
<Word>commit</Word>
<Word>completion</Word>
<Word>compress</Word>
<Word>concat</Word>
<Word>concat_ws</Word>
<Word>connect</Word>
<Word>connection</Word>
<Word>constant</Word>
<Word>constraint</Word>
<Word>constraints</Word>
<Word>constructorcreate</Word>
<Word>contains</Word>
<Word>containsable</Word>
<Word>continue</Word>
<Word>conv</Word>
<Word>convert</Word>
<Word>corr</Word>
<Word>corresponding</Word>
<Word>cos</Word>
<Word>cot</Word>
<Word>count</Word>
<Word>count_big</Word>
<Word>covar_pop</Word>
<Word>covar_samp</Word>
<Word>create</Word>
<Word>cross</Word>
<Word>cube</Word>
<Word>cume_dist</Word>
<Word>current</Word>
<Word>current_date</Word>
<Word>current_path</Word>
<Word>current_role</Word>
<Word>current_time</Word>
<Word>current_timestamp</Word>
<Word>current_user</Word>
<Word>currval</Word>
<Word>cursor</Word>
<Word>cycle</Word>
<Word>data</Word>
<Word>datalength</Word>
<Word>databasepropertyex</Word>
<Word>date</Word>
<Word>date_add</Word>
<Word>date_format</Word>
<Word>date_sub</Word>
<Word>dateadd</Word>
<Word>datediff</Word>
<Word>datename</Word>
<Word>datepart</Word>
<Word>datetime</Word>
<Word>day</Word>
<Word>db_id</Word>
<Word>db_name</Word>
<Word>deallocate</Word>
<Word>dec</Word>
<Word>declare</Word>
<Word>decimal</Word>
<Word>decode</Word>
<Word>default</Word>
<Word>deferrable</Word>
<Word>deferred</Word>
<Word>degrees</Word>
<Word>delete</Word>
<Word>dense_rank</Word>
<Word>depth</Word>
<Word>deref</Word>
<Word>desc</Word>
<Word>describe</Word>
<Word>descriptor</Word>
<Word>destroy</Word>
<Word>destructor</Word>
<Word>deterministic</Word>
<Word>diagnostics</Word>
<Word>dictionary</Word>
<Word>disconnect</Word>
<Word>difference</Word>
<Word>distinct</Word>
<Word>do</Word>
<Word>domain</Word>
<Word>double</Word>
<Word>drop</Word>
<Word>dump</Word>
<Word>dynamic</Word>
<Word>each</Word>
<Word>else</Word>
<Word>elsif</Word>
<Word>empth</Word>
<Word>encode</Word>
<Word>encrypt</Word>
<Word>end</Word>
<Word>end-exec</Word>
<Word>equals</Word>
<Word>escape</Word>
<Word>every</Word>
<Word>except</Word>
<Word>exception</Word>
<Word>exclusive</Word>
<Word>exec</Word>
<Word>execute</Word>
<Word>exists</Word>
<Word>exit</Word>
<Word>exp</Word>
<Word>export_set</Word>
<Word>extends</Word>
<Word>external</Word>
<Word>extract</Word>
<Word>false</Word>
<Word>fetch</Word>
<Word>first</Word>
<Word>first_value</Word>
<Word>file</Word>
<Word>float</Word>
<Word>floor</Word>
<Word>file_id</Word>
<Word>file_name</Word>
<Word>filegroup_id</Word>
<Word>filegroup_name</Word>
<Word>filegroupproperty</Word>
<Word>fileproperty</Word>
<Word>for</Word>
<Word>forall</Word>
<Word>foreign</Word>
<Word>format</Word>
<Word>formatmessage</Word>
<Word>found</Word>
<Word>freetexttable</Word>
<Word>from</Word>
<Word>from_days</Word>
<Word>fulltextcatalog</Word>
<Word>fulltextservice</Word>
<Word>function</Word>
<Word>general</Word>
<Word>get</Word>
<Word>get_lock</Word>
<Word>getdate</Word>
<Word>getansinull</Word>
<Word>getutcdate</Word>
<Word>global</Word>
<Word>go</Word>
<Word>goto</Word>
<Word>grant</Word>
<Word>greatest</Word>
<Word>group</Word>
<Word>grouping</Word>
<Word>having</Word>
<Word>heap</Word>
<Word>hex</Word>
<Word>hextoraw</Word>
<Word>host</Word>
<Word>host_id</Word>
<Word>host_name</Word>
<Word>hour</Word>
<Word>ident_incr</Word>
<Word>ident_seed</Word>
<Word>ident_current</Word>
<Word>identified</Word>
<Word>identity</Word>
<Word>if</Word>
<Word>ifnull</Word>
<Word>ignore</Word>
<Word>immediate</Word>
<Word>in</Word>
<Word>increment</Word>
<Word>index</Word>
<Word>index_col</Word>
<Word>indexproperty</Word>
<Word>indicator</Word>
<Word>initcap</Word>
<Word>initial</Word>
<Word>initialize</Word>
<Word>initially</Word>
<Word>inner</Word>
<Word>inout</Word>
<Word>input</Word>
<Word>insert</Word>
<Word>instr</Word>
<Word>instrb</Word>
<Word>int</Word>
<Word>integer</Word>
<Word>interface</Word>
<Word>intersect</Word>
<Word>interval</Word>
<Word>into</Word>
<Word>is</Word>
<Word>is_member</Word>
<Word>is_srvrolemember</Word>
<Word>is_null</Word>
<Word>is_numeric</Word>
<Word>isdate</Word>
<Word>isnull</Word>
<Word>isolation</Word>
<Word>iterate</Word>
<Word>java</Word>
<Word>join</Word>
<Word>key</Word>
<Word>lag</Word>
<Word>language</Word>
<Word>large</Word>
<Word>last</Word>
<Word>last_day</Word>
<Word>last_value</Word>
<Word>lateral</Word>
<Word>lcase</Word>
<Word>lead</Word>
<Word>leading</Word>
<Word>least</Word>
<Word>left</Word>
<Word>len</Word>
<Word>length</Word>
<Word>lengthb</Word>
<Word>less</Word>
<Word>level</Word>
<Word>like</Word>
<Word>limit</Word>
<Word>limited</Word>
<Word>ln</Word>
<Word>lpad</Word>
<Word>local</Word>
<Word>localtime</Word>
<Word>localtimestamp</Word>
<Word>locator</Word>
<Word>lock</Word>
<Word>log</Word>
<Word>log10</Word>
<Word>long</Word>
<Word>loop</Word>
<Word>lower</Word>
<Word>ltrim</Word>
<Word>make_ref</Word>
<Word>map</Word>
<Word>match</Word>
<Word>max</Word>
<Word>maxextents</Word>
<Word>mid</Word>
<Word>min</Word>
<Word>minus</Word>
<Word>minute</Word>
<Word>mlslabel</Word>
<Word>mod</Word>
<Word>mode</Word>
<Word>modifies</Word>
<Word>modify</Word>
<Word>module</Word>
<Word>month</Word>
<Word>months_between</Word>
<Word>names</Word>
<Word>national</Word>
<Word>natural</Word>
<Word>naturaln</Word>
<Word>nchar</Word>
<Word>nclob</Word>
<Word>new</Word>
<Word>new_time</Word>
<Word>newid</Word>
<Word>next</Word>
<Word>next_day</Word>
<Word>nextval</Word>
<Word>no</Word>
<Word>noaudit</Word>
<Word>nocompress</Word>
<Word>nocopy</Word>
<Word>nolock</Word>
<Word>none</Word>
<Word>not</Word>
<Word>nowait</Word>
<Word>null</Word>
<Word>nullif</Word>
<Word>number</Word>
<Word>number_base</Word>
<Word>numeric</Word>
<Word>nvl</Word>
<Word>nvl2</Word>
<Word>object</Word>
<Word>object_id</Word>
<Word>object_name</Word>
<Word>object_property</Word>
<Word>ocirowid</Word>
<Word>oct</Word>
<Word>of</Word>
<Word>off</Word>
<Word>offline</Word>
<Word>old</Word>
<Word>on</Word>
<Word>online</Word>
<Word>only</Word>
<Word>opaque</Word>
<Word>open</Word>
<Word>operator</Word>
<Word>operation</Word>
<Word>option</Word>
<Word>or</Word>
<Word>ord</Word>
<Word>order</Word>
<Word>ordinalityorganization</Word>
<Word>others</Word>
<Word>out</Word>
<Word>outer</Word>
<Word>output</Word>
<Word>package</Word>
<Word>pad</Word>
<Word>parameter</Word>
<Word>parameters</Word>
<Word>partial</Word>
<Word>partition</Word>
<Word>path</Word>
<Word>pctfree</Word>
<Word>percent_rank</Word>
<Word>pi</Word>
<Word>pls_integer</Word>
<Word>positive</Word>
<Word>positiven</Word>
<Word>postfix</Word>
<Word>pow</Word>
<Word>power</Word>
<Word>pragma</Word>
<Word>precision</Word>
<Word>prefix</Word>
<Word>preorder</Word>
<Word>prepare</Word>
<Word>preserve</Word>
<Word>primary</Word>
<Word>prior</Word>
<Word>private</Word>
<Word>privileges</Word>
<Word>procedure</Word>
<Word>public</Word>
<Word>radians</Word>
<Word>raise</Word>
<Word>rand</Word>
<Word>range</Word>
<Word>rank</Word>
<Word>ratio_to_export</Word>
<Word>raw</Word>
<Word>rawtohex</Word>
<Word>read</Word>
<Word>reads</Word>
<Word>real</Word>
<Word>record</Word>
<Word>recursive</Word>
<Word>ref</Word>
<Word>references</Word>
<Word>referencing</Word>
<Word>reftohex</Word>
<Word>relative</Word>
<Word>release</Word>
<Word>release_lock</Word>
<Word>rename</Word>
<Word>repeat</Word>
<Word>replace</Word>
<Word>resource</Word>
<Word>restrict</Word>
<Word>result</Word>
<Word>return</Word>
<Word>returns</Word>
<Word>reverse</Word>
<Word>revoke</Word>
<Word>right</Word>
<Word>rollback</Word>
<Word>rollup</Word>
<Word>round</Word>
<Word>routine</Word>
<Word>row</Word>
<Word>row_number</Word>
<Word>rowid</Word>
<Word>rowidtochar</Word>
<Word>rowlabel</Word>
<Word>rowlock</Word>
<Word>rownum</Word>
<Word>rows</Word>
<Word>rowtype</Word>
<Word>rpad</Word>
<Word>rtrim</Word>
<Word>savepoint</Word>
<Word>schema</Word>
<Word>scroll</Word>
<Word>scope</Word>
<Word>search</Word>
<Word>second</Word>
<Word>section</Word>
<Word>seddev_samp</Word>
<Word>select</Word>
<Word>separate</Word>
<Word>sequence</Word>
<Word>session</Word>
<Word>session_user</Word>
<Word>set</Word>
<Word>sets</Word>
<Word>share</Word>
<Word>sign</Word>
<Word>sin</Word>
<Word>sinh</Word>
<Word>size</Word>
<Word>smallint</Word>
<Word>some</Word>
<Word>soundex</Word>
<Word>space</Word>
<Word>specific</Word>
<Word>specifictype</Word>
<Word>sql</Word>
<Word>sqlcode</Word>
<Word>sqlerrm</Word>
<Word>sqlexception</Word>
<Word>sqlstate</Word>
<Word>sqlwarning</Word>
<Word>sqrt</Word>
<Word>start</Word>
<Word>state</Word>
<Word>statement</Word>
<Word>static</Word>
<Word>std</Word>
<Word>stddev</Word>
<Word>stdev_pop</Word>
<Word>strcmp</Word>
<Word>structure</Word>
<Word>subdate</Word>
<Word>substr</Word>
<Word>substrb</Word>
<Word>substring</Word>
<Word>substring_index</Word>
<Word>subtype</Word>
<Word>successful</Word>
<Word>sum</Word>
<Word>synonym</Word>
<Word>sys_context</Word>
<Word>sys_guid</Word>
<Word>sysdate</Word>
<Word>system_user</Word>
<Word>table</Word>
<Word>tan</Word>
<Word>tanh</Word>
<Word>temporary</Word>
<Word>terminate</Word>
<Word>than</Word>
<Word>then</Word>
<Word>time</Word>
<Word>timestamp</Word>
<Word>timezone_abbr</Word>
<Word>timezone_minute</Word>
<Word>timezone_hour</Word>
<Word>timezone_region</Word>
<Word>tinyint</Word>
<Word>to</Word>
<Word>to_char</Word>
<Word>to_date</Word>
<Word>to_days</Word>
<Word>to_number</Word>
<Word>to_single_byte</Word>
<Word>trailing</Word>
<Word>transaction</Word>
<Word>translate</Word>
<Word>translation</Word>
<Word>treat</Word>
<Word>trigger</Word>
<Word>trim</Word>
<Word>true</Word>
<Word>trunc</Word>
<Word>truncate</Word>
<Word>type</Word>
<Word>ucase</Word>
<Word>uid</Word>
<Word>under</Word>
<Word>union</Word>
<Word>unique</Word>
<Word>unknown</Word>
<Word>unnest</Word>
<Word>update</Word>
<Word>upper</Word>
<Word>usage</Word>
<Word>use</Word>
<Word>user</Word>
<Word>userenv</Word>
<Word>using</Word>
<Word>validate</Word>
<Word>value</Word>
<Word>values</Word>
<Word>var_pop</Word>
<Word>var_samp</Word>
<Word>varbinary</Word>
<Word>varchar</Word>
<Word>varchar2</Word>
<Word>variable</Word>
<Word>variance</Word>
<Word>varying</Word>
<Word>view</Word>
<Word>vsize</Word>
<Word>when</Word>
<Word>whenever</Word>
<Word>where</Word>
<Word>with</Word>
<Word>without</Word>
<Word>while</Word>
<Word>work</Word>
<Word>write</Word>
<Word>year</Word>
<Word>zone</Word>
</Keywords>
</RuleSet>
</SyntaxDefinition>
<MSG> Update TSQL file #125
https://github.com/icsharpcode/AvalonEdit/pull/125
<DFF> @@ -559,6 +559,7 @@
<Word>timezone_region</Word>
<Word>tinyint</Word>
<Word>to</Word>
+ <Word>top</Word>
<Word>to_char</Word>
<Word>to_date</Word>
<Word>to_days</Word>
| 1 | Update TSQL file #125 | 0 | .xshd | xshd | mit | AvaloniaUI/AvaloniaEdit |
10066926 | <NME> TSQL-Mode.xshd
<BEF> <?xml version="1.0"?>
<SyntaxDefinition name="TSQL" extensions=".sql" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
<Color name="Comment" foreground="Green" exampleText="-- comment" />
<Color name="Char" foreground="Red" exampleText="name = 'abc'"/>
<Color name="Keywords" fontWeight="bold" foreground="Blue" exampleText="SELECT FROM"/>
<Property name="DocCommentMarker" value="///" />
<RuleSet name="CommentMarkerSet">
<Keywords fontWeight="bold" foreground="Red">
<Word>TODO</Word>
<Word>FIXME</Word>
</Keywords>
<Keywords fontWeight="bold" foreground="#E0E000">
<Word>HACK</Word>
<Word>UNDONE</Word>
</Keywords>
</RuleSet>
<RuleSet ignoreCase="true">
<Span color="Comment" ruleSet="CommentMarkerSet">
<Begin>--</Begin>
</Span>
<Span color="Comment" ruleSet="CommentMarkerSet" multiline="true">
<Begin>/\*</Begin>
<End>\*/</End>
</Span>
<Span color="Char">
<Begin>'</Begin>
<End>'</End>
<RuleSet>
<Span begin="\\" end="."/>
</RuleSet>
</Span>
<Keywords color="Keywords">
<Word>abs</Word>
<Word>absolute</Word>
<Word>access</Word>
<Word>acos</Word>
<Word>add</Word>
<Word>add_months</Word>
<Word>adddate</Word>
<Word>admin</Word>
<Word>after</Word>
<Word>aggregate</Word>
<Word>all</Word>
<Word>allocate</Word>
<Word>alter</Word>
<Word>and</Word>
<Word>any</Word>
<Word>app_name</Word>
<Word>are</Word>
<Word>array</Word>
<Word>as</Word>
<Word>asc</Word>
<Word>ascii</Word>
<Word>asin</Word>
<Word>assertion</Word>
<Word>at</Word>
<Word>atan</Word>
<Word>atn2</Word>
<Word>audit</Word>
<Word>authid</Word>
<Word>authorization</Word>
<Word>autonomous_transaction</Word>
<Word>avg</Word>
<Word>before</Word>
<Word>begin</Word>
<Word>benchmark</Word>
<Word>between</Word>
<Word>bfilename</Word>
<Word>bigint</Word>
<Word>bin</Word>
<Word>binary</Word>
<Word>binary_checksum</Word>
<Word>binary_integer</Word>
<Word>bit</Word>
<Word>bit_count</Word>
<Word>bit_and</Word>
<Word>bit_or</Word>
<Word>blob</Word>
<Word>body</Word>
<Word>boolean</Word>
<Word>both</Word>
<Word>breadth</Word>
<Word>bulk</Word>
<Word>by</Word>
<Word>call</Word>
<Word>cascade</Word>
<Word>cascaded</Word>
<Word>case</Word>
<Word>cast</Word>
<Word>catalog</Word>
<Word>ceil</Word>
<Word>ceiling</Word>
<Word>char</Word>
<Word>char_base</Word>
<Word>character</Word>
<Word>charindex</Word>
<Word>chartorowid</Word>
<Word>check</Word>
<Word>checksum</Word>
<Word>checksum_agg</Word>
<Word>chr</Word>
<Word>class</Word>
<Word>clob</Word>
<Word>close</Word>
<Word>cluster</Word>
<Word>coalesce</Word>
<Word>col_length</Word>
<Word>col_name</Word>
<Word>collate</Word>
<Word>collation</Word>
<Word>collect</Word>
<Word>column</Word>
<Word>comment</Word>
<Word>commit</Word>
<Word>completion</Word>
<Word>compress</Word>
<Word>concat</Word>
<Word>concat_ws</Word>
<Word>connect</Word>
<Word>connection</Word>
<Word>constant</Word>
<Word>constraint</Word>
<Word>constraints</Word>
<Word>constructorcreate</Word>
<Word>contains</Word>
<Word>containsable</Word>
<Word>continue</Word>
<Word>conv</Word>
<Word>convert</Word>
<Word>corr</Word>
<Word>corresponding</Word>
<Word>cos</Word>
<Word>cot</Word>
<Word>count</Word>
<Word>count_big</Word>
<Word>covar_pop</Word>
<Word>covar_samp</Word>
<Word>create</Word>
<Word>cross</Word>
<Word>cube</Word>
<Word>cume_dist</Word>
<Word>current</Word>
<Word>current_date</Word>
<Word>current_path</Word>
<Word>current_role</Word>
<Word>current_time</Word>
<Word>current_timestamp</Word>
<Word>current_user</Word>
<Word>currval</Word>
<Word>cursor</Word>
<Word>cycle</Word>
<Word>data</Word>
<Word>datalength</Word>
<Word>databasepropertyex</Word>
<Word>date</Word>
<Word>date_add</Word>
<Word>date_format</Word>
<Word>date_sub</Word>
<Word>dateadd</Word>
<Word>datediff</Word>
<Word>datename</Word>
<Word>datepart</Word>
<Word>datetime</Word>
<Word>day</Word>
<Word>db_id</Word>
<Word>db_name</Word>
<Word>deallocate</Word>
<Word>dec</Word>
<Word>declare</Word>
<Word>decimal</Word>
<Word>decode</Word>
<Word>default</Word>
<Word>deferrable</Word>
<Word>deferred</Word>
<Word>degrees</Word>
<Word>delete</Word>
<Word>dense_rank</Word>
<Word>depth</Word>
<Word>deref</Word>
<Word>desc</Word>
<Word>describe</Word>
<Word>descriptor</Word>
<Word>destroy</Word>
<Word>destructor</Word>
<Word>deterministic</Word>
<Word>diagnostics</Word>
<Word>dictionary</Word>
<Word>disconnect</Word>
<Word>difference</Word>
<Word>distinct</Word>
<Word>do</Word>
<Word>domain</Word>
<Word>double</Word>
<Word>drop</Word>
<Word>dump</Word>
<Word>dynamic</Word>
<Word>each</Word>
<Word>else</Word>
<Word>elsif</Word>
<Word>empth</Word>
<Word>encode</Word>
<Word>encrypt</Word>
<Word>end</Word>
<Word>end-exec</Word>
<Word>equals</Word>
<Word>escape</Word>
<Word>every</Word>
<Word>except</Word>
<Word>exception</Word>
<Word>exclusive</Word>
<Word>exec</Word>
<Word>execute</Word>
<Word>exists</Word>
<Word>exit</Word>
<Word>exp</Word>
<Word>export_set</Word>
<Word>extends</Word>
<Word>external</Word>
<Word>extract</Word>
<Word>false</Word>
<Word>fetch</Word>
<Word>first</Word>
<Word>first_value</Word>
<Word>file</Word>
<Word>float</Word>
<Word>floor</Word>
<Word>file_id</Word>
<Word>file_name</Word>
<Word>filegroup_id</Word>
<Word>filegroup_name</Word>
<Word>filegroupproperty</Word>
<Word>fileproperty</Word>
<Word>for</Word>
<Word>forall</Word>
<Word>foreign</Word>
<Word>format</Word>
<Word>formatmessage</Word>
<Word>found</Word>
<Word>freetexttable</Word>
<Word>from</Word>
<Word>from_days</Word>
<Word>fulltextcatalog</Word>
<Word>fulltextservice</Word>
<Word>function</Word>
<Word>general</Word>
<Word>get</Word>
<Word>get_lock</Word>
<Word>getdate</Word>
<Word>getansinull</Word>
<Word>getutcdate</Word>
<Word>global</Word>
<Word>go</Word>
<Word>goto</Word>
<Word>grant</Word>
<Word>greatest</Word>
<Word>group</Word>
<Word>grouping</Word>
<Word>having</Word>
<Word>heap</Word>
<Word>hex</Word>
<Word>hextoraw</Word>
<Word>host</Word>
<Word>host_id</Word>
<Word>host_name</Word>
<Word>hour</Word>
<Word>ident_incr</Word>
<Word>ident_seed</Word>
<Word>ident_current</Word>
<Word>identified</Word>
<Word>identity</Word>
<Word>if</Word>
<Word>ifnull</Word>
<Word>ignore</Word>
<Word>immediate</Word>
<Word>in</Word>
<Word>increment</Word>
<Word>index</Word>
<Word>index_col</Word>
<Word>indexproperty</Word>
<Word>indicator</Word>
<Word>initcap</Word>
<Word>initial</Word>
<Word>initialize</Word>
<Word>initially</Word>
<Word>inner</Word>
<Word>inout</Word>
<Word>input</Word>
<Word>insert</Word>
<Word>instr</Word>
<Word>instrb</Word>
<Word>int</Word>
<Word>integer</Word>
<Word>interface</Word>
<Word>intersect</Word>
<Word>interval</Word>
<Word>into</Word>
<Word>is</Word>
<Word>is_member</Word>
<Word>is_srvrolemember</Word>
<Word>is_null</Word>
<Word>is_numeric</Word>
<Word>isdate</Word>
<Word>isnull</Word>
<Word>isolation</Word>
<Word>iterate</Word>
<Word>java</Word>
<Word>join</Word>
<Word>key</Word>
<Word>lag</Word>
<Word>language</Word>
<Word>large</Word>
<Word>last</Word>
<Word>last_day</Word>
<Word>last_value</Word>
<Word>lateral</Word>
<Word>lcase</Word>
<Word>lead</Word>
<Word>leading</Word>
<Word>least</Word>
<Word>left</Word>
<Word>len</Word>
<Word>length</Word>
<Word>lengthb</Word>
<Word>less</Word>
<Word>level</Word>
<Word>like</Word>
<Word>limit</Word>
<Word>limited</Word>
<Word>ln</Word>
<Word>lpad</Word>
<Word>local</Word>
<Word>localtime</Word>
<Word>localtimestamp</Word>
<Word>locator</Word>
<Word>lock</Word>
<Word>log</Word>
<Word>log10</Word>
<Word>long</Word>
<Word>loop</Word>
<Word>lower</Word>
<Word>ltrim</Word>
<Word>make_ref</Word>
<Word>map</Word>
<Word>match</Word>
<Word>max</Word>
<Word>maxextents</Word>
<Word>mid</Word>
<Word>min</Word>
<Word>minus</Word>
<Word>minute</Word>
<Word>mlslabel</Word>
<Word>mod</Word>
<Word>mode</Word>
<Word>modifies</Word>
<Word>modify</Word>
<Word>module</Word>
<Word>month</Word>
<Word>months_between</Word>
<Word>names</Word>
<Word>national</Word>
<Word>natural</Word>
<Word>naturaln</Word>
<Word>nchar</Word>
<Word>nclob</Word>
<Word>new</Word>
<Word>new_time</Word>
<Word>newid</Word>
<Word>next</Word>
<Word>next_day</Word>
<Word>nextval</Word>
<Word>no</Word>
<Word>noaudit</Word>
<Word>nocompress</Word>
<Word>nocopy</Word>
<Word>nolock</Word>
<Word>none</Word>
<Word>not</Word>
<Word>nowait</Word>
<Word>null</Word>
<Word>nullif</Word>
<Word>number</Word>
<Word>number_base</Word>
<Word>numeric</Word>
<Word>nvl</Word>
<Word>nvl2</Word>
<Word>object</Word>
<Word>object_id</Word>
<Word>object_name</Word>
<Word>object_property</Word>
<Word>ocirowid</Word>
<Word>oct</Word>
<Word>of</Word>
<Word>off</Word>
<Word>offline</Word>
<Word>old</Word>
<Word>on</Word>
<Word>online</Word>
<Word>only</Word>
<Word>opaque</Word>
<Word>open</Word>
<Word>operator</Word>
<Word>operation</Word>
<Word>option</Word>
<Word>or</Word>
<Word>ord</Word>
<Word>order</Word>
<Word>ordinalityorganization</Word>
<Word>others</Word>
<Word>out</Word>
<Word>outer</Word>
<Word>output</Word>
<Word>package</Word>
<Word>pad</Word>
<Word>parameter</Word>
<Word>parameters</Word>
<Word>partial</Word>
<Word>partition</Word>
<Word>path</Word>
<Word>pctfree</Word>
<Word>percent_rank</Word>
<Word>pi</Word>
<Word>pls_integer</Word>
<Word>positive</Word>
<Word>positiven</Word>
<Word>postfix</Word>
<Word>pow</Word>
<Word>power</Word>
<Word>pragma</Word>
<Word>precision</Word>
<Word>prefix</Word>
<Word>preorder</Word>
<Word>prepare</Word>
<Word>preserve</Word>
<Word>primary</Word>
<Word>prior</Word>
<Word>private</Word>
<Word>privileges</Word>
<Word>procedure</Word>
<Word>public</Word>
<Word>radians</Word>
<Word>raise</Word>
<Word>rand</Word>
<Word>range</Word>
<Word>rank</Word>
<Word>ratio_to_export</Word>
<Word>raw</Word>
<Word>rawtohex</Word>
<Word>read</Word>
<Word>reads</Word>
<Word>real</Word>
<Word>record</Word>
<Word>recursive</Word>
<Word>ref</Word>
<Word>references</Word>
<Word>referencing</Word>
<Word>reftohex</Word>
<Word>relative</Word>
<Word>release</Word>
<Word>release_lock</Word>
<Word>rename</Word>
<Word>repeat</Word>
<Word>replace</Word>
<Word>resource</Word>
<Word>restrict</Word>
<Word>result</Word>
<Word>return</Word>
<Word>returns</Word>
<Word>reverse</Word>
<Word>revoke</Word>
<Word>right</Word>
<Word>rollback</Word>
<Word>rollup</Word>
<Word>round</Word>
<Word>routine</Word>
<Word>row</Word>
<Word>row_number</Word>
<Word>rowid</Word>
<Word>rowidtochar</Word>
<Word>rowlabel</Word>
<Word>rowlock</Word>
<Word>rownum</Word>
<Word>rows</Word>
<Word>rowtype</Word>
<Word>rpad</Word>
<Word>rtrim</Word>
<Word>savepoint</Word>
<Word>schema</Word>
<Word>scroll</Word>
<Word>scope</Word>
<Word>search</Word>
<Word>second</Word>
<Word>section</Word>
<Word>seddev_samp</Word>
<Word>select</Word>
<Word>separate</Word>
<Word>sequence</Word>
<Word>session</Word>
<Word>session_user</Word>
<Word>set</Word>
<Word>sets</Word>
<Word>share</Word>
<Word>sign</Word>
<Word>sin</Word>
<Word>sinh</Word>
<Word>size</Word>
<Word>smallint</Word>
<Word>some</Word>
<Word>soundex</Word>
<Word>space</Word>
<Word>specific</Word>
<Word>specifictype</Word>
<Word>sql</Word>
<Word>sqlcode</Word>
<Word>sqlerrm</Word>
<Word>sqlexception</Word>
<Word>sqlstate</Word>
<Word>sqlwarning</Word>
<Word>sqrt</Word>
<Word>start</Word>
<Word>state</Word>
<Word>statement</Word>
<Word>static</Word>
<Word>std</Word>
<Word>stddev</Word>
<Word>stdev_pop</Word>
<Word>strcmp</Word>
<Word>structure</Word>
<Word>subdate</Word>
<Word>substr</Word>
<Word>substrb</Word>
<Word>substring</Word>
<Word>substring_index</Word>
<Word>subtype</Word>
<Word>successful</Word>
<Word>sum</Word>
<Word>synonym</Word>
<Word>sys_context</Word>
<Word>sys_guid</Word>
<Word>sysdate</Word>
<Word>system_user</Word>
<Word>table</Word>
<Word>tan</Word>
<Word>tanh</Word>
<Word>temporary</Word>
<Word>terminate</Word>
<Word>than</Word>
<Word>then</Word>
<Word>time</Word>
<Word>timestamp</Word>
<Word>timezone_abbr</Word>
<Word>timezone_minute</Word>
<Word>timezone_hour</Word>
<Word>timezone_region</Word>
<Word>tinyint</Word>
<Word>to</Word>
<Word>to_char</Word>
<Word>to_date</Word>
<Word>to_days</Word>
<Word>to_number</Word>
<Word>to_single_byte</Word>
<Word>trailing</Word>
<Word>transaction</Word>
<Word>translate</Word>
<Word>translation</Word>
<Word>treat</Word>
<Word>trigger</Word>
<Word>trim</Word>
<Word>true</Word>
<Word>trunc</Word>
<Word>truncate</Word>
<Word>type</Word>
<Word>ucase</Word>
<Word>uid</Word>
<Word>under</Word>
<Word>union</Word>
<Word>unique</Word>
<Word>unknown</Word>
<Word>unnest</Word>
<Word>update</Word>
<Word>upper</Word>
<Word>usage</Word>
<Word>use</Word>
<Word>user</Word>
<Word>userenv</Word>
<Word>using</Word>
<Word>validate</Word>
<Word>value</Word>
<Word>values</Word>
<Word>var_pop</Word>
<Word>var_samp</Word>
<Word>varbinary</Word>
<Word>varchar</Word>
<Word>varchar2</Word>
<Word>variable</Word>
<Word>variance</Word>
<Word>varying</Word>
<Word>view</Word>
<Word>vsize</Word>
<Word>when</Word>
<Word>whenever</Word>
<Word>where</Word>
<Word>with</Word>
<Word>without</Word>
<Word>while</Word>
<Word>work</Word>
<Word>write</Word>
<Word>year</Word>
<Word>zone</Word>
</Keywords>
</RuleSet>
</SyntaxDefinition>
<MSG> Update TSQL file #125
https://github.com/icsharpcode/AvalonEdit/pull/125
<DFF> @@ -559,6 +559,7 @@
<Word>timezone_region</Word>
<Word>tinyint</Word>
<Word>to</Word>
+ <Word>top</Word>
<Word>to_char</Word>
<Word>to_date</Word>
<Word>to_days</Word>
| 1 | Update TSQL file #125 | 0 | .xshd | xshd | mit | AvaloniaUI/AvaloniaEdit |
10066927 | <NME> TSQL-Mode.xshd
<BEF> <?xml version="1.0"?>
<SyntaxDefinition name="TSQL" extensions=".sql" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
<Color name="Comment" foreground="Green" exampleText="-- comment" />
<Color name="Char" foreground="Red" exampleText="name = 'abc'"/>
<Color name="Keywords" fontWeight="bold" foreground="Blue" exampleText="SELECT FROM"/>
<Property name="DocCommentMarker" value="///" />
<RuleSet name="CommentMarkerSet">
<Keywords fontWeight="bold" foreground="Red">
<Word>TODO</Word>
<Word>FIXME</Word>
</Keywords>
<Keywords fontWeight="bold" foreground="#E0E000">
<Word>HACK</Word>
<Word>UNDONE</Word>
</Keywords>
</RuleSet>
<RuleSet ignoreCase="true">
<Span color="Comment" ruleSet="CommentMarkerSet">
<Begin>--</Begin>
</Span>
<Span color="Comment" ruleSet="CommentMarkerSet" multiline="true">
<Begin>/\*</Begin>
<End>\*/</End>
</Span>
<Span color="Char">
<Begin>'</Begin>
<End>'</End>
<RuleSet>
<Span begin="\\" end="."/>
</RuleSet>
</Span>
<Keywords color="Keywords">
<Word>abs</Word>
<Word>absolute</Word>
<Word>access</Word>
<Word>acos</Word>
<Word>add</Word>
<Word>add_months</Word>
<Word>adddate</Word>
<Word>admin</Word>
<Word>after</Word>
<Word>aggregate</Word>
<Word>all</Word>
<Word>allocate</Word>
<Word>alter</Word>
<Word>and</Word>
<Word>any</Word>
<Word>app_name</Word>
<Word>are</Word>
<Word>array</Word>
<Word>as</Word>
<Word>asc</Word>
<Word>ascii</Word>
<Word>asin</Word>
<Word>assertion</Word>
<Word>at</Word>
<Word>atan</Word>
<Word>atn2</Word>
<Word>audit</Word>
<Word>authid</Word>
<Word>authorization</Word>
<Word>autonomous_transaction</Word>
<Word>avg</Word>
<Word>before</Word>
<Word>begin</Word>
<Word>benchmark</Word>
<Word>between</Word>
<Word>bfilename</Word>
<Word>bigint</Word>
<Word>bin</Word>
<Word>binary</Word>
<Word>binary_checksum</Word>
<Word>binary_integer</Word>
<Word>bit</Word>
<Word>bit_count</Word>
<Word>bit_and</Word>
<Word>bit_or</Word>
<Word>blob</Word>
<Word>body</Word>
<Word>boolean</Word>
<Word>both</Word>
<Word>breadth</Word>
<Word>bulk</Word>
<Word>by</Word>
<Word>call</Word>
<Word>cascade</Word>
<Word>cascaded</Word>
<Word>case</Word>
<Word>cast</Word>
<Word>catalog</Word>
<Word>ceil</Word>
<Word>ceiling</Word>
<Word>char</Word>
<Word>char_base</Word>
<Word>character</Word>
<Word>charindex</Word>
<Word>chartorowid</Word>
<Word>check</Word>
<Word>checksum</Word>
<Word>checksum_agg</Word>
<Word>chr</Word>
<Word>class</Word>
<Word>clob</Word>
<Word>close</Word>
<Word>cluster</Word>
<Word>coalesce</Word>
<Word>col_length</Word>
<Word>col_name</Word>
<Word>collate</Word>
<Word>collation</Word>
<Word>collect</Word>
<Word>column</Word>
<Word>comment</Word>
<Word>commit</Word>
<Word>completion</Word>
<Word>compress</Word>
<Word>concat</Word>
<Word>concat_ws</Word>
<Word>connect</Word>
<Word>connection</Word>
<Word>constant</Word>
<Word>constraint</Word>
<Word>constraints</Word>
<Word>constructorcreate</Word>
<Word>contains</Word>
<Word>containsable</Word>
<Word>continue</Word>
<Word>conv</Word>
<Word>convert</Word>
<Word>corr</Word>
<Word>corresponding</Word>
<Word>cos</Word>
<Word>cot</Word>
<Word>count</Word>
<Word>count_big</Word>
<Word>covar_pop</Word>
<Word>covar_samp</Word>
<Word>create</Word>
<Word>cross</Word>
<Word>cube</Word>
<Word>cume_dist</Word>
<Word>current</Word>
<Word>current_date</Word>
<Word>current_path</Word>
<Word>current_role</Word>
<Word>current_time</Word>
<Word>current_timestamp</Word>
<Word>current_user</Word>
<Word>currval</Word>
<Word>cursor</Word>
<Word>cycle</Word>
<Word>data</Word>
<Word>datalength</Word>
<Word>databasepropertyex</Word>
<Word>date</Word>
<Word>date_add</Word>
<Word>date_format</Word>
<Word>date_sub</Word>
<Word>dateadd</Word>
<Word>datediff</Word>
<Word>datename</Word>
<Word>datepart</Word>
<Word>datetime</Word>
<Word>day</Word>
<Word>db_id</Word>
<Word>db_name</Word>
<Word>deallocate</Word>
<Word>dec</Word>
<Word>declare</Word>
<Word>decimal</Word>
<Word>decode</Word>
<Word>default</Word>
<Word>deferrable</Word>
<Word>deferred</Word>
<Word>degrees</Word>
<Word>delete</Word>
<Word>dense_rank</Word>
<Word>depth</Word>
<Word>deref</Word>
<Word>desc</Word>
<Word>describe</Word>
<Word>descriptor</Word>
<Word>destroy</Word>
<Word>destructor</Word>
<Word>deterministic</Word>
<Word>diagnostics</Word>
<Word>dictionary</Word>
<Word>disconnect</Word>
<Word>difference</Word>
<Word>distinct</Word>
<Word>do</Word>
<Word>domain</Word>
<Word>double</Word>
<Word>drop</Word>
<Word>dump</Word>
<Word>dynamic</Word>
<Word>each</Word>
<Word>else</Word>
<Word>elsif</Word>
<Word>empth</Word>
<Word>encode</Word>
<Word>encrypt</Word>
<Word>end</Word>
<Word>end-exec</Word>
<Word>equals</Word>
<Word>escape</Word>
<Word>every</Word>
<Word>except</Word>
<Word>exception</Word>
<Word>exclusive</Word>
<Word>exec</Word>
<Word>execute</Word>
<Word>exists</Word>
<Word>exit</Word>
<Word>exp</Word>
<Word>export_set</Word>
<Word>extends</Word>
<Word>external</Word>
<Word>extract</Word>
<Word>false</Word>
<Word>fetch</Word>
<Word>first</Word>
<Word>first_value</Word>
<Word>file</Word>
<Word>float</Word>
<Word>floor</Word>
<Word>file_id</Word>
<Word>file_name</Word>
<Word>filegroup_id</Word>
<Word>filegroup_name</Word>
<Word>filegroupproperty</Word>
<Word>fileproperty</Word>
<Word>for</Word>
<Word>forall</Word>
<Word>foreign</Word>
<Word>format</Word>
<Word>formatmessage</Word>
<Word>found</Word>
<Word>freetexttable</Word>
<Word>from</Word>
<Word>from_days</Word>
<Word>fulltextcatalog</Word>
<Word>fulltextservice</Word>
<Word>function</Word>
<Word>general</Word>
<Word>get</Word>
<Word>get_lock</Word>
<Word>getdate</Word>
<Word>getansinull</Word>
<Word>getutcdate</Word>
<Word>global</Word>
<Word>go</Word>
<Word>goto</Word>
<Word>grant</Word>
<Word>greatest</Word>
<Word>group</Word>
<Word>grouping</Word>
<Word>having</Word>
<Word>heap</Word>
<Word>hex</Word>
<Word>hextoraw</Word>
<Word>host</Word>
<Word>host_id</Word>
<Word>host_name</Word>
<Word>hour</Word>
<Word>ident_incr</Word>
<Word>ident_seed</Word>
<Word>ident_current</Word>
<Word>identified</Word>
<Word>identity</Word>
<Word>if</Word>
<Word>ifnull</Word>
<Word>ignore</Word>
<Word>immediate</Word>
<Word>in</Word>
<Word>increment</Word>
<Word>index</Word>
<Word>index_col</Word>
<Word>indexproperty</Word>
<Word>indicator</Word>
<Word>initcap</Word>
<Word>initial</Word>
<Word>initialize</Word>
<Word>initially</Word>
<Word>inner</Word>
<Word>inout</Word>
<Word>input</Word>
<Word>insert</Word>
<Word>instr</Word>
<Word>instrb</Word>
<Word>int</Word>
<Word>integer</Word>
<Word>interface</Word>
<Word>intersect</Word>
<Word>interval</Word>
<Word>into</Word>
<Word>is</Word>
<Word>is_member</Word>
<Word>is_srvrolemember</Word>
<Word>is_null</Word>
<Word>is_numeric</Word>
<Word>isdate</Word>
<Word>isnull</Word>
<Word>isolation</Word>
<Word>iterate</Word>
<Word>java</Word>
<Word>join</Word>
<Word>key</Word>
<Word>lag</Word>
<Word>language</Word>
<Word>large</Word>
<Word>last</Word>
<Word>last_day</Word>
<Word>last_value</Word>
<Word>lateral</Word>
<Word>lcase</Word>
<Word>lead</Word>
<Word>leading</Word>
<Word>least</Word>
<Word>left</Word>
<Word>len</Word>
<Word>length</Word>
<Word>lengthb</Word>
<Word>less</Word>
<Word>level</Word>
<Word>like</Word>
<Word>limit</Word>
<Word>limited</Word>
<Word>ln</Word>
<Word>lpad</Word>
<Word>local</Word>
<Word>localtime</Word>
<Word>localtimestamp</Word>
<Word>locator</Word>
<Word>lock</Word>
<Word>log</Word>
<Word>log10</Word>
<Word>long</Word>
<Word>loop</Word>
<Word>lower</Word>
<Word>ltrim</Word>
<Word>make_ref</Word>
<Word>map</Word>
<Word>match</Word>
<Word>max</Word>
<Word>maxextents</Word>
<Word>mid</Word>
<Word>min</Word>
<Word>minus</Word>
<Word>minute</Word>
<Word>mlslabel</Word>
<Word>mod</Word>
<Word>mode</Word>
<Word>modifies</Word>
<Word>modify</Word>
<Word>module</Word>
<Word>month</Word>
<Word>months_between</Word>
<Word>names</Word>
<Word>national</Word>
<Word>natural</Word>
<Word>naturaln</Word>
<Word>nchar</Word>
<Word>nclob</Word>
<Word>new</Word>
<Word>new_time</Word>
<Word>newid</Word>
<Word>next</Word>
<Word>next_day</Word>
<Word>nextval</Word>
<Word>no</Word>
<Word>noaudit</Word>
<Word>nocompress</Word>
<Word>nocopy</Word>
<Word>nolock</Word>
<Word>none</Word>
<Word>not</Word>
<Word>nowait</Word>
<Word>null</Word>
<Word>nullif</Word>
<Word>number</Word>
<Word>number_base</Word>
<Word>numeric</Word>
<Word>nvl</Word>
<Word>nvl2</Word>
<Word>object</Word>
<Word>object_id</Word>
<Word>object_name</Word>
<Word>object_property</Word>
<Word>ocirowid</Word>
<Word>oct</Word>
<Word>of</Word>
<Word>off</Word>
<Word>offline</Word>
<Word>old</Word>
<Word>on</Word>
<Word>online</Word>
<Word>only</Word>
<Word>opaque</Word>
<Word>open</Word>
<Word>operator</Word>
<Word>operation</Word>
<Word>option</Word>
<Word>or</Word>
<Word>ord</Word>
<Word>order</Word>
<Word>ordinalityorganization</Word>
<Word>others</Word>
<Word>out</Word>
<Word>outer</Word>
<Word>output</Word>
<Word>package</Word>
<Word>pad</Word>
<Word>parameter</Word>
<Word>parameters</Word>
<Word>partial</Word>
<Word>partition</Word>
<Word>path</Word>
<Word>pctfree</Word>
<Word>percent_rank</Word>
<Word>pi</Word>
<Word>pls_integer</Word>
<Word>positive</Word>
<Word>positiven</Word>
<Word>postfix</Word>
<Word>pow</Word>
<Word>power</Word>
<Word>pragma</Word>
<Word>precision</Word>
<Word>prefix</Word>
<Word>preorder</Word>
<Word>prepare</Word>
<Word>preserve</Word>
<Word>primary</Word>
<Word>prior</Word>
<Word>private</Word>
<Word>privileges</Word>
<Word>procedure</Word>
<Word>public</Word>
<Word>radians</Word>
<Word>raise</Word>
<Word>rand</Word>
<Word>range</Word>
<Word>rank</Word>
<Word>ratio_to_export</Word>
<Word>raw</Word>
<Word>rawtohex</Word>
<Word>read</Word>
<Word>reads</Word>
<Word>real</Word>
<Word>record</Word>
<Word>recursive</Word>
<Word>ref</Word>
<Word>references</Word>
<Word>referencing</Word>
<Word>reftohex</Word>
<Word>relative</Word>
<Word>release</Word>
<Word>release_lock</Word>
<Word>rename</Word>
<Word>repeat</Word>
<Word>replace</Word>
<Word>resource</Word>
<Word>restrict</Word>
<Word>result</Word>
<Word>return</Word>
<Word>returns</Word>
<Word>reverse</Word>
<Word>revoke</Word>
<Word>right</Word>
<Word>rollback</Word>
<Word>rollup</Word>
<Word>round</Word>
<Word>routine</Word>
<Word>row</Word>
<Word>row_number</Word>
<Word>rowid</Word>
<Word>rowidtochar</Word>
<Word>rowlabel</Word>
<Word>rowlock</Word>
<Word>rownum</Word>
<Word>rows</Word>
<Word>rowtype</Word>
<Word>rpad</Word>
<Word>rtrim</Word>
<Word>savepoint</Word>
<Word>schema</Word>
<Word>scroll</Word>
<Word>scope</Word>
<Word>search</Word>
<Word>second</Word>
<Word>section</Word>
<Word>seddev_samp</Word>
<Word>select</Word>
<Word>separate</Word>
<Word>sequence</Word>
<Word>session</Word>
<Word>session_user</Word>
<Word>set</Word>
<Word>sets</Word>
<Word>share</Word>
<Word>sign</Word>
<Word>sin</Word>
<Word>sinh</Word>
<Word>size</Word>
<Word>smallint</Word>
<Word>some</Word>
<Word>soundex</Word>
<Word>space</Word>
<Word>specific</Word>
<Word>specifictype</Word>
<Word>sql</Word>
<Word>sqlcode</Word>
<Word>sqlerrm</Word>
<Word>sqlexception</Word>
<Word>sqlstate</Word>
<Word>sqlwarning</Word>
<Word>sqrt</Word>
<Word>start</Word>
<Word>state</Word>
<Word>statement</Word>
<Word>static</Word>
<Word>std</Word>
<Word>stddev</Word>
<Word>stdev_pop</Word>
<Word>strcmp</Word>
<Word>structure</Word>
<Word>subdate</Word>
<Word>substr</Word>
<Word>substrb</Word>
<Word>substring</Word>
<Word>substring_index</Word>
<Word>subtype</Word>
<Word>successful</Word>
<Word>sum</Word>
<Word>synonym</Word>
<Word>sys_context</Word>
<Word>sys_guid</Word>
<Word>sysdate</Word>
<Word>system_user</Word>
<Word>table</Word>
<Word>tan</Word>
<Word>tanh</Word>
<Word>temporary</Word>
<Word>terminate</Word>
<Word>than</Word>
<Word>then</Word>
<Word>time</Word>
<Word>timestamp</Word>
<Word>timezone_abbr</Word>
<Word>timezone_minute</Word>
<Word>timezone_hour</Word>
<Word>timezone_region</Word>
<Word>tinyint</Word>
<Word>to</Word>
<Word>to_char</Word>
<Word>to_date</Word>
<Word>to_days</Word>
<Word>to_number</Word>
<Word>to_single_byte</Word>
<Word>trailing</Word>
<Word>transaction</Word>
<Word>translate</Word>
<Word>translation</Word>
<Word>treat</Word>
<Word>trigger</Word>
<Word>trim</Word>
<Word>true</Word>
<Word>trunc</Word>
<Word>truncate</Word>
<Word>type</Word>
<Word>ucase</Word>
<Word>uid</Word>
<Word>under</Word>
<Word>union</Word>
<Word>unique</Word>
<Word>unknown</Word>
<Word>unnest</Word>
<Word>update</Word>
<Word>upper</Word>
<Word>usage</Word>
<Word>use</Word>
<Word>user</Word>
<Word>userenv</Word>
<Word>using</Word>
<Word>validate</Word>
<Word>value</Word>
<Word>values</Word>
<Word>var_pop</Word>
<Word>var_samp</Word>
<Word>varbinary</Word>
<Word>varchar</Word>
<Word>varchar2</Word>
<Word>variable</Word>
<Word>variance</Word>
<Word>varying</Word>
<Word>view</Word>
<Word>vsize</Word>
<Word>when</Word>
<Word>whenever</Word>
<Word>where</Word>
<Word>with</Word>
<Word>without</Word>
<Word>while</Word>
<Word>work</Word>
<Word>write</Word>
<Word>year</Word>
<Word>zone</Word>
</Keywords>
</RuleSet>
</SyntaxDefinition>
<MSG> Update TSQL file #125
https://github.com/icsharpcode/AvalonEdit/pull/125
<DFF> @@ -559,6 +559,7 @@
<Word>timezone_region</Word>
<Word>tinyint</Word>
<Word>to</Word>
+ <Word>top</Word>
<Word>to_char</Word>
<Word>to_date</Word>
<Word>to_days</Word>
| 1 | Update TSQL file #125 | 0 | .xshd | xshd | mit | AvaloniaUI/AvaloniaEdit |
10066928 | <NME> TSQL-Mode.xshd
<BEF> <?xml version="1.0"?>
<SyntaxDefinition name="TSQL" extensions=".sql" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
<Color name="Comment" foreground="Green" exampleText="-- comment" />
<Color name="Char" foreground="Red" exampleText="name = 'abc'"/>
<Color name="Keywords" fontWeight="bold" foreground="Blue" exampleText="SELECT FROM"/>
<Property name="DocCommentMarker" value="///" />
<RuleSet name="CommentMarkerSet">
<Keywords fontWeight="bold" foreground="Red">
<Word>TODO</Word>
<Word>FIXME</Word>
</Keywords>
<Keywords fontWeight="bold" foreground="#E0E000">
<Word>HACK</Word>
<Word>UNDONE</Word>
</Keywords>
</RuleSet>
<RuleSet ignoreCase="true">
<Span color="Comment" ruleSet="CommentMarkerSet">
<Begin>--</Begin>
</Span>
<Span color="Comment" ruleSet="CommentMarkerSet" multiline="true">
<Begin>/\*</Begin>
<End>\*/</End>
</Span>
<Span color="Char">
<Begin>'</Begin>
<End>'</End>
<RuleSet>
<Span begin="\\" end="."/>
</RuleSet>
</Span>
<Keywords color="Keywords">
<Word>abs</Word>
<Word>absolute</Word>
<Word>access</Word>
<Word>acos</Word>
<Word>add</Word>
<Word>add_months</Word>
<Word>adddate</Word>
<Word>admin</Word>
<Word>after</Word>
<Word>aggregate</Word>
<Word>all</Word>
<Word>allocate</Word>
<Word>alter</Word>
<Word>and</Word>
<Word>any</Word>
<Word>app_name</Word>
<Word>are</Word>
<Word>array</Word>
<Word>as</Word>
<Word>asc</Word>
<Word>ascii</Word>
<Word>asin</Word>
<Word>assertion</Word>
<Word>at</Word>
<Word>atan</Word>
<Word>atn2</Word>
<Word>audit</Word>
<Word>authid</Word>
<Word>authorization</Word>
<Word>autonomous_transaction</Word>
<Word>avg</Word>
<Word>before</Word>
<Word>begin</Word>
<Word>benchmark</Word>
<Word>between</Word>
<Word>bfilename</Word>
<Word>bigint</Word>
<Word>bin</Word>
<Word>binary</Word>
<Word>binary_checksum</Word>
<Word>binary_integer</Word>
<Word>bit</Word>
<Word>bit_count</Word>
<Word>bit_and</Word>
<Word>bit_or</Word>
<Word>blob</Word>
<Word>body</Word>
<Word>boolean</Word>
<Word>both</Word>
<Word>breadth</Word>
<Word>bulk</Word>
<Word>by</Word>
<Word>call</Word>
<Word>cascade</Word>
<Word>cascaded</Word>
<Word>case</Word>
<Word>cast</Word>
<Word>catalog</Word>
<Word>ceil</Word>
<Word>ceiling</Word>
<Word>char</Word>
<Word>char_base</Word>
<Word>character</Word>
<Word>charindex</Word>
<Word>chartorowid</Word>
<Word>check</Word>
<Word>checksum</Word>
<Word>checksum_agg</Word>
<Word>chr</Word>
<Word>class</Word>
<Word>clob</Word>
<Word>close</Word>
<Word>cluster</Word>
<Word>coalesce</Word>
<Word>col_length</Word>
<Word>col_name</Word>
<Word>collate</Word>
<Word>collation</Word>
<Word>collect</Word>
<Word>column</Word>
<Word>comment</Word>
<Word>commit</Word>
<Word>completion</Word>
<Word>compress</Word>
<Word>concat</Word>
<Word>concat_ws</Word>
<Word>connect</Word>
<Word>connection</Word>
<Word>constant</Word>
<Word>constraint</Word>
<Word>constraints</Word>
<Word>constructorcreate</Word>
<Word>contains</Word>
<Word>containsable</Word>
<Word>continue</Word>
<Word>conv</Word>
<Word>convert</Word>
<Word>corr</Word>
<Word>corresponding</Word>
<Word>cos</Word>
<Word>cot</Word>
<Word>count</Word>
<Word>count_big</Word>
<Word>covar_pop</Word>
<Word>covar_samp</Word>
<Word>create</Word>
<Word>cross</Word>
<Word>cube</Word>
<Word>cume_dist</Word>
<Word>current</Word>
<Word>current_date</Word>
<Word>current_path</Word>
<Word>current_role</Word>
<Word>current_time</Word>
<Word>current_timestamp</Word>
<Word>current_user</Word>
<Word>currval</Word>
<Word>cursor</Word>
<Word>cycle</Word>
<Word>data</Word>
<Word>datalength</Word>
<Word>databasepropertyex</Word>
<Word>date</Word>
<Word>date_add</Word>
<Word>date_format</Word>
<Word>date_sub</Word>
<Word>dateadd</Word>
<Word>datediff</Word>
<Word>datename</Word>
<Word>datepart</Word>
<Word>datetime</Word>
<Word>day</Word>
<Word>db_id</Word>
<Word>db_name</Word>
<Word>deallocate</Word>
<Word>dec</Word>
<Word>declare</Word>
<Word>decimal</Word>
<Word>decode</Word>
<Word>default</Word>
<Word>deferrable</Word>
<Word>deferred</Word>
<Word>degrees</Word>
<Word>delete</Word>
<Word>dense_rank</Word>
<Word>depth</Word>
<Word>deref</Word>
<Word>desc</Word>
<Word>describe</Word>
<Word>descriptor</Word>
<Word>destroy</Word>
<Word>destructor</Word>
<Word>deterministic</Word>
<Word>diagnostics</Word>
<Word>dictionary</Word>
<Word>disconnect</Word>
<Word>difference</Word>
<Word>distinct</Word>
<Word>do</Word>
<Word>domain</Word>
<Word>double</Word>
<Word>drop</Word>
<Word>dump</Word>
<Word>dynamic</Word>
<Word>each</Word>
<Word>else</Word>
<Word>elsif</Word>
<Word>empth</Word>
<Word>encode</Word>
<Word>encrypt</Word>
<Word>end</Word>
<Word>end-exec</Word>
<Word>equals</Word>
<Word>escape</Word>
<Word>every</Word>
<Word>except</Word>
<Word>exception</Word>
<Word>exclusive</Word>
<Word>exec</Word>
<Word>execute</Word>
<Word>exists</Word>
<Word>exit</Word>
<Word>exp</Word>
<Word>export_set</Word>
<Word>extends</Word>
<Word>external</Word>
<Word>extract</Word>
<Word>false</Word>
<Word>fetch</Word>
<Word>first</Word>
<Word>first_value</Word>
<Word>file</Word>
<Word>float</Word>
<Word>floor</Word>
<Word>file_id</Word>
<Word>file_name</Word>
<Word>filegroup_id</Word>
<Word>filegroup_name</Word>
<Word>filegroupproperty</Word>
<Word>fileproperty</Word>
<Word>for</Word>
<Word>forall</Word>
<Word>foreign</Word>
<Word>format</Word>
<Word>formatmessage</Word>
<Word>found</Word>
<Word>freetexttable</Word>
<Word>from</Word>
<Word>from_days</Word>
<Word>fulltextcatalog</Word>
<Word>fulltextservice</Word>
<Word>function</Word>
<Word>general</Word>
<Word>get</Word>
<Word>get_lock</Word>
<Word>getdate</Word>
<Word>getansinull</Word>
<Word>getutcdate</Word>
<Word>global</Word>
<Word>go</Word>
<Word>goto</Word>
<Word>grant</Word>
<Word>greatest</Word>
<Word>group</Word>
<Word>grouping</Word>
<Word>having</Word>
<Word>heap</Word>
<Word>hex</Word>
<Word>hextoraw</Word>
<Word>host</Word>
<Word>host_id</Word>
<Word>host_name</Word>
<Word>hour</Word>
<Word>ident_incr</Word>
<Word>ident_seed</Word>
<Word>ident_current</Word>
<Word>identified</Word>
<Word>identity</Word>
<Word>if</Word>
<Word>ifnull</Word>
<Word>ignore</Word>
<Word>immediate</Word>
<Word>in</Word>
<Word>increment</Word>
<Word>index</Word>
<Word>index_col</Word>
<Word>indexproperty</Word>
<Word>indicator</Word>
<Word>initcap</Word>
<Word>initial</Word>
<Word>initialize</Word>
<Word>initially</Word>
<Word>inner</Word>
<Word>inout</Word>
<Word>input</Word>
<Word>insert</Word>
<Word>instr</Word>
<Word>instrb</Word>
<Word>int</Word>
<Word>integer</Word>
<Word>interface</Word>
<Word>intersect</Word>
<Word>interval</Word>
<Word>into</Word>
<Word>is</Word>
<Word>is_member</Word>
<Word>is_srvrolemember</Word>
<Word>is_null</Word>
<Word>is_numeric</Word>
<Word>isdate</Word>
<Word>isnull</Word>
<Word>isolation</Word>
<Word>iterate</Word>
<Word>java</Word>
<Word>join</Word>
<Word>key</Word>
<Word>lag</Word>
<Word>language</Word>
<Word>large</Word>
<Word>last</Word>
<Word>last_day</Word>
<Word>last_value</Word>
<Word>lateral</Word>
<Word>lcase</Word>
<Word>lead</Word>
<Word>leading</Word>
<Word>least</Word>
<Word>left</Word>
<Word>len</Word>
<Word>length</Word>
<Word>lengthb</Word>
<Word>less</Word>
<Word>level</Word>
<Word>like</Word>
<Word>limit</Word>
<Word>limited</Word>
<Word>ln</Word>
<Word>lpad</Word>
<Word>local</Word>
<Word>localtime</Word>
<Word>localtimestamp</Word>
<Word>locator</Word>
<Word>lock</Word>
<Word>log</Word>
<Word>log10</Word>
<Word>long</Word>
<Word>loop</Word>
<Word>lower</Word>
<Word>ltrim</Word>
<Word>make_ref</Word>
<Word>map</Word>
<Word>match</Word>
<Word>max</Word>
<Word>maxextents</Word>
<Word>mid</Word>
<Word>min</Word>
<Word>minus</Word>
<Word>minute</Word>
<Word>mlslabel</Word>
<Word>mod</Word>
<Word>mode</Word>
<Word>modifies</Word>
<Word>modify</Word>
<Word>module</Word>
<Word>month</Word>
<Word>months_between</Word>
<Word>names</Word>
<Word>national</Word>
<Word>natural</Word>
<Word>naturaln</Word>
<Word>nchar</Word>
<Word>nclob</Word>
<Word>new</Word>
<Word>new_time</Word>
<Word>newid</Word>
<Word>next</Word>
<Word>next_day</Word>
<Word>nextval</Word>
<Word>no</Word>
<Word>noaudit</Word>
<Word>nocompress</Word>
<Word>nocopy</Word>
<Word>nolock</Word>
<Word>none</Word>
<Word>not</Word>
<Word>nowait</Word>
<Word>null</Word>
<Word>nullif</Word>
<Word>number</Word>
<Word>number_base</Word>
<Word>numeric</Word>
<Word>nvl</Word>
<Word>nvl2</Word>
<Word>object</Word>
<Word>object_id</Word>
<Word>object_name</Word>
<Word>object_property</Word>
<Word>ocirowid</Word>
<Word>oct</Word>
<Word>of</Word>
<Word>off</Word>
<Word>offline</Word>
<Word>old</Word>
<Word>on</Word>
<Word>online</Word>
<Word>only</Word>
<Word>opaque</Word>
<Word>open</Word>
<Word>operator</Word>
<Word>operation</Word>
<Word>option</Word>
<Word>or</Word>
<Word>ord</Word>
<Word>order</Word>
<Word>ordinalityorganization</Word>
<Word>others</Word>
<Word>out</Word>
<Word>outer</Word>
<Word>output</Word>
<Word>package</Word>
<Word>pad</Word>
<Word>parameter</Word>
<Word>parameters</Word>
<Word>partial</Word>
<Word>partition</Word>
<Word>path</Word>
<Word>pctfree</Word>
<Word>percent_rank</Word>
<Word>pi</Word>
<Word>pls_integer</Word>
<Word>positive</Word>
<Word>positiven</Word>
<Word>postfix</Word>
<Word>pow</Word>
<Word>power</Word>
<Word>pragma</Word>
<Word>precision</Word>
<Word>prefix</Word>
<Word>preorder</Word>
<Word>prepare</Word>
<Word>preserve</Word>
<Word>primary</Word>
<Word>prior</Word>
<Word>private</Word>
<Word>privileges</Word>
<Word>procedure</Word>
<Word>public</Word>
<Word>radians</Word>
<Word>raise</Word>
<Word>rand</Word>
<Word>range</Word>
<Word>rank</Word>
<Word>ratio_to_export</Word>
<Word>raw</Word>
<Word>rawtohex</Word>
<Word>read</Word>
<Word>reads</Word>
<Word>real</Word>
<Word>record</Word>
<Word>recursive</Word>
<Word>ref</Word>
<Word>references</Word>
<Word>referencing</Word>
<Word>reftohex</Word>
<Word>relative</Word>
<Word>release</Word>
<Word>release_lock</Word>
<Word>rename</Word>
<Word>repeat</Word>
<Word>replace</Word>
<Word>resource</Word>
<Word>restrict</Word>
<Word>result</Word>
<Word>return</Word>
<Word>returns</Word>
<Word>reverse</Word>
<Word>revoke</Word>
<Word>right</Word>
<Word>rollback</Word>
<Word>rollup</Word>
<Word>round</Word>
<Word>routine</Word>
<Word>row</Word>
<Word>row_number</Word>
<Word>rowid</Word>
<Word>rowidtochar</Word>
<Word>rowlabel</Word>
<Word>rowlock</Word>
<Word>rownum</Word>
<Word>rows</Word>
<Word>rowtype</Word>
<Word>rpad</Word>
<Word>rtrim</Word>
<Word>savepoint</Word>
<Word>schema</Word>
<Word>scroll</Word>
<Word>scope</Word>
<Word>search</Word>
<Word>second</Word>
<Word>section</Word>
<Word>seddev_samp</Word>
<Word>select</Word>
<Word>separate</Word>
<Word>sequence</Word>
<Word>session</Word>
<Word>session_user</Word>
<Word>set</Word>
<Word>sets</Word>
<Word>share</Word>
<Word>sign</Word>
<Word>sin</Word>
<Word>sinh</Word>
<Word>size</Word>
<Word>smallint</Word>
<Word>some</Word>
<Word>soundex</Word>
<Word>space</Word>
<Word>specific</Word>
<Word>specifictype</Word>
<Word>sql</Word>
<Word>sqlcode</Word>
<Word>sqlerrm</Word>
<Word>sqlexception</Word>
<Word>sqlstate</Word>
<Word>sqlwarning</Word>
<Word>sqrt</Word>
<Word>start</Word>
<Word>state</Word>
<Word>statement</Word>
<Word>static</Word>
<Word>std</Word>
<Word>stddev</Word>
<Word>stdev_pop</Word>
<Word>strcmp</Word>
<Word>structure</Word>
<Word>subdate</Word>
<Word>substr</Word>
<Word>substrb</Word>
<Word>substring</Word>
<Word>substring_index</Word>
<Word>subtype</Word>
<Word>successful</Word>
<Word>sum</Word>
<Word>synonym</Word>
<Word>sys_context</Word>
<Word>sys_guid</Word>
<Word>sysdate</Word>
<Word>system_user</Word>
<Word>table</Word>
<Word>tan</Word>
<Word>tanh</Word>
<Word>temporary</Word>
<Word>terminate</Word>
<Word>than</Word>
<Word>then</Word>
<Word>time</Word>
<Word>timestamp</Word>
<Word>timezone_abbr</Word>
<Word>timezone_minute</Word>
<Word>timezone_hour</Word>
<Word>timezone_region</Word>
<Word>tinyint</Word>
<Word>to</Word>
<Word>to_char</Word>
<Word>to_date</Word>
<Word>to_days</Word>
<Word>to_number</Word>
<Word>to_single_byte</Word>
<Word>trailing</Word>
<Word>transaction</Word>
<Word>translate</Word>
<Word>translation</Word>
<Word>treat</Word>
<Word>trigger</Word>
<Word>trim</Word>
<Word>true</Word>
<Word>trunc</Word>
<Word>truncate</Word>
<Word>type</Word>
<Word>ucase</Word>
<Word>uid</Word>
<Word>under</Word>
<Word>union</Word>
<Word>unique</Word>
<Word>unknown</Word>
<Word>unnest</Word>
<Word>update</Word>
<Word>upper</Word>
<Word>usage</Word>
<Word>use</Word>
<Word>user</Word>
<Word>userenv</Word>
<Word>using</Word>
<Word>validate</Word>
<Word>value</Word>
<Word>values</Word>
<Word>var_pop</Word>
<Word>var_samp</Word>
<Word>varbinary</Word>
<Word>varchar</Word>
<Word>varchar2</Word>
<Word>variable</Word>
<Word>variance</Word>
<Word>varying</Word>
<Word>view</Word>
<Word>vsize</Word>
<Word>when</Word>
<Word>whenever</Word>
<Word>where</Word>
<Word>with</Word>
<Word>without</Word>
<Word>while</Word>
<Word>work</Word>
<Word>write</Word>
<Word>year</Word>
<Word>zone</Word>
</Keywords>
</RuleSet>
</SyntaxDefinition>
<MSG> Update TSQL file #125
https://github.com/icsharpcode/AvalonEdit/pull/125
<DFF> @@ -559,6 +559,7 @@
<Word>timezone_region</Word>
<Word>tinyint</Word>
<Word>to</Word>
+ <Word>top</Word>
<Word>to_char</Word>
<Word>to_date</Word>
<Word>to_days</Word>
| 1 | Update TSQL file #125 | 0 | .xshd | xshd | mit | AvaloniaUI/AvaloniaEdit |
10066929 | <NME> TSQL-Mode.xshd
<BEF> <?xml version="1.0"?>
<SyntaxDefinition name="TSQL" extensions=".sql" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
<Color name="Comment" foreground="Green" exampleText="-- comment" />
<Color name="Char" foreground="Red" exampleText="name = 'abc'"/>
<Color name="Keywords" fontWeight="bold" foreground="Blue" exampleText="SELECT FROM"/>
<Property name="DocCommentMarker" value="///" />
<RuleSet name="CommentMarkerSet">
<Keywords fontWeight="bold" foreground="Red">
<Word>TODO</Word>
<Word>FIXME</Word>
</Keywords>
<Keywords fontWeight="bold" foreground="#E0E000">
<Word>HACK</Word>
<Word>UNDONE</Word>
</Keywords>
</RuleSet>
<RuleSet ignoreCase="true">
<Span color="Comment" ruleSet="CommentMarkerSet">
<Begin>--</Begin>
</Span>
<Span color="Comment" ruleSet="CommentMarkerSet" multiline="true">
<Begin>/\*</Begin>
<End>\*/</End>
</Span>
<Span color="Char">
<Begin>'</Begin>
<End>'</End>
<RuleSet>
<Span begin="\\" end="."/>
</RuleSet>
</Span>
<Keywords color="Keywords">
<Word>abs</Word>
<Word>absolute</Word>
<Word>access</Word>
<Word>acos</Word>
<Word>add</Word>
<Word>add_months</Word>
<Word>adddate</Word>
<Word>admin</Word>
<Word>after</Word>
<Word>aggregate</Word>
<Word>all</Word>
<Word>allocate</Word>
<Word>alter</Word>
<Word>and</Word>
<Word>any</Word>
<Word>app_name</Word>
<Word>are</Word>
<Word>array</Word>
<Word>as</Word>
<Word>asc</Word>
<Word>ascii</Word>
<Word>asin</Word>
<Word>assertion</Word>
<Word>at</Word>
<Word>atan</Word>
<Word>atn2</Word>
<Word>audit</Word>
<Word>authid</Word>
<Word>authorization</Word>
<Word>autonomous_transaction</Word>
<Word>avg</Word>
<Word>before</Word>
<Word>begin</Word>
<Word>benchmark</Word>
<Word>between</Word>
<Word>bfilename</Word>
<Word>bigint</Word>
<Word>bin</Word>
<Word>binary</Word>
<Word>binary_checksum</Word>
<Word>binary_integer</Word>
<Word>bit</Word>
<Word>bit_count</Word>
<Word>bit_and</Word>
<Word>bit_or</Word>
<Word>blob</Word>
<Word>body</Word>
<Word>boolean</Word>
<Word>both</Word>
<Word>breadth</Word>
<Word>bulk</Word>
<Word>by</Word>
<Word>call</Word>
<Word>cascade</Word>
<Word>cascaded</Word>
<Word>case</Word>
<Word>cast</Word>
<Word>catalog</Word>
<Word>ceil</Word>
<Word>ceiling</Word>
<Word>char</Word>
<Word>char_base</Word>
<Word>character</Word>
<Word>charindex</Word>
<Word>chartorowid</Word>
<Word>check</Word>
<Word>checksum</Word>
<Word>checksum_agg</Word>
<Word>chr</Word>
<Word>class</Word>
<Word>clob</Word>
<Word>close</Word>
<Word>cluster</Word>
<Word>coalesce</Word>
<Word>col_length</Word>
<Word>col_name</Word>
<Word>collate</Word>
<Word>collation</Word>
<Word>collect</Word>
<Word>column</Word>
<Word>comment</Word>
<Word>commit</Word>
<Word>completion</Word>
<Word>compress</Word>
<Word>concat</Word>
<Word>concat_ws</Word>
<Word>connect</Word>
<Word>connection</Word>
<Word>constant</Word>
<Word>constraint</Word>
<Word>constraints</Word>
<Word>constructorcreate</Word>
<Word>contains</Word>
<Word>containsable</Word>
<Word>continue</Word>
<Word>conv</Word>
<Word>convert</Word>
<Word>corr</Word>
<Word>corresponding</Word>
<Word>cos</Word>
<Word>cot</Word>
<Word>count</Word>
<Word>count_big</Word>
<Word>covar_pop</Word>
<Word>covar_samp</Word>
<Word>create</Word>
<Word>cross</Word>
<Word>cube</Word>
<Word>cume_dist</Word>
<Word>current</Word>
<Word>current_date</Word>
<Word>current_path</Word>
<Word>current_role</Word>
<Word>current_time</Word>
<Word>current_timestamp</Word>
<Word>current_user</Word>
<Word>currval</Word>
<Word>cursor</Word>
<Word>cycle</Word>
<Word>data</Word>
<Word>datalength</Word>
<Word>databasepropertyex</Word>
<Word>date</Word>
<Word>date_add</Word>
<Word>date_format</Word>
<Word>date_sub</Word>
<Word>dateadd</Word>
<Word>datediff</Word>
<Word>datename</Word>
<Word>datepart</Word>
<Word>datetime</Word>
<Word>day</Word>
<Word>db_id</Word>
<Word>db_name</Word>
<Word>deallocate</Word>
<Word>dec</Word>
<Word>declare</Word>
<Word>decimal</Word>
<Word>decode</Word>
<Word>default</Word>
<Word>deferrable</Word>
<Word>deferred</Word>
<Word>degrees</Word>
<Word>delete</Word>
<Word>dense_rank</Word>
<Word>depth</Word>
<Word>deref</Word>
<Word>desc</Word>
<Word>describe</Word>
<Word>descriptor</Word>
<Word>destroy</Word>
<Word>destructor</Word>
<Word>deterministic</Word>
<Word>diagnostics</Word>
<Word>dictionary</Word>
<Word>disconnect</Word>
<Word>difference</Word>
<Word>distinct</Word>
<Word>do</Word>
<Word>domain</Word>
<Word>double</Word>
<Word>drop</Word>
<Word>dump</Word>
<Word>dynamic</Word>
<Word>each</Word>
<Word>else</Word>
<Word>elsif</Word>
<Word>empth</Word>
<Word>encode</Word>
<Word>encrypt</Word>
<Word>end</Word>
<Word>end-exec</Word>
<Word>equals</Word>
<Word>escape</Word>
<Word>every</Word>
<Word>except</Word>
<Word>exception</Word>
<Word>exclusive</Word>
<Word>exec</Word>
<Word>execute</Word>
<Word>exists</Word>
<Word>exit</Word>
<Word>exp</Word>
<Word>export_set</Word>
<Word>extends</Word>
<Word>external</Word>
<Word>extract</Word>
<Word>false</Word>
<Word>fetch</Word>
<Word>first</Word>
<Word>first_value</Word>
<Word>file</Word>
<Word>float</Word>
<Word>floor</Word>
<Word>file_id</Word>
<Word>file_name</Word>
<Word>filegroup_id</Word>
<Word>filegroup_name</Word>
<Word>filegroupproperty</Word>
<Word>fileproperty</Word>
<Word>for</Word>
<Word>forall</Word>
<Word>foreign</Word>
<Word>format</Word>
<Word>formatmessage</Word>
<Word>found</Word>
<Word>freetexttable</Word>
<Word>from</Word>
<Word>from_days</Word>
<Word>fulltextcatalog</Word>
<Word>fulltextservice</Word>
<Word>function</Word>
<Word>general</Word>
<Word>get</Word>
<Word>get_lock</Word>
<Word>getdate</Word>
<Word>getansinull</Word>
<Word>getutcdate</Word>
<Word>global</Word>
<Word>go</Word>
<Word>goto</Word>
<Word>grant</Word>
<Word>greatest</Word>
<Word>group</Word>
<Word>grouping</Word>
<Word>having</Word>
<Word>heap</Word>
<Word>hex</Word>
<Word>hextoraw</Word>
<Word>host</Word>
<Word>host_id</Word>
<Word>host_name</Word>
<Word>hour</Word>
<Word>ident_incr</Word>
<Word>ident_seed</Word>
<Word>ident_current</Word>
<Word>identified</Word>
<Word>identity</Word>
<Word>if</Word>
<Word>ifnull</Word>
<Word>ignore</Word>
<Word>immediate</Word>
<Word>in</Word>
<Word>increment</Word>
<Word>index</Word>
<Word>index_col</Word>
<Word>indexproperty</Word>
<Word>indicator</Word>
<Word>initcap</Word>
<Word>initial</Word>
<Word>initialize</Word>
<Word>initially</Word>
<Word>inner</Word>
<Word>inout</Word>
<Word>input</Word>
<Word>insert</Word>
<Word>instr</Word>
<Word>instrb</Word>
<Word>int</Word>
<Word>integer</Word>
<Word>interface</Word>
<Word>intersect</Word>
<Word>interval</Word>
<Word>into</Word>
<Word>is</Word>
<Word>is_member</Word>
<Word>is_srvrolemember</Word>
<Word>is_null</Word>
<Word>is_numeric</Word>
<Word>isdate</Word>
<Word>isnull</Word>
<Word>isolation</Word>
<Word>iterate</Word>
<Word>java</Word>
<Word>join</Word>
<Word>key</Word>
<Word>lag</Word>
<Word>language</Word>
<Word>large</Word>
<Word>last</Word>
<Word>last_day</Word>
<Word>last_value</Word>
<Word>lateral</Word>
<Word>lcase</Word>
<Word>lead</Word>
<Word>leading</Word>
<Word>least</Word>
<Word>left</Word>
<Word>len</Word>
<Word>length</Word>
<Word>lengthb</Word>
<Word>less</Word>
<Word>level</Word>
<Word>like</Word>
<Word>limit</Word>
<Word>limited</Word>
<Word>ln</Word>
<Word>lpad</Word>
<Word>local</Word>
<Word>localtime</Word>
<Word>localtimestamp</Word>
<Word>locator</Word>
<Word>lock</Word>
<Word>log</Word>
<Word>log10</Word>
<Word>long</Word>
<Word>loop</Word>
<Word>lower</Word>
<Word>ltrim</Word>
<Word>make_ref</Word>
<Word>map</Word>
<Word>match</Word>
<Word>max</Word>
<Word>maxextents</Word>
<Word>mid</Word>
<Word>min</Word>
<Word>minus</Word>
<Word>minute</Word>
<Word>mlslabel</Word>
<Word>mod</Word>
<Word>mode</Word>
<Word>modifies</Word>
<Word>modify</Word>
<Word>module</Word>
<Word>month</Word>
<Word>months_between</Word>
<Word>names</Word>
<Word>national</Word>
<Word>natural</Word>
<Word>naturaln</Word>
<Word>nchar</Word>
<Word>nclob</Word>
<Word>new</Word>
<Word>new_time</Word>
<Word>newid</Word>
<Word>next</Word>
<Word>next_day</Word>
<Word>nextval</Word>
<Word>no</Word>
<Word>noaudit</Word>
<Word>nocompress</Word>
<Word>nocopy</Word>
<Word>nolock</Word>
<Word>none</Word>
<Word>not</Word>
<Word>nowait</Word>
<Word>null</Word>
<Word>nullif</Word>
<Word>number</Word>
<Word>number_base</Word>
<Word>numeric</Word>
<Word>nvl</Word>
<Word>nvl2</Word>
<Word>object</Word>
<Word>object_id</Word>
<Word>object_name</Word>
<Word>object_property</Word>
<Word>ocirowid</Word>
<Word>oct</Word>
<Word>of</Word>
<Word>off</Word>
<Word>offline</Word>
<Word>old</Word>
<Word>on</Word>
<Word>online</Word>
<Word>only</Word>
<Word>opaque</Word>
<Word>open</Word>
<Word>operator</Word>
<Word>operation</Word>
<Word>option</Word>
<Word>or</Word>
<Word>ord</Word>
<Word>order</Word>
<Word>ordinalityorganization</Word>
<Word>others</Word>
<Word>out</Word>
<Word>outer</Word>
<Word>output</Word>
<Word>package</Word>
<Word>pad</Word>
<Word>parameter</Word>
<Word>parameters</Word>
<Word>partial</Word>
<Word>partition</Word>
<Word>path</Word>
<Word>pctfree</Word>
<Word>percent_rank</Word>
<Word>pi</Word>
<Word>pls_integer</Word>
<Word>positive</Word>
<Word>positiven</Word>
<Word>postfix</Word>
<Word>pow</Word>
<Word>power</Word>
<Word>pragma</Word>
<Word>precision</Word>
<Word>prefix</Word>
<Word>preorder</Word>
<Word>prepare</Word>
<Word>preserve</Word>
<Word>primary</Word>
<Word>prior</Word>
<Word>private</Word>
<Word>privileges</Word>
<Word>procedure</Word>
<Word>public</Word>
<Word>radians</Word>
<Word>raise</Word>
<Word>rand</Word>
<Word>range</Word>
<Word>rank</Word>
<Word>ratio_to_export</Word>
<Word>raw</Word>
<Word>rawtohex</Word>
<Word>read</Word>
<Word>reads</Word>
<Word>real</Word>
<Word>record</Word>
<Word>recursive</Word>
<Word>ref</Word>
<Word>references</Word>
<Word>referencing</Word>
<Word>reftohex</Word>
<Word>relative</Word>
<Word>release</Word>
<Word>release_lock</Word>
<Word>rename</Word>
<Word>repeat</Word>
<Word>replace</Word>
<Word>resource</Word>
<Word>restrict</Word>
<Word>result</Word>
<Word>return</Word>
<Word>returns</Word>
<Word>reverse</Word>
<Word>revoke</Word>
<Word>right</Word>
<Word>rollback</Word>
<Word>rollup</Word>
<Word>round</Word>
<Word>routine</Word>
<Word>row</Word>
<Word>row_number</Word>
<Word>rowid</Word>
<Word>rowidtochar</Word>
<Word>rowlabel</Word>
<Word>rowlock</Word>
<Word>rownum</Word>
<Word>rows</Word>
<Word>rowtype</Word>
<Word>rpad</Word>
<Word>rtrim</Word>
<Word>savepoint</Word>
<Word>schema</Word>
<Word>scroll</Word>
<Word>scope</Word>
<Word>search</Word>
<Word>second</Word>
<Word>section</Word>
<Word>seddev_samp</Word>
<Word>select</Word>
<Word>separate</Word>
<Word>sequence</Word>
<Word>session</Word>
<Word>session_user</Word>
<Word>set</Word>
<Word>sets</Word>
<Word>share</Word>
<Word>sign</Word>
<Word>sin</Word>
<Word>sinh</Word>
<Word>size</Word>
<Word>smallint</Word>
<Word>some</Word>
<Word>soundex</Word>
<Word>space</Word>
<Word>specific</Word>
<Word>specifictype</Word>
<Word>sql</Word>
<Word>sqlcode</Word>
<Word>sqlerrm</Word>
<Word>sqlexception</Word>
<Word>sqlstate</Word>
<Word>sqlwarning</Word>
<Word>sqrt</Word>
<Word>start</Word>
<Word>state</Word>
<Word>statement</Word>
<Word>static</Word>
<Word>std</Word>
<Word>stddev</Word>
<Word>stdev_pop</Word>
<Word>strcmp</Word>
<Word>structure</Word>
<Word>subdate</Word>
<Word>substr</Word>
<Word>substrb</Word>
<Word>substring</Word>
<Word>substring_index</Word>
<Word>subtype</Word>
<Word>successful</Word>
<Word>sum</Word>
<Word>synonym</Word>
<Word>sys_context</Word>
<Word>sys_guid</Word>
<Word>sysdate</Word>
<Word>system_user</Word>
<Word>table</Word>
<Word>tan</Word>
<Word>tanh</Word>
<Word>temporary</Word>
<Word>terminate</Word>
<Word>than</Word>
<Word>then</Word>
<Word>time</Word>
<Word>timestamp</Word>
<Word>timezone_abbr</Word>
<Word>timezone_minute</Word>
<Word>timezone_hour</Word>
<Word>timezone_region</Word>
<Word>tinyint</Word>
<Word>to</Word>
<Word>to_char</Word>
<Word>to_date</Word>
<Word>to_days</Word>
<Word>to_number</Word>
<Word>to_single_byte</Word>
<Word>trailing</Word>
<Word>transaction</Word>
<Word>translate</Word>
<Word>translation</Word>
<Word>treat</Word>
<Word>trigger</Word>
<Word>trim</Word>
<Word>true</Word>
<Word>trunc</Word>
<Word>truncate</Word>
<Word>type</Word>
<Word>ucase</Word>
<Word>uid</Word>
<Word>under</Word>
<Word>union</Word>
<Word>unique</Word>
<Word>unknown</Word>
<Word>unnest</Word>
<Word>update</Word>
<Word>upper</Word>
<Word>usage</Word>
<Word>use</Word>
<Word>user</Word>
<Word>userenv</Word>
<Word>using</Word>
<Word>validate</Word>
<Word>value</Word>
<Word>values</Word>
<Word>var_pop</Word>
<Word>var_samp</Word>
<Word>varbinary</Word>
<Word>varchar</Word>
<Word>varchar2</Word>
<Word>variable</Word>
<Word>variance</Word>
<Word>varying</Word>
<Word>view</Word>
<Word>vsize</Word>
<Word>when</Word>
<Word>whenever</Word>
<Word>where</Word>
<Word>with</Word>
<Word>without</Word>
<Word>while</Word>
<Word>work</Word>
<Word>write</Word>
<Word>year</Word>
<Word>zone</Word>
</Keywords>
</RuleSet>
</SyntaxDefinition>
<MSG> Update TSQL file #125
https://github.com/icsharpcode/AvalonEdit/pull/125
<DFF> @@ -559,6 +559,7 @@
<Word>timezone_region</Word>
<Word>tinyint</Word>
<Word>to</Word>
+ <Word>top</Word>
<Word>to_char</Word>
<Word>to_date</Word>
<Word>to_days</Word>
| 1 | Update TSQL file #125 | 0 | .xshd | xshd | mit | AvaloniaUI/AvaloniaEdit |
10066930 | <NME> TSQL-Mode.xshd
<BEF> <?xml version="1.0"?>
<SyntaxDefinition name="TSQL" extensions=".sql" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
<Color name="Comment" foreground="Green" exampleText="-- comment" />
<Color name="Char" foreground="Red" exampleText="name = 'abc'"/>
<Color name="Keywords" fontWeight="bold" foreground="Blue" exampleText="SELECT FROM"/>
<Property name="DocCommentMarker" value="///" />
<RuleSet name="CommentMarkerSet">
<Keywords fontWeight="bold" foreground="Red">
<Word>TODO</Word>
<Word>FIXME</Word>
</Keywords>
<Keywords fontWeight="bold" foreground="#E0E000">
<Word>HACK</Word>
<Word>UNDONE</Word>
</Keywords>
</RuleSet>
<RuleSet ignoreCase="true">
<Span color="Comment" ruleSet="CommentMarkerSet">
<Begin>--</Begin>
</Span>
<Span color="Comment" ruleSet="CommentMarkerSet" multiline="true">
<Begin>/\*</Begin>
<End>\*/</End>
</Span>
<Span color="Char">
<Begin>'</Begin>
<End>'</End>
<RuleSet>
<Span begin="\\" end="."/>
</RuleSet>
</Span>
<Keywords color="Keywords">
<Word>abs</Word>
<Word>absolute</Word>
<Word>access</Word>
<Word>acos</Word>
<Word>add</Word>
<Word>add_months</Word>
<Word>adddate</Word>
<Word>admin</Word>
<Word>after</Word>
<Word>aggregate</Word>
<Word>all</Word>
<Word>allocate</Word>
<Word>alter</Word>
<Word>and</Word>
<Word>any</Word>
<Word>app_name</Word>
<Word>are</Word>
<Word>array</Word>
<Word>as</Word>
<Word>asc</Word>
<Word>ascii</Word>
<Word>asin</Word>
<Word>assertion</Word>
<Word>at</Word>
<Word>atan</Word>
<Word>atn2</Word>
<Word>audit</Word>
<Word>authid</Word>
<Word>authorization</Word>
<Word>autonomous_transaction</Word>
<Word>avg</Word>
<Word>before</Word>
<Word>begin</Word>
<Word>benchmark</Word>
<Word>between</Word>
<Word>bfilename</Word>
<Word>bigint</Word>
<Word>bin</Word>
<Word>binary</Word>
<Word>binary_checksum</Word>
<Word>binary_integer</Word>
<Word>bit</Word>
<Word>bit_count</Word>
<Word>bit_and</Word>
<Word>bit_or</Word>
<Word>blob</Word>
<Word>body</Word>
<Word>boolean</Word>
<Word>both</Word>
<Word>breadth</Word>
<Word>bulk</Word>
<Word>by</Word>
<Word>call</Word>
<Word>cascade</Word>
<Word>cascaded</Word>
<Word>case</Word>
<Word>cast</Word>
<Word>catalog</Word>
<Word>ceil</Word>
<Word>ceiling</Word>
<Word>char</Word>
<Word>char_base</Word>
<Word>character</Word>
<Word>charindex</Word>
<Word>chartorowid</Word>
<Word>check</Word>
<Word>checksum</Word>
<Word>checksum_agg</Word>
<Word>chr</Word>
<Word>class</Word>
<Word>clob</Word>
<Word>close</Word>
<Word>cluster</Word>
<Word>coalesce</Word>
<Word>col_length</Word>
<Word>col_name</Word>
<Word>collate</Word>
<Word>collation</Word>
<Word>collect</Word>
<Word>column</Word>
<Word>comment</Word>
<Word>commit</Word>
<Word>completion</Word>
<Word>compress</Word>
<Word>concat</Word>
<Word>concat_ws</Word>
<Word>connect</Word>
<Word>connection</Word>
<Word>constant</Word>
<Word>constraint</Word>
<Word>constraints</Word>
<Word>constructorcreate</Word>
<Word>contains</Word>
<Word>containsable</Word>
<Word>continue</Word>
<Word>conv</Word>
<Word>convert</Word>
<Word>corr</Word>
<Word>corresponding</Word>
<Word>cos</Word>
<Word>cot</Word>
<Word>count</Word>
<Word>count_big</Word>
<Word>covar_pop</Word>
<Word>covar_samp</Word>
<Word>create</Word>
<Word>cross</Word>
<Word>cube</Word>
<Word>cume_dist</Word>
<Word>current</Word>
<Word>current_date</Word>
<Word>current_path</Word>
<Word>current_role</Word>
<Word>current_time</Word>
<Word>current_timestamp</Word>
<Word>current_user</Word>
<Word>currval</Word>
<Word>cursor</Word>
<Word>cycle</Word>
<Word>data</Word>
<Word>datalength</Word>
<Word>databasepropertyex</Word>
<Word>date</Word>
<Word>date_add</Word>
<Word>date_format</Word>
<Word>date_sub</Word>
<Word>dateadd</Word>
<Word>datediff</Word>
<Word>datename</Word>
<Word>datepart</Word>
<Word>datetime</Word>
<Word>day</Word>
<Word>db_id</Word>
<Word>db_name</Word>
<Word>deallocate</Word>
<Word>dec</Word>
<Word>declare</Word>
<Word>decimal</Word>
<Word>decode</Word>
<Word>default</Word>
<Word>deferrable</Word>
<Word>deferred</Word>
<Word>degrees</Word>
<Word>delete</Word>
<Word>dense_rank</Word>
<Word>depth</Word>
<Word>deref</Word>
<Word>desc</Word>
<Word>describe</Word>
<Word>descriptor</Word>
<Word>destroy</Word>
<Word>destructor</Word>
<Word>deterministic</Word>
<Word>diagnostics</Word>
<Word>dictionary</Word>
<Word>disconnect</Word>
<Word>difference</Word>
<Word>distinct</Word>
<Word>do</Word>
<Word>domain</Word>
<Word>double</Word>
<Word>drop</Word>
<Word>dump</Word>
<Word>dynamic</Word>
<Word>each</Word>
<Word>else</Word>
<Word>elsif</Word>
<Word>empth</Word>
<Word>encode</Word>
<Word>encrypt</Word>
<Word>end</Word>
<Word>end-exec</Word>
<Word>equals</Word>
<Word>escape</Word>
<Word>every</Word>
<Word>except</Word>
<Word>exception</Word>
<Word>exclusive</Word>
<Word>exec</Word>
<Word>execute</Word>
<Word>exists</Word>
<Word>exit</Word>
<Word>exp</Word>
<Word>export_set</Word>
<Word>extends</Word>
<Word>external</Word>
<Word>extract</Word>
<Word>false</Word>
<Word>fetch</Word>
<Word>first</Word>
<Word>first_value</Word>
<Word>file</Word>
<Word>float</Word>
<Word>floor</Word>
<Word>file_id</Word>
<Word>file_name</Word>
<Word>filegroup_id</Word>
<Word>filegroup_name</Word>
<Word>filegroupproperty</Word>
<Word>fileproperty</Word>
<Word>for</Word>
<Word>forall</Word>
<Word>foreign</Word>
<Word>format</Word>
<Word>formatmessage</Word>
<Word>found</Word>
<Word>freetexttable</Word>
<Word>from</Word>
<Word>from_days</Word>
<Word>fulltextcatalog</Word>
<Word>fulltextservice</Word>
<Word>function</Word>
<Word>general</Word>
<Word>get</Word>
<Word>get_lock</Word>
<Word>getdate</Word>
<Word>getansinull</Word>
<Word>getutcdate</Word>
<Word>global</Word>
<Word>go</Word>
<Word>goto</Word>
<Word>grant</Word>
<Word>greatest</Word>
<Word>group</Word>
<Word>grouping</Word>
<Word>having</Word>
<Word>heap</Word>
<Word>hex</Word>
<Word>hextoraw</Word>
<Word>host</Word>
<Word>host_id</Word>
<Word>host_name</Word>
<Word>hour</Word>
<Word>ident_incr</Word>
<Word>ident_seed</Word>
<Word>ident_current</Word>
<Word>identified</Word>
<Word>identity</Word>
<Word>if</Word>
<Word>ifnull</Word>
<Word>ignore</Word>
<Word>immediate</Word>
<Word>in</Word>
<Word>increment</Word>
<Word>index</Word>
<Word>index_col</Word>
<Word>indexproperty</Word>
<Word>indicator</Word>
<Word>initcap</Word>
<Word>initial</Word>
<Word>initialize</Word>
<Word>initially</Word>
<Word>inner</Word>
<Word>inout</Word>
<Word>input</Word>
<Word>insert</Word>
<Word>instr</Word>
<Word>instrb</Word>
<Word>int</Word>
<Word>integer</Word>
<Word>interface</Word>
<Word>intersect</Word>
<Word>interval</Word>
<Word>into</Word>
<Word>is</Word>
<Word>is_member</Word>
<Word>is_srvrolemember</Word>
<Word>is_null</Word>
<Word>is_numeric</Word>
<Word>isdate</Word>
<Word>isnull</Word>
<Word>isolation</Word>
<Word>iterate</Word>
<Word>java</Word>
<Word>join</Word>
<Word>key</Word>
<Word>lag</Word>
<Word>language</Word>
<Word>large</Word>
<Word>last</Word>
<Word>last_day</Word>
<Word>last_value</Word>
<Word>lateral</Word>
<Word>lcase</Word>
<Word>lead</Word>
<Word>leading</Word>
<Word>least</Word>
<Word>left</Word>
<Word>len</Word>
<Word>length</Word>
<Word>lengthb</Word>
<Word>less</Word>
<Word>level</Word>
<Word>like</Word>
<Word>limit</Word>
<Word>limited</Word>
<Word>ln</Word>
<Word>lpad</Word>
<Word>local</Word>
<Word>localtime</Word>
<Word>localtimestamp</Word>
<Word>locator</Word>
<Word>lock</Word>
<Word>log</Word>
<Word>log10</Word>
<Word>long</Word>
<Word>loop</Word>
<Word>lower</Word>
<Word>ltrim</Word>
<Word>make_ref</Word>
<Word>map</Word>
<Word>match</Word>
<Word>max</Word>
<Word>maxextents</Word>
<Word>mid</Word>
<Word>min</Word>
<Word>minus</Word>
<Word>minute</Word>
<Word>mlslabel</Word>
<Word>mod</Word>
<Word>mode</Word>
<Word>modifies</Word>
<Word>modify</Word>
<Word>module</Word>
<Word>month</Word>
<Word>months_between</Word>
<Word>names</Word>
<Word>national</Word>
<Word>natural</Word>
<Word>naturaln</Word>
<Word>nchar</Word>
<Word>nclob</Word>
<Word>new</Word>
<Word>new_time</Word>
<Word>newid</Word>
<Word>next</Word>
<Word>next_day</Word>
<Word>nextval</Word>
<Word>no</Word>
<Word>noaudit</Word>
<Word>nocompress</Word>
<Word>nocopy</Word>
<Word>nolock</Word>
<Word>none</Word>
<Word>not</Word>
<Word>nowait</Word>
<Word>null</Word>
<Word>nullif</Word>
<Word>number</Word>
<Word>number_base</Word>
<Word>numeric</Word>
<Word>nvl</Word>
<Word>nvl2</Word>
<Word>object</Word>
<Word>object_id</Word>
<Word>object_name</Word>
<Word>object_property</Word>
<Word>ocirowid</Word>
<Word>oct</Word>
<Word>of</Word>
<Word>off</Word>
<Word>offline</Word>
<Word>old</Word>
<Word>on</Word>
<Word>online</Word>
<Word>only</Word>
<Word>opaque</Word>
<Word>open</Word>
<Word>operator</Word>
<Word>operation</Word>
<Word>option</Word>
<Word>or</Word>
<Word>ord</Word>
<Word>order</Word>
<Word>ordinalityorganization</Word>
<Word>others</Word>
<Word>out</Word>
<Word>outer</Word>
<Word>output</Word>
<Word>package</Word>
<Word>pad</Word>
<Word>parameter</Word>
<Word>parameters</Word>
<Word>partial</Word>
<Word>partition</Word>
<Word>path</Word>
<Word>pctfree</Word>
<Word>percent_rank</Word>
<Word>pi</Word>
<Word>pls_integer</Word>
<Word>positive</Word>
<Word>positiven</Word>
<Word>postfix</Word>
<Word>pow</Word>
<Word>power</Word>
<Word>pragma</Word>
<Word>precision</Word>
<Word>prefix</Word>
<Word>preorder</Word>
<Word>prepare</Word>
<Word>preserve</Word>
<Word>primary</Word>
<Word>prior</Word>
<Word>private</Word>
<Word>privileges</Word>
<Word>procedure</Word>
<Word>public</Word>
<Word>radians</Word>
<Word>raise</Word>
<Word>rand</Word>
<Word>range</Word>
<Word>rank</Word>
<Word>ratio_to_export</Word>
<Word>raw</Word>
<Word>rawtohex</Word>
<Word>read</Word>
<Word>reads</Word>
<Word>real</Word>
<Word>record</Word>
<Word>recursive</Word>
<Word>ref</Word>
<Word>references</Word>
<Word>referencing</Word>
<Word>reftohex</Word>
<Word>relative</Word>
<Word>release</Word>
<Word>release_lock</Word>
<Word>rename</Word>
<Word>repeat</Word>
<Word>replace</Word>
<Word>resource</Word>
<Word>restrict</Word>
<Word>result</Word>
<Word>return</Word>
<Word>returns</Word>
<Word>reverse</Word>
<Word>revoke</Word>
<Word>right</Word>
<Word>rollback</Word>
<Word>rollup</Word>
<Word>round</Word>
<Word>routine</Word>
<Word>row</Word>
<Word>row_number</Word>
<Word>rowid</Word>
<Word>rowidtochar</Word>
<Word>rowlabel</Word>
<Word>rowlock</Word>
<Word>rownum</Word>
<Word>rows</Word>
<Word>rowtype</Word>
<Word>rpad</Word>
<Word>rtrim</Word>
<Word>savepoint</Word>
<Word>schema</Word>
<Word>scroll</Word>
<Word>scope</Word>
<Word>search</Word>
<Word>second</Word>
<Word>section</Word>
<Word>seddev_samp</Word>
<Word>select</Word>
<Word>separate</Word>
<Word>sequence</Word>
<Word>session</Word>
<Word>session_user</Word>
<Word>set</Word>
<Word>sets</Word>
<Word>share</Word>
<Word>sign</Word>
<Word>sin</Word>
<Word>sinh</Word>
<Word>size</Word>
<Word>smallint</Word>
<Word>some</Word>
<Word>soundex</Word>
<Word>space</Word>
<Word>specific</Word>
<Word>specifictype</Word>
<Word>sql</Word>
<Word>sqlcode</Word>
<Word>sqlerrm</Word>
<Word>sqlexception</Word>
<Word>sqlstate</Word>
<Word>sqlwarning</Word>
<Word>sqrt</Word>
<Word>start</Word>
<Word>state</Word>
<Word>statement</Word>
<Word>static</Word>
<Word>std</Word>
<Word>stddev</Word>
<Word>stdev_pop</Word>
<Word>strcmp</Word>
<Word>structure</Word>
<Word>subdate</Word>
<Word>substr</Word>
<Word>substrb</Word>
<Word>substring</Word>
<Word>substring_index</Word>
<Word>subtype</Word>
<Word>successful</Word>
<Word>sum</Word>
<Word>synonym</Word>
<Word>sys_context</Word>
<Word>sys_guid</Word>
<Word>sysdate</Word>
<Word>system_user</Word>
<Word>table</Word>
<Word>tan</Word>
<Word>tanh</Word>
<Word>temporary</Word>
<Word>terminate</Word>
<Word>than</Word>
<Word>then</Word>
<Word>time</Word>
<Word>timestamp</Word>
<Word>timezone_abbr</Word>
<Word>timezone_minute</Word>
<Word>timezone_hour</Word>
<Word>timezone_region</Word>
<Word>tinyint</Word>
<Word>to</Word>
<Word>to_char</Word>
<Word>to_date</Word>
<Word>to_days</Word>
<Word>to_number</Word>
<Word>to_single_byte</Word>
<Word>trailing</Word>
<Word>transaction</Word>
<Word>translate</Word>
<Word>translation</Word>
<Word>treat</Word>
<Word>trigger</Word>
<Word>trim</Word>
<Word>true</Word>
<Word>trunc</Word>
<Word>truncate</Word>
<Word>type</Word>
<Word>ucase</Word>
<Word>uid</Word>
<Word>under</Word>
<Word>union</Word>
<Word>unique</Word>
<Word>unknown</Word>
<Word>unnest</Word>
<Word>update</Word>
<Word>upper</Word>
<Word>usage</Word>
<Word>use</Word>
<Word>user</Word>
<Word>userenv</Word>
<Word>using</Word>
<Word>validate</Word>
<Word>value</Word>
<Word>values</Word>
<Word>var_pop</Word>
<Word>var_samp</Word>
<Word>varbinary</Word>
<Word>varchar</Word>
<Word>varchar2</Word>
<Word>variable</Word>
<Word>variance</Word>
<Word>varying</Word>
<Word>view</Word>
<Word>vsize</Word>
<Word>when</Word>
<Word>whenever</Word>
<Word>where</Word>
<Word>with</Word>
<Word>without</Word>
<Word>while</Word>
<Word>work</Word>
<Word>write</Word>
<Word>year</Word>
<Word>zone</Word>
</Keywords>
</RuleSet>
</SyntaxDefinition>
<MSG> Update TSQL file #125
https://github.com/icsharpcode/AvalonEdit/pull/125
<DFF> @@ -559,6 +559,7 @@
<Word>timezone_region</Word>
<Word>tinyint</Word>
<Word>to</Word>
+ <Word>top</Word>
<Word>to_char</Word>
<Word>to_date</Word>
<Word>to_days</Word>
| 1 | Update TSQL file #125 | 0 | .xshd | xshd | mit | AvaloniaUI/AvaloniaEdit |
10066931 | <NME> TSQL-Mode.xshd
<BEF> <?xml version="1.0"?>
<SyntaxDefinition name="TSQL" extensions=".sql" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
<Color name="Comment" foreground="Green" exampleText="-- comment" />
<Color name="Char" foreground="Red" exampleText="name = 'abc'"/>
<Color name="Keywords" fontWeight="bold" foreground="Blue" exampleText="SELECT FROM"/>
<Property name="DocCommentMarker" value="///" />
<RuleSet name="CommentMarkerSet">
<Keywords fontWeight="bold" foreground="Red">
<Word>TODO</Word>
<Word>FIXME</Word>
</Keywords>
<Keywords fontWeight="bold" foreground="#E0E000">
<Word>HACK</Word>
<Word>UNDONE</Word>
</Keywords>
</RuleSet>
<RuleSet ignoreCase="true">
<Span color="Comment" ruleSet="CommentMarkerSet">
<Begin>--</Begin>
</Span>
<Span color="Comment" ruleSet="CommentMarkerSet" multiline="true">
<Begin>/\*</Begin>
<End>\*/</End>
</Span>
<Span color="Char">
<Begin>'</Begin>
<End>'</End>
<RuleSet>
<Span begin="\\" end="."/>
</RuleSet>
</Span>
<Keywords color="Keywords">
<Word>abs</Word>
<Word>absolute</Word>
<Word>access</Word>
<Word>acos</Word>
<Word>add</Word>
<Word>add_months</Word>
<Word>adddate</Word>
<Word>admin</Word>
<Word>after</Word>
<Word>aggregate</Word>
<Word>all</Word>
<Word>allocate</Word>
<Word>alter</Word>
<Word>and</Word>
<Word>any</Word>
<Word>app_name</Word>
<Word>are</Word>
<Word>array</Word>
<Word>as</Word>
<Word>asc</Word>
<Word>ascii</Word>
<Word>asin</Word>
<Word>assertion</Word>
<Word>at</Word>
<Word>atan</Word>
<Word>atn2</Word>
<Word>audit</Word>
<Word>authid</Word>
<Word>authorization</Word>
<Word>autonomous_transaction</Word>
<Word>avg</Word>
<Word>before</Word>
<Word>begin</Word>
<Word>benchmark</Word>
<Word>between</Word>
<Word>bfilename</Word>
<Word>bigint</Word>
<Word>bin</Word>
<Word>binary</Word>
<Word>binary_checksum</Word>
<Word>binary_integer</Word>
<Word>bit</Word>
<Word>bit_count</Word>
<Word>bit_and</Word>
<Word>bit_or</Word>
<Word>blob</Word>
<Word>body</Word>
<Word>boolean</Word>
<Word>both</Word>
<Word>breadth</Word>
<Word>bulk</Word>
<Word>by</Word>
<Word>call</Word>
<Word>cascade</Word>
<Word>cascaded</Word>
<Word>case</Word>
<Word>cast</Word>
<Word>catalog</Word>
<Word>ceil</Word>
<Word>ceiling</Word>
<Word>char</Word>
<Word>char_base</Word>
<Word>character</Word>
<Word>charindex</Word>
<Word>chartorowid</Word>
<Word>check</Word>
<Word>checksum</Word>
<Word>checksum_agg</Word>
<Word>chr</Word>
<Word>class</Word>
<Word>clob</Word>
<Word>close</Word>
<Word>cluster</Word>
<Word>coalesce</Word>
<Word>col_length</Word>
<Word>col_name</Word>
<Word>collate</Word>
<Word>collation</Word>
<Word>collect</Word>
<Word>column</Word>
<Word>comment</Word>
<Word>commit</Word>
<Word>completion</Word>
<Word>compress</Word>
<Word>concat</Word>
<Word>concat_ws</Word>
<Word>connect</Word>
<Word>connection</Word>
<Word>constant</Word>
<Word>constraint</Word>
<Word>constraints</Word>
<Word>constructorcreate</Word>
<Word>contains</Word>
<Word>containsable</Word>
<Word>continue</Word>
<Word>conv</Word>
<Word>convert</Word>
<Word>corr</Word>
<Word>corresponding</Word>
<Word>cos</Word>
<Word>cot</Word>
<Word>count</Word>
<Word>count_big</Word>
<Word>covar_pop</Word>
<Word>covar_samp</Word>
<Word>create</Word>
<Word>cross</Word>
<Word>cube</Word>
<Word>cume_dist</Word>
<Word>current</Word>
<Word>current_date</Word>
<Word>current_path</Word>
<Word>current_role</Word>
<Word>current_time</Word>
<Word>current_timestamp</Word>
<Word>current_user</Word>
<Word>currval</Word>
<Word>cursor</Word>
<Word>cycle</Word>
<Word>data</Word>
<Word>datalength</Word>
<Word>databasepropertyex</Word>
<Word>date</Word>
<Word>date_add</Word>
<Word>date_format</Word>
<Word>date_sub</Word>
<Word>dateadd</Word>
<Word>datediff</Word>
<Word>datename</Word>
<Word>datepart</Word>
<Word>datetime</Word>
<Word>day</Word>
<Word>db_id</Word>
<Word>db_name</Word>
<Word>deallocate</Word>
<Word>dec</Word>
<Word>declare</Word>
<Word>decimal</Word>
<Word>decode</Word>
<Word>default</Word>
<Word>deferrable</Word>
<Word>deferred</Word>
<Word>degrees</Word>
<Word>delete</Word>
<Word>dense_rank</Word>
<Word>depth</Word>
<Word>deref</Word>
<Word>desc</Word>
<Word>describe</Word>
<Word>descriptor</Word>
<Word>destroy</Word>
<Word>destructor</Word>
<Word>deterministic</Word>
<Word>diagnostics</Word>
<Word>dictionary</Word>
<Word>disconnect</Word>
<Word>difference</Word>
<Word>distinct</Word>
<Word>do</Word>
<Word>domain</Word>
<Word>double</Word>
<Word>drop</Word>
<Word>dump</Word>
<Word>dynamic</Word>
<Word>each</Word>
<Word>else</Word>
<Word>elsif</Word>
<Word>empth</Word>
<Word>encode</Word>
<Word>encrypt</Word>
<Word>end</Word>
<Word>end-exec</Word>
<Word>equals</Word>
<Word>escape</Word>
<Word>every</Word>
<Word>except</Word>
<Word>exception</Word>
<Word>exclusive</Word>
<Word>exec</Word>
<Word>execute</Word>
<Word>exists</Word>
<Word>exit</Word>
<Word>exp</Word>
<Word>export_set</Word>
<Word>extends</Word>
<Word>external</Word>
<Word>extract</Word>
<Word>false</Word>
<Word>fetch</Word>
<Word>first</Word>
<Word>first_value</Word>
<Word>file</Word>
<Word>float</Word>
<Word>floor</Word>
<Word>file_id</Word>
<Word>file_name</Word>
<Word>filegroup_id</Word>
<Word>filegroup_name</Word>
<Word>filegroupproperty</Word>
<Word>fileproperty</Word>
<Word>for</Word>
<Word>forall</Word>
<Word>foreign</Word>
<Word>format</Word>
<Word>formatmessage</Word>
<Word>found</Word>
<Word>freetexttable</Word>
<Word>from</Word>
<Word>from_days</Word>
<Word>fulltextcatalog</Word>
<Word>fulltextservice</Word>
<Word>function</Word>
<Word>general</Word>
<Word>get</Word>
<Word>get_lock</Word>
<Word>getdate</Word>
<Word>getansinull</Word>
<Word>getutcdate</Word>
<Word>global</Word>
<Word>go</Word>
<Word>goto</Word>
<Word>grant</Word>
<Word>greatest</Word>
<Word>group</Word>
<Word>grouping</Word>
<Word>having</Word>
<Word>heap</Word>
<Word>hex</Word>
<Word>hextoraw</Word>
<Word>host</Word>
<Word>host_id</Word>
<Word>host_name</Word>
<Word>hour</Word>
<Word>ident_incr</Word>
<Word>ident_seed</Word>
<Word>ident_current</Word>
<Word>identified</Word>
<Word>identity</Word>
<Word>if</Word>
<Word>ifnull</Word>
<Word>ignore</Word>
<Word>immediate</Word>
<Word>in</Word>
<Word>increment</Word>
<Word>index</Word>
<Word>index_col</Word>
<Word>indexproperty</Word>
<Word>indicator</Word>
<Word>initcap</Word>
<Word>initial</Word>
<Word>initialize</Word>
<Word>initially</Word>
<Word>inner</Word>
<Word>inout</Word>
<Word>input</Word>
<Word>insert</Word>
<Word>instr</Word>
<Word>instrb</Word>
<Word>int</Word>
<Word>integer</Word>
<Word>interface</Word>
<Word>intersect</Word>
<Word>interval</Word>
<Word>into</Word>
<Word>is</Word>
<Word>is_member</Word>
<Word>is_srvrolemember</Word>
<Word>is_null</Word>
<Word>is_numeric</Word>
<Word>isdate</Word>
<Word>isnull</Word>
<Word>isolation</Word>
<Word>iterate</Word>
<Word>java</Word>
<Word>join</Word>
<Word>key</Word>
<Word>lag</Word>
<Word>language</Word>
<Word>large</Word>
<Word>last</Word>
<Word>last_day</Word>
<Word>last_value</Word>
<Word>lateral</Word>
<Word>lcase</Word>
<Word>lead</Word>
<Word>leading</Word>
<Word>least</Word>
<Word>left</Word>
<Word>len</Word>
<Word>length</Word>
<Word>lengthb</Word>
<Word>less</Word>
<Word>level</Word>
<Word>like</Word>
<Word>limit</Word>
<Word>limited</Word>
<Word>ln</Word>
<Word>lpad</Word>
<Word>local</Word>
<Word>localtime</Word>
<Word>localtimestamp</Word>
<Word>locator</Word>
<Word>lock</Word>
<Word>log</Word>
<Word>log10</Word>
<Word>long</Word>
<Word>loop</Word>
<Word>lower</Word>
<Word>ltrim</Word>
<Word>make_ref</Word>
<Word>map</Word>
<Word>match</Word>
<Word>max</Word>
<Word>maxextents</Word>
<Word>mid</Word>
<Word>min</Word>
<Word>minus</Word>
<Word>minute</Word>
<Word>mlslabel</Word>
<Word>mod</Word>
<Word>mode</Word>
<Word>modifies</Word>
<Word>modify</Word>
<Word>module</Word>
<Word>month</Word>
<Word>months_between</Word>
<Word>names</Word>
<Word>national</Word>
<Word>natural</Word>
<Word>naturaln</Word>
<Word>nchar</Word>
<Word>nclob</Word>
<Word>new</Word>
<Word>new_time</Word>
<Word>newid</Word>
<Word>next</Word>
<Word>next_day</Word>
<Word>nextval</Word>
<Word>no</Word>
<Word>noaudit</Word>
<Word>nocompress</Word>
<Word>nocopy</Word>
<Word>nolock</Word>
<Word>none</Word>
<Word>not</Word>
<Word>nowait</Word>
<Word>null</Word>
<Word>nullif</Word>
<Word>number</Word>
<Word>number_base</Word>
<Word>numeric</Word>
<Word>nvl</Word>
<Word>nvl2</Word>
<Word>object</Word>
<Word>object_id</Word>
<Word>object_name</Word>
<Word>object_property</Word>
<Word>ocirowid</Word>
<Word>oct</Word>
<Word>of</Word>
<Word>off</Word>
<Word>offline</Word>
<Word>old</Word>
<Word>on</Word>
<Word>online</Word>
<Word>only</Word>
<Word>opaque</Word>
<Word>open</Word>
<Word>operator</Word>
<Word>operation</Word>
<Word>option</Word>
<Word>or</Word>
<Word>ord</Word>
<Word>order</Word>
<Word>ordinalityorganization</Word>
<Word>others</Word>
<Word>out</Word>
<Word>outer</Word>
<Word>output</Word>
<Word>package</Word>
<Word>pad</Word>
<Word>parameter</Word>
<Word>parameters</Word>
<Word>partial</Word>
<Word>partition</Word>
<Word>path</Word>
<Word>pctfree</Word>
<Word>percent_rank</Word>
<Word>pi</Word>
<Word>pls_integer</Word>
<Word>positive</Word>
<Word>positiven</Word>
<Word>postfix</Word>
<Word>pow</Word>
<Word>power</Word>
<Word>pragma</Word>
<Word>precision</Word>
<Word>prefix</Word>
<Word>preorder</Word>
<Word>prepare</Word>
<Word>preserve</Word>
<Word>primary</Word>
<Word>prior</Word>
<Word>private</Word>
<Word>privileges</Word>
<Word>procedure</Word>
<Word>public</Word>
<Word>radians</Word>
<Word>raise</Word>
<Word>rand</Word>
<Word>range</Word>
<Word>rank</Word>
<Word>ratio_to_export</Word>
<Word>raw</Word>
<Word>rawtohex</Word>
<Word>read</Word>
<Word>reads</Word>
<Word>real</Word>
<Word>record</Word>
<Word>recursive</Word>
<Word>ref</Word>
<Word>references</Word>
<Word>referencing</Word>
<Word>reftohex</Word>
<Word>relative</Word>
<Word>release</Word>
<Word>release_lock</Word>
<Word>rename</Word>
<Word>repeat</Word>
<Word>replace</Word>
<Word>resource</Word>
<Word>restrict</Word>
<Word>result</Word>
<Word>return</Word>
<Word>returns</Word>
<Word>reverse</Word>
<Word>revoke</Word>
<Word>right</Word>
<Word>rollback</Word>
<Word>rollup</Word>
<Word>round</Word>
<Word>routine</Word>
<Word>row</Word>
<Word>row_number</Word>
<Word>rowid</Word>
<Word>rowidtochar</Word>
<Word>rowlabel</Word>
<Word>rowlock</Word>
<Word>rownum</Word>
<Word>rows</Word>
<Word>rowtype</Word>
<Word>rpad</Word>
<Word>rtrim</Word>
<Word>savepoint</Word>
<Word>schema</Word>
<Word>scroll</Word>
<Word>scope</Word>
<Word>search</Word>
<Word>second</Word>
<Word>section</Word>
<Word>seddev_samp</Word>
<Word>select</Word>
<Word>separate</Word>
<Word>sequence</Word>
<Word>session</Word>
<Word>session_user</Word>
<Word>set</Word>
<Word>sets</Word>
<Word>share</Word>
<Word>sign</Word>
<Word>sin</Word>
<Word>sinh</Word>
<Word>size</Word>
<Word>smallint</Word>
<Word>some</Word>
<Word>soundex</Word>
<Word>space</Word>
<Word>specific</Word>
<Word>specifictype</Word>
<Word>sql</Word>
<Word>sqlcode</Word>
<Word>sqlerrm</Word>
<Word>sqlexception</Word>
<Word>sqlstate</Word>
<Word>sqlwarning</Word>
<Word>sqrt</Word>
<Word>start</Word>
<Word>state</Word>
<Word>statement</Word>
<Word>static</Word>
<Word>std</Word>
<Word>stddev</Word>
<Word>stdev_pop</Word>
<Word>strcmp</Word>
<Word>structure</Word>
<Word>subdate</Word>
<Word>substr</Word>
<Word>substrb</Word>
<Word>substring</Word>
<Word>substring_index</Word>
<Word>subtype</Word>
<Word>successful</Word>
<Word>sum</Word>
<Word>synonym</Word>
<Word>sys_context</Word>
<Word>sys_guid</Word>
<Word>sysdate</Word>
<Word>system_user</Word>
<Word>table</Word>
<Word>tan</Word>
<Word>tanh</Word>
<Word>temporary</Word>
<Word>terminate</Word>
<Word>than</Word>
<Word>then</Word>
<Word>time</Word>
<Word>timestamp</Word>
<Word>timezone_abbr</Word>
<Word>timezone_minute</Word>
<Word>timezone_hour</Word>
<Word>timezone_region</Word>
<Word>tinyint</Word>
<Word>to</Word>
<Word>to_char</Word>
<Word>to_date</Word>
<Word>to_days</Word>
<Word>to_number</Word>
<Word>to_single_byte</Word>
<Word>trailing</Word>
<Word>transaction</Word>
<Word>translate</Word>
<Word>translation</Word>
<Word>treat</Word>
<Word>trigger</Word>
<Word>trim</Word>
<Word>true</Word>
<Word>trunc</Word>
<Word>truncate</Word>
<Word>type</Word>
<Word>ucase</Word>
<Word>uid</Word>
<Word>under</Word>
<Word>union</Word>
<Word>unique</Word>
<Word>unknown</Word>
<Word>unnest</Word>
<Word>update</Word>
<Word>upper</Word>
<Word>usage</Word>
<Word>use</Word>
<Word>user</Word>
<Word>userenv</Word>
<Word>using</Word>
<Word>validate</Word>
<Word>value</Word>
<Word>values</Word>
<Word>var_pop</Word>
<Word>var_samp</Word>
<Word>varbinary</Word>
<Word>varchar</Word>
<Word>varchar2</Word>
<Word>variable</Word>
<Word>variance</Word>
<Word>varying</Word>
<Word>view</Word>
<Word>vsize</Word>
<Word>when</Word>
<Word>whenever</Word>
<Word>where</Word>
<Word>with</Word>
<Word>without</Word>
<Word>while</Word>
<Word>work</Word>
<Word>write</Word>
<Word>year</Word>
<Word>zone</Word>
</Keywords>
</RuleSet>
</SyntaxDefinition>
<MSG> Update TSQL file #125
https://github.com/icsharpcode/AvalonEdit/pull/125
<DFF> @@ -559,6 +559,7 @@
<Word>timezone_region</Word>
<Word>tinyint</Word>
<Word>to</Word>
+ <Word>top</Word>
<Word>to_char</Word>
<Word>to_date</Word>
<Word>to_days</Word>
| 1 | Update TSQL file #125 | 0 | .xshd | xshd | mit | AvaloniaUI/AvaloniaEdit |
10066932 | <NME> TSQL-Mode.xshd
<BEF> <?xml version="1.0"?>
<SyntaxDefinition name="TSQL" extensions=".sql" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
<Color name="Comment" foreground="Green" exampleText="-- comment" />
<Color name="Char" foreground="Red" exampleText="name = 'abc'"/>
<Color name="Keywords" fontWeight="bold" foreground="Blue" exampleText="SELECT FROM"/>
<Property name="DocCommentMarker" value="///" />
<RuleSet name="CommentMarkerSet">
<Keywords fontWeight="bold" foreground="Red">
<Word>TODO</Word>
<Word>FIXME</Word>
</Keywords>
<Keywords fontWeight="bold" foreground="#E0E000">
<Word>HACK</Word>
<Word>UNDONE</Word>
</Keywords>
</RuleSet>
<RuleSet ignoreCase="true">
<Span color="Comment" ruleSet="CommentMarkerSet">
<Begin>--</Begin>
</Span>
<Span color="Comment" ruleSet="CommentMarkerSet" multiline="true">
<Begin>/\*</Begin>
<End>\*/</End>
</Span>
<Span color="Char">
<Begin>'</Begin>
<End>'</End>
<RuleSet>
<Span begin="\\" end="."/>
</RuleSet>
</Span>
<Keywords color="Keywords">
<Word>abs</Word>
<Word>absolute</Word>
<Word>access</Word>
<Word>acos</Word>
<Word>add</Word>
<Word>add_months</Word>
<Word>adddate</Word>
<Word>admin</Word>
<Word>after</Word>
<Word>aggregate</Word>
<Word>all</Word>
<Word>allocate</Word>
<Word>alter</Word>
<Word>and</Word>
<Word>any</Word>
<Word>app_name</Word>
<Word>are</Word>
<Word>array</Word>
<Word>as</Word>
<Word>asc</Word>
<Word>ascii</Word>
<Word>asin</Word>
<Word>assertion</Word>
<Word>at</Word>
<Word>atan</Word>
<Word>atn2</Word>
<Word>audit</Word>
<Word>authid</Word>
<Word>authorization</Word>
<Word>autonomous_transaction</Word>
<Word>avg</Word>
<Word>before</Word>
<Word>begin</Word>
<Word>benchmark</Word>
<Word>between</Word>
<Word>bfilename</Word>
<Word>bigint</Word>
<Word>bin</Word>
<Word>binary</Word>
<Word>binary_checksum</Word>
<Word>binary_integer</Word>
<Word>bit</Word>
<Word>bit_count</Word>
<Word>bit_and</Word>
<Word>bit_or</Word>
<Word>blob</Word>
<Word>body</Word>
<Word>boolean</Word>
<Word>both</Word>
<Word>breadth</Word>
<Word>bulk</Word>
<Word>by</Word>
<Word>call</Word>
<Word>cascade</Word>
<Word>cascaded</Word>
<Word>case</Word>
<Word>cast</Word>
<Word>catalog</Word>
<Word>ceil</Word>
<Word>ceiling</Word>
<Word>char</Word>
<Word>char_base</Word>
<Word>character</Word>
<Word>charindex</Word>
<Word>chartorowid</Word>
<Word>check</Word>
<Word>checksum</Word>
<Word>checksum_agg</Word>
<Word>chr</Word>
<Word>class</Word>
<Word>clob</Word>
<Word>close</Word>
<Word>cluster</Word>
<Word>coalesce</Word>
<Word>col_length</Word>
<Word>col_name</Word>
<Word>collate</Word>
<Word>collation</Word>
<Word>collect</Word>
<Word>column</Word>
<Word>comment</Word>
<Word>commit</Word>
<Word>completion</Word>
<Word>compress</Word>
<Word>concat</Word>
<Word>concat_ws</Word>
<Word>connect</Word>
<Word>connection</Word>
<Word>constant</Word>
<Word>constraint</Word>
<Word>constraints</Word>
<Word>constructorcreate</Word>
<Word>contains</Word>
<Word>containsable</Word>
<Word>continue</Word>
<Word>conv</Word>
<Word>convert</Word>
<Word>corr</Word>
<Word>corresponding</Word>
<Word>cos</Word>
<Word>cot</Word>
<Word>count</Word>
<Word>count_big</Word>
<Word>covar_pop</Word>
<Word>covar_samp</Word>
<Word>create</Word>
<Word>cross</Word>
<Word>cube</Word>
<Word>cume_dist</Word>
<Word>current</Word>
<Word>current_date</Word>
<Word>current_path</Word>
<Word>current_role</Word>
<Word>current_time</Word>
<Word>current_timestamp</Word>
<Word>current_user</Word>
<Word>currval</Word>
<Word>cursor</Word>
<Word>cycle</Word>
<Word>data</Word>
<Word>datalength</Word>
<Word>databasepropertyex</Word>
<Word>date</Word>
<Word>date_add</Word>
<Word>date_format</Word>
<Word>date_sub</Word>
<Word>dateadd</Word>
<Word>datediff</Word>
<Word>datename</Word>
<Word>datepart</Word>
<Word>datetime</Word>
<Word>day</Word>
<Word>db_id</Word>
<Word>db_name</Word>
<Word>deallocate</Word>
<Word>dec</Word>
<Word>declare</Word>
<Word>decimal</Word>
<Word>decode</Word>
<Word>default</Word>
<Word>deferrable</Word>
<Word>deferred</Word>
<Word>degrees</Word>
<Word>delete</Word>
<Word>dense_rank</Word>
<Word>depth</Word>
<Word>deref</Word>
<Word>desc</Word>
<Word>describe</Word>
<Word>descriptor</Word>
<Word>destroy</Word>
<Word>destructor</Word>
<Word>deterministic</Word>
<Word>diagnostics</Word>
<Word>dictionary</Word>
<Word>disconnect</Word>
<Word>difference</Word>
<Word>distinct</Word>
<Word>do</Word>
<Word>domain</Word>
<Word>double</Word>
<Word>drop</Word>
<Word>dump</Word>
<Word>dynamic</Word>
<Word>each</Word>
<Word>else</Word>
<Word>elsif</Word>
<Word>empth</Word>
<Word>encode</Word>
<Word>encrypt</Word>
<Word>end</Word>
<Word>end-exec</Word>
<Word>equals</Word>
<Word>escape</Word>
<Word>every</Word>
<Word>except</Word>
<Word>exception</Word>
<Word>exclusive</Word>
<Word>exec</Word>
<Word>execute</Word>
<Word>exists</Word>
<Word>exit</Word>
<Word>exp</Word>
<Word>export_set</Word>
<Word>extends</Word>
<Word>external</Word>
<Word>extract</Word>
<Word>false</Word>
<Word>fetch</Word>
<Word>first</Word>
<Word>first_value</Word>
<Word>file</Word>
<Word>float</Word>
<Word>floor</Word>
<Word>file_id</Word>
<Word>file_name</Word>
<Word>filegroup_id</Word>
<Word>filegroup_name</Word>
<Word>filegroupproperty</Word>
<Word>fileproperty</Word>
<Word>for</Word>
<Word>forall</Word>
<Word>foreign</Word>
<Word>format</Word>
<Word>formatmessage</Word>
<Word>found</Word>
<Word>freetexttable</Word>
<Word>from</Word>
<Word>from_days</Word>
<Word>fulltextcatalog</Word>
<Word>fulltextservice</Word>
<Word>function</Word>
<Word>general</Word>
<Word>get</Word>
<Word>get_lock</Word>
<Word>getdate</Word>
<Word>getansinull</Word>
<Word>getutcdate</Word>
<Word>global</Word>
<Word>go</Word>
<Word>goto</Word>
<Word>grant</Word>
<Word>greatest</Word>
<Word>group</Word>
<Word>grouping</Word>
<Word>having</Word>
<Word>heap</Word>
<Word>hex</Word>
<Word>hextoraw</Word>
<Word>host</Word>
<Word>host_id</Word>
<Word>host_name</Word>
<Word>hour</Word>
<Word>ident_incr</Word>
<Word>ident_seed</Word>
<Word>ident_current</Word>
<Word>identified</Word>
<Word>identity</Word>
<Word>if</Word>
<Word>ifnull</Word>
<Word>ignore</Word>
<Word>immediate</Word>
<Word>in</Word>
<Word>increment</Word>
<Word>index</Word>
<Word>index_col</Word>
<Word>indexproperty</Word>
<Word>indicator</Word>
<Word>initcap</Word>
<Word>initial</Word>
<Word>initialize</Word>
<Word>initially</Word>
<Word>inner</Word>
<Word>inout</Word>
<Word>input</Word>
<Word>insert</Word>
<Word>instr</Word>
<Word>instrb</Word>
<Word>int</Word>
<Word>integer</Word>
<Word>interface</Word>
<Word>intersect</Word>
<Word>interval</Word>
<Word>into</Word>
<Word>is</Word>
<Word>is_member</Word>
<Word>is_srvrolemember</Word>
<Word>is_null</Word>
<Word>is_numeric</Word>
<Word>isdate</Word>
<Word>isnull</Word>
<Word>isolation</Word>
<Word>iterate</Word>
<Word>java</Word>
<Word>join</Word>
<Word>key</Word>
<Word>lag</Word>
<Word>language</Word>
<Word>large</Word>
<Word>last</Word>
<Word>last_day</Word>
<Word>last_value</Word>
<Word>lateral</Word>
<Word>lcase</Word>
<Word>lead</Word>
<Word>leading</Word>
<Word>least</Word>
<Word>left</Word>
<Word>len</Word>
<Word>length</Word>
<Word>lengthb</Word>
<Word>less</Word>
<Word>level</Word>
<Word>like</Word>
<Word>limit</Word>
<Word>limited</Word>
<Word>ln</Word>
<Word>lpad</Word>
<Word>local</Word>
<Word>localtime</Word>
<Word>localtimestamp</Word>
<Word>locator</Word>
<Word>lock</Word>
<Word>log</Word>
<Word>log10</Word>
<Word>long</Word>
<Word>loop</Word>
<Word>lower</Word>
<Word>ltrim</Word>
<Word>make_ref</Word>
<Word>map</Word>
<Word>match</Word>
<Word>max</Word>
<Word>maxextents</Word>
<Word>mid</Word>
<Word>min</Word>
<Word>minus</Word>
<Word>minute</Word>
<Word>mlslabel</Word>
<Word>mod</Word>
<Word>mode</Word>
<Word>modifies</Word>
<Word>modify</Word>
<Word>module</Word>
<Word>month</Word>
<Word>months_between</Word>
<Word>names</Word>
<Word>national</Word>
<Word>natural</Word>
<Word>naturaln</Word>
<Word>nchar</Word>
<Word>nclob</Word>
<Word>new</Word>
<Word>new_time</Word>
<Word>newid</Word>
<Word>next</Word>
<Word>next_day</Word>
<Word>nextval</Word>
<Word>no</Word>
<Word>noaudit</Word>
<Word>nocompress</Word>
<Word>nocopy</Word>
<Word>nolock</Word>
<Word>none</Word>
<Word>not</Word>
<Word>nowait</Word>
<Word>null</Word>
<Word>nullif</Word>
<Word>number</Word>
<Word>number_base</Word>
<Word>numeric</Word>
<Word>nvl</Word>
<Word>nvl2</Word>
<Word>object</Word>
<Word>object_id</Word>
<Word>object_name</Word>
<Word>object_property</Word>
<Word>ocirowid</Word>
<Word>oct</Word>
<Word>of</Word>
<Word>off</Word>
<Word>offline</Word>
<Word>old</Word>
<Word>on</Word>
<Word>online</Word>
<Word>only</Word>
<Word>opaque</Word>
<Word>open</Word>
<Word>operator</Word>
<Word>operation</Word>
<Word>option</Word>
<Word>or</Word>
<Word>ord</Word>
<Word>order</Word>
<Word>ordinalityorganization</Word>
<Word>others</Word>
<Word>out</Word>
<Word>outer</Word>
<Word>output</Word>
<Word>package</Word>
<Word>pad</Word>
<Word>parameter</Word>
<Word>parameters</Word>
<Word>partial</Word>
<Word>partition</Word>
<Word>path</Word>
<Word>pctfree</Word>
<Word>percent_rank</Word>
<Word>pi</Word>
<Word>pls_integer</Word>
<Word>positive</Word>
<Word>positiven</Word>
<Word>postfix</Word>
<Word>pow</Word>
<Word>power</Word>
<Word>pragma</Word>
<Word>precision</Word>
<Word>prefix</Word>
<Word>preorder</Word>
<Word>prepare</Word>
<Word>preserve</Word>
<Word>primary</Word>
<Word>prior</Word>
<Word>private</Word>
<Word>privileges</Word>
<Word>procedure</Word>
<Word>public</Word>
<Word>radians</Word>
<Word>raise</Word>
<Word>rand</Word>
<Word>range</Word>
<Word>rank</Word>
<Word>ratio_to_export</Word>
<Word>raw</Word>
<Word>rawtohex</Word>
<Word>read</Word>
<Word>reads</Word>
<Word>real</Word>
<Word>record</Word>
<Word>recursive</Word>
<Word>ref</Word>
<Word>references</Word>
<Word>referencing</Word>
<Word>reftohex</Word>
<Word>relative</Word>
<Word>release</Word>
<Word>release_lock</Word>
<Word>rename</Word>
<Word>repeat</Word>
<Word>replace</Word>
<Word>resource</Word>
<Word>restrict</Word>
<Word>result</Word>
<Word>return</Word>
<Word>returns</Word>
<Word>reverse</Word>
<Word>revoke</Word>
<Word>right</Word>
<Word>rollback</Word>
<Word>rollup</Word>
<Word>round</Word>
<Word>routine</Word>
<Word>row</Word>
<Word>row_number</Word>
<Word>rowid</Word>
<Word>rowidtochar</Word>
<Word>rowlabel</Word>
<Word>rowlock</Word>
<Word>rownum</Word>
<Word>rows</Word>
<Word>rowtype</Word>
<Word>rpad</Word>
<Word>rtrim</Word>
<Word>savepoint</Word>
<Word>schema</Word>
<Word>scroll</Word>
<Word>scope</Word>
<Word>search</Word>
<Word>second</Word>
<Word>section</Word>
<Word>seddev_samp</Word>
<Word>select</Word>
<Word>separate</Word>
<Word>sequence</Word>
<Word>session</Word>
<Word>session_user</Word>
<Word>set</Word>
<Word>sets</Word>
<Word>share</Word>
<Word>sign</Word>
<Word>sin</Word>
<Word>sinh</Word>
<Word>size</Word>
<Word>smallint</Word>
<Word>some</Word>
<Word>soundex</Word>
<Word>space</Word>
<Word>specific</Word>
<Word>specifictype</Word>
<Word>sql</Word>
<Word>sqlcode</Word>
<Word>sqlerrm</Word>
<Word>sqlexception</Word>
<Word>sqlstate</Word>
<Word>sqlwarning</Word>
<Word>sqrt</Word>
<Word>start</Word>
<Word>state</Word>
<Word>statement</Word>
<Word>static</Word>
<Word>std</Word>
<Word>stddev</Word>
<Word>stdev_pop</Word>
<Word>strcmp</Word>
<Word>structure</Word>
<Word>subdate</Word>
<Word>substr</Word>
<Word>substrb</Word>
<Word>substring</Word>
<Word>substring_index</Word>
<Word>subtype</Word>
<Word>successful</Word>
<Word>sum</Word>
<Word>synonym</Word>
<Word>sys_context</Word>
<Word>sys_guid</Word>
<Word>sysdate</Word>
<Word>system_user</Word>
<Word>table</Word>
<Word>tan</Word>
<Word>tanh</Word>
<Word>temporary</Word>
<Word>terminate</Word>
<Word>than</Word>
<Word>then</Word>
<Word>time</Word>
<Word>timestamp</Word>
<Word>timezone_abbr</Word>
<Word>timezone_minute</Word>
<Word>timezone_hour</Word>
<Word>timezone_region</Word>
<Word>tinyint</Word>
<Word>to</Word>
<Word>to_char</Word>
<Word>to_date</Word>
<Word>to_days</Word>
<Word>to_number</Word>
<Word>to_single_byte</Word>
<Word>trailing</Word>
<Word>transaction</Word>
<Word>translate</Word>
<Word>translation</Word>
<Word>treat</Word>
<Word>trigger</Word>
<Word>trim</Word>
<Word>true</Word>
<Word>trunc</Word>
<Word>truncate</Word>
<Word>type</Word>
<Word>ucase</Word>
<Word>uid</Word>
<Word>under</Word>
<Word>union</Word>
<Word>unique</Word>
<Word>unknown</Word>
<Word>unnest</Word>
<Word>update</Word>
<Word>upper</Word>
<Word>usage</Word>
<Word>use</Word>
<Word>user</Word>
<Word>userenv</Word>
<Word>using</Word>
<Word>validate</Word>
<Word>value</Word>
<Word>values</Word>
<Word>var_pop</Word>
<Word>var_samp</Word>
<Word>varbinary</Word>
<Word>varchar</Word>
<Word>varchar2</Word>
<Word>variable</Word>
<Word>variance</Word>
<Word>varying</Word>
<Word>view</Word>
<Word>vsize</Word>
<Word>when</Word>
<Word>whenever</Word>
<Word>where</Word>
<Word>with</Word>
<Word>without</Word>
<Word>while</Word>
<Word>work</Word>
<Word>write</Word>
<Word>year</Word>
<Word>zone</Word>
</Keywords>
</RuleSet>
</SyntaxDefinition>
<MSG> Update TSQL file #125
https://github.com/icsharpcode/AvalonEdit/pull/125
<DFF> @@ -559,6 +559,7 @@
<Word>timezone_region</Word>
<Word>tinyint</Word>
<Word>to</Word>
+ <Word>top</Word>
<Word>to_char</Word>
<Word>to_date</Word>
<Word>to_days</Word>
| 1 | Update TSQL file #125 | 0 | .xshd | xshd | mit | AvaloniaUI/AvaloniaEdit |
10066933 | <NME> TSQL-Mode.xshd
<BEF> <?xml version="1.0"?>
<SyntaxDefinition name="TSQL" extensions=".sql" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
<Color name="Comment" foreground="Green" exampleText="-- comment" />
<Color name="Char" foreground="Red" exampleText="name = 'abc'"/>
<Color name="Keywords" fontWeight="bold" foreground="Blue" exampleText="SELECT FROM"/>
<Property name="DocCommentMarker" value="///" />
<RuleSet name="CommentMarkerSet">
<Keywords fontWeight="bold" foreground="Red">
<Word>TODO</Word>
<Word>FIXME</Word>
</Keywords>
<Keywords fontWeight="bold" foreground="#E0E000">
<Word>HACK</Word>
<Word>UNDONE</Word>
</Keywords>
</RuleSet>
<RuleSet ignoreCase="true">
<Span color="Comment" ruleSet="CommentMarkerSet">
<Begin>--</Begin>
</Span>
<Span color="Comment" ruleSet="CommentMarkerSet" multiline="true">
<Begin>/\*</Begin>
<End>\*/</End>
</Span>
<Span color="Char">
<Begin>'</Begin>
<End>'</End>
<RuleSet>
<Span begin="\\" end="."/>
</RuleSet>
</Span>
<Keywords color="Keywords">
<Word>abs</Word>
<Word>absolute</Word>
<Word>access</Word>
<Word>acos</Word>
<Word>add</Word>
<Word>add_months</Word>
<Word>adddate</Word>
<Word>admin</Word>
<Word>after</Word>
<Word>aggregate</Word>
<Word>all</Word>
<Word>allocate</Word>
<Word>alter</Word>
<Word>and</Word>
<Word>any</Word>
<Word>app_name</Word>
<Word>are</Word>
<Word>array</Word>
<Word>as</Word>
<Word>asc</Word>
<Word>ascii</Word>
<Word>asin</Word>
<Word>assertion</Word>
<Word>at</Word>
<Word>atan</Word>
<Word>atn2</Word>
<Word>audit</Word>
<Word>authid</Word>
<Word>authorization</Word>
<Word>autonomous_transaction</Word>
<Word>avg</Word>
<Word>before</Word>
<Word>begin</Word>
<Word>benchmark</Word>
<Word>between</Word>
<Word>bfilename</Word>
<Word>bigint</Word>
<Word>bin</Word>
<Word>binary</Word>
<Word>binary_checksum</Word>
<Word>binary_integer</Word>
<Word>bit</Word>
<Word>bit_count</Word>
<Word>bit_and</Word>
<Word>bit_or</Word>
<Word>blob</Word>
<Word>body</Word>
<Word>boolean</Word>
<Word>both</Word>
<Word>breadth</Word>
<Word>bulk</Word>
<Word>by</Word>
<Word>call</Word>
<Word>cascade</Word>
<Word>cascaded</Word>
<Word>case</Word>
<Word>cast</Word>
<Word>catalog</Word>
<Word>ceil</Word>
<Word>ceiling</Word>
<Word>char</Word>
<Word>char_base</Word>
<Word>character</Word>
<Word>charindex</Word>
<Word>chartorowid</Word>
<Word>check</Word>
<Word>checksum</Word>
<Word>checksum_agg</Word>
<Word>chr</Word>
<Word>class</Word>
<Word>clob</Word>
<Word>close</Word>
<Word>cluster</Word>
<Word>coalesce</Word>
<Word>col_length</Word>
<Word>col_name</Word>
<Word>collate</Word>
<Word>collation</Word>
<Word>collect</Word>
<Word>column</Word>
<Word>comment</Word>
<Word>commit</Word>
<Word>completion</Word>
<Word>compress</Word>
<Word>concat</Word>
<Word>concat_ws</Word>
<Word>connect</Word>
<Word>connection</Word>
<Word>constant</Word>
<Word>constraint</Word>
<Word>constraints</Word>
<Word>constructorcreate</Word>
<Word>contains</Word>
<Word>containsable</Word>
<Word>continue</Word>
<Word>conv</Word>
<Word>convert</Word>
<Word>corr</Word>
<Word>corresponding</Word>
<Word>cos</Word>
<Word>cot</Word>
<Word>count</Word>
<Word>count_big</Word>
<Word>covar_pop</Word>
<Word>covar_samp</Word>
<Word>create</Word>
<Word>cross</Word>
<Word>cube</Word>
<Word>cume_dist</Word>
<Word>current</Word>
<Word>current_date</Word>
<Word>current_path</Word>
<Word>current_role</Word>
<Word>current_time</Word>
<Word>current_timestamp</Word>
<Word>current_user</Word>
<Word>currval</Word>
<Word>cursor</Word>
<Word>cycle</Word>
<Word>data</Word>
<Word>datalength</Word>
<Word>databasepropertyex</Word>
<Word>date</Word>
<Word>date_add</Word>
<Word>date_format</Word>
<Word>date_sub</Word>
<Word>dateadd</Word>
<Word>datediff</Word>
<Word>datename</Word>
<Word>datepart</Word>
<Word>datetime</Word>
<Word>day</Word>
<Word>db_id</Word>
<Word>db_name</Word>
<Word>deallocate</Word>
<Word>dec</Word>
<Word>declare</Word>
<Word>decimal</Word>
<Word>decode</Word>
<Word>default</Word>
<Word>deferrable</Word>
<Word>deferred</Word>
<Word>degrees</Word>
<Word>delete</Word>
<Word>dense_rank</Word>
<Word>depth</Word>
<Word>deref</Word>
<Word>desc</Word>
<Word>describe</Word>
<Word>descriptor</Word>
<Word>destroy</Word>
<Word>destructor</Word>
<Word>deterministic</Word>
<Word>diagnostics</Word>
<Word>dictionary</Word>
<Word>disconnect</Word>
<Word>difference</Word>
<Word>distinct</Word>
<Word>do</Word>
<Word>domain</Word>
<Word>double</Word>
<Word>drop</Word>
<Word>dump</Word>
<Word>dynamic</Word>
<Word>each</Word>
<Word>else</Word>
<Word>elsif</Word>
<Word>empth</Word>
<Word>encode</Word>
<Word>encrypt</Word>
<Word>end</Word>
<Word>end-exec</Word>
<Word>equals</Word>
<Word>escape</Word>
<Word>every</Word>
<Word>except</Word>
<Word>exception</Word>
<Word>exclusive</Word>
<Word>exec</Word>
<Word>execute</Word>
<Word>exists</Word>
<Word>exit</Word>
<Word>exp</Word>
<Word>export_set</Word>
<Word>extends</Word>
<Word>external</Word>
<Word>extract</Word>
<Word>false</Word>
<Word>fetch</Word>
<Word>first</Word>
<Word>first_value</Word>
<Word>file</Word>
<Word>float</Word>
<Word>floor</Word>
<Word>file_id</Word>
<Word>file_name</Word>
<Word>filegroup_id</Word>
<Word>filegroup_name</Word>
<Word>filegroupproperty</Word>
<Word>fileproperty</Word>
<Word>for</Word>
<Word>forall</Word>
<Word>foreign</Word>
<Word>format</Word>
<Word>formatmessage</Word>
<Word>found</Word>
<Word>freetexttable</Word>
<Word>from</Word>
<Word>from_days</Word>
<Word>fulltextcatalog</Word>
<Word>fulltextservice</Word>
<Word>function</Word>
<Word>general</Word>
<Word>get</Word>
<Word>get_lock</Word>
<Word>getdate</Word>
<Word>getansinull</Word>
<Word>getutcdate</Word>
<Word>global</Word>
<Word>go</Word>
<Word>goto</Word>
<Word>grant</Word>
<Word>greatest</Word>
<Word>group</Word>
<Word>grouping</Word>
<Word>having</Word>
<Word>heap</Word>
<Word>hex</Word>
<Word>hextoraw</Word>
<Word>host</Word>
<Word>host_id</Word>
<Word>host_name</Word>
<Word>hour</Word>
<Word>ident_incr</Word>
<Word>ident_seed</Word>
<Word>ident_current</Word>
<Word>identified</Word>
<Word>identity</Word>
<Word>if</Word>
<Word>ifnull</Word>
<Word>ignore</Word>
<Word>immediate</Word>
<Word>in</Word>
<Word>increment</Word>
<Word>index</Word>
<Word>index_col</Word>
<Word>indexproperty</Word>
<Word>indicator</Word>
<Word>initcap</Word>
<Word>initial</Word>
<Word>initialize</Word>
<Word>initially</Word>
<Word>inner</Word>
<Word>inout</Word>
<Word>input</Word>
<Word>insert</Word>
<Word>instr</Word>
<Word>instrb</Word>
<Word>int</Word>
<Word>integer</Word>
<Word>interface</Word>
<Word>intersect</Word>
<Word>interval</Word>
<Word>into</Word>
<Word>is</Word>
<Word>is_member</Word>
<Word>is_srvrolemember</Word>
<Word>is_null</Word>
<Word>is_numeric</Word>
<Word>isdate</Word>
<Word>isnull</Word>
<Word>isolation</Word>
<Word>iterate</Word>
<Word>java</Word>
<Word>join</Word>
<Word>key</Word>
<Word>lag</Word>
<Word>language</Word>
<Word>large</Word>
<Word>last</Word>
<Word>last_day</Word>
<Word>last_value</Word>
<Word>lateral</Word>
<Word>lcase</Word>
<Word>lead</Word>
<Word>leading</Word>
<Word>least</Word>
<Word>left</Word>
<Word>len</Word>
<Word>length</Word>
<Word>lengthb</Word>
<Word>less</Word>
<Word>level</Word>
<Word>like</Word>
<Word>limit</Word>
<Word>limited</Word>
<Word>ln</Word>
<Word>lpad</Word>
<Word>local</Word>
<Word>localtime</Word>
<Word>localtimestamp</Word>
<Word>locator</Word>
<Word>lock</Word>
<Word>log</Word>
<Word>log10</Word>
<Word>long</Word>
<Word>loop</Word>
<Word>lower</Word>
<Word>ltrim</Word>
<Word>make_ref</Word>
<Word>map</Word>
<Word>match</Word>
<Word>max</Word>
<Word>maxextents</Word>
<Word>mid</Word>
<Word>min</Word>
<Word>minus</Word>
<Word>minute</Word>
<Word>mlslabel</Word>
<Word>mod</Word>
<Word>mode</Word>
<Word>modifies</Word>
<Word>modify</Word>
<Word>module</Word>
<Word>month</Word>
<Word>months_between</Word>
<Word>names</Word>
<Word>national</Word>
<Word>natural</Word>
<Word>naturaln</Word>
<Word>nchar</Word>
<Word>nclob</Word>
<Word>new</Word>
<Word>new_time</Word>
<Word>newid</Word>
<Word>next</Word>
<Word>next_day</Word>
<Word>nextval</Word>
<Word>no</Word>
<Word>noaudit</Word>
<Word>nocompress</Word>
<Word>nocopy</Word>
<Word>nolock</Word>
<Word>none</Word>
<Word>not</Word>
<Word>nowait</Word>
<Word>null</Word>
<Word>nullif</Word>
<Word>number</Word>
<Word>number_base</Word>
<Word>numeric</Word>
<Word>nvl</Word>
<Word>nvl2</Word>
<Word>object</Word>
<Word>object_id</Word>
<Word>object_name</Word>
<Word>object_property</Word>
<Word>ocirowid</Word>
<Word>oct</Word>
<Word>of</Word>
<Word>off</Word>
<Word>offline</Word>
<Word>old</Word>
<Word>on</Word>
<Word>online</Word>
<Word>only</Word>
<Word>opaque</Word>
<Word>open</Word>
<Word>operator</Word>
<Word>operation</Word>
<Word>option</Word>
<Word>or</Word>
<Word>ord</Word>
<Word>order</Word>
<Word>ordinalityorganization</Word>
<Word>others</Word>
<Word>out</Word>
<Word>outer</Word>
<Word>output</Word>
<Word>package</Word>
<Word>pad</Word>
<Word>parameter</Word>
<Word>parameters</Word>
<Word>partial</Word>
<Word>partition</Word>
<Word>path</Word>
<Word>pctfree</Word>
<Word>percent_rank</Word>
<Word>pi</Word>
<Word>pls_integer</Word>
<Word>positive</Word>
<Word>positiven</Word>
<Word>postfix</Word>
<Word>pow</Word>
<Word>power</Word>
<Word>pragma</Word>
<Word>precision</Word>
<Word>prefix</Word>
<Word>preorder</Word>
<Word>prepare</Word>
<Word>preserve</Word>
<Word>primary</Word>
<Word>prior</Word>
<Word>private</Word>
<Word>privileges</Word>
<Word>procedure</Word>
<Word>public</Word>
<Word>radians</Word>
<Word>raise</Word>
<Word>rand</Word>
<Word>range</Word>
<Word>rank</Word>
<Word>ratio_to_export</Word>
<Word>raw</Word>
<Word>rawtohex</Word>
<Word>read</Word>
<Word>reads</Word>
<Word>real</Word>
<Word>record</Word>
<Word>recursive</Word>
<Word>ref</Word>
<Word>references</Word>
<Word>referencing</Word>
<Word>reftohex</Word>
<Word>relative</Word>
<Word>release</Word>
<Word>release_lock</Word>
<Word>rename</Word>
<Word>repeat</Word>
<Word>replace</Word>
<Word>resource</Word>
<Word>restrict</Word>
<Word>result</Word>
<Word>return</Word>
<Word>returns</Word>
<Word>reverse</Word>
<Word>revoke</Word>
<Word>right</Word>
<Word>rollback</Word>
<Word>rollup</Word>
<Word>round</Word>
<Word>routine</Word>
<Word>row</Word>
<Word>row_number</Word>
<Word>rowid</Word>
<Word>rowidtochar</Word>
<Word>rowlabel</Word>
<Word>rowlock</Word>
<Word>rownum</Word>
<Word>rows</Word>
<Word>rowtype</Word>
<Word>rpad</Word>
<Word>rtrim</Word>
<Word>savepoint</Word>
<Word>schema</Word>
<Word>scroll</Word>
<Word>scope</Word>
<Word>search</Word>
<Word>second</Word>
<Word>section</Word>
<Word>seddev_samp</Word>
<Word>select</Word>
<Word>separate</Word>
<Word>sequence</Word>
<Word>session</Word>
<Word>session_user</Word>
<Word>set</Word>
<Word>sets</Word>
<Word>share</Word>
<Word>sign</Word>
<Word>sin</Word>
<Word>sinh</Word>
<Word>size</Word>
<Word>smallint</Word>
<Word>some</Word>
<Word>soundex</Word>
<Word>space</Word>
<Word>specific</Word>
<Word>specifictype</Word>
<Word>sql</Word>
<Word>sqlcode</Word>
<Word>sqlerrm</Word>
<Word>sqlexception</Word>
<Word>sqlstate</Word>
<Word>sqlwarning</Word>
<Word>sqrt</Word>
<Word>start</Word>
<Word>state</Word>
<Word>statement</Word>
<Word>static</Word>
<Word>std</Word>
<Word>stddev</Word>
<Word>stdev_pop</Word>
<Word>strcmp</Word>
<Word>structure</Word>
<Word>subdate</Word>
<Word>substr</Word>
<Word>substrb</Word>
<Word>substring</Word>
<Word>substring_index</Word>
<Word>subtype</Word>
<Word>successful</Word>
<Word>sum</Word>
<Word>synonym</Word>
<Word>sys_context</Word>
<Word>sys_guid</Word>
<Word>sysdate</Word>
<Word>system_user</Word>
<Word>table</Word>
<Word>tan</Word>
<Word>tanh</Word>
<Word>temporary</Word>
<Word>terminate</Word>
<Word>than</Word>
<Word>then</Word>
<Word>time</Word>
<Word>timestamp</Word>
<Word>timezone_abbr</Word>
<Word>timezone_minute</Word>
<Word>timezone_hour</Word>
<Word>timezone_region</Word>
<Word>tinyint</Word>
<Word>to</Word>
<Word>to_char</Word>
<Word>to_date</Word>
<Word>to_days</Word>
<Word>to_number</Word>
<Word>to_single_byte</Word>
<Word>trailing</Word>
<Word>transaction</Word>
<Word>translate</Word>
<Word>translation</Word>
<Word>treat</Word>
<Word>trigger</Word>
<Word>trim</Word>
<Word>true</Word>
<Word>trunc</Word>
<Word>truncate</Word>
<Word>type</Word>
<Word>ucase</Word>
<Word>uid</Word>
<Word>under</Word>
<Word>union</Word>
<Word>unique</Word>
<Word>unknown</Word>
<Word>unnest</Word>
<Word>update</Word>
<Word>upper</Word>
<Word>usage</Word>
<Word>use</Word>
<Word>user</Word>
<Word>userenv</Word>
<Word>using</Word>
<Word>validate</Word>
<Word>value</Word>
<Word>values</Word>
<Word>var_pop</Word>
<Word>var_samp</Word>
<Word>varbinary</Word>
<Word>varchar</Word>
<Word>varchar2</Word>
<Word>variable</Word>
<Word>variance</Word>
<Word>varying</Word>
<Word>view</Word>
<Word>vsize</Word>
<Word>when</Word>
<Word>whenever</Word>
<Word>where</Word>
<Word>with</Word>
<Word>without</Word>
<Word>while</Word>
<Word>work</Word>
<Word>write</Word>
<Word>year</Word>
<Word>zone</Word>
</Keywords>
</RuleSet>
</SyntaxDefinition>
<MSG> Update TSQL file #125
https://github.com/icsharpcode/AvalonEdit/pull/125
<DFF> @@ -559,6 +559,7 @@
<Word>timezone_region</Word>
<Word>tinyint</Word>
<Word>to</Word>
+ <Word>top</Word>
<Word>to_char</Word>
<Word>to_date</Word>
<Word>to_days</Word>
| 1 | Update TSQL file #125 | 0 | .xshd | xshd | mit | AvaloniaUI/AvaloniaEdit |
10066934 | <NME> TSQL-Mode.xshd
<BEF> <?xml version="1.0"?>
<SyntaxDefinition name="TSQL" extensions=".sql" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
<Color name="Comment" foreground="Green" exampleText="-- comment" />
<Color name="Char" foreground="Red" exampleText="name = 'abc'"/>
<Color name="Keywords" fontWeight="bold" foreground="Blue" exampleText="SELECT FROM"/>
<Property name="DocCommentMarker" value="///" />
<RuleSet name="CommentMarkerSet">
<Keywords fontWeight="bold" foreground="Red">
<Word>TODO</Word>
<Word>FIXME</Word>
</Keywords>
<Keywords fontWeight="bold" foreground="#E0E000">
<Word>HACK</Word>
<Word>UNDONE</Word>
</Keywords>
</RuleSet>
<RuleSet ignoreCase="true">
<Span color="Comment" ruleSet="CommentMarkerSet">
<Begin>--</Begin>
</Span>
<Span color="Comment" ruleSet="CommentMarkerSet" multiline="true">
<Begin>/\*</Begin>
<End>\*/</End>
</Span>
<Span color="Char">
<Begin>'</Begin>
<End>'</End>
<RuleSet>
<Span begin="\\" end="."/>
</RuleSet>
</Span>
<Keywords color="Keywords">
<Word>abs</Word>
<Word>absolute</Word>
<Word>access</Word>
<Word>acos</Word>
<Word>add</Word>
<Word>add_months</Word>
<Word>adddate</Word>
<Word>admin</Word>
<Word>after</Word>
<Word>aggregate</Word>
<Word>all</Word>
<Word>allocate</Word>
<Word>alter</Word>
<Word>and</Word>
<Word>any</Word>
<Word>app_name</Word>
<Word>are</Word>
<Word>array</Word>
<Word>as</Word>
<Word>asc</Word>
<Word>ascii</Word>
<Word>asin</Word>
<Word>assertion</Word>
<Word>at</Word>
<Word>atan</Word>
<Word>atn2</Word>
<Word>audit</Word>
<Word>authid</Word>
<Word>authorization</Word>
<Word>autonomous_transaction</Word>
<Word>avg</Word>
<Word>before</Word>
<Word>begin</Word>
<Word>benchmark</Word>
<Word>between</Word>
<Word>bfilename</Word>
<Word>bigint</Word>
<Word>bin</Word>
<Word>binary</Word>
<Word>binary_checksum</Word>
<Word>binary_integer</Word>
<Word>bit</Word>
<Word>bit_count</Word>
<Word>bit_and</Word>
<Word>bit_or</Word>
<Word>blob</Word>
<Word>body</Word>
<Word>boolean</Word>
<Word>both</Word>
<Word>breadth</Word>
<Word>bulk</Word>
<Word>by</Word>
<Word>call</Word>
<Word>cascade</Word>
<Word>cascaded</Word>
<Word>case</Word>
<Word>cast</Word>
<Word>catalog</Word>
<Word>ceil</Word>
<Word>ceiling</Word>
<Word>char</Word>
<Word>char_base</Word>
<Word>character</Word>
<Word>charindex</Word>
<Word>chartorowid</Word>
<Word>check</Word>
<Word>checksum</Word>
<Word>checksum_agg</Word>
<Word>chr</Word>
<Word>class</Word>
<Word>clob</Word>
<Word>close</Word>
<Word>cluster</Word>
<Word>coalesce</Word>
<Word>col_length</Word>
<Word>col_name</Word>
<Word>collate</Word>
<Word>collation</Word>
<Word>collect</Word>
<Word>column</Word>
<Word>comment</Word>
<Word>commit</Word>
<Word>completion</Word>
<Word>compress</Word>
<Word>concat</Word>
<Word>concat_ws</Word>
<Word>connect</Word>
<Word>connection</Word>
<Word>constant</Word>
<Word>constraint</Word>
<Word>constraints</Word>
<Word>constructorcreate</Word>
<Word>contains</Word>
<Word>containsable</Word>
<Word>continue</Word>
<Word>conv</Word>
<Word>convert</Word>
<Word>corr</Word>
<Word>corresponding</Word>
<Word>cos</Word>
<Word>cot</Word>
<Word>count</Word>
<Word>count_big</Word>
<Word>covar_pop</Word>
<Word>covar_samp</Word>
<Word>create</Word>
<Word>cross</Word>
<Word>cube</Word>
<Word>cume_dist</Word>
<Word>current</Word>
<Word>current_date</Word>
<Word>current_path</Word>
<Word>current_role</Word>
<Word>current_time</Word>
<Word>current_timestamp</Word>
<Word>current_user</Word>
<Word>currval</Word>
<Word>cursor</Word>
<Word>cycle</Word>
<Word>data</Word>
<Word>datalength</Word>
<Word>databasepropertyex</Word>
<Word>date</Word>
<Word>date_add</Word>
<Word>date_format</Word>
<Word>date_sub</Word>
<Word>dateadd</Word>
<Word>datediff</Word>
<Word>datename</Word>
<Word>datepart</Word>
<Word>datetime</Word>
<Word>day</Word>
<Word>db_id</Word>
<Word>db_name</Word>
<Word>deallocate</Word>
<Word>dec</Word>
<Word>declare</Word>
<Word>decimal</Word>
<Word>decode</Word>
<Word>default</Word>
<Word>deferrable</Word>
<Word>deferred</Word>
<Word>degrees</Word>
<Word>delete</Word>
<Word>dense_rank</Word>
<Word>depth</Word>
<Word>deref</Word>
<Word>desc</Word>
<Word>describe</Word>
<Word>descriptor</Word>
<Word>destroy</Word>
<Word>destructor</Word>
<Word>deterministic</Word>
<Word>diagnostics</Word>
<Word>dictionary</Word>
<Word>disconnect</Word>
<Word>difference</Word>
<Word>distinct</Word>
<Word>do</Word>
<Word>domain</Word>
<Word>double</Word>
<Word>drop</Word>
<Word>dump</Word>
<Word>dynamic</Word>
<Word>each</Word>
<Word>else</Word>
<Word>elsif</Word>
<Word>empth</Word>
<Word>encode</Word>
<Word>encrypt</Word>
<Word>end</Word>
<Word>end-exec</Word>
<Word>equals</Word>
<Word>escape</Word>
<Word>every</Word>
<Word>except</Word>
<Word>exception</Word>
<Word>exclusive</Word>
<Word>exec</Word>
<Word>execute</Word>
<Word>exists</Word>
<Word>exit</Word>
<Word>exp</Word>
<Word>export_set</Word>
<Word>extends</Word>
<Word>external</Word>
<Word>extract</Word>
<Word>false</Word>
<Word>fetch</Word>
<Word>first</Word>
<Word>first_value</Word>
<Word>file</Word>
<Word>float</Word>
<Word>floor</Word>
<Word>file_id</Word>
<Word>file_name</Word>
<Word>filegroup_id</Word>
<Word>filegroup_name</Word>
<Word>filegroupproperty</Word>
<Word>fileproperty</Word>
<Word>for</Word>
<Word>forall</Word>
<Word>foreign</Word>
<Word>format</Word>
<Word>formatmessage</Word>
<Word>found</Word>
<Word>freetexttable</Word>
<Word>from</Word>
<Word>from_days</Word>
<Word>fulltextcatalog</Word>
<Word>fulltextservice</Word>
<Word>function</Word>
<Word>general</Word>
<Word>get</Word>
<Word>get_lock</Word>
<Word>getdate</Word>
<Word>getansinull</Word>
<Word>getutcdate</Word>
<Word>global</Word>
<Word>go</Word>
<Word>goto</Word>
<Word>grant</Word>
<Word>greatest</Word>
<Word>group</Word>
<Word>grouping</Word>
<Word>having</Word>
<Word>heap</Word>
<Word>hex</Word>
<Word>hextoraw</Word>
<Word>host</Word>
<Word>host_id</Word>
<Word>host_name</Word>
<Word>hour</Word>
<Word>ident_incr</Word>
<Word>ident_seed</Word>
<Word>ident_current</Word>
<Word>identified</Word>
<Word>identity</Word>
<Word>if</Word>
<Word>ifnull</Word>
<Word>ignore</Word>
<Word>immediate</Word>
<Word>in</Word>
<Word>increment</Word>
<Word>index</Word>
<Word>index_col</Word>
<Word>indexproperty</Word>
<Word>indicator</Word>
<Word>initcap</Word>
<Word>initial</Word>
<Word>initialize</Word>
<Word>initially</Word>
<Word>inner</Word>
<Word>inout</Word>
<Word>input</Word>
<Word>insert</Word>
<Word>instr</Word>
<Word>instrb</Word>
<Word>int</Word>
<Word>integer</Word>
<Word>interface</Word>
<Word>intersect</Word>
<Word>interval</Word>
<Word>into</Word>
<Word>is</Word>
<Word>is_member</Word>
<Word>is_srvrolemember</Word>
<Word>is_null</Word>
<Word>is_numeric</Word>
<Word>isdate</Word>
<Word>isnull</Word>
<Word>isolation</Word>
<Word>iterate</Word>
<Word>java</Word>
<Word>join</Word>
<Word>key</Word>
<Word>lag</Word>
<Word>language</Word>
<Word>large</Word>
<Word>last</Word>
<Word>last_day</Word>
<Word>last_value</Word>
<Word>lateral</Word>
<Word>lcase</Word>
<Word>lead</Word>
<Word>leading</Word>
<Word>least</Word>
<Word>left</Word>
<Word>len</Word>
<Word>length</Word>
<Word>lengthb</Word>
<Word>less</Word>
<Word>level</Word>
<Word>like</Word>
<Word>limit</Word>
<Word>limited</Word>
<Word>ln</Word>
<Word>lpad</Word>
<Word>local</Word>
<Word>localtime</Word>
<Word>localtimestamp</Word>
<Word>locator</Word>
<Word>lock</Word>
<Word>log</Word>
<Word>log10</Word>
<Word>long</Word>
<Word>loop</Word>
<Word>lower</Word>
<Word>ltrim</Word>
<Word>make_ref</Word>
<Word>map</Word>
<Word>match</Word>
<Word>max</Word>
<Word>maxextents</Word>
<Word>mid</Word>
<Word>min</Word>
<Word>minus</Word>
<Word>minute</Word>
<Word>mlslabel</Word>
<Word>mod</Word>
<Word>mode</Word>
<Word>modifies</Word>
<Word>modify</Word>
<Word>module</Word>
<Word>month</Word>
<Word>months_between</Word>
<Word>names</Word>
<Word>national</Word>
<Word>natural</Word>
<Word>naturaln</Word>
<Word>nchar</Word>
<Word>nclob</Word>
<Word>new</Word>
<Word>new_time</Word>
<Word>newid</Word>
<Word>next</Word>
<Word>next_day</Word>
<Word>nextval</Word>
<Word>no</Word>
<Word>noaudit</Word>
<Word>nocompress</Word>
<Word>nocopy</Word>
<Word>nolock</Word>
<Word>none</Word>
<Word>not</Word>
<Word>nowait</Word>
<Word>null</Word>
<Word>nullif</Word>
<Word>number</Word>
<Word>number_base</Word>
<Word>numeric</Word>
<Word>nvl</Word>
<Word>nvl2</Word>
<Word>object</Word>
<Word>object_id</Word>
<Word>object_name</Word>
<Word>object_property</Word>
<Word>ocirowid</Word>
<Word>oct</Word>
<Word>of</Word>
<Word>off</Word>
<Word>offline</Word>
<Word>old</Word>
<Word>on</Word>
<Word>online</Word>
<Word>only</Word>
<Word>opaque</Word>
<Word>open</Word>
<Word>operator</Word>
<Word>operation</Word>
<Word>option</Word>
<Word>or</Word>
<Word>ord</Word>
<Word>order</Word>
<Word>ordinalityorganization</Word>
<Word>others</Word>
<Word>out</Word>
<Word>outer</Word>
<Word>output</Word>
<Word>package</Word>
<Word>pad</Word>
<Word>parameter</Word>
<Word>parameters</Word>
<Word>partial</Word>
<Word>partition</Word>
<Word>path</Word>
<Word>pctfree</Word>
<Word>percent_rank</Word>
<Word>pi</Word>
<Word>pls_integer</Word>
<Word>positive</Word>
<Word>positiven</Word>
<Word>postfix</Word>
<Word>pow</Word>
<Word>power</Word>
<Word>pragma</Word>
<Word>precision</Word>
<Word>prefix</Word>
<Word>preorder</Word>
<Word>prepare</Word>
<Word>preserve</Word>
<Word>primary</Word>
<Word>prior</Word>
<Word>private</Word>
<Word>privileges</Word>
<Word>procedure</Word>
<Word>public</Word>
<Word>radians</Word>
<Word>raise</Word>
<Word>rand</Word>
<Word>range</Word>
<Word>rank</Word>
<Word>ratio_to_export</Word>
<Word>raw</Word>
<Word>rawtohex</Word>
<Word>read</Word>
<Word>reads</Word>
<Word>real</Word>
<Word>record</Word>
<Word>recursive</Word>
<Word>ref</Word>
<Word>references</Word>
<Word>referencing</Word>
<Word>reftohex</Word>
<Word>relative</Word>
<Word>release</Word>
<Word>release_lock</Word>
<Word>rename</Word>
<Word>repeat</Word>
<Word>replace</Word>
<Word>resource</Word>
<Word>restrict</Word>
<Word>result</Word>
<Word>return</Word>
<Word>returns</Word>
<Word>reverse</Word>
<Word>revoke</Word>
<Word>right</Word>
<Word>rollback</Word>
<Word>rollup</Word>
<Word>round</Word>
<Word>routine</Word>
<Word>row</Word>
<Word>row_number</Word>
<Word>rowid</Word>
<Word>rowidtochar</Word>
<Word>rowlabel</Word>
<Word>rowlock</Word>
<Word>rownum</Word>
<Word>rows</Word>
<Word>rowtype</Word>
<Word>rpad</Word>
<Word>rtrim</Word>
<Word>savepoint</Word>
<Word>schema</Word>
<Word>scroll</Word>
<Word>scope</Word>
<Word>search</Word>
<Word>second</Word>
<Word>section</Word>
<Word>seddev_samp</Word>
<Word>select</Word>
<Word>separate</Word>
<Word>sequence</Word>
<Word>session</Word>
<Word>session_user</Word>
<Word>set</Word>
<Word>sets</Word>
<Word>share</Word>
<Word>sign</Word>
<Word>sin</Word>
<Word>sinh</Word>
<Word>size</Word>
<Word>smallint</Word>
<Word>some</Word>
<Word>soundex</Word>
<Word>space</Word>
<Word>specific</Word>
<Word>specifictype</Word>
<Word>sql</Word>
<Word>sqlcode</Word>
<Word>sqlerrm</Word>
<Word>sqlexception</Word>
<Word>sqlstate</Word>
<Word>sqlwarning</Word>
<Word>sqrt</Word>
<Word>start</Word>
<Word>state</Word>
<Word>statement</Word>
<Word>static</Word>
<Word>std</Word>
<Word>stddev</Word>
<Word>stdev_pop</Word>
<Word>strcmp</Word>
<Word>structure</Word>
<Word>subdate</Word>
<Word>substr</Word>
<Word>substrb</Word>
<Word>substring</Word>
<Word>substring_index</Word>
<Word>subtype</Word>
<Word>successful</Word>
<Word>sum</Word>
<Word>synonym</Word>
<Word>sys_context</Word>
<Word>sys_guid</Word>
<Word>sysdate</Word>
<Word>system_user</Word>
<Word>table</Word>
<Word>tan</Word>
<Word>tanh</Word>
<Word>temporary</Word>
<Word>terminate</Word>
<Word>than</Word>
<Word>then</Word>
<Word>time</Word>
<Word>timestamp</Word>
<Word>timezone_abbr</Word>
<Word>timezone_minute</Word>
<Word>timezone_hour</Word>
<Word>timezone_region</Word>
<Word>tinyint</Word>
<Word>to</Word>
<Word>to_char</Word>
<Word>to_date</Word>
<Word>to_days</Word>
<Word>to_number</Word>
<Word>to_single_byte</Word>
<Word>trailing</Word>
<Word>transaction</Word>
<Word>translate</Word>
<Word>translation</Word>
<Word>treat</Word>
<Word>trigger</Word>
<Word>trim</Word>
<Word>true</Word>
<Word>trunc</Word>
<Word>truncate</Word>
<Word>type</Word>
<Word>ucase</Word>
<Word>uid</Word>
<Word>under</Word>
<Word>union</Word>
<Word>unique</Word>
<Word>unknown</Word>
<Word>unnest</Word>
<Word>update</Word>
<Word>upper</Word>
<Word>usage</Word>
<Word>use</Word>
<Word>user</Word>
<Word>userenv</Word>
<Word>using</Word>
<Word>validate</Word>
<Word>value</Word>
<Word>values</Word>
<Word>var_pop</Word>
<Word>var_samp</Word>
<Word>varbinary</Word>
<Word>varchar</Word>
<Word>varchar2</Word>
<Word>variable</Word>
<Word>variance</Word>
<Word>varying</Word>
<Word>view</Word>
<Word>vsize</Word>
<Word>when</Word>
<Word>whenever</Word>
<Word>where</Word>
<Word>with</Word>
<Word>without</Word>
<Word>while</Word>
<Word>work</Word>
<Word>write</Word>
<Word>year</Word>
<Word>zone</Word>
</Keywords>
</RuleSet>
</SyntaxDefinition>
<MSG> Update TSQL file #125
https://github.com/icsharpcode/AvalonEdit/pull/125
<DFF> @@ -559,6 +559,7 @@
<Word>timezone_region</Word>
<Word>tinyint</Word>
<Word>to</Word>
+ <Word>top</Word>
<Word>to_char</Word>
<Word>to_date</Word>
<Word>to_days</Word>
| 1 | Update TSQL file #125 | 0 | .xshd | xshd | mit | AvaloniaUI/AvaloniaEdit |
10066935 | <NME> TSQL-Mode.xshd
<BEF> <?xml version="1.0"?>
<SyntaxDefinition name="TSQL" extensions=".sql" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
<Color name="Comment" foreground="Green" exampleText="-- comment" />
<Color name="Char" foreground="Red" exampleText="name = 'abc'"/>
<Color name="Keywords" fontWeight="bold" foreground="Blue" exampleText="SELECT FROM"/>
<Property name="DocCommentMarker" value="///" />
<RuleSet name="CommentMarkerSet">
<Keywords fontWeight="bold" foreground="Red">
<Word>TODO</Word>
<Word>FIXME</Word>
</Keywords>
<Keywords fontWeight="bold" foreground="#E0E000">
<Word>HACK</Word>
<Word>UNDONE</Word>
</Keywords>
</RuleSet>
<RuleSet ignoreCase="true">
<Span color="Comment" ruleSet="CommentMarkerSet">
<Begin>--</Begin>
</Span>
<Span color="Comment" ruleSet="CommentMarkerSet" multiline="true">
<Begin>/\*</Begin>
<End>\*/</End>
</Span>
<Span color="Char">
<Begin>'</Begin>
<End>'</End>
<RuleSet>
<Span begin="\\" end="."/>
</RuleSet>
</Span>
<Keywords color="Keywords">
<Word>abs</Word>
<Word>absolute</Word>
<Word>access</Word>
<Word>acos</Word>
<Word>add</Word>
<Word>add_months</Word>
<Word>adddate</Word>
<Word>admin</Word>
<Word>after</Word>
<Word>aggregate</Word>
<Word>all</Word>
<Word>allocate</Word>
<Word>alter</Word>
<Word>and</Word>
<Word>any</Word>
<Word>app_name</Word>
<Word>are</Word>
<Word>array</Word>
<Word>as</Word>
<Word>asc</Word>
<Word>ascii</Word>
<Word>asin</Word>
<Word>assertion</Word>
<Word>at</Word>
<Word>atan</Word>
<Word>atn2</Word>
<Word>audit</Word>
<Word>authid</Word>
<Word>authorization</Word>
<Word>autonomous_transaction</Word>
<Word>avg</Word>
<Word>before</Word>
<Word>begin</Word>
<Word>benchmark</Word>
<Word>between</Word>
<Word>bfilename</Word>
<Word>bigint</Word>
<Word>bin</Word>
<Word>binary</Word>
<Word>binary_checksum</Word>
<Word>binary_integer</Word>
<Word>bit</Word>
<Word>bit_count</Word>
<Word>bit_and</Word>
<Word>bit_or</Word>
<Word>blob</Word>
<Word>body</Word>
<Word>boolean</Word>
<Word>both</Word>
<Word>breadth</Word>
<Word>bulk</Word>
<Word>by</Word>
<Word>call</Word>
<Word>cascade</Word>
<Word>cascaded</Word>
<Word>case</Word>
<Word>cast</Word>
<Word>catalog</Word>
<Word>ceil</Word>
<Word>ceiling</Word>
<Word>char</Word>
<Word>char_base</Word>
<Word>character</Word>
<Word>charindex</Word>
<Word>chartorowid</Word>
<Word>check</Word>
<Word>checksum</Word>
<Word>checksum_agg</Word>
<Word>chr</Word>
<Word>class</Word>
<Word>clob</Word>
<Word>close</Word>
<Word>cluster</Word>
<Word>coalesce</Word>
<Word>col_length</Word>
<Word>col_name</Word>
<Word>collate</Word>
<Word>collation</Word>
<Word>collect</Word>
<Word>column</Word>
<Word>comment</Word>
<Word>commit</Word>
<Word>completion</Word>
<Word>compress</Word>
<Word>concat</Word>
<Word>concat_ws</Word>
<Word>connect</Word>
<Word>connection</Word>
<Word>constant</Word>
<Word>constraint</Word>
<Word>constraints</Word>
<Word>constructorcreate</Word>
<Word>contains</Word>
<Word>containsable</Word>
<Word>continue</Word>
<Word>conv</Word>
<Word>convert</Word>
<Word>corr</Word>
<Word>corresponding</Word>
<Word>cos</Word>
<Word>cot</Word>
<Word>count</Word>
<Word>count_big</Word>
<Word>covar_pop</Word>
<Word>covar_samp</Word>
<Word>create</Word>
<Word>cross</Word>
<Word>cube</Word>
<Word>cume_dist</Word>
<Word>current</Word>
<Word>current_date</Word>
<Word>current_path</Word>
<Word>current_role</Word>
<Word>current_time</Word>
<Word>current_timestamp</Word>
<Word>current_user</Word>
<Word>currval</Word>
<Word>cursor</Word>
<Word>cycle</Word>
<Word>data</Word>
<Word>datalength</Word>
<Word>databasepropertyex</Word>
<Word>date</Word>
<Word>date_add</Word>
<Word>date_format</Word>
<Word>date_sub</Word>
<Word>dateadd</Word>
<Word>datediff</Word>
<Word>datename</Word>
<Word>datepart</Word>
<Word>datetime</Word>
<Word>day</Word>
<Word>db_id</Word>
<Word>db_name</Word>
<Word>deallocate</Word>
<Word>dec</Word>
<Word>declare</Word>
<Word>decimal</Word>
<Word>decode</Word>
<Word>default</Word>
<Word>deferrable</Word>
<Word>deferred</Word>
<Word>degrees</Word>
<Word>delete</Word>
<Word>dense_rank</Word>
<Word>depth</Word>
<Word>deref</Word>
<Word>desc</Word>
<Word>describe</Word>
<Word>descriptor</Word>
<Word>destroy</Word>
<Word>destructor</Word>
<Word>deterministic</Word>
<Word>diagnostics</Word>
<Word>dictionary</Word>
<Word>disconnect</Word>
<Word>difference</Word>
<Word>distinct</Word>
<Word>do</Word>
<Word>domain</Word>
<Word>double</Word>
<Word>drop</Word>
<Word>dump</Word>
<Word>dynamic</Word>
<Word>each</Word>
<Word>else</Word>
<Word>elsif</Word>
<Word>empth</Word>
<Word>encode</Word>
<Word>encrypt</Word>
<Word>end</Word>
<Word>end-exec</Word>
<Word>equals</Word>
<Word>escape</Word>
<Word>every</Word>
<Word>except</Word>
<Word>exception</Word>
<Word>exclusive</Word>
<Word>exec</Word>
<Word>execute</Word>
<Word>exists</Word>
<Word>exit</Word>
<Word>exp</Word>
<Word>export_set</Word>
<Word>extends</Word>
<Word>external</Word>
<Word>extract</Word>
<Word>false</Word>
<Word>fetch</Word>
<Word>first</Word>
<Word>first_value</Word>
<Word>file</Word>
<Word>float</Word>
<Word>floor</Word>
<Word>file_id</Word>
<Word>file_name</Word>
<Word>filegroup_id</Word>
<Word>filegroup_name</Word>
<Word>filegroupproperty</Word>
<Word>fileproperty</Word>
<Word>for</Word>
<Word>forall</Word>
<Word>foreign</Word>
<Word>format</Word>
<Word>formatmessage</Word>
<Word>found</Word>
<Word>freetexttable</Word>
<Word>from</Word>
<Word>from_days</Word>
<Word>fulltextcatalog</Word>
<Word>fulltextservice</Word>
<Word>function</Word>
<Word>general</Word>
<Word>get</Word>
<Word>get_lock</Word>
<Word>getdate</Word>
<Word>getansinull</Word>
<Word>getutcdate</Word>
<Word>global</Word>
<Word>go</Word>
<Word>goto</Word>
<Word>grant</Word>
<Word>greatest</Word>
<Word>group</Word>
<Word>grouping</Word>
<Word>having</Word>
<Word>heap</Word>
<Word>hex</Word>
<Word>hextoraw</Word>
<Word>host</Word>
<Word>host_id</Word>
<Word>host_name</Word>
<Word>hour</Word>
<Word>ident_incr</Word>
<Word>ident_seed</Word>
<Word>ident_current</Word>
<Word>identified</Word>
<Word>identity</Word>
<Word>if</Word>
<Word>ifnull</Word>
<Word>ignore</Word>
<Word>immediate</Word>
<Word>in</Word>
<Word>increment</Word>
<Word>index</Word>
<Word>index_col</Word>
<Word>indexproperty</Word>
<Word>indicator</Word>
<Word>initcap</Word>
<Word>initial</Word>
<Word>initialize</Word>
<Word>initially</Word>
<Word>inner</Word>
<Word>inout</Word>
<Word>input</Word>
<Word>insert</Word>
<Word>instr</Word>
<Word>instrb</Word>
<Word>int</Word>
<Word>integer</Word>
<Word>interface</Word>
<Word>intersect</Word>
<Word>interval</Word>
<Word>into</Word>
<Word>is</Word>
<Word>is_member</Word>
<Word>is_srvrolemember</Word>
<Word>is_null</Word>
<Word>is_numeric</Word>
<Word>isdate</Word>
<Word>isnull</Word>
<Word>isolation</Word>
<Word>iterate</Word>
<Word>java</Word>
<Word>join</Word>
<Word>key</Word>
<Word>lag</Word>
<Word>language</Word>
<Word>large</Word>
<Word>last</Word>
<Word>last_day</Word>
<Word>last_value</Word>
<Word>lateral</Word>
<Word>lcase</Word>
<Word>lead</Word>
<Word>leading</Word>
<Word>least</Word>
<Word>left</Word>
<Word>len</Word>
<Word>length</Word>
<Word>lengthb</Word>
<Word>less</Word>
<Word>level</Word>
<Word>like</Word>
<Word>limit</Word>
<Word>limited</Word>
<Word>ln</Word>
<Word>lpad</Word>
<Word>local</Word>
<Word>localtime</Word>
<Word>localtimestamp</Word>
<Word>locator</Word>
<Word>lock</Word>
<Word>log</Word>
<Word>log10</Word>
<Word>long</Word>
<Word>loop</Word>
<Word>lower</Word>
<Word>ltrim</Word>
<Word>make_ref</Word>
<Word>map</Word>
<Word>match</Word>
<Word>max</Word>
<Word>maxextents</Word>
<Word>mid</Word>
<Word>min</Word>
<Word>minus</Word>
<Word>minute</Word>
<Word>mlslabel</Word>
<Word>mod</Word>
<Word>mode</Word>
<Word>modifies</Word>
<Word>modify</Word>
<Word>module</Word>
<Word>month</Word>
<Word>months_between</Word>
<Word>names</Word>
<Word>national</Word>
<Word>natural</Word>
<Word>naturaln</Word>
<Word>nchar</Word>
<Word>nclob</Word>
<Word>new</Word>
<Word>new_time</Word>
<Word>newid</Word>
<Word>next</Word>
<Word>next_day</Word>
<Word>nextval</Word>
<Word>no</Word>
<Word>noaudit</Word>
<Word>nocompress</Word>
<Word>nocopy</Word>
<Word>nolock</Word>
<Word>none</Word>
<Word>not</Word>
<Word>nowait</Word>
<Word>null</Word>
<Word>nullif</Word>
<Word>number</Word>
<Word>number_base</Word>
<Word>numeric</Word>
<Word>nvl</Word>
<Word>nvl2</Word>
<Word>object</Word>
<Word>object_id</Word>
<Word>object_name</Word>
<Word>object_property</Word>
<Word>ocirowid</Word>
<Word>oct</Word>
<Word>of</Word>
<Word>off</Word>
<Word>offline</Word>
<Word>old</Word>
<Word>on</Word>
<Word>online</Word>
<Word>only</Word>
<Word>opaque</Word>
<Word>open</Word>
<Word>operator</Word>
<Word>operation</Word>
<Word>option</Word>
<Word>or</Word>
<Word>ord</Word>
<Word>order</Word>
<Word>ordinalityorganization</Word>
<Word>others</Word>
<Word>out</Word>
<Word>outer</Word>
<Word>output</Word>
<Word>package</Word>
<Word>pad</Word>
<Word>parameter</Word>
<Word>parameters</Word>
<Word>partial</Word>
<Word>partition</Word>
<Word>path</Word>
<Word>pctfree</Word>
<Word>percent_rank</Word>
<Word>pi</Word>
<Word>pls_integer</Word>
<Word>positive</Word>
<Word>positiven</Word>
<Word>postfix</Word>
<Word>pow</Word>
<Word>power</Word>
<Word>pragma</Word>
<Word>precision</Word>
<Word>prefix</Word>
<Word>preorder</Word>
<Word>prepare</Word>
<Word>preserve</Word>
<Word>primary</Word>
<Word>prior</Word>
<Word>private</Word>
<Word>privileges</Word>
<Word>procedure</Word>
<Word>public</Word>
<Word>radians</Word>
<Word>raise</Word>
<Word>rand</Word>
<Word>range</Word>
<Word>rank</Word>
<Word>ratio_to_export</Word>
<Word>raw</Word>
<Word>rawtohex</Word>
<Word>read</Word>
<Word>reads</Word>
<Word>real</Word>
<Word>record</Word>
<Word>recursive</Word>
<Word>ref</Word>
<Word>references</Word>
<Word>referencing</Word>
<Word>reftohex</Word>
<Word>relative</Word>
<Word>release</Word>
<Word>release_lock</Word>
<Word>rename</Word>
<Word>repeat</Word>
<Word>replace</Word>
<Word>resource</Word>
<Word>restrict</Word>
<Word>result</Word>
<Word>return</Word>
<Word>returns</Word>
<Word>reverse</Word>
<Word>revoke</Word>
<Word>right</Word>
<Word>rollback</Word>
<Word>rollup</Word>
<Word>round</Word>
<Word>routine</Word>
<Word>row</Word>
<Word>row_number</Word>
<Word>rowid</Word>
<Word>rowidtochar</Word>
<Word>rowlabel</Word>
<Word>rowlock</Word>
<Word>rownum</Word>
<Word>rows</Word>
<Word>rowtype</Word>
<Word>rpad</Word>
<Word>rtrim</Word>
<Word>savepoint</Word>
<Word>schema</Word>
<Word>scroll</Word>
<Word>scope</Word>
<Word>search</Word>
<Word>second</Word>
<Word>section</Word>
<Word>seddev_samp</Word>
<Word>select</Word>
<Word>separate</Word>
<Word>sequence</Word>
<Word>session</Word>
<Word>session_user</Word>
<Word>set</Word>
<Word>sets</Word>
<Word>share</Word>
<Word>sign</Word>
<Word>sin</Word>
<Word>sinh</Word>
<Word>size</Word>
<Word>smallint</Word>
<Word>some</Word>
<Word>soundex</Word>
<Word>space</Word>
<Word>specific</Word>
<Word>specifictype</Word>
<Word>sql</Word>
<Word>sqlcode</Word>
<Word>sqlerrm</Word>
<Word>sqlexception</Word>
<Word>sqlstate</Word>
<Word>sqlwarning</Word>
<Word>sqrt</Word>
<Word>start</Word>
<Word>state</Word>
<Word>statement</Word>
<Word>static</Word>
<Word>std</Word>
<Word>stddev</Word>
<Word>stdev_pop</Word>
<Word>strcmp</Word>
<Word>structure</Word>
<Word>subdate</Word>
<Word>substr</Word>
<Word>substrb</Word>
<Word>substring</Word>
<Word>substring_index</Word>
<Word>subtype</Word>
<Word>successful</Word>
<Word>sum</Word>
<Word>synonym</Word>
<Word>sys_context</Word>
<Word>sys_guid</Word>
<Word>sysdate</Word>
<Word>system_user</Word>
<Word>table</Word>
<Word>tan</Word>
<Word>tanh</Word>
<Word>temporary</Word>
<Word>terminate</Word>
<Word>than</Word>
<Word>then</Word>
<Word>time</Word>
<Word>timestamp</Word>
<Word>timezone_abbr</Word>
<Word>timezone_minute</Word>
<Word>timezone_hour</Word>
<Word>timezone_region</Word>
<Word>tinyint</Word>
<Word>to</Word>
<Word>to_char</Word>
<Word>to_date</Word>
<Word>to_days</Word>
<Word>to_number</Word>
<Word>to_single_byte</Word>
<Word>trailing</Word>
<Word>transaction</Word>
<Word>translate</Word>
<Word>translation</Word>
<Word>treat</Word>
<Word>trigger</Word>
<Word>trim</Word>
<Word>true</Word>
<Word>trunc</Word>
<Word>truncate</Word>
<Word>type</Word>
<Word>ucase</Word>
<Word>uid</Word>
<Word>under</Word>
<Word>union</Word>
<Word>unique</Word>
<Word>unknown</Word>
<Word>unnest</Word>
<Word>update</Word>
<Word>upper</Word>
<Word>usage</Word>
<Word>use</Word>
<Word>user</Word>
<Word>userenv</Word>
<Word>using</Word>
<Word>validate</Word>
<Word>value</Word>
<Word>values</Word>
<Word>var_pop</Word>
<Word>var_samp</Word>
<Word>varbinary</Word>
<Word>varchar</Word>
<Word>varchar2</Word>
<Word>variable</Word>
<Word>variance</Word>
<Word>varying</Word>
<Word>view</Word>
<Word>vsize</Word>
<Word>when</Word>
<Word>whenever</Word>
<Word>where</Word>
<Word>with</Word>
<Word>without</Word>
<Word>while</Word>
<Word>work</Word>
<Word>write</Word>
<Word>year</Word>
<Word>zone</Word>
</Keywords>
</RuleSet>
</SyntaxDefinition>
<MSG> Update TSQL file #125
https://github.com/icsharpcode/AvalonEdit/pull/125
<DFF> @@ -559,6 +559,7 @@
<Word>timezone_region</Word>
<Word>tinyint</Word>
<Word>to</Word>
+ <Word>top</Word>
<Word>to_char</Word>
<Word>to_date</Word>
<Word>to_days</Word>
| 1 | Update TSQL file #125 | 0 | .xshd | xshd | mit | AvaloniaUI/AvaloniaEdit |
10066936 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>0612,0618</WarningsNotAsErrors>
<PackageId>Avalonia.AvaloniaEdit</PackageId>
</PropertyGroup>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.5.2-build4323-alpha" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
<None Remove="Search\Assets\CaseSensitive.png" />
<None Remove="Search\Assets\CompleteWord.png" />
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> lastest avalonia
<DFF> @@ -9,7 +9,7 @@
</ItemGroup>
<ItemGroup>
- <PackageReference Include="Avalonia" Version="0.5.2-build4323-alpha" />
+ <PackageReference Include="Avalonia" Version="0.5.2-build4356-alpha" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
| 1 | lastest avalonia | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066937 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>0612,0618</WarningsNotAsErrors>
<PackageId>Avalonia.AvaloniaEdit</PackageId>
</PropertyGroup>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.5.2-build4323-alpha" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
<None Remove="Search\Assets\CaseSensitive.png" />
<None Remove="Search\Assets\CompleteWord.png" />
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> lastest avalonia
<DFF> @@ -9,7 +9,7 @@
</ItemGroup>
<ItemGroup>
- <PackageReference Include="Avalonia" Version="0.5.2-build4323-alpha" />
+ <PackageReference Include="Avalonia" Version="0.5.2-build4356-alpha" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
| 1 | lastest avalonia | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066938 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>0612,0618</WarningsNotAsErrors>
<PackageId>Avalonia.AvaloniaEdit</PackageId>
</PropertyGroup>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.5.2-build4323-alpha" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
<None Remove="Search\Assets\CaseSensitive.png" />
<None Remove="Search\Assets\CompleteWord.png" />
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> lastest avalonia
<DFF> @@ -9,7 +9,7 @@
</ItemGroup>
<ItemGroup>
- <PackageReference Include="Avalonia" Version="0.5.2-build4323-alpha" />
+ <PackageReference Include="Avalonia" Version="0.5.2-build4356-alpha" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
| 1 | lastest avalonia | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066939 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>0612,0618</WarningsNotAsErrors>
<PackageId>Avalonia.AvaloniaEdit</PackageId>
</PropertyGroup>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.5.2-build4323-alpha" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
<None Remove="Search\Assets\CaseSensitive.png" />
<None Remove="Search\Assets\CompleteWord.png" />
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> lastest avalonia
<DFF> @@ -9,7 +9,7 @@
</ItemGroup>
<ItemGroup>
- <PackageReference Include="Avalonia" Version="0.5.2-build4323-alpha" />
+ <PackageReference Include="Avalonia" Version="0.5.2-build4356-alpha" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
| 1 | lastest avalonia | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066940 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>0612,0618</WarningsNotAsErrors>
<PackageId>Avalonia.AvaloniaEdit</PackageId>
</PropertyGroup>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.5.2-build4323-alpha" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
<None Remove="Search\Assets\CaseSensitive.png" />
<None Remove="Search\Assets\CompleteWord.png" />
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> lastest avalonia
<DFF> @@ -9,7 +9,7 @@
</ItemGroup>
<ItemGroup>
- <PackageReference Include="Avalonia" Version="0.5.2-build4323-alpha" />
+ <PackageReference Include="Avalonia" Version="0.5.2-build4356-alpha" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
| 1 | lastest avalonia | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066941 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>0612,0618</WarningsNotAsErrors>
<PackageId>Avalonia.AvaloniaEdit</PackageId>
</PropertyGroup>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.5.2-build4323-alpha" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
<None Remove="Search\Assets\CaseSensitive.png" />
<None Remove="Search\Assets\CompleteWord.png" />
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> lastest avalonia
<DFF> @@ -9,7 +9,7 @@
</ItemGroup>
<ItemGroup>
- <PackageReference Include="Avalonia" Version="0.5.2-build4323-alpha" />
+ <PackageReference Include="Avalonia" Version="0.5.2-build4356-alpha" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
| 1 | lastest avalonia | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066942 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>0612,0618</WarningsNotAsErrors>
<PackageId>Avalonia.AvaloniaEdit</PackageId>
</PropertyGroup>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.5.2-build4323-alpha" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
<None Remove="Search\Assets\CaseSensitive.png" />
<None Remove="Search\Assets\CompleteWord.png" />
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> lastest avalonia
<DFF> @@ -9,7 +9,7 @@
</ItemGroup>
<ItemGroup>
- <PackageReference Include="Avalonia" Version="0.5.2-build4323-alpha" />
+ <PackageReference Include="Avalonia" Version="0.5.2-build4356-alpha" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
| 1 | lastest avalonia | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066943 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>0612,0618</WarningsNotAsErrors>
<PackageId>Avalonia.AvaloniaEdit</PackageId>
</PropertyGroup>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.5.2-build4323-alpha" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
<None Remove="Search\Assets\CaseSensitive.png" />
<None Remove="Search\Assets\CompleteWord.png" />
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> lastest avalonia
<DFF> @@ -9,7 +9,7 @@
</ItemGroup>
<ItemGroup>
- <PackageReference Include="Avalonia" Version="0.5.2-build4323-alpha" />
+ <PackageReference Include="Avalonia" Version="0.5.2-build4356-alpha" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
| 1 | lastest avalonia | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066944 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>0612,0618</WarningsNotAsErrors>
<PackageId>Avalonia.AvaloniaEdit</PackageId>
</PropertyGroup>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.5.2-build4323-alpha" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
<None Remove="Search\Assets\CaseSensitive.png" />
<None Remove="Search\Assets\CompleteWord.png" />
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> lastest avalonia
<DFF> @@ -9,7 +9,7 @@
</ItemGroup>
<ItemGroup>
- <PackageReference Include="Avalonia" Version="0.5.2-build4323-alpha" />
+ <PackageReference Include="Avalonia" Version="0.5.2-build4356-alpha" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
| 1 | lastest avalonia | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066945 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>0612,0618</WarningsNotAsErrors>
<PackageId>Avalonia.AvaloniaEdit</PackageId>
</PropertyGroup>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.5.2-build4323-alpha" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
<None Remove="Search\Assets\CaseSensitive.png" />
<None Remove="Search\Assets\CompleteWord.png" />
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> lastest avalonia
<DFF> @@ -9,7 +9,7 @@
</ItemGroup>
<ItemGroup>
- <PackageReference Include="Avalonia" Version="0.5.2-build4323-alpha" />
+ <PackageReference Include="Avalonia" Version="0.5.2-build4356-alpha" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
| 1 | lastest avalonia | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066946 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>0612,0618</WarningsNotAsErrors>
<PackageId>Avalonia.AvaloniaEdit</PackageId>
</PropertyGroup>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.5.2-build4323-alpha" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
<None Remove="Search\Assets\CaseSensitive.png" />
<None Remove="Search\Assets\CompleteWord.png" />
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> lastest avalonia
<DFF> @@ -9,7 +9,7 @@
</ItemGroup>
<ItemGroup>
- <PackageReference Include="Avalonia" Version="0.5.2-build4323-alpha" />
+ <PackageReference Include="Avalonia" Version="0.5.2-build4356-alpha" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
| 1 | lastest avalonia | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066947 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>0612,0618</WarningsNotAsErrors>
<PackageId>Avalonia.AvaloniaEdit</PackageId>
</PropertyGroup>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.5.2-build4323-alpha" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
<None Remove="Search\Assets\CaseSensitive.png" />
<None Remove="Search\Assets\CompleteWord.png" />
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> lastest avalonia
<DFF> @@ -9,7 +9,7 @@
</ItemGroup>
<ItemGroup>
- <PackageReference Include="Avalonia" Version="0.5.2-build4323-alpha" />
+ <PackageReference Include="Avalonia" Version="0.5.2-build4356-alpha" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
| 1 | lastest avalonia | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066948 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>0612,0618</WarningsNotAsErrors>
<PackageId>Avalonia.AvaloniaEdit</PackageId>
</PropertyGroup>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.5.2-build4323-alpha" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
<None Remove="Search\Assets\CaseSensitive.png" />
<None Remove="Search\Assets\CompleteWord.png" />
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> lastest avalonia
<DFF> @@ -9,7 +9,7 @@
</ItemGroup>
<ItemGroup>
- <PackageReference Include="Avalonia" Version="0.5.2-build4323-alpha" />
+ <PackageReference Include="Avalonia" Version="0.5.2-build4356-alpha" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
| 1 | lastest avalonia | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
10066949 | <NME> AvaloniaEdit.csproj
<BEF> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsNotAsErrors>0612,0618</WarningsNotAsErrors>
<PackageId>Avalonia.AvaloniaEdit</PackageId>
</PropertyGroup>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.5.2-build4323-alpha" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
<None Remove="Search\Assets\CaseSensitive.png" />
<None Remove="Search\Assets\CompleteWord.png" />
<None Remove="Search\Assets\FindNext.png" />
<None Remove="Search\Assets\FindPrevious.png" />
<None Remove="Search\Assets\RegularExpression.png" />
<None Remove="Search\Assets\ReplaceAll.png" />
<None Remove="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Search\Assets\CaseSensitive.png" />
<EmbeddedResource Include="Search\Assets\CompleteWord.png" />
<EmbeddedResource Include="Search\Assets\FindNext.png" />
<EmbeddedResource Include="Search\Assets\FindPrevious.png" />
<EmbeddedResource Include="Search\Assets\RegularExpression.png" />
<EmbeddedResource Include="Search\Assets\ReplaceAll.png" />
<EmbeddedResource Include="Search\Assets\ReplaceNext.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="SR.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SR.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="SR.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="ChangeAliasesOfSystemDrawing" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Splat'">
<Aliases>SystemDrawing</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
<MSG> lastest avalonia
<DFF> @@ -9,7 +9,7 @@
</ItemGroup>
<ItemGroup>
- <PackageReference Include="Avalonia" Version="0.5.2-build4323-alpha" />
+ <PackageReference Include="Avalonia" Version="0.5.2-build4356-alpha" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
</ItemGroup>
| 1 | lastest avalonia | 1 | .csproj | csproj | mit | AvaloniaUI/AvaloniaEdit |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.