diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2021-03-27 14:12:47 +0100 |
|---|---|---|
| committer | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2021-03-27 14:12:47 +0100 |
| commit | 983371d5934520e5a29a105e88ce893eaeca3663 (patch) | |
| tree | ebfed89ac3c7dd4110a82adc06eac9a196e3810a /Samples/ShowCase | |
| parent | bb9053da569aceaa3f58a97bfbc42c7a178cf9a1 (diff) | |
wip
Diffstat (limited to 'Samples/ShowCase')
| -rw-r--r-- | Samples/ShowCase/Editor.cs | 44 | ||||
| -rw-r--r-- | Samples/ShowCase/ui/showcase.crow | 5 |
2 files changed, 47 insertions, 2 deletions
diff --git a/Samples/ShowCase/Editor.cs b/Samples/ShowCase/Editor.cs new file mode 100644 index 00000000..315a5a9d --- /dev/null +++ b/Samples/ShowCase/Editor.cs @@ -0,0 +1,44 @@ +// Copyright (c) 2013-2019 Bruyère Jean-Philippe <jp_bruyere@hotmail.com> +// +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) + +using System; +using Glfw; +using Crow.Text; + +namespace Crow +{ + public class Editor : TextBox { + public override void onKeyDown(object sender, KeyEventArgs e) + { + TextSpan selection = Selection; + if (e.Key == Key.Tab && !selection.IsEmpty) { + int lineStart = lines.GetLocation (selection.Start).Line; + int lineEnd = lines.GetLocation (selection.End).Line; + + if (IFace.Shift) { + for (int l = lineStart; l <= lineEnd; l++) { + if (Text[lines[l].Start] == '\t') + update (new TextChange (lines[l].Start, 1, "")); + else if (Char.IsWhiteSpace (Text[lines[l].Start])) { + int i = 1; + while (i < lines[l].Length && i < Interface.TAB_SIZE && Char.IsWhiteSpace (Text[i])) + i++; + update (new TextChange (lines[l].Start, i, "")); + } + } + + }else{ + for (int l = lineStart; l <= lineEnd; l++) + update (new TextChange (lines[l].Start, 0, "\t")); + } + + selectionStart = new CharLocation (lineStart, 0); + CurrentLoc = new CharLocation (lineEnd, lines[lineEnd].Length); + + return; + } + base.onKeyDown(sender, e); + } + } +}
\ No newline at end of file diff --git a/Samples/ShowCase/ui/showcase.crow b/Samples/ShowCase/ui/showcase.crow index 5b0e467c..3d589b3d 100644 --- a/Samples/ShowCase/ui/showcase.crow +++ b/Samples/ShowCase/ui/showcase.crow @@ -29,8 +29,9 @@ <Label Text="{../../tb.CurrentColumn}" Margin="2"/> </HorizontalStack> <HorizontalStack> - <TextBox Name="tb" Text="{Source}" Multiline="true" Font="consolas, 12" Focusable="true" Height="Stretched" Width="Stretched" - TextChanged="onTextChanged" KeyDown="textView_KeyDown" ContextCommands="{EditorCommands}"/> + <Editor Name="tb" Text="{Source}" Multiline="true" Font="consolas, 12" Focusable="true" Height="Stretched" Width="Stretched" + TextChanged="onTextChanged" KeyDown="textView_KeyDown" ContextCommands="{EditorCommands}" + Foreground="DarkGrey" Background="White"/> <!--SelectionChanged="onSelectedTextChanged"--> <ScrollBar Value="{²../tb.ScrollY}" LargeIncrement="{../tb.PageHeight}" SmallIncrement="1" |