mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
* Initial plan * Change MessageBox to return nullable int instead of -1 Co-authored-by: tig <585482+tig@users.noreply.github.com> * Initial plan * Add fencing to prevent mixing Application models Co-authored-by: tig <585482+tig@users.noreply.github.com> * Fix fence logic to work with parallel tests Co-authored-by: tig <585482+tig@users.noreply.github.com> * WIP: Fixing Application issues. * Refactor error messages into constants Co-authored-by: tig <585482+tig@users.noreply.github.com> * Refactor ConfigurationProperty properties to use static backing fields and raise events Co-authored-by: tig <585482+tig@users.noreply.github.com> * Reset static Application properties in ResetStateStatic Co-authored-by: tig <585482+tig@users.noreply.github.com> * Refactor tests to decouple from global Application state Commented out `driver ??= Application.Driver` assignments in `DriverAssert` to prevent automatic global driver assignment. Removed `Application.ResetState(true)` calls and commented out state validation assertions in `GlobalTestSetup` to reduce dependency on global state. Reintroduced `ApplicationForceDriverTests` and `ApplicationModelFencingTests` to validate `ForceDriver` behavior and ensure proper handling of legacy and modern Application models. Skipped certain `ToAnsiTests` that rely on `Application`. Removed direct `Application.Driver` assignments in `ViewDrawingClippingTests` and `ViewDrawingFlowTests`. Performed general cleanup of redundant code and unused imports to simplify the codebase. * WIP: Fixed Parallel tests; non-Parallel still broken Refactor application model usage tracking Refactored `ApplicationModelUsage` into a public enum in the new `Terminal.Gui.App` namespace, making it accessible across the codebase. Replaced the private `_modelUsage` field in `ApplicationImpl` with a public static `ModelUsage` property to improve clarity and accessibility. Renamed error message constants for consistency and updated methods like `SetInstance` and `MarkInstanceBasedModelUsed` to use the new `ModelUsage` property. Removed the private `ApplicationModelUsage` enum from `ApplicationImpl`. Updated test cases to use `ApplicationImpl.Instance` instead of `Application.Create` to enforce the legacy static model. Skipped obsolete tests in `ApplicationForceDriverTests` and added null checks in `DriverAssert` and `SelectorBase` to handle edge cases. Commented out an unused line in `WindowsOutput` and made general improvements to code readability, maintainability, and consistency. * WIP: Almost there! Refactored tests and code to align with the modern instance-based application model. Key changes include: - Disabled Sixel rendering in `OutputBase.cs` due to dependency on legacy static `Application` object. - Hardcoded `force16Colors` to `false` in `WindowsOutput.cs` with a `BUGBUG` note. - Updated `ApplicationImplTests` to use `ApplicationImpl.SetInstance` and return `ApplicationImpl.Instance`. - Refactored `ApplicationModelFencingTests` to use `Application.Create()` and added `ResetModelUsageTracking()` for model switching. - Removed legacy `DriverTests` and reintroduced updated versions with cross-platform driver tests. - Reverted `ArrangementTests` and `ShortcutTests` to use legacy static `ApplicationImpl.Instance`. - Reintroduced driver tests in `DriverTests.cs` with modern `Application.Create()` and added `TestTop` for driver content verification. - General cleanup, including removal of outdated code and addition of `BUGBUG` notes for temporary workarounds. * Fixed all modelusage bugs? Replaced static `Application` references with instance-based `App` context across the codebase. Updated calls to `Application.RequestStop()` and `Application.Screen` to use `App?.RequestStop()` and `App?.Screen` for better encapsulation and flexibility. Refactored test infrastructure to align with the new context, including reintroducing `FakeApplicationFactory` and `FakeApplicationLifecycle` for testing purposes. Improved logging, error handling, and test clarity by adding `logWriter` support and simplifying test setup. Removed redundant or obsolete code, such as `NetSequences` and the old `FakeApplicationFactory` implementation. Updated documentation to reflect the new `IApplication.RequestStop()` usage. * merged * Refactor KeyboardImpl and modernize MessageBoxTests Refactored the `KeyboardImpl` class to remove hardcoded default key values, replacing them with uninitialized fields for dynamic configuration. Updated key binding logic to use `ReplaceCommands` instead of `Add` for better handling of dynamic changes. Removed unnecessary `KeyBindings.Clear()` calls to avoid side effects. Rewrote `MessageBoxTests.cs` to improve readability, maintainability, and adherence to modern C# standards. Enabled nullable reference checks, updated the namespace, and restructured test methods for clarity. Marked non-functional tests with `[Theory(Skip)]` and improved test organization with parameterized inputs. Enhanced test assertions, lifecycle handling, and error handling across the test suite. Updated `UICatalog_AboutBox` to use multiline string literals for expected outputs. These changes improve the overall maintainability and flexibility of the codebase. * Atempt to fix windows only CI/CD Unit tests failure Refactor Application lifecycle and test cleanup Refactored the `Application` class to phase out legacy static properties `SessionStack` and `TopRunnable` from `Application.Current.cs`. These were reintroduced in a new file `Application.TopRunnable.cs` for better modularity, while retaining their `[Obsolete]` status. Updated `ApplicationPopoverTests.cs` to replace `Application.ResetState(true)` with `Application.Shutdown()` for consistent application state cleanup. Added explicit cleanup for `Application.TopRunnable` in relevant test cases to ensure proper resource management. Adjusted namespaces and `using` directives to support the new structure. These changes improve code organization and align with updated application lifecycle management practices. * Fixes #<Issue> - Dispose TopRunnable in cleanup logic Updated the `finally` block in `ApplicationPopoverTests` to dispose of the `Application.TopRunnable` object if it is not null, ensuring proper resource cleanup. Previously, the property was being set to `null` without disposal. The `Application.Shutdown()` call remains unchanged. * Improve thread safety, reduce static dependencies, and align the codebase with the updated `IApplication` interface. Refactored the `MainThreadId` property to improve encapsulation: - Updated `Application.MainThreadId` to use `ApplicationImpl.Instance` directly. - Added `MainThreadId` to `ApplicationImpl` and `IApplication`. - Removed redundant `MainThreadId` from `ApplicationImpl.Run.cs`. Updated `EnqueueMouseEvent` to include an `IApplication?` parameter: - Modified `FakeInputProcessor`, `InputProcessorImpl`, and `WindowsInputProcessor` to support the new parameter. - Updated `IInputProcessor` interface to reflect the new method signature. - Adjusted `GuiTestContext` and `EnqueueMouseEventTests` to pass `IApplication` where required. Improved test coverage and code maintainability: - Added test cases for negative positions and empty mouse events. - Commented out legacy code in `GraphView` and `FakeDriverBase`. - Enhanced readability in `EnqueueMouseEventTests`. These changes improve thread safety, reduce static dependencies, and align the codebase with the updated `IApplication` interface. * Fixed more bugs. Enabled nullable reference types across multiple files to improve code safety. Refactored and modularized test classes, improving readability and maintainability. Removed outdated test cases and added new tests for edge cases, including culture-specific and non-Gregorian calendar handling. Addressed timeout issues in `ScenarioTests` with a watchdog timer and improved error handling. Updated `ApplicationImplTests` to use instance fields instead of static references for better test isolation. Refactored `ScenarioTests` to dynamically load and test all UI Catalog scenarios, with macOS-specific skips for known issues. Aligned `MessageBox.Query` calls with updated API signatures. Performed general code cleanup, including removing unused directives, improving formatting, and consolidating repetitive logic into helper methods. * Made the `InputBindings<TEvent, TBinding>` class thread-safe by replacing the internal `Dictionary<TEvent, TBinding>` with `ConcurrentDictionary<TEvent, TBinding>`. This fixes parallel test failures where "Collection was modified; enumeration operation may not execute" exceptions were thrown. ## Changes Made ### 1. InputBindings.cs - **File**: `Terminal.Gui/Input/InputBindings.cs` - **Change**: Replaced `Dictionary` with `ConcurrentDictionary` - **Key modifications**: - Changed `_bindings` from `Dictionary<TEvent, TBinding>` to `ConcurrentDictionary<TEvent, TBinding>` - Updated `Add()` methods to use `TryAdd()` instead of checking with `TryGet()` then `Add()` - Updated `Remove()` to use `TryRemove()` (no need to check existence first) - Updated `ReplaceCommands()` to use `ContainsKey()` instead of `TryGet()` - Added `.ToList()` to `GetAllFromCommands()` to create a snapshot for safe enumeration - Added comment explaining that `ConcurrentDictionary` provides snapshot enumeration in `GetBindings()` - Added `.ToArray()` to `Clear(Command[])` to create snapshot before iteration ### 2. Thread Safety Test Suite - **File**: `Tests/UnitTestsParallelizable/Input/InputBindingsThreadSafetyTests.cs` - **New file** with comprehensive thread safety tests: - `Add_ConcurrentAccess_NoExceptions` - Tests concurrent additions - `GetBindings_DuringConcurrentModification_NoExceptions` - Tests enumeration during modifications - `TryGet_ConcurrentAccess_ReturnsConsistentResults` - Tests concurrent reads - `Clear_ConcurrentAccess_NoExceptions` - Tests concurrent clearing - `Remove_ConcurrentAccess_NoExceptions` - Tests concurrent removals - `Replace_ConcurrentAccess_NoExceptions` - Tests concurrent replacements - `GetAllFromCommands_DuringModification_NoExceptions` - Tests LINQ queries during modifications - `MixedOperations_ConcurrentAccess_NoExceptions` - Tests mixed operations (add/read/remove) - `KeyBindings_ConcurrentAccess_NoExceptions` - Tests actual `KeyBindings` class - `MouseBindings_ConcurrentAccess_NoExceptions` - Tests actual `MouseBindings` class ## Benefits of ConcurrentDictionary Approach 1. **Lock-Free Reads**: Most read operations don't require locks, improving performance 2. **Snapshot Enumeration**: Built-in support for safe enumeration during concurrent modifications 3. **Simplified Code**: No need for explicit `lock` statements or lock objects 4. **Better Scalability**: Multiple threads can read/write simultaneously 5. **No "Collection was modified" Exceptions**: Enumeration creates a snapshot ## Performance Characteristics - **Read Operations**: Lock-free, very fast - **Write Operations**: Uses fine-grained locking internally, minimal contention - **Memory Overhead**: Slightly higher than `Dictionary` but negligible in practice - **Enumeration**: Creates a snapshot, safe for concurrent modifications ## Test Results - **Original failing test now passes**: `ApplicationImplTests.Init_CreatesKeybindings` - **10 new thread safety tests**: All passing - **All 11,741 parallelizable tests**: All passing (11,731 passed, 10 skipped) - **All 1,779 non-parallelizable tests**: All passing (1,762 passed, 17 skipped) - **No compilation errors**: Clean build with no xUnit1031 warnings (suppressed with pragmas) ## Verification The original failure was: ``` System.InvalidOperationException: Collection was modified; enumeration operation may not execute. ``` This occurred in parallelizable tests when multiple threads accessed `KeyBindings.GetBindings()` simultaneously. The `ConcurrentDictionary` implementation resolves this by providing thread-safe operations and snapshot enumeration. ## Notes - The xUnit1031 warnings about using `Task.WaitAll` instead of `async/await` have been suppressed with `#pragma warning disable xUnit1031` directives, as these are intentional blocking operations in stress tests that test concurrent scenarios - All existing functionality is preserved; this is a drop-in replacement - No changes to public API surface - Existing tests continue to pass * Make InputBindings and KeyboardImpl thread-safe for concurrent access Replace Dictionary with ConcurrentDictionary in InputBindings<TEvent, TBinding> and KeyboardImpl to enable safe parallel test execution and multi-threaded usage. Changes: - InputBindings: Replace Dictionary with ConcurrentDictionary for _bindings - InputBindings: Make Replace() atomic using AddOrUpdate instead of Remove+Add - InputBindings: Make ReplaceCommands() atomic using AddOrUpdate - InputBindings: Add IsValid() check to both Add() overloads - InputBindings: Add defensive .ToList()/.ToArray() for safe LINQ enumeration - KeyboardImpl: Replace Dictionary with ConcurrentDictionary for _commandImplementations - KeyboardImpl: Change AddKeyBindings() to use ReplaceCommands for idempotent initialization - Add 10 comprehensive thread safety tests for InputBindings - Add 9 comprehensive thread safety tests for KeyboardImpl The ConcurrentDictionary implementation provides: - Lock-free reads for better performance under concurrent access - Atomic operations for Replace/ReplaceCommands preventing race conditions - Snapshot enumeration preventing "Collection was modified" exceptions - No breaking API changes - maintains backward compatibility All 11,750 parallelizable tests pass (11,740 passed, 10 skipped). Fixes race conditions that caused ApplicationImplTests.Init_CreatesKeybindings to fail intermittently during parallel test execution. * Decouple ApplicationImpl from Application static props Removed initialization of `Force16Colors` and `ForceDriver` from `Application` static properties in the `ApplicationImpl` constructor. The class still subscribes to the `Force16ColorsChanged` and `ForceDriverChanged` events, but no longer sets initial values for these properties. This change simplifies the constructor and reduces coupling between `ApplicationImpl` and `Application`. * Refactored keyboard initialization in `ApplicationImpl` to use `Application` static properties for default key assignments, ensuring synchronization with pre-`Init()` changes. Improved `KeyboardImpl` initialization to avoid premature `ApplicationImpl.Instance` access, enhancing testability. Standardized constant naming conventions and improved code readability in thread safety tests for `KeyboardImpl` and `InputBindings`. Updated `TestInputBindings` implementation for clarity and conciseness. Applied consistent code style improvements across files, including spacing, formatting, and variable naming, to enhance maintainability and readability. * Fix race conditions in parallel tests - thread-safe ApplicationImpl and KeyboardImpl Fixes intermittent failures in parallel tests caused by three separate race conditions: 1. **KeyboardImpl constructor race condition** - Constructor was accessing Application.QuitKey/ArrangeKey/etc which triggered ApplicationImpl.Instance getter, setting ModelUsage=LegacyStatic before Application.Create() was called - Changed constructor to initialize keys with hard-coded defaults instead - Added synchronization from Application static properties during Init() 2. **InputBindings.Replace() race condition** - Between GetOrAdd(oldEventArgs) and AddOrUpdate(newEventArgs), another thread could modify bindings, causing stale data to overwrite valid bindings - Added early return for same-key case (oldEventArgs == newEventArgs) - Kept atomic operations with proper updateValueFactory handling - Added detailed thread-safety documentation 3. **ApplicationImpl model usage fence checks race condition** - Two threads calling Init() simultaneously could both pass fence checks before either set ModelUsage, allowing improper model mixing - Added _modelUsageLock for thread-safe synchronization - Made all ModelUsage operations atomic (Instance getter, SetInstance, MarkInstanceBasedModelUsed, ResetModelUsageTracking, Init fence checks) **Files Changed:** - Terminal.Gui/App/ApplicationImpl.cs - Added _modelUsageLock, made all ModelUsage access thread-safe - Terminal.Gui/App/ApplicationImpl.Lifecycle.cs - Thread-safe fence checks in Init(), sync keyboard keys from Application properties - Terminal.Gui/App/Keyboard/KeyboardImpl.cs - Fixed constructor to not trigger ApplicationImpl.Instance - Terminal.Gui/Input/InputBindings.cs - Fixed Replace() race condition with proper atomic operations **Testing:** - All 11 ApplicationImplTests pass - All 9 KeyboardImplThreadSafetyTests pass - All 10 InputBindingsThreadSafetyTests pass - No more intermittent "Cannot use modern instance-based model after using legacy static Application model" errors in parallel test execution The root cause was KeyboardImpl constructor accessing Application static properties during object creation, which would lazily initialize ApplicationImpl.Instance and set the wrong ModelUsage before Application.Create() could mark it as InstanceBased. * Warning cleanup * docs: Add comprehensive MessageBox and Clipboard API documentation - Updated MessageBox class docs with nullable return value explanation - Created docfx/docs/messagebox-clipboard-changes-v2.md migration guide - Updated migratingfromv1.md with quick links to major changes - Created PR-SUMMARY.md documenting all changes - Added examples for both instance-based and legacy patterns - Documented application model fencing and thread safety improvements The documentation covers: • MessageBox nullable int? returns (null = cancelled) • Clipboard refactoring from static to instance-based • Application model usage fencing to prevent pattern mixing • Thread safety improvements in KeyboardImpl and InputBindings • Complete migration guide with code examples • Benefits and rationale for all changes * Refactor static properties to use backing fields Refactored static properties in multiple classes (`Button`, `CheckBox`, `Dialog`, `FrameView`, `MessageBox`, `StatusBar`, and `Window`) to use private backing fields for better encapsulation and configurability. Default values are now stored in private static fields, allowing overrides via configuration files (e.g., `Resources/config.json`). Updated property definitions to use `get`/`set` accessors interacting with the backing fields. Retained the `[ConfigurationProperty]` attribute to ensure runtime configurability. Removed redundant code, improved XML documentation, adjusted namespace declarations for consistency, and performed general code cleanup to enhance readability and maintainability. * Fix Windows-only parallel test failure by preventing ConfigurationManager from triggering ApplicationImpl.Instance Problem: `MessageBoxTests.Location_And_Size_Correct` was failing only on Windows in parallel tests with: System.InvalidOperationException: Cannot use modern instance-based model (Application.Create) after using legacy static Application model (Application.Init/ApplicationImpl.Instance). Root Cause (maybe): View classes (MessageBox, Dialog, Window, Button, CheckBox, FrameView, StatusBar) had `[ConfigurationProperty]` decorated auto-properties with inline initializers. When ConfigurationManager's module initializer scanned assemblies using reflection, accessing these auto-properties could trigger lazy initialization of other static members, which in some cases indirectly referenced `ApplicationImpl.Instance`, marking the model as "legacy" before parallel tests called `Application.Create()`. Solution: Converted all `[ConfigurationProperty]` auto-properties in View classes to use private backing fields with explicit getters/setters, matching the pattern used by `Application.QuitKey`. This prevents any code execution during reflection-based property discovery. Files Changed: - Terminal.Gui/Views/MessageBox.cs - 4 properties converted - Terminal.Gui/Views/Dialog.cs - 6 properties converted - Terminal.Gui/Views/Window.cs - 2 properties converted - Terminal.Gui/Views/Button.cs - 2 properties converted - Terminal.Gui/Views/CheckBox.cs - 1 property converted - Terminal.Gui/Views/FrameView.cs - 1 property converted - Terminal.Gui/Views/StatusBar.cs - 1 property converted Test Reorganization: - Moved `ConfigurationManagerTests.GetConfigPropertiesByScope_Gets` from UnitTestsParallelizable to UnitTests (defines custom ConfigurationProperty which affects global state) - Moved `SourcesManagerTests.Sources_StaysConsistentWhenUpdateFails` from UnitTestsParallelizable to UnitTests (modifies static ConfigurationManager.ThrowOnJsonErrors property) Best Practice: All `[ConfigurationProperty]` decorated static properties should use private backing fields to avoid triggering lazy initialization during ConfigurationManager's module initialization. Fixes: Windows-only parallel test failure in MessageBoxTests * Add thread-safety to CollectionNavigator classes - Add lock-based synchronization to CollectionNavigatorBase for _searchString and _lastKeystroke fields - Add lock-based synchronization to CollectionNavigator for Collection property access - Protect ElementAt and GetCollectionLength methods with locks - Add 6 comprehensive thread-safety tests covering: - Concurrent SearchString access - Concurrent Collection property access - Concurrent navigation operations (50 parallel tasks) - Concurrent collection modification with readers/writers - Concurrent search string changes - Stress test with 100 tasks × 1000 operations each All tests pass (31/31) including new thread-safety tests. The implementation uses lock-based synchronization rather than concurrent collections because: - IList interface is not thread-safe by design - CollectionNavigator is internal and used by UI components (ListView/TreeView) - Matches existing Terminal.Gui patterns (Scope<T>, ConfigProperty) - Provides simpler and more predictable behavior Fixes thread-safety issues when CollectionNavigator is accessed from multiple threads. * cleanup * Run parallel unit tests 10 times with varying parallelization to expose concurrency issues Co-authored-by: tig <585482+tig@users.noreply.github.com> * Fix parallel unit tests workflow - use proper xUnit parallelization parameters Co-authored-by: tig <585482+tig@users.noreply.github.com> * Fix environment variable reference in workflow - use proper bash syntax Co-authored-by: tig <585482+tig@users.noreply.github.com> * Run parallel tests 10 times sequentially instead of matrix expansion Co-authored-by: tig <585482+tig@users.noreply.github.com> * Make ConfigurationManager thread-safe - use ConcurrentDictionary and add locks Co-authored-by: tig <585482+tig@users.noreply.github.com> * Add Debug.Fail to detect legacy Application usage in parallelizable tests Co-authored-by: tig <585482+tig@users.noreply.github.com> * Move ScrollSliderTests to UnitTests project - they access legacy Application model Co-authored-by: tig <585482+tig@users.noreply.github.com> * Revert ScrollSliderTests move and document root cause analysis Co-authored-by: tig <585482+tig@users.noreply.github.com> * Remove Debug.Fail and move ScrollSliderTests to UnitTests project Co-authored-by: tig <585482+tig@users.noreply.github.com> * Re-add Debug.Fail to detect legacy Application usage in parallelizable tests Co-authored-by: tig <585482+tig@users.noreply.github.com> * Refactor tests and improve parallelization support Commented out `Debug.Fail` statements in `Application.Lifecycle.cs` and `ApplicationImpl.cs` to prevent interruptions during parallel tests. Refactored `ToString` in `ApplicationImpl.cs` to use an expression-bodied member and removed unused imports. Rewrote tests in `ClipRegionTests.cs` and `ScrollSliderTests.cs` to remove global state dependencies and migrated them to the `UnitTests_Parallelizable` namespace. Enabled nullable annotations and updated assertions for clarity and modern patterns. Improved test coverage by adding scenarios for clamping, layout, and size calculations. Updated `README.md` to include `[SetupFakeApplication]` in the list of patterns that block parallelization and clarified migration guidelines. Replaced `[SetupFakeDriver]` with `[SetupFakeApplication]` in examples. Added `<Folder Include="Drivers\" />` to `UnitTests.csproj` for better organization. Adjusted test project references to reflect test migration. Enhanced test output validation in `ScrollSliderTests.cs`. Removed redundant test cases and improved documentation to align with modern C# practices and ensure maintainability. * marked as a "TODO" for potential future configurability. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: tig <585482+tig@users.noreply.github.com> Co-authored-by: Tig <tig@users.noreply.github.com>
7313 lines
275 KiB
C#
7313 lines
275 KiB
C#
using System.Reflection;
|
||
using System.Text;
|
||
using System.Text.RegularExpressions;
|
||
using UnitTests;
|
||
using Xunit.Abstractions;
|
||
|
||
namespace UnitTests.ViewsTests;
|
||
|
||
public class TextViewTests
|
||
{
|
||
private static TextView _textView;
|
||
private readonly ITestOutputHelper _output;
|
||
public TextViewTests (ITestOutputHelper output) { _output = output; }
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void AllowsReturn_Setting_To_True_Changes_Multiline_To_True_If_It_Is_False ()
|
||
{
|
||
Assert.True (_textView.AllowsReturn);
|
||
Assert.True (_textView.Multiline);
|
||
Assert.Equal (4, _textView.TabWidth);
|
||
Assert.True (_textView.AllowsTab);
|
||
_textView.NewKeyDownEvent (Key.Enter);
|
||
|
||
Assert.Equal (
|
||
Environment.NewLine + "TAB to jump between text fields.",
|
||
_textView.Text
|
||
);
|
||
|
||
_textView.AllowsReturn = false;
|
||
Assert.False (_textView.AllowsReturn);
|
||
Assert.False (_textView.Multiline);
|
||
Assert.Equal (0, _textView.TabWidth);
|
||
Assert.False (_textView.AllowsTab);
|
||
_textView.NewKeyDownEvent (Key.Enter);
|
||
|
||
Assert.Equal (
|
||
Environment.NewLine + "TAB to jump between text fields.",
|
||
_textView.Text
|
||
);
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void AllowsTab_Setting_To_True_Changes_TabWidth_To_Default_If_It_Is_Zero ()
|
||
{
|
||
_textView.TabWidth = 0;
|
||
Assert.Equal (0, _textView.TabWidth);
|
||
Assert.True (_textView.AllowsTab);
|
||
Assert.True (_textView.AllowsReturn);
|
||
Assert.True (_textView.Multiline);
|
||
_textView.AllowsTab = true;
|
||
Assert.True (_textView.AllowsTab);
|
||
Assert.Equal (4, _textView.TabWidth);
|
||
Assert.True (_textView.AllowsReturn);
|
||
Assert.True (_textView.Multiline);
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void BackTab_Test_Follow_By_Tab ()
|
||
{
|
||
var top = new Toplevel ();
|
||
top.Add (_textView);
|
||
|
||
Application.Iteration += OnApplicationOnIteration;
|
||
|
||
Application.Run (top);
|
||
Application.Iteration -= OnApplicationOnIteration;
|
||
top.Dispose ();
|
||
|
||
return;
|
||
|
||
void OnApplicationOnIteration (object s, EventArgs<IApplication> a)
|
||
{
|
||
int width = _textView.Viewport.Width - 1;
|
||
Assert.Equal (30, width + 1);
|
||
Assert.Equal (10, _textView.Height);
|
||
_textView.Text = "";
|
||
|
||
for (var i = 0; i < 100; i++)
|
||
{
|
||
_textView.Text += "\t";
|
||
}
|
||
|
||
var col = 100;
|
||
int tabWidth = _textView.TabWidth;
|
||
int leftCol = _textView.LeftColumn;
|
||
_textView.MoveEnd ();
|
||
Assert.Equal (new (col, 0), _textView.CursorPosition);
|
||
leftCol = GetLeftCol (leftCol);
|
||
Assert.Equal (leftCol, _textView.LeftColumn);
|
||
|
||
while (col > 0)
|
||
{
|
||
col--;
|
||
_textView.NewKeyDownEvent (Key.Tab.WithShift);
|
||
Assert.Equal (new (col, 0), _textView.CursorPosition);
|
||
leftCol = GetLeftCol (leftCol);
|
||
Assert.Equal (leftCol, _textView.LeftColumn);
|
||
}
|
||
|
||
while (col < 100)
|
||
{
|
||
col++;
|
||
_textView.NewKeyDownEvent (Key.Tab);
|
||
Assert.Equal (new (col, 0), _textView.CursorPosition);
|
||
leftCol = GetLeftCol (leftCol);
|
||
Assert.Equal (leftCol, _textView.LeftColumn);
|
||
}
|
||
|
||
Application.TopRunnable.Remove (_textView);
|
||
Application.RequestStop ();
|
||
}
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void CanFocus_False_Wont_Focus_With_Mouse ()
|
||
{
|
||
Toplevel top = new ();
|
||
var tv = new TextView { Width = Dim.Fill (), CanFocus = false, ReadOnly = true, Text = "some text" };
|
||
|
||
var fv = new FrameView
|
||
{
|
||
Width = Dim.Fill (), Height = Dim.Fill (), CanFocus = false, Title = "I shouldn't get focus"
|
||
};
|
||
fv.Add (tv);
|
||
top.Add (fv);
|
||
|
||
Application.Begin (top);
|
||
|
||
Assert.False (tv.CanFocus);
|
||
Assert.False (tv.HasFocus);
|
||
Assert.False (fv.CanFocus);
|
||
Assert.False (fv.HasFocus);
|
||
|
||
tv.NewMouseEvent (new () { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked });
|
||
|
||
Assert.Empty (tv.SelectedText);
|
||
Assert.False (tv.CanFocus);
|
||
Assert.False (tv.HasFocus);
|
||
Assert.False (fv.CanFocus);
|
||
Assert.False (fv.HasFocus);
|
||
|
||
fv.CanFocus = true;
|
||
tv.CanFocus = true;
|
||
tv.NewMouseEvent (new () { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked });
|
||
|
||
Assert.Equal ("some ", tv.SelectedText);
|
||
Assert.True (tv.CanFocus);
|
||
Assert.True (tv.HasFocus);
|
||
Assert.True (fv.CanFocus);
|
||
Assert.True (fv.HasFocus);
|
||
|
||
fv.CanFocus = false;
|
||
tv.NewMouseEvent (new () { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked });
|
||
|
||
Assert.Equal ("some ", tv.SelectedText); // Setting CanFocus to false don't change the SelectedText
|
||
Assert.True (tv.CanFocus); // v2: CanFocus is not longer automatically changed
|
||
Assert.False (tv.HasFocus);
|
||
Assert.False (fv.CanFocus);
|
||
Assert.False (fv.HasFocus);
|
||
top.Dispose ();
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void Changing_Selection_Or_CursorPosition_Update_SelectedLength_And_SelectedText ()
|
||
{
|
||
_textView.SelectionStartColumn = 2;
|
||
_textView.SelectionStartRow = 0;
|
||
Assert.Equal (0, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (2, _textView.SelectedLength);
|
||
Assert.Equal ("TA", _textView.SelectedText);
|
||
_textView.CursorPosition = new (20, 0);
|
||
Assert.Equal (2, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (18, _textView.SelectedLength);
|
||
Assert.Equal ("B to jump between ", _textView.SelectedText);
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void ContentsChanged_Event_Fires_On_Init ()
|
||
{
|
||
Application.StopAfterFirstIteration = true;
|
||
|
||
var expectedRow = 0;
|
||
var expectedCol = 0;
|
||
var eventcount = 0;
|
||
|
||
var tv = new TextView { Width = 50, Height = 10 };
|
||
|
||
tv.ContentsChanged += (s, e) =>
|
||
{
|
||
eventcount++;
|
||
Assert.Equal (expectedRow, e.Row);
|
||
Assert.Equal (expectedCol, e.Col);
|
||
};
|
||
|
||
var top = new Toplevel ();
|
||
top.Add (tv);
|
||
Application.Begin (top);
|
||
Assert.Equal (1, eventcount);
|
||
top.Dispose ();
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void ContentsChanged_Event_Fires_On_InsertText ()
|
||
{
|
||
var eventcount = 0;
|
||
|
||
var tv = new TextView { Width = 50, Height = 10 };
|
||
tv.CursorPosition = Point.Empty;
|
||
|
||
tv.ContentsChanged += (s, e) => { eventcount++; };
|
||
|
||
Assert.Equal (0, eventcount);
|
||
|
||
tv.InsertText ("a");
|
||
Assert.Equal (1, eventcount);
|
||
|
||
tv.CursorPosition = Point.Empty;
|
||
tv.InsertText ("bcd");
|
||
Assert.Equal (4, eventcount);
|
||
|
||
tv.InsertText ("e");
|
||
Assert.Equal (5, eventcount);
|
||
|
||
tv.InsertText ("\n");
|
||
Assert.Equal (6, eventcount);
|
||
|
||
tv.InsertText ("1234");
|
||
Assert.Equal (10, eventcount);
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void ContentsChanged_Event_Fires_On_Set_Text ()
|
||
{
|
||
Application.StopAfterFirstIteration = true;
|
||
var eventcount = 0;
|
||
|
||
var expectedRow = 0;
|
||
var expectedCol = 0;
|
||
|
||
var tv = new TextView
|
||
{
|
||
Width = 50,
|
||
Height = 10,
|
||
|
||
// you'd think col would be 3, but it's 0 because TextView sets
|
||
// row/col = 0 when you set Text
|
||
Text = "abc"
|
||
};
|
||
|
||
tv.ContentsChanged += (s, e) =>
|
||
{
|
||
eventcount++;
|
||
Assert.Equal (expectedRow, e.Row);
|
||
Assert.Equal (expectedCol, e.Col);
|
||
};
|
||
|
||
Assert.Equal ("abc", tv.Text);
|
||
|
||
var top = new Toplevel ();
|
||
top.Add (tv);
|
||
SessionToken rs = Application.Begin (top);
|
||
Assert.Equal (1, eventcount); // for Initialize
|
||
|
||
expectedCol = 0;
|
||
tv.Text = "defg";
|
||
Assert.Equal (2, eventcount); // for set Text = "defg"
|
||
top.Dispose ();
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void ContentsChanged_Event_Fires_On_Typing ()
|
||
{
|
||
Application.StopAfterFirstIteration = true;
|
||
var eventcount = 0;
|
||
|
||
var expectedRow = 0;
|
||
var expectedCol = 0;
|
||
|
||
var tv = new TextView { Width = 50, Height = 10 };
|
||
|
||
tv.ContentsChanged += (s, e) =>
|
||
{
|
||
eventcount++;
|
||
Assert.Equal (expectedRow, e.Row);
|
||
Assert.Equal (expectedCol, e.Col);
|
||
};
|
||
|
||
var top = new Toplevel ();
|
||
top.Add (tv);
|
||
SessionToken rs = Application.Begin (top);
|
||
Assert.Equal (1, eventcount); // for Initialize
|
||
|
||
expectedCol = 0;
|
||
tv.Text = "ay";
|
||
Assert.Equal (2, eventcount);
|
||
|
||
expectedCol = 1;
|
||
tv.NewKeyDownEvent (Key.Y.WithShift);
|
||
Assert.Equal (3, eventcount);
|
||
Assert.Equal ("Yay", tv.Text);
|
||
top.Dispose ();
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void ContentsChanged_Event_Fires_On_Undo_Redo ()
|
||
{
|
||
var eventcount = 0;
|
||
var expectedEventCount = 0;
|
||
|
||
_textView.ContentsChanged += (s, e) => { eventcount++; };
|
||
|
||
expectedEventCount++;
|
||
_textView.Text = "This is the first line.\nThis is the second line.\nThis is the third line.";
|
||
Assert.Equal (expectedEventCount, eventcount);
|
||
|
||
expectedEventCount++;
|
||
Assert.True (_textView.NewKeyDownEvent (Key.Enter));
|
||
Assert.Equal (expectedEventCount, eventcount);
|
||
|
||
// Undo
|
||
expectedEventCount++;
|
||
Assert.True (_textView.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal (expectedEventCount, eventcount);
|
||
|
||
// Redo
|
||
expectedEventCount++;
|
||
Assert.True (_textView.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal (expectedEventCount, eventcount);
|
||
|
||
// Undo
|
||
expectedEventCount++;
|
||
Assert.True (_textView.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal (expectedEventCount, eventcount);
|
||
|
||
// Redo
|
||
expectedEventCount++;
|
||
Assert.True (_textView.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal (expectedEventCount, eventcount);
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void ContentsChanged_Event_Fires_Using_Copy_Or_Cut_Tests ()
|
||
{
|
||
var eventcount = 0;
|
||
|
||
_textView.ContentsChanged += (s, e) => { eventcount++; };
|
||
|
||
var expectedEventCount = 1;
|
||
|
||
// reset
|
||
_textView.Text = TextViewTestsSetupFakeApplication.Txt;
|
||
Assert.Equal (expectedEventCount, eventcount);
|
||
|
||
expectedEventCount += 3;
|
||
Copy_Or_Cut_And_Paste_With_No_Selection ();
|
||
Assert.Equal (expectedEventCount, eventcount);
|
||
|
||
// reset
|
||
expectedEventCount += 1;
|
||
_textView.Text = TextViewTestsSetupFakeApplication.Txt;
|
||
Assert.Equal (expectedEventCount, eventcount);
|
||
|
||
expectedEventCount += 3;
|
||
Copy_Or_Cut_And_Paste_With_Selection ();
|
||
Assert.Equal (expectedEventCount, eventcount);
|
||
|
||
// reset
|
||
expectedEventCount += 1;
|
||
_textView.Text = TextViewTestsSetupFakeApplication.Txt;
|
||
Assert.Equal (expectedEventCount, eventcount);
|
||
|
||
expectedEventCount += 1;
|
||
Copy_Or_Cut_Not_Null_If_Has_Selection ();
|
||
Assert.Equal (expectedEventCount, eventcount);
|
||
|
||
// reset
|
||
expectedEventCount += 1;
|
||
_textView.Text = TextViewTestsSetupFakeApplication.Txt;
|
||
Assert.Equal (expectedEventCount, eventcount);
|
||
|
||
expectedEventCount += 1;
|
||
Copy_Or_Cut_Null_If_No_Selection ();
|
||
Assert.Equal (expectedEventCount, eventcount);
|
||
|
||
// reset
|
||
expectedEventCount += 1;
|
||
_textView.Text = TextViewTestsSetupFakeApplication.Txt;
|
||
Assert.Equal (expectedEventCount, eventcount);
|
||
|
||
expectedEventCount += 4;
|
||
Copy_Without_Selection ();
|
||
Assert.Equal (expectedEventCount, eventcount);
|
||
|
||
// reset
|
||
expectedEventCount += 1;
|
||
_textView.Text = TextViewTestsSetupFakeApplication.Txt;
|
||
Assert.Equal (expectedEventCount, eventcount);
|
||
|
||
expectedEventCount += 4;
|
||
Copy_Without_Selection ();
|
||
Assert.Equal (expectedEventCount, eventcount);
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void ContentsChanged_Event_Fires_Using_Kill_Delete_Tests ()
|
||
{
|
||
var eventcount = 0;
|
||
|
||
_textView.ContentsChanged += (s, e) => { eventcount++; };
|
||
|
||
var expectedEventCount = 1;
|
||
Kill_Delete_WordForward ();
|
||
Assert.Equal (expectedEventCount, eventcount); // for Initialize
|
||
|
||
expectedEventCount += 1;
|
||
Kill_Delete_WordBackward ();
|
||
Assert.Equal (expectedEventCount, eventcount);
|
||
|
||
expectedEventCount += 2;
|
||
Kill_To_End_Delete_Forwards_Copy_To_The_Clipboard_And_Paste ();
|
||
Assert.Equal (expectedEventCount, eventcount);
|
||
|
||
expectedEventCount += 2;
|
||
Kill_To_Start_Delete_Backwards_Copy_To_The_Clipboard_And_Paste ();
|
||
Assert.Equal (expectedEventCount, eventcount);
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void ContentsChanged_Event_NoFires_On_CursorPosition ()
|
||
{
|
||
var eventcount = 0;
|
||
|
||
var tv = new TextView { Width = 50, Height = 10 };
|
||
|
||
tv.ContentsChanged += (s, e) => { eventcount++; };
|
||
Assert.Equal (0, eventcount);
|
||
|
||
tv.CursorPosition = Point.Empty;
|
||
|
||
Assert.Equal (0, eventcount);
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void Copy_Or_Cut_And_Paste_With_No_Selection ()
|
||
{
|
||
_textView.SelectionStartColumn = 20;
|
||
_textView.SelectionStartRow = 0;
|
||
_textView.CursorPosition = new (24, 0);
|
||
_textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy
|
||
Assert.Equal ("text", _textView.SelectedText);
|
||
Assert.Equal ("TAB to jump between text fields.", _textView.Text);
|
||
_textView.SelectionStartColumn = 0;
|
||
_textView.SelectionStartRow = 0;
|
||
Assert.Equal (new (24, 0), _textView.CursorPosition);
|
||
Assert.True (_textView.IsSelecting);
|
||
_textView.IsSelecting = false;
|
||
_textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste
|
||
Assert.Equal (new (28, 0), _textView.CursorPosition);
|
||
Assert.False (_textView.IsSelecting);
|
||
Assert.Equal ("TAB to jump between texttext fields.", _textView.Text);
|
||
_textView.SelectionStartColumn = 24;
|
||
_textView.SelectionStartRow = 0;
|
||
_textView.NewKeyDownEvent (Key.W.WithCtrl); // Cut
|
||
Assert.Equal (new (24, 0), _textView.CursorPosition);
|
||
Assert.False (_textView.IsSelecting);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
Assert.Equal ("TAB to jump between text fields.", _textView.Text);
|
||
_textView.SelectionStartColumn = 0;
|
||
_textView.SelectionStartRow = 0;
|
||
_textView.IsSelecting = false;
|
||
_textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste
|
||
Assert.Equal (new (28, 0), _textView.CursorPosition);
|
||
Assert.False (_textView.IsSelecting);
|
||
Assert.Equal ("TAB to jump between texttext fields.", _textView.Text);
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void Copy_Or_Cut_And_Paste_With_Selection ()
|
||
{
|
||
_textView.SelectionStartColumn = 20;
|
||
_textView.SelectionStartRow = 0;
|
||
_textView.CursorPosition = new (24, 0);
|
||
_textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy
|
||
Assert.Equal ("text", _textView.SelectedText);
|
||
Assert.Equal ("TAB to jump between text fields.", _textView.Text);
|
||
_textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste
|
||
Assert.Equal ("TAB to jump between text fields.", _textView.Text);
|
||
_textView.SelectionStartColumn = 20;
|
||
_textView.SelectionStartRow = 0;
|
||
_textView.NewKeyDownEvent (Key.W.WithCtrl); // Cut
|
||
_textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste
|
||
Assert.Equal ("TAB to jump between text fields.", _textView.Text);
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void Copy_Or_Cut_Not_Null_If_Has_Selection ()
|
||
{
|
||
_textView.SelectionStartColumn = 20;
|
||
_textView.SelectionStartRow = 0;
|
||
_textView.CursorPosition = new (24, 0);
|
||
_textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy
|
||
Assert.Equal ("text", _textView.SelectedText);
|
||
_textView.NewKeyDownEvent (Key.W.WithCtrl); // Cut
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void Copy_Or_Cut_Null_If_No_Selection ()
|
||
{
|
||
_textView.SelectionStartColumn = 0;
|
||
_textView.SelectionStartRow = 0;
|
||
_textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
_textView.NewKeyDownEvent (Key.W.WithCtrl); // Cut
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void Copy_Paste_Surrogate_Pairs ()
|
||
{
|
||
_textView.Text = "TextView with some more test text. Unicode shouldn't 𝔹Aℝ𝔽!";
|
||
_textView.SelectAll ();
|
||
_textView.Cut ();
|
||
|
||
Assert.Equal (
|
||
"TextView with some more test text. Unicode shouldn't 𝔹Aℝ𝔽!",
|
||
Application.Driver?.Clipboard.GetClipboardData ()
|
||
);
|
||
Assert.Equal (string.Empty, _textView.Text);
|
||
_textView.Paste ();
|
||
Assert.Equal ("TextView with some more test text. Unicode shouldn't 𝔹Aℝ𝔽!", _textView.Text);
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void Copy_Without_Selection ()
|
||
{
|
||
_textView.Text = "This is the first line.\nThis is the second line.\n";
|
||
_textView.CursorPosition = new (0, _textView.Lines - 1);
|
||
_textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy
|
||
_textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}{Environment.NewLine}",
|
||
_textView.Text
|
||
);
|
||
_textView.CursorPosition = new (3, 1);
|
||
_textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy
|
||
_textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the second line.{Environment.NewLine}{Environment.NewLine}",
|
||
_textView.Text
|
||
);
|
||
Assert.Equal (new (3, 2), _textView.CursorPosition);
|
||
_textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the second line.{Environment.NewLine}{Environment.NewLine}",
|
||
_textView.Text
|
||
);
|
||
Assert.Equal (new (3, 3), _textView.CursorPosition);
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void Cursor_Position_Multiline_False_Initialization ()
|
||
{
|
||
Assert.False (_textView.IsInitialized);
|
||
Assert.True (_textView.Multiline);
|
||
_textView.Multiline = false;
|
||
Assert.Equal (32, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
Assert.Equal ("TAB to jump between text fields.", _textView.Text);
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void CursorPosition_With_Value_Greater_Than_Text_Length_Changes_To_Text_Length ()
|
||
{
|
||
_textView.CursorPosition = new (33, 1);
|
||
Assert.Equal (32, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void CursorPosition_With_Value_Less_Than_Zero_Changes_To_Zero ()
|
||
{
|
||
_textView.CursorPosition = new (-1, -1);
|
||
Assert.Equal (0, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void Cut_Not_Allowed_If_ReadOnly_Is_True ()
|
||
{
|
||
_textView.ReadOnly = true;
|
||
_textView.SelectionStartColumn = 20;
|
||
_textView.SelectionStartRow = 0;
|
||
_textView.CursorPosition = new (24, 0);
|
||
_textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy
|
||
Assert.Equal ("text", _textView.SelectedText);
|
||
|
||
_textView.NewKeyDownEvent (
|
||
Key.W.WithCtrl
|
||
); // Selecting is set to false after Cut.
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
_textView.ReadOnly = false;
|
||
Assert.False (_textView.IsSelecting);
|
||
_textView.IsSelecting = true; // Needed to set Selecting to true.
|
||
_textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy
|
||
Assert.Equal ("text", _textView.SelectedText);
|
||
_textView.NewKeyDownEvent (Key.W.WithCtrl); // Cut
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void DeleteTextBackwards_WordWrap_False_Return_Undo ()
|
||
{
|
||
const string text = "This is the first line.\nThis is the second line.\n";
|
||
var tv = new TextView { Width = Dim.Fill (), Height = Dim.Fill (), Text = text };
|
||
string envText = tv.Text;
|
||
var top = new Toplevel ();
|
||
top.Add (tv);
|
||
SessionToken rs = Application.Begin (top);
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
|
||
Assert.False (tv.WordWrap);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||
@"
|
||
This is the first line.
|
||
This is the second line.
|
||
",
|
||
_output
|
||
);
|
||
|
||
tv.CursorPosition = new (3, 0);
|
||
Assert.Equal (new (3, 0), tv.CursorPosition);
|
||
Assert.True (tv.NewKeyDownEvent (Key.Backspace));
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
Assert.Equal (new (2, 0), tv.CursorPosition);
|
||
|
||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||
@"
|
||
Ths is the first line.
|
||
This is the second line.
|
||
",
|
||
_output
|
||
);
|
||
|
||
tv.CursorPosition = new (0, 1);
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
Assert.True (tv.NewKeyDownEvent (Key.Backspace));
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
Assert.Equal (new (22, 0), tv.CursorPosition);
|
||
|
||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||
@"
|
||
Ths is the first line.This is the second line.
|
||
",
|
||
_output
|
||
);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Enter));
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
|
||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||
@"
|
||
Ths is the first line.
|
||
This is the second line.
|
||
",
|
||
_output
|
||
);
|
||
|
||
while (tv.Text != envText)
|
||
{
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
}
|
||
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
Assert.Equal (envText, tv.Text);
|
||
Assert.Equal (new (3, 0), tv.CursorPosition);
|
||
Assert.False (tv.IsDirty);
|
||
top.Dispose ();
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void DeleteTextBackwards_WordWrap_True_Return_Undo ()
|
||
{
|
||
const string text = "This is the first line.\nThis is the second line.\n";
|
||
var tv = new TextView { Width = Dim.Fill (), Height = Dim.Fill (), Text = text, WordWrap = true };
|
||
string envText = tv.Text;
|
||
var top = new Toplevel ();
|
||
top.Add (tv);
|
||
SessionToken rs = Application.Begin (top);
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
|
||
Assert.True (tv.WordWrap);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||
@"
|
||
This is the first line.
|
||
This is the second line.
|
||
",
|
||
_output
|
||
);
|
||
|
||
tv.CursorPosition = new (3, 0);
|
||
Assert.Equal (new (3, 0), tv.CursorPosition);
|
||
Assert.True (tv.NewKeyDownEvent (Key.Backspace));
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
Assert.Equal (new (2, 0), tv.CursorPosition);
|
||
|
||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||
@"
|
||
Ths is the first line.
|
||
This is the second line.
|
||
",
|
||
_output
|
||
);
|
||
|
||
tv.CursorPosition = new (0, 1);
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
Assert.True (tv.NewKeyDownEvent (Key.Backspace));
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
Assert.Equal (new (22, 0), tv.CursorPosition);
|
||
|
||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||
@"
|
||
Ths is the first line.This is the second line.
|
||
",
|
||
_output
|
||
);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Enter));
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
|
||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||
@"
|
||
Ths is the first line.
|
||
This is the second line.
|
||
",
|
||
_output
|
||
);
|
||
|
||
while (tv.Text != envText)
|
||
{
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
}
|
||
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
|
||
Assert.Equal (envText, tv.Text);
|
||
Assert.Equal (new (3, 0), tv.CursorPosition);
|
||
Assert.False (tv.IsDirty);
|
||
top.Dispose ();
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void DeleteTextForwards_WordWrap_False_Return_Undo ()
|
||
{
|
||
const string text = "This is the first line.\nThis is the second line.\n";
|
||
var tv = new TextView { Width = Dim.Fill (), Height = Dim.Fill (), Text = text };
|
||
string envText = tv.Text;
|
||
var top = new Toplevel ();
|
||
top.Add (tv);
|
||
SessionToken rs = Application.Begin (top);
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
|
||
Assert.False (tv.WordWrap);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||
@"
|
||
This is the first line.
|
||
This is the second line.
|
||
",
|
||
_output
|
||
);
|
||
|
||
tv.CursorPosition = new (2, 0);
|
||
Assert.Equal (new (2, 0), tv.CursorPosition);
|
||
Assert.True (tv.NewKeyDownEvent (Key.Delete));
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
Assert.Equal (new (2, 0), tv.CursorPosition);
|
||
|
||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||
@"
|
||
Ths is the first line.
|
||
This is the second line.
|
||
",
|
||
_output
|
||
);
|
||
|
||
tv.CursorPosition = new (22, 0);
|
||
Assert.Equal (new (22, 0), tv.CursorPosition);
|
||
Assert.True (tv.NewKeyDownEvent (Key.Delete));
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
Assert.Equal (new (22, 0), tv.CursorPosition);
|
||
|
||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||
@"
|
||
Ths is the first line.This is the second line.
|
||
",
|
||
_output
|
||
);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Enter));
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
|
||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||
@"
|
||
Ths is the first line.
|
||
This is the second line.
|
||
",
|
||
_output
|
||
);
|
||
|
||
while (tv.Text != envText)
|
||
{
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
}
|
||
|
||
Assert.Equal (envText, tv.Text);
|
||
Assert.Equal (new (2, 0), tv.CursorPosition);
|
||
Assert.False (tv.IsDirty);
|
||
top.Dispose ();
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void DeleteTextForwards_WordWrap_True_Return_Undo ()
|
||
{
|
||
const string text = "This is the first line.\nThis is the second line.\n";
|
||
var tv = new TextView { Width = Dim.Fill (), Height = Dim.Fill (), Text = text, WordWrap = true };
|
||
string envText = tv.Text;
|
||
var top = new Toplevel ();
|
||
top.Add (tv);
|
||
SessionToken rs = Application.Begin (top);
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
|
||
Assert.True (tv.WordWrap);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||
@"
|
||
This is the first line.
|
||
This is the second line.
|
||
",
|
||
_output
|
||
);
|
||
|
||
tv.CursorPosition = new (2, 0);
|
||
Assert.Equal (new (2, 0), tv.CursorPosition);
|
||
Assert.True (tv.NewKeyDownEvent (Key.Delete));
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
Assert.Equal (new (2, 0), tv.CursorPosition);
|
||
|
||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||
@"
|
||
Ths is the first line.
|
||
This is the second line.
|
||
",
|
||
_output
|
||
);
|
||
|
||
tv.CursorPosition = new (22, 0);
|
||
Assert.Equal (new (22, 0), tv.CursorPosition);
|
||
Assert.True (tv.NewKeyDownEvent (Key.Delete));
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
Assert.Equal (new (22, 0), tv.CursorPosition);
|
||
|
||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||
@"
|
||
Ths is the first line.This is the second line.
|
||
",
|
||
_output
|
||
);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Enter));
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
|
||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||
@"
|
||
Ths is the first line.
|
||
This is the second line.
|
||
",
|
||
_output
|
||
);
|
||
|
||
while (tv.Text != envText)
|
||
{
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
}
|
||
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
|
||
Assert.Equal (envText, tv.Text);
|
||
Assert.Equal (new (2, 0), tv.CursorPosition);
|
||
Assert.False (tv.IsDirty);
|
||
top.Dispose ();
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void DesiredCursorVisibility_Horizontal_Navigation ()
|
||
{
|
||
var text = "";
|
||
|
||
for (var i = 0; i < 12; i++)
|
||
{
|
||
text += $"{i.ToString () [^1]}";
|
||
}
|
||
|
||
var tv = new TextView { Width = 10, Height = 10 };
|
||
tv.Text = text;
|
||
var top = new Toplevel ();
|
||
top.Add (tv);
|
||
Application.Begin (top);
|
||
|
||
Assert.Equal (0, tv.LeftColumn);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Application.PositionCursor ();
|
||
Assert.Equal (CursorVisibility.Default, tv.CursorVisibility);
|
||
|
||
for (var i = 0; i < 12; i++)
|
||
{
|
||
tv.NewMouseEvent (new () { Flags = MouseFlags.WheeledRight });
|
||
Assert.Equal (Math.Min (i + 1, 11), tv.LeftColumn);
|
||
Application.PositionCursor ();
|
||
Application.Driver!.GetCursorVisibility (out CursorVisibility cursorVisibility);
|
||
Assert.Equal (CursorVisibility.Invisible, cursorVisibility);
|
||
}
|
||
|
||
for (var i = 11; i > 0; i--)
|
||
{
|
||
tv.NewMouseEvent (new () { Flags = MouseFlags.WheeledLeft });
|
||
Assert.Equal (i - 1, tv.LeftColumn);
|
||
|
||
Application.PositionCursor ();
|
||
Application.Driver!.GetCursorVisibility (out CursorVisibility cursorVisibility);
|
||
|
||
if (i - 1 == 0)
|
||
{
|
||
Assert.Equal (CursorVisibility.Default, cursorVisibility);
|
||
}
|
||
else
|
||
{
|
||
Assert.Equal (CursorVisibility.Invisible, cursorVisibility);
|
||
}
|
||
}
|
||
|
||
top.Dispose ();
|
||
Application.Shutdown ();
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void DesiredCursorVisibility_Vertical_Navigation ()
|
||
{
|
||
var text = "";
|
||
|
||
for (var i = 0; i < 12; i++)
|
||
{
|
||
text += $"This is the line {i}\n";
|
||
}
|
||
|
||
var tv = new TextView { Width = 10, Height = 10 };
|
||
tv.Text = text;
|
||
var top = new Toplevel ();
|
||
top.Add (tv);
|
||
Application.Begin (top);
|
||
|
||
Assert.Equal (0, tv.TopRow);
|
||
Application.PositionCursor ();
|
||
Assert.Equal (CursorVisibility.Default, tv.CursorVisibility);
|
||
|
||
for (var i = 0; i < 12; i++)
|
||
{
|
||
tv.NewMouseEvent (new () { Flags = MouseFlags.WheeledDown });
|
||
Application.PositionCursor ();
|
||
Assert.Equal (i + 1, tv.TopRow);
|
||
Application.Driver!.GetCursorVisibility (out CursorVisibility cursorVisibility);
|
||
Assert.Equal (CursorVisibility.Invisible, cursorVisibility);
|
||
}
|
||
|
||
for (var i = 12; i > 0; i--)
|
||
{
|
||
tv.NewMouseEvent (new () { Flags = MouseFlags.WheeledUp });
|
||
Application.PositionCursor ();
|
||
Assert.Equal (i - 1, tv.TopRow);
|
||
|
||
Application.PositionCursor ();
|
||
Application.Driver!.GetCursorVisibility (out CursorVisibility cursorVisibility);
|
||
|
||
if (i - 1 == 0)
|
||
{
|
||
Assert.Equal (CursorVisibility.Default, cursorVisibility);
|
||
}
|
||
else
|
||
{
|
||
Assert.Equal (CursorVisibility.Invisible, cursorVisibility);
|
||
}
|
||
}
|
||
|
||
top.Dispose ();
|
||
Application.Shutdown ();
|
||
}
|
||
|
||
[Fact]
|
||
[AutoInitShutdown ()]
|
||
public void HistoryText_Undo_Redo_Copy_Without_Selection_Multi_Line_Paste ()
|
||
{
|
||
var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
|
||
var tv = new TextView { App = ApplicationImpl.Instance, Text = text };
|
||
|
||
tv.CursorPosition = new (23, 0);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.C.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.Equal ("This is the first line.", Clipboard.Contents);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (23, 0), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (4, tv.Lines);
|
||
Assert.Equal (new (23, 1), tv.CursorPosition);
|
||
|
||
// Undo
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (23, 0), tv.CursorPosition);
|
||
|
||
// Redo
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (4, tv.Lines);
|
||
Assert.Equal (new (23, 1), tv.CursorPosition);
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void HistoryText_Undo_Redo_Cut_Multi_Line_Another_Selected_Paste ()
|
||
{
|
||
var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
|
||
var tv = new TextView
|
||
{
|
||
App = ApplicationImpl.Instance,
|
||
Text = text
|
||
};
|
||
|
||
tv.SelectionStartColumn = 12;
|
||
tv.CursorPosition = new (17, 0);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.W.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (12, 0), tv.CursorPosition);
|
||
|
||
tv.SelectionStartColumn = 12;
|
||
tv.SelectionStartRow = 1;
|
||
tv.CursorPosition = new (18, 1);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the line.{Environment.NewLine}This is the first line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (17, 1), tv.CursorPosition);
|
||
|
||
// Undo
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (12, 1), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (12, 0), tv.CursorPosition);
|
||
|
||
// Redo
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (12, 0), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the line.{Environment.NewLine}This is the first line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (17, 1), tv.CursorPosition);
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void HistoryText_Undo_Redo_Cut_Multi_Line_Selected_Paste ()
|
||
{
|
||
var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
|
||
var tv = new TextView
|
||
{
|
||
App = ApplicationImpl.Instance,
|
||
Text = text
|
||
};
|
||
|
||
tv.SelectionStartColumn = 12;
|
||
tv.CursorPosition = new (17, 0);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.W.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (12, 0), tv.CursorPosition);
|
||
|
||
tv.SelectionStartColumn = 12;
|
||
tv.CursorPosition = new (11, 1);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
|
||
Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (17, 0), tv.CursorPosition);
|
||
|
||
// Undo
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (12, 0), tv.CursorPosition);
|
||
|
||
// Redo
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (17, 0), tv.CursorPosition);
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void HistoryText_Undo_Redo_Cut_Simple_Paste_Starting ()
|
||
{
|
||
var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
|
||
var tv = new TextView
|
||
{
|
||
App = ApplicationImpl.Instance,
|
||
Text = text
|
||
};
|
||
|
||
tv.SelectionStartColumn = 12;
|
||
tv.CursorPosition = new (18, 1);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.W.WithCtrl));
|
||
Assert.Equal ($"This is the line.{Environment.NewLine}This is the third line.", tv.Text);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (12, 0), tv.CursorPosition);
|
||
|
||
tv.IsSelecting = false;
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (18, 1), tv.CursorPosition);
|
||
|
||
// Undo
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"This is the line.{Environment.NewLine}This is the third line.", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (12, 0), tv.CursorPosition);
|
||
|
||
// Redo
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (18, 1), tv.CursorPosition);
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void HistoryText_Undo_Redo_Empty_Copy_Without_Selection_Multi_Line_Selected_Paste ()
|
||
{
|
||
var text = "\nThis is the first line.\nThis is the second line.";
|
||
var tv = new TextView
|
||
{
|
||
App = ApplicationImpl.Instance,
|
||
Text = text
|
||
};
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.C.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"{Environment.NewLine}{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (4, tv.Lines);
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
|
||
// Undo
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
// Redo
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"{Environment.NewLine}{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (4, tv.Lines);
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void HistoryText_Undo_Redo_KillToEndOfLine ()
|
||
{
|
||
var text = "First line.\nSecond line.";
|
||
var tv = new TextView
|
||
{
|
||
App = ApplicationImpl.Instance,
|
||
Text = text
|
||
};
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.K.WithCtrl));
|
||
Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.Equal ("First line.", Clipboard.Contents);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.K.WithCtrl));
|
||
Assert.Equal ("Second line.", tv.Text);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.Equal ($"First line.{Environment.NewLine}", Clipboard.Contents);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.K.WithCtrl));
|
||
Assert.Equal ("", tv.Text);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.Equal ($"First line.{Environment.NewLine}Second line.", Clipboard.Contents);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
// Undo
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ("Second line.", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
// Redo
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ("Second line.", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ("", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void HistoryText_Undo_Redo_KillToLeftStart ()
|
||
{
|
||
var text = "First line.\nSecond line.";
|
||
var tv = new TextView
|
||
{
|
||
App = ApplicationImpl.Instance,
|
||
Text = text
|
||
};
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.End.WithCtrl));
|
||
Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (12, 1), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl.WithShift));
|
||
Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.Equal ("Second line.", Clipboard.Contents);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl.WithShift));
|
||
Assert.Equal ("First line.", tv.Text);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.Equal ($"Second line.{Environment.NewLine}", Clipboard.Contents);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (11, 0), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl.WithShift));
|
||
Assert.Equal ("", tv.Text);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.Equal ($"Second line.{Environment.NewLine}First line.", Clipboard.Contents);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
// Undo
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ("First line.", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (11, 0), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (12, 1), tv.CursorPosition);
|
||
|
||
// Redo
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ("First line.", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (11, 0), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ("", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void HistoryText_Undo_Redo_Multi_Line_DeleteCharLeft ()
|
||
{
|
||
var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
|
||
var tv = new TextView { Width = 10, Height = 2, Text = text };
|
||
Toplevel top = new ();
|
||
top.Add (tv);
|
||
Application.Begin (top);
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
var ntimes = 3;
|
||
tv.CursorPosition = new (7, 1);
|
||
|
||
for (var i = 0; i < ntimes; i++)
|
||
{
|
||
tv.DeleteCharLeft ();
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (4, 1), tv.CursorPosition);
|
||
|
||
tv.CursorPosition = new (7, 0);
|
||
|
||
for (var i = 0; i < ntimes; i++)
|
||
{
|
||
tv.DeleteCharLeft ();
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (4, 0), tv.CursorPosition);
|
||
|
||
tv.CursorPosition = new (7, 2);
|
||
|
||
for (var i = 0; i < ntimes; i++)
|
||
{
|
||
tv.DeleteCharLeft ();
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (4, 2), tv.CursorPosition);
|
||
|
||
for (var i = 0; i < ntimes; i++)
|
||
{
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
|
||
switch (i)
|
||
{
|
||
case 0:
|
||
Assert.Equal (
|
||
$"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (5, 2), tv.CursorPosition);
|
||
|
||
break;
|
||
case 1:
|
||
Assert.Equal (
|
||
$"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This i the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (6, 2), tv.CursorPosition);
|
||
|
||
break;
|
||
case 2:
|
||
Assert.Equal (
|
||
$"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (7, 2), tv.CursorPosition);
|
||
|
||
break;
|
||
}
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (7, 2), tv.CursorPosition);
|
||
|
||
for (var i = 0; i < ntimes; i++)
|
||
{
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
|
||
switch (i)
|
||
{
|
||
case 0:
|
||
Assert.Equal (
|
||
$"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (5, 0), tv.CursorPosition);
|
||
|
||
break;
|
||
case 1:
|
||
Assert.Equal (
|
||
$"This i the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (6, 0), tv.CursorPosition);
|
||
|
||
break;
|
||
case 2:
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (7, 0), tv.CursorPosition);
|
||
|
||
break;
|
||
}
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (7, 0), tv.CursorPosition);
|
||
|
||
for (var i = 0; i < ntimes; i++)
|
||
{
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
|
||
switch (i)
|
||
{
|
||
case 0:
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (5, 1), tv.CursorPosition);
|
||
|
||
break;
|
||
case 1:
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This i the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (6, 1), tv.CursorPosition);
|
||
|
||
break;
|
||
case 2:
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (7, 1), tv.CursorPosition);
|
||
|
||
break;
|
||
}
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (7, 1), tv.CursorPosition);
|
||
|
||
for (var i = 0; i < ntimes; i++)
|
||
{
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (4, 1), tv.CursorPosition);
|
||
|
||
for (var i = 0; i < ntimes; i++)
|
||
{
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (4, 0), tv.CursorPosition);
|
||
|
||
for (var i = 0; i < ntimes; i++)
|
||
{
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (4, 2), tv.CursorPosition);
|
||
top.Dispose ();
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void HistoryText_Undo_Redo_Multi_Line_DeleteCharRight ()
|
||
{
|
||
var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
|
||
var tv = new TextView { Width = 10, Height = 2, Text = text };
|
||
Toplevel top = new ();
|
||
top.Add (tv);
|
||
Application.Begin (top);
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
var ntimes = 3;
|
||
tv.CursorPosition = new (7, 1);
|
||
|
||
for (var i = 0; i < ntimes; i++)
|
||
{
|
||
tv.DeleteCharRight ();
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (7, 1), tv.CursorPosition);
|
||
|
||
tv.CursorPosition = new (7, 0);
|
||
|
||
for (var i = 0; i < ntimes; i++)
|
||
{
|
||
tv.DeleteCharRight ();
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (7, 0), tv.CursorPosition);
|
||
|
||
tv.CursorPosition = new (7, 2);
|
||
|
||
for (var i = 0; i < ntimes; i++)
|
||
{
|
||
tv.DeleteCharRight ();
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This ise third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (7, 2), tv.CursorPosition);
|
||
|
||
for (var i = 0; i < ntimes; i++)
|
||
{
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (7, 2), tv.CursorPosition);
|
||
|
||
for (var i = 0; i < ntimes; i++)
|
||
{
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (7, 0), tv.CursorPosition);
|
||
|
||
for (var i = 0; i < ntimes; i++)
|
||
{
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (7, 1), tv.CursorPosition);
|
||
|
||
for (var i = 0; i < ntimes; i++)
|
||
{
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (7, 1), tv.CursorPosition);
|
||
|
||
for (var i = 0; i < ntimes; i++)
|
||
{
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (7, 0), tv.CursorPosition);
|
||
|
||
for (var i = 0; i < ntimes; i++)
|
||
{
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This ise first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This ise third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (7, 2), tv.CursorPosition);
|
||
top.Dispose ();
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void HistoryText_Undo_Redo_Multi_Line_InsertText ()
|
||
{
|
||
var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
|
||
var tv = new TextView { Width = 10, Height = 2, Text = text };
|
||
Toplevel top = new ();
|
||
top.Add (tv);
|
||
Application.Begin (top);
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
var messy = " messy";
|
||
tv.CursorPosition = new (7, 1);
|
||
tv.InsertText (messy);
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (13, 1), tv.CursorPosition);
|
||
|
||
tv.CursorPosition = new (7, 0);
|
||
tv.InsertText (messy);
|
||
|
||
Assert.Equal (
|
||
$"This is messy the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (13, 0), tv.CursorPosition);
|
||
|
||
tv.CursorPosition = new (7, 2);
|
||
tv.InsertText (messy);
|
||
|
||
Assert.Equal (
|
||
$"This is messy the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is messy the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (13, 2), tv.CursorPosition);
|
||
|
||
for (var i = 0; i < messy.Length; i++)
|
||
{
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This is messy the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (7, 2), tv.CursorPosition);
|
||
|
||
for (var i = 0; i < messy.Length; i++)
|
||
{
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (7, 0), tv.CursorPosition);
|
||
|
||
for (var i = 0; i < messy.Length; i++)
|
||
{
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (7, 1), tv.CursorPosition);
|
||
|
||
for (var i = 0; i < messy.Length; i++)
|
||
{
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (13, 1), tv.CursorPosition);
|
||
|
||
for (var i = 0; i < messy.Length; i++)
|
||
{
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This is messy the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (13, 0), tv.CursorPosition);
|
||
|
||
for (var i = 0; i < messy.Length; i++)
|
||
{
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This is messy the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is messy the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (13, 2), tv.CursorPosition);
|
||
top.Dispose ();
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void HistoryText_Undo_Redo_Multi_Line_Selected_Copy_Simple_Paste_Starting_On_Letter ()
|
||
{
|
||
var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
|
||
var tv = new TextView
|
||
{
|
||
App = ApplicationImpl.Instance,
|
||
Text = text
|
||
};
|
||
|
||
tv.SelectionStartColumn = 12;
|
||
tv.CursorPosition = new (18, 1);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.C.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal ($"first line.{Environment.NewLine}This is the second", tv.SelectedText);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (18, 1), tv.CursorPosition);
|
||
|
||
tv.IsSelecting = false;
|
||
tv.CursorPosition = new (17, 1);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the seconfirst line.{Environment.NewLine}This is the secondd line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (4, tv.Lines);
|
||
Assert.Equal (new (18, 2), tv.CursorPosition);
|
||
|
||
// Undo
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (17, 1), tv.CursorPosition);
|
||
|
||
// Redo
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the seconfirst line.{Environment.NewLine}This is the secondd line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (4, tv.Lines);
|
||
Assert.Equal (new (18, 2), tv.CursorPosition);
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void HistoryText_Undo_Redo_Multi_Line_Selected_Copy_Simple_Paste_Starting_On_Space ()
|
||
{
|
||
var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
|
||
var tv = new TextView
|
||
{
|
||
App = ApplicationImpl.Instance,
|
||
Text = text
|
||
};
|
||
|
||
tv.SelectionStartColumn = 12;
|
||
tv.CursorPosition = new (18, 1);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.C.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal ($"first line.{Environment.NewLine}This is the second", tv.SelectedText);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (18, 1), tv.CursorPosition);
|
||
|
||
tv.IsSelecting = false;
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the secondfirst line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (4, tv.Lines);
|
||
Assert.Equal (new (18, 2), tv.CursorPosition);
|
||
|
||
// Undo
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (18, 1), tv.CursorPosition);
|
||
|
||
// Redo
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the secondfirst line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (4, tv.Lines);
|
||
Assert.Equal (new (18, 2), tv.CursorPosition);
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText ()
|
||
{
|
||
var text =
|
||
$"This is the first line.{Environment.NewLine}This is the second line.\nThis is the third line.";
|
||
var tv = new TextView { Width = 10, Height = 2, Text = text };
|
||
Toplevel top = new ();
|
||
top.Add (tv);
|
||
Application.Begin (top);
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
var messy = " messy";
|
||
tv.CursorPosition = new (7, 0);
|
||
tv.SelectionStartColumn = 11;
|
||
tv.SelectionStartRow = 2;
|
||
Assert.Equal (51 + Environment.NewLine.Length * 2, tv.SelectedLength);
|
||
|
||
for (var i = 0; i < messy.Length; i++)
|
||
{
|
||
tv.InsertText (messy [i].ToString ());
|
||
|
||
switch (i)
|
||
{
|
||
case 0:
|
||
Assert.Equal ("This is third line.", tv.Text);
|
||
Assert.Equal (new (8, 0), tv.CursorPosition);
|
||
|
||
break;
|
||
case 1:
|
||
Assert.Equal ("This is m third line.", tv.Text);
|
||
Assert.Equal (new (9, 0), tv.CursorPosition);
|
||
|
||
break;
|
||
case 2:
|
||
Assert.Equal ("This is me third line.", tv.Text);
|
||
Assert.Equal (new (10, 0), tv.CursorPosition);
|
||
|
||
break;
|
||
case 3:
|
||
Assert.Equal ("This is mes third line.", tv.Text);
|
||
Assert.Equal (new (11, 0), tv.CursorPosition);
|
||
|
||
break;
|
||
case 4:
|
||
Assert.Equal ("This is mess third line.", tv.Text);
|
||
Assert.Equal (new (12, 0), tv.CursorPosition);
|
||
|
||
break;
|
||
case 5:
|
||
Assert.Equal ("This is messy third line.", tv.Text);
|
||
Assert.Equal (new (13, 0), tv.CursorPosition);
|
||
|
||
break;
|
||
}
|
||
}
|
||
|
||
Assert.Equal ("This is messy third line.", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (13, 0), tv.CursorPosition);
|
||
Assert.Equal (11, tv.SelectionStartColumn);
|
||
Assert.Equal (2, tv.SelectionStartRow);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
|
||
for (var i = 0; i < messy.Length; i++)
|
||
{
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
|
||
switch (i)
|
||
{
|
||
case 0:
|
||
Assert.Equal ("This is mess third line.", tv.Text);
|
||
Assert.Equal (new (12, 0), tv.CursorPosition);
|
||
|
||
break;
|
||
case 1:
|
||
Assert.Equal ("This is mes third line.", tv.Text);
|
||
Assert.Equal (new (11, 0), tv.CursorPosition);
|
||
|
||
break;
|
||
case 2:
|
||
Assert.Equal ("This is me third line.", tv.Text);
|
||
Assert.Equal (new (10, 0), tv.CursorPosition);
|
||
|
||
break;
|
||
case 3:
|
||
Assert.Equal ("This is m third line.", tv.Text);
|
||
Assert.Equal (new (9, 0), tv.CursorPosition);
|
||
|
||
break;
|
||
case 4:
|
||
Assert.Equal ("This is third line.", tv.Text);
|
||
Assert.Equal (new (8, 0), tv.CursorPosition);
|
||
|
||
break;
|
||
case 5:
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (7, 0), tv.CursorPosition);
|
||
|
||
break;
|
||
}
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (7, 0), tv.CursorPosition);
|
||
Assert.Equal (11, tv.SelectionStartColumn);
|
||
Assert.Equal (2, tv.SelectionStartRow);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
|
||
for (var i = 0; i < messy.Length; i++)
|
||
{
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
|
||
switch (i)
|
||
{
|
||
case 0:
|
||
Assert.Equal ("This is third line.", tv.Text);
|
||
Assert.Equal (new (8, 0), tv.CursorPosition);
|
||
|
||
break;
|
||
case 1:
|
||
Assert.Equal ("This is m third line.", tv.Text);
|
||
Assert.Equal (new (9, 0), tv.CursorPosition);
|
||
|
||
break;
|
||
case 2:
|
||
Assert.Equal ("This is me third line.", tv.Text);
|
||
Assert.Equal (new (10, 0), tv.CursorPosition);
|
||
|
||
break;
|
||
case 3:
|
||
Assert.Equal ("This is mes third line.", tv.Text);
|
||
Assert.Equal (new (11, 0), tv.CursorPosition);
|
||
|
||
break;
|
||
case 4:
|
||
Assert.Equal ("This is mess third line.", tv.Text);
|
||
Assert.Equal (new (12, 0), tv.CursorPosition);
|
||
|
||
break;
|
||
case 5:
|
||
Assert.Equal ("This is messy third line.", tv.Text);
|
||
Assert.Equal (new (13, 0), tv.CursorPosition);
|
||
|
||
break;
|
||
}
|
||
}
|
||
|
||
Assert.Equal ("This is messy third line.", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (13, 0), tv.CursorPosition);
|
||
Assert.Equal (11, tv.SelectionStartColumn);
|
||
Assert.Equal (2, tv.SelectionStartRow);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
top.Dispose ();
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText_Twice_On_Same_Line ()
|
||
{
|
||
var text = "One\nTwo\nThree";
|
||
var tv = new TextView { Width = 10, Height = 2, Text = text };
|
||
Toplevel top = new ();
|
||
top.Add (tv);
|
||
Application.Begin (top);
|
||
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.False (tv.IsDirty);
|
||
|
||
tv.SelectionStartColumn = 0;
|
||
tv.SelectionStartRow = 0;
|
||
tv.CursorPosition = new (0, 1);
|
||
Assert.Equal (3 + Environment.NewLine.Length, tv.SelectedLength);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.D1));
|
||
Assert.Equal ($"1Two{Environment.NewLine}Three", tv.Text);
|
||
Assert.Equal (new (1, 0), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
tv.SelectionStartColumn = 1;
|
||
tv.SelectionStartRow = 0;
|
||
tv.CursorPosition = new (1, 1);
|
||
Assert.Equal (4 + Environment.NewLine.Length, tv.SelectedLength);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.D2));
|
||
Assert.Equal ("12hree", tv.Text);
|
||
Assert.Equal (new (2, 0), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"1Two{Environment.NewLine}Three", tv.Text);
|
||
Assert.Equal (new (1, 1), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.False (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"1Two{Environment.NewLine}Three", tv.Text);
|
||
Assert.Equal (new (1, 0), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ("12hree", tv.Text);
|
||
Assert.Equal (new (2, 0), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
top.Dispose ();
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void HistoryText_Undo_Redo_Multi_Line_Selected_InsertText_Twice_On_Same_Line_With_End_Line ()
|
||
{
|
||
var text = "One\nTwo\nThree\n";
|
||
var tv = new TextView { Width = 10, Height = 2, Text = text };
|
||
Toplevel top = new ();
|
||
top.Add (tv);
|
||
Application.Begin (top);
|
||
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (4, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.False (tv.IsDirty);
|
||
|
||
tv.SelectionStartColumn = 0;
|
||
tv.SelectionStartRow = 0;
|
||
tv.CursorPosition = new (0, 1);
|
||
Assert.Equal (3 + Environment.NewLine.Length, tv.SelectedLength);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.D1));
|
||
Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (new (1, 0), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
tv.SelectionStartColumn = 1;
|
||
tv.SelectionStartRow = 0;
|
||
tv.CursorPosition = new (1, 1);
|
||
Assert.Equal (4 + Environment.NewLine.Length, tv.SelectedLength);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.D2));
|
||
Assert.Equal ($"12hree{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (new (2, 0), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (new (1, 1), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (4, tv.Lines);
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.False (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (new (1, 0), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"12hree{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (new (2, 0), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
top.Dispose ();
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void HistoryText_Undo_Redo_Multi_Line_Selected_With_Empty_Text ()
|
||
{
|
||
var tv = new TextView { Width = 10, Height = 2 };
|
||
Toplevel top = new ();
|
||
top.Add (tv);
|
||
Application.Begin (top);
|
||
|
||
Assert.Equal ("", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.False (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.O.WithShift));
|
||
Assert.Equal ("O", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (1, 0), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.N));
|
||
Assert.Equal ("On", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (2, 0), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.E));
|
||
Assert.Equal ("One", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (3, 0), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Enter));
|
||
Assert.Equal ($"One{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.T.WithShift));
|
||
Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (1, 1), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.W));
|
||
Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (2, 1), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.O));
|
||
Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (3, 1), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Enter));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (0, 2), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.T.WithShift));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (1, 2), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.H));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (2, 2), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (3, 2), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.E));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (4, 2), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.E));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (5, 2), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Enter));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (4, tv.Lines);
|
||
Assert.Equal (new (0, 3), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
tv.SelectionStartColumn = 0;
|
||
tv.SelectionStartRow = 0;
|
||
tv.CursorPosition = new (0, 1);
|
||
Assert.Equal (3 + Environment.NewLine.Length, tv.SelectedLength);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.D1));
|
||
Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (1, 0), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
tv.SelectionStartColumn = 1;
|
||
tv.SelectionStartRow = 0;
|
||
tv.CursorPosition = new (1, 1);
|
||
Assert.Equal (4 + Environment.NewLine.Length, tv.SelectedLength);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.D2));
|
||
Assert.Equal ($"12hree{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (2, 0), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
// Undoing
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (1, 1), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (4, tv.Lines);
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (5, 2), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (4, 2), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (3, 2), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (2, 2), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (1, 2), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (0, 2), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (3, 1), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (2, 1), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (1, 1), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ("One", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (3, 0), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ("On", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (2, 0), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ("O", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (1, 0), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ("", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.False (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ("", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.False (tv.IsDirty);
|
||
|
||
// Redoing
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ("O", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (1, 0), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ("On", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (2, 0), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ("One", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (3, 0), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (1, 1), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (2, 1), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (3, 1), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (0, 2), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (1, 2), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (2, 2), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (3, 2), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (4, 2), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (5, 2), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (4, tv.Lines);
|
||
Assert.Equal (new (0, 3), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (1, 0), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"12hree{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (2, 0), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
top.Dispose ();
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void HistoryText_Undo_Redo_Multi_Line_With_Empty_Text ()
|
||
{
|
||
var tv = new TextView { Width = 10, Height = 2 };
|
||
Toplevel top = new ();
|
||
top.Add (tv);
|
||
Application.Begin (top);
|
||
|
||
Assert.Equal ("", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.False (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.O.WithShift));
|
||
Assert.Equal ("O", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (1, 0), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.N));
|
||
Assert.Equal ("On", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (2, 0), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.E));
|
||
Assert.Equal ("One", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (3, 0), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Enter));
|
||
Assert.Equal ($"One{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.T.WithShift));
|
||
Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (1, 1), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.W));
|
||
Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (2, 1), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.O));
|
||
Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (3, 1), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Enter));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (0, 2), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.T.WithShift));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (1, 2), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.H));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (2, 2), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (3, 2), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.E));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (4, 2), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.E));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (5, 2), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Enter));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (4, tv.Lines);
|
||
Assert.Equal (new (0, 3), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
// Undoing
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (5, 2), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (4, 2), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (3, 2), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (2, 2), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (1, 2), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (0, 2), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (3, 1), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (2, 1), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (1, 1), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ("One", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (3, 0), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ("On", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (2, 0), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ("O", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (1, 0), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ("", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.False (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ("", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.False (tv.IsDirty);
|
||
|
||
// Redoing
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ("O", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (1, 0), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ("On", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (2, 0), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ("One", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (3, 0), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}T", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (1, 1), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (2, 1), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Two", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (3, 1), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (0, 2), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (1, 2), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (2, 2), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (3, 2), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (4, 2), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (5, 2), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (4, tv.Lines);
|
||
Assert.Equal (new (0, 3), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (4, tv.Lines);
|
||
Assert.Equal (new (0, 3), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
top.Dispose ();
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void HistoryText_Undo_Redo_Setting_Clipboard_Multi_Line_Selected_Paste ()
|
||
{
|
||
var text = "This is the first line.\nThis is the second line.";
|
||
var tv = new TextView
|
||
{
|
||
App = ApplicationImpl.Instance,
|
||
Text = text
|
||
};
|
||
|
||
Clipboard.Contents = "Inserted\nNewLine";
|
||
|
||
Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"Inserted{Environment.NewLine}NewLineThis is the first line.{Environment.NewLine}This is the second line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (7, 1), tv.CursorPosition);
|
||
|
||
// Undo
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
// Redo
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"Inserted{Environment.NewLine}NewLineThis is the first line.{Environment.NewLine}This is the second line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (7, 1), tv.CursorPosition);
|
||
}
|
||
|
||
[Fact]
|
||
[AutoInitShutdown ()]
|
||
public void HistoryText_Undo_Redo_Simple_Copy_Multi_Line_Selected_Paste ()
|
||
{
|
||
var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
|
||
var tv = new TextView
|
||
{
|
||
App = ApplicationImpl.Instance,
|
||
Text = text
|
||
};
|
||
|
||
tv.SelectionStartColumn = 12;
|
||
tv.CursorPosition = new (17, 0);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.C.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal ("first", tv.SelectedText);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (17, 0), tv.CursorPosition);
|
||
|
||
tv.SelectionStartColumn = 12;
|
||
tv.CursorPosition = new (11, 1);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
|
||
Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (17, 0), tv.CursorPosition);
|
||
|
||
// Undo
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (12, 0), tv.CursorPosition);
|
||
|
||
// Redo
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (17, 0), tv.CursorPosition);
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void HistoryText_Undo_Redo_Single_Line_DeleteCharLeft ()
|
||
{
|
||
var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
|
||
var tv = new TextView { Width = 10, Height = 2, Text = text };
|
||
Toplevel top = new ();
|
||
top.Add (tv);
|
||
Application.Begin (top);
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
var ntimes = 3;
|
||
tv.CursorPosition = new (7, 1);
|
||
|
||
for (var i = 0; i < ntimes; i++)
|
||
{
|
||
tv.DeleteCharLeft ();
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (4, 1), tv.CursorPosition);
|
||
|
||
for (var i = 0; i < ntimes; i++)
|
||
{
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (7, 1), tv.CursorPosition);
|
||
|
||
for (var i = 0; i < ntimes; i++)
|
||
{
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (4, 1), tv.CursorPosition);
|
||
top.Dispose ();
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void HistoryText_Undo_Redo_Single_Line_DeleteCharRight ()
|
||
{
|
||
var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
|
||
var tv = new TextView { Width = 10, Height = 2, Text = text };
|
||
Toplevel top = new ();
|
||
top.Add (tv);
|
||
Application.Begin (top);
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
var ntimes = 3;
|
||
tv.CursorPosition = new (7, 1);
|
||
|
||
for (var i = 0; i < ntimes; i++)
|
||
{
|
||
tv.DeleteCharRight ();
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (7, 1), tv.CursorPosition);
|
||
|
||
for (var i = 0; i < ntimes; i++)
|
||
{
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (7, 1), tv.CursorPosition);
|
||
|
||
for (var i = 0; i < ntimes; i++)
|
||
{
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This ise second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (7, 1), tv.CursorPosition);
|
||
top.Dispose ();
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void HistoryText_Undo_Redo_Single_Line_InsertText ()
|
||
{
|
||
var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
|
||
var tv = new TextView { Width = 10, Height = 2, Text = text };
|
||
Toplevel top = new ();
|
||
top.Add (tv);
|
||
Application.Begin (top);
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
var messy = " messy";
|
||
tv.CursorPosition = new (7, 1);
|
||
tv.InsertText (messy);
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (13, 1), tv.CursorPosition);
|
||
|
||
for (var i = 0; i < messy.Length; i++)
|
||
{
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (7, 1), tv.CursorPosition);
|
||
|
||
for (var i = 0; i < messy.Length; i++)
|
||
{
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is messy the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (13, 1), tv.CursorPosition);
|
||
top.Dispose ();
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void HistoryText_Undo_Redo_Single_Line_Selected_DeleteCharLeft ()
|
||
{
|
||
var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
|
||
var tv = new TextView { Width = 10, Height = 2, Text = text };
|
||
Toplevel top = new ();
|
||
top.Add (tv);
|
||
Application.Begin (top);
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
var ntimes = 3;
|
||
tv.CursorPosition = new (7, 1);
|
||
tv.SelectionStartColumn = 11;
|
||
tv.SelectionStartRow = 1;
|
||
Assert.Equal (4, tv.SelectedLength);
|
||
|
||
for (var i = 0; i < ntimes; i++)
|
||
{
|
||
tv.DeleteCharLeft ();
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (5, 1), tv.CursorPosition);
|
||
Assert.Equal (11, tv.SelectionStartColumn);
|
||
Assert.Equal (1, tv.SelectionStartRow);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
|
||
for (var i = 0; i < ntimes; i++)
|
||
{
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (7, 1), tv.CursorPosition);
|
||
Assert.Equal (11, tv.SelectionStartColumn);
|
||
Assert.Equal (1, tv.SelectionStartRow);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
|
||
for (var i = 0; i < ntimes; i++)
|
||
{
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (5, 1), tv.CursorPosition);
|
||
Assert.Equal (11, tv.SelectionStartColumn);
|
||
Assert.Equal (1, tv.SelectionStartRow);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
top.Dispose ();
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void HistoryText_Undo_Redo_Single_Line_Selected_DeleteCharRight ()
|
||
{
|
||
var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
|
||
var tv = new TextView { Width = 10, Height = 2, Text = text };
|
||
Toplevel top = new ();
|
||
top.Add (tv);
|
||
Application.Begin (top);
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
var ntimes = 3;
|
||
tv.CursorPosition = new (7, 1);
|
||
tv.SelectionStartColumn = 11;
|
||
tv.SelectionStartRow = 1;
|
||
Assert.Equal (4, tv.SelectedLength);
|
||
|
||
for (var i = 0; i < ntimes; i++)
|
||
{
|
||
tv.DeleteCharRight ();
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This isecond line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (7, 1), tv.CursorPosition);
|
||
Assert.Equal (11, tv.SelectionStartColumn);
|
||
Assert.Equal (1, tv.SelectionStartRow);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
|
||
for (var i = 0; i < ntimes; i++)
|
||
{
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (7, 1), tv.CursorPosition);
|
||
Assert.Equal (11, tv.SelectionStartColumn);
|
||
Assert.Equal (1, tv.SelectionStartRow);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
|
||
for (var i = 0; i < ntimes; i++)
|
||
{
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This isecond line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (7, 1), tv.CursorPosition);
|
||
Assert.Equal (11, tv.SelectionStartColumn);
|
||
Assert.Equal (1, tv.SelectionStartRow);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
top.Dispose ();
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void HistoryText_Undo_Redo_Single_Line_Selected_InsertText ()
|
||
{
|
||
var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
|
||
var tv = new TextView { Width = 10, Height = 2, Text = text };
|
||
Toplevel top = new ();
|
||
top.Add (tv);
|
||
Application.Begin (top);
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
var messy = " messy";
|
||
tv.CursorPosition = new (7, 1);
|
||
tv.SelectionStartColumn = 11;
|
||
tv.SelectionStartRow = 1;
|
||
Assert.Equal (4, tv.SelectedLength);
|
||
tv.InsertText (messy);
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is messy second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (13, 1), tv.CursorPosition);
|
||
Assert.Equal (11, tv.SelectionStartColumn);
|
||
Assert.Equal (1, tv.SelectionStartRow);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
|
||
for (var i = 0; i < messy.Length; i++)
|
||
{
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (7, 1), tv.CursorPosition);
|
||
Assert.Equal (11, tv.SelectionStartColumn);
|
||
Assert.Equal (1, tv.SelectionStartRow);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
|
||
for (var i = 0; i < messy.Length; i++)
|
||
{
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
}
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is messy second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (13, 1), tv.CursorPosition);
|
||
Assert.Equal (11, tv.SelectionStartColumn);
|
||
Assert.Equal (1, tv.SelectionStartRow);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
top.Dispose ();
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void KeyBindings_Command ()
|
||
{
|
||
var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
|
||
var tv = new TextView { Width = 10, Height = 2, Text = text };
|
||
Toplevel top = new ();
|
||
top.Add (tv);
|
||
Application.Begin (top);
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.False (tv.ReadOnly);
|
||
Assert.True (tv.CanFocus);
|
||
Assert.False (tv.IsSelecting);
|
||
|
||
var g = (SingleWordSuggestionGenerator)tv.Autocomplete.SuggestionGenerator;
|
||
|
||
tv.CanFocus = false;
|
||
Assert.True (tv.NewKeyDownEvent (Key.CursorLeft));
|
||
Assert.False (tv.IsSelecting);
|
||
tv.CanFocus = true;
|
||
Assert.False (tv.NewKeyDownEvent (Key.CursorLeft));
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.CursorRight));
|
||
Assert.Equal (new (1, 0), tv.CursorPosition);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.End.WithCtrl));
|
||
Assert.Equal (2, tv.CurrentRow);
|
||
Assert.Equal (23, tv.CurrentColumn);
|
||
Assert.Equal (tv.CurrentColumn, tv.GetCurrentLine ().Count);
|
||
Assert.Equal (new (23, 2), tv.CursorPosition);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.False (tv.NewKeyDownEvent (Key.CursorRight));
|
||
Assert.NotNull (tv.Autocomplete);
|
||
Assert.Empty (g.AllSuggestions);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.F.WithShift));
|
||
tv.Draw ();
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (24, 2), tv.CursorPosition);
|
||
Assert.Empty (tv.Autocomplete.Suggestions);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
tv.Draw ();
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (23, 2), tv.CursorPosition);
|
||
Assert.Empty (tv.Autocomplete.Suggestions);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
tv.Draw ();
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (24, 2), tv.CursorPosition);
|
||
Assert.Empty (tv.Autocomplete.Suggestions);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.Backspace));
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (23, 2), tv.CursorPosition);
|
||
|
||
g.AllSuggestions = Regex.Matches (tv.Text, "\\w+")
|
||
.Select (s => s.Value)
|
||
.Distinct ()
|
||
.ToList ();
|
||
Assert.Equal (7, g.AllSuggestions.Count);
|
||
Assert.Equal ("This", g.AllSuggestions [0]);
|
||
Assert.Equal ("is", g.AllSuggestions [1]);
|
||
Assert.Equal ("the", g.AllSuggestions [2]);
|
||
Assert.Equal ("first", g.AllSuggestions [3]);
|
||
Assert.Equal ("line", g.AllSuggestions [4]);
|
||
Assert.Equal ("second", g.AllSuggestions [5]);
|
||
Assert.Equal ("third", g.AllSuggestions [^1]);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.F.WithShift));
|
||
tv.Draw ();
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (24, 2), tv.CursorPosition);
|
||
Assert.Single (tv.Autocomplete.Suggestions);
|
||
Assert.Equal ("first", tv.Autocomplete.Suggestions [0].Replacement);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.Enter));
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (28, 2), tv.CursorPosition);
|
||
Assert.Empty (tv.Autocomplete.Suggestions);
|
||
Assert.False (tv.Autocomplete.Visible);
|
||
g.AllSuggestions = new ();
|
||
tv.Autocomplete.ClearSuggestions ();
|
||
Assert.Empty (g.AllSuggestions);
|
||
Assert.Empty (tv.Autocomplete.Suggestions);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.PageUp));
|
||
Assert.Equal (24, tv.GetCurrentLine ().Count);
|
||
Assert.Equal (new (24, 1), tv.CursorPosition);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (new (Key.PageUp)));
|
||
Assert.Equal (23, tv.GetCurrentLine ().Count);
|
||
Assert.Equal (new (23, 0), tv.CursorPosition);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.PageDown));
|
||
Assert.Equal (24, tv.GetCurrentLine ().Count);
|
||
Assert.Equal (new (23, 1), tv.CursorPosition); // gets the previous length
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.V.WithCtrl));
|
||
Assert.Equal (28, tv.GetCurrentLine ().Count);
|
||
Assert.Equal (new (23, 2), tv.CursorPosition); // gets the previous length
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.PageUp.WithShift));
|
||
Assert.Equal (24, tv.GetCurrentLine ().Count);
|
||
Assert.Equal (new (23, 1), tv.CursorPosition); // gets the previous length
|
||
Assert.Equal (24 + Environment.NewLine.Length, tv.SelectedLength);
|
||
Assert.Equal ($".{Environment.NewLine}This is the third line.", tv.SelectedText);
|
||
Assert.True (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.PageDown.WithShift));
|
||
Assert.Equal (28, tv.GetCurrentLine ().Count);
|
||
Assert.Equal (new (23, 2), tv.CursorPosition); // gets the previous length
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.True (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.Home.WithCtrl));
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.N.WithCtrl));
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.P.WithCtrl));
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.CursorDown));
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.CursorUp));
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.CursorDown.WithShift));
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
Assert.Equal (23 + Environment.NewLine.Length, tv.SelectedLength);
|
||
Assert.Equal ($"This is the first line.{Environment.NewLine}", tv.SelectedText);
|
||
Assert.True (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.CursorUp.WithShift));
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.True (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.F.WithCtrl));
|
||
Assert.Equal (new (1, 0), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.B.WithCtrl));
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.CursorRight));
|
||
Assert.Equal (new (1, 0), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.CursorLeft));
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.CursorRight.WithShift));
|
||
Assert.Equal (new (1, 0), tv.CursorPosition);
|
||
Assert.Equal (1, tv.SelectedLength);
|
||
Assert.Equal ("T", tv.SelectedText);
|
||
Assert.True (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.CursorLeft.WithShift));
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.True (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.Delete));
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.Delete));
|
||
|
||
Assert.Equal (
|
||
$"his is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.D.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"is is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.True (tv.NewKeyDownEvent (Key.End));
|
||
|
||
Assert.Equal (
|
||
$"is is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (21, 0), tv.CursorPosition);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.Backspace));
|
||
|
||
Assert.Equal (
|
||
$"is is the first line{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (20, 0), tv.CursorPosition);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.Backspace));
|
||
|
||
Assert.Equal (
|
||
$"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (19, 0), tv.CursorPosition);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.Home));
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.End.WithShift));
|
||
Assert.Equal (new (19, 0), tv.CursorPosition);
|
||
Assert.Equal (19, tv.SelectedLength);
|
||
Assert.Equal ("is is the first lin", tv.SelectedText);
|
||
Assert.True (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.Home.WithShift));
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.True (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.E.WithCtrl));
|
||
Assert.Equal (new (19, 0), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.Home));
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.K.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.Equal ("is is the first lin", Clipboard.Contents);
|
||
Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (19, 0), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.Equal ("is is the first lin", Clipboard.Contents);
|
||
tv.CursorPosition = Point.Empty;
|
||
Assert.True (tv.NewKeyDownEvent (Key.Delete.WithCtrl.WithShift));
|
||
|
||
Assert.Equal (
|
||
$"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.Equal ("is is the first lin", Clipboard.Contents);
|
||
Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (19, 0), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.Equal ("is is the first lin", Clipboard.Contents);
|
||
Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl.WithShift));
|
||
|
||
Assert.Equal (
|
||
$"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
tv.ReadOnly = true;
|
||
Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
tv.ReadOnly = false;
|
||
Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (19, 0), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.Equal (0, tv.SelectionStartColumn);
|
||
Assert.Equal (0, tv.SelectionStartRow);
|
||
Assert.True (tv.NewKeyDownEvent (Key.Space.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (19, 0), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.True (tv.IsSelecting);
|
||
Assert.Equal (19, tv.SelectionStartColumn);
|
||
Assert.Equal (0, tv.SelectionStartRow);
|
||
Assert.True (tv.NewKeyDownEvent (Key.Space.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (19, 0), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.Equal (19, tv.SelectionStartColumn);
|
||
Assert.Equal (0, tv.SelectionStartRow);
|
||
tv.SelectionStartColumn = 0;
|
||
Assert.True (tv.NewKeyDownEvent (Key.C.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (19, 0), tv.CursorPosition);
|
||
Assert.Equal (19, tv.SelectedLength);
|
||
Assert.Equal ("is is the first lin", tv.SelectedText);
|
||
Assert.True (tv.IsSelecting);
|
||
Assert.Equal (0, tv.SelectionStartColumn);
|
||
Assert.Equal (0, tv.SelectionStartRow);
|
||
Assert.True (tv.NewKeyDownEvent (Key.C.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (19, 0), tv.CursorPosition);
|
||
Assert.Equal (19, tv.SelectedLength);
|
||
Assert.Equal ("is is the first lin", tv.SelectedText);
|
||
Assert.True (tv.IsSelecting);
|
||
Assert.Equal (0, tv.SelectionStartColumn);
|
||
Assert.Equal (0, tv.SelectionStartRow);
|
||
Assert.True (tv.NewKeyDownEvent (Key.X.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.Equal (0, tv.SelectionStartColumn);
|
||
Assert.Equal (0, tv.SelectionStartRow);
|
||
Assert.Equal ("is is the first lin", Clipboard.Contents);
|
||
Assert.True (tv.NewKeyDownEvent (Key.W.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.Equal (0, tv.SelectionStartColumn);
|
||
Assert.Equal (0, tv.SelectionStartRow);
|
||
Assert.Equal ("", Clipboard.Contents);
|
||
Assert.True (tv.NewKeyDownEvent (Key.X.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.Equal (0, tv.SelectionStartColumn);
|
||
Assert.Equal (0, tv.SelectionStartRow);
|
||
Assert.Equal ("", Clipboard.Contents);
|
||
Assert.True (tv.NewKeyDownEvent (Key.End.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (28, 2), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.CursorLeft.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (23, 2), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.CursorLeft.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (22, 2), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.CursorLeft.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (18, 2), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.CursorLeft.WithShift.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (12, 2), tv.CursorPosition);
|
||
Assert.Equal (6, tv.SelectedLength);
|
||
Assert.Equal ("third ", tv.SelectedText);
|
||
Assert.True (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.CursorLeft.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (8, 2), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.CursorRight.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (12, 2), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.CursorRight.WithShift.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (18, 2), tv.CursorPosition);
|
||
Assert.Equal (6, tv.SelectedLength);
|
||
Assert.Equal ("third ", tv.SelectedText);
|
||
Assert.True (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.CursorRight.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (22, 2), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.CursorRight.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (23, 2), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.CursorRight.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (28, 2), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.Home.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.Delete.WithCtrl));
|
||
Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.End.WithCtrl));
|
||
Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third line.first", tv.Text);
|
||
Assert.Equal (new (28, 1), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl));
|
||
Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third line.", tv.Text);
|
||
Assert.Equal (new (23, 1), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl));
|
||
Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third line", tv.Text);
|
||
Assert.Equal (new (22, 1), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl));
|
||
Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.Text);
|
||
Assert.Equal (new (18, 1), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.AllowsReturn);
|
||
|
||
tv.AllowsReturn = false;
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.False (tv.NewKeyDownEvent (Key.Enter)); // Accepted event not handled
|
||
Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.Text);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.False (tv.AllowsReturn);
|
||
|
||
tv.AllowsReturn = true;
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.True (tv.NewKeyDownEvent (Key.Enter));
|
||
|
||
Assert.Equal (
|
||
$"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.AllowsReturn);
|
||
Assert.True (tv.NewKeyDownEvent (Key.End.WithShift.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (18, 2), tv.CursorPosition);
|
||
Assert.Equal (42 + Environment.NewLine.Length, tv.SelectedLength);
|
||
Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.SelectedText);
|
||
Assert.True (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.Home.WithShift.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.Equal (Environment.NewLine.Length, tv.SelectedLength);
|
||
Assert.Equal ($"{Environment.NewLine}", tv.SelectedText);
|
||
Assert.True (tv.IsSelecting);
|
||
Assert.True (tv.NewKeyDownEvent (Key.A.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (new (18, 2), tv.CursorPosition);
|
||
Assert.Equal (42 + Environment.NewLine.Length * 2, tv.SelectedLength);
|
||
|
||
Assert.Equal (
|
||
$"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ",
|
||
tv.SelectedText
|
||
);
|
||
Assert.True (tv.IsSelecting);
|
||
Assert.True (tv.Used);
|
||
Assert.True (tv.NewKeyDownEvent (Key.InsertChar));
|
||
Assert.False (tv.Used);
|
||
Assert.True (tv.AllowsTab);
|
||
Assert.Equal (new (18, 2), tv.CursorPosition);
|
||
Assert.True (tv.IsSelecting);
|
||
tv.AllowsTab = false;
|
||
Assert.False (tv.NewKeyDownEvent (Key.Tab));
|
||
|
||
Assert.Equal (
|
||
$"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ",
|
||
tv.Text
|
||
);
|
||
Assert.False (tv.AllowsTab);
|
||
tv.AllowsTab = true;
|
||
Assert.Equal (new (18, 2), tv.CursorPosition);
|
||
Assert.True (tv.IsSelecting);
|
||
tv.IsSelecting = false;
|
||
Assert.True (tv.NewKeyDownEvent (Key.Tab));
|
||
|
||
Assert.Equal (
|
||
$"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third \t",
|
||
tv.Text
|
||
);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.AllowsTab);
|
||
tv.AllowsTab = false;
|
||
Assert.False (tv.NewKeyDownEvent (Key.Tab.WithShift));
|
||
|
||
Assert.Equal (
|
||
$"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third \t",
|
||
tv.Text
|
||
);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.False (tv.AllowsTab);
|
||
tv.AllowsTab = true;
|
||
Assert.True (tv.NewKeyDownEvent (Key.Tab.WithShift));
|
||
|
||
Assert.Equal (
|
||
$"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ",
|
||
tv.Text
|
||
);
|
||
Assert.False (tv.IsSelecting);
|
||
Assert.True (tv.AllowsTab);
|
||
Assert.False (tv.NewKeyDownEvent (Key.F6));
|
||
Assert.False (tv.NewKeyDownEvent (Application.NextTabGroupKey));
|
||
Assert.False (tv.NewKeyDownEvent (Key.F6.WithShift));
|
||
Assert.False (tv.NewKeyDownEvent (Application.PrevTabGroupKey));
|
||
|
||
Assert.True (tv.NewKeyDownEvent (PopoverMenu.DefaultKey));
|
||
Assert.True (tv.ContextMenu != null && tv.ContextMenu.Visible);
|
||
Assert.False (tv.IsSelecting);
|
||
top.Dispose ();
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void Kill_Delete_WordBackward ()
|
||
{
|
||
_textView.Text = "This is the first line.";
|
||
_textView.MoveEnd ();
|
||
var iteration = 0;
|
||
var iterationsFinished = false;
|
||
|
||
while (!iterationsFinished)
|
||
{
|
||
_textView.NewKeyDownEvent (Key.Backspace.WithCtrl);
|
||
|
||
switch (iteration)
|
||
{
|
||
case 0:
|
||
Assert.Equal (22, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal ("This is the first line", _textView.Text);
|
||
|
||
break;
|
||
case 1:
|
||
Assert.Equal (18, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal ("This is the first ", _textView.Text);
|
||
|
||
break;
|
||
case 2:
|
||
Assert.Equal (12, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal ("This is the ", _textView.Text);
|
||
|
||
break;
|
||
case 3:
|
||
Assert.Equal (8, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal ("This is ", _textView.Text);
|
||
|
||
break;
|
||
case 4:
|
||
Assert.Equal (5, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal ("This ", _textView.Text);
|
||
|
||
break;
|
||
case 5:
|
||
Assert.Equal (0, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal ("", _textView.Text);
|
||
|
||
break;
|
||
default:
|
||
iterationsFinished = true;
|
||
|
||
break;
|
||
}
|
||
|
||
iteration++;
|
||
}
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void Kill_Delete_WordBackward_Multiline ()
|
||
{
|
||
_textView.Text = "This is the first line.\nThis is the second line.";
|
||
_textView.Width = 4;
|
||
_textView.MoveEnd ();
|
||
var iteration = 0;
|
||
var iterationsFinished = false;
|
||
|
||
while (!iterationsFinished)
|
||
{
|
||
_textView.NewKeyDownEvent (Key.Backspace.WithCtrl);
|
||
|
||
switch (iteration)
|
||
{
|
||
case 0:
|
||
Assert.Equal (23, _textView.CursorPosition.X);
|
||
Assert.Equal (1, _textView.CursorPosition.Y);
|
||
|
||
Assert.Equal (
|
||
"This is the first line."
|
||
+ Environment.NewLine
|
||
+ "This is the second line",
|
||
_textView.Text
|
||
);
|
||
|
||
break;
|
||
case 1:
|
||
Assert.Equal (19, _textView.CursorPosition.X);
|
||
Assert.Equal (1, _textView.CursorPosition.Y);
|
||
|
||
Assert.Equal (
|
||
"This is the first line."
|
||
+ Environment.NewLine
|
||
+ "This is the second ",
|
||
_textView.Text
|
||
);
|
||
|
||
break;
|
||
case 2:
|
||
Assert.Equal (12, _textView.CursorPosition.X);
|
||
Assert.Equal (1, _textView.CursorPosition.Y);
|
||
|
||
Assert.Equal (
|
||
"This is the first line."
|
||
+ Environment.NewLine
|
||
+ "This is the ",
|
||
_textView.Text
|
||
);
|
||
|
||
break;
|
||
case 3:
|
||
Assert.Equal (8, _textView.CursorPosition.X);
|
||
Assert.Equal (1, _textView.CursorPosition.Y);
|
||
|
||
Assert.Equal (
|
||
"This is the first line."
|
||
+ Environment.NewLine
|
||
+ "This is ",
|
||
_textView.Text
|
||
);
|
||
|
||
break;
|
||
case 4:
|
||
Assert.Equal (5, _textView.CursorPosition.X);
|
||
Assert.Equal (1, _textView.CursorPosition.Y);
|
||
|
||
Assert.Equal (
|
||
"This is the first line."
|
||
+ Environment.NewLine
|
||
+ "This ",
|
||
_textView.Text
|
||
);
|
||
|
||
break;
|
||
case 5:
|
||
Assert.Equal (0, _textView.CursorPosition.X);
|
||
Assert.Equal (1, _textView.CursorPosition.Y);
|
||
Assert.Equal ("This is the first line." + Environment.NewLine, _textView.Text);
|
||
|
||
break;
|
||
case 6:
|
||
Assert.Equal (23, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal ("This is the first line.", _textView.Text);
|
||
|
||
break;
|
||
case 7:
|
||
Assert.Equal (22, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal ("This is the first line", _textView.Text);
|
||
|
||
break;
|
||
case 8:
|
||
Assert.Equal (18, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal ("This is the first ", _textView.Text);
|
||
|
||
break;
|
||
case 9:
|
||
Assert.Equal (12, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal ("This is the ", _textView.Text);
|
||
|
||
break;
|
||
case 10:
|
||
Assert.Equal (8, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal ("This is ", _textView.Text);
|
||
|
||
break;
|
||
case 11:
|
||
Assert.Equal (5, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal ("This ", _textView.Text);
|
||
|
||
break;
|
||
case 12:
|
||
Assert.Equal (0, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal ("", _textView.Text);
|
||
|
||
break;
|
||
default:
|
||
iterationsFinished = true;
|
||
|
||
break;
|
||
}
|
||
|
||
iteration++;
|
||
}
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void Kill_Delete_WordForward ()
|
||
{
|
||
_textView.Text = "This is the first line.";
|
||
var iteration = 0;
|
||
var iterationsFinished = false;
|
||
|
||
while (!iterationsFinished)
|
||
{
|
||
_textView.NewKeyDownEvent (Key.Delete.WithCtrl);
|
||
|
||
switch (iteration)
|
||
{
|
||
case 0:
|
||
Assert.Equal (0, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal ("is the first line.", _textView.Text);
|
||
|
||
break;
|
||
case 1:
|
||
Assert.Equal (0, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal ("the first line.", _textView.Text);
|
||
|
||
break;
|
||
case 2:
|
||
Assert.Equal (0, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal ("first line.", _textView.Text);
|
||
|
||
break;
|
||
case 3:
|
||
Assert.Equal (0, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal ("line.", _textView.Text);
|
||
|
||
break;
|
||
case 4:
|
||
Assert.Equal (0, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (".", _textView.Text);
|
||
|
||
break;
|
||
case 5:
|
||
Assert.Equal (0, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal ("", _textView.Text);
|
||
|
||
break;
|
||
default:
|
||
iterationsFinished = true;
|
||
|
||
break;
|
||
}
|
||
|
||
iteration++;
|
||
}
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void Kill_Delete_WordForward_Multiline ()
|
||
{
|
||
_textView.Text = "This is the first line.\nThis is the second line.";
|
||
_textView.Width = 4;
|
||
var iteration = 0;
|
||
var iterationsFinished = false;
|
||
|
||
while (!iterationsFinished)
|
||
{
|
||
_textView.NewKeyDownEvent (Key.Delete.WithCtrl);
|
||
|
||
switch (iteration)
|
||
{
|
||
case 0:
|
||
Assert.Equal (0, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
|
||
Assert.Equal (
|
||
"is the first line."
|
||
+ Environment.NewLine
|
||
+ "This is the second line.",
|
||
_textView.Text
|
||
);
|
||
|
||
break;
|
||
case 1:
|
||
Assert.Equal (0, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
|
||
Assert.Equal (
|
||
"the first line."
|
||
+ Environment.NewLine
|
||
+ "This is the second line.",
|
||
_textView.Text
|
||
);
|
||
|
||
break;
|
||
case 2:
|
||
Assert.Equal (0, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
|
||
Assert.Equal (
|
||
"first line."
|
||
+ Environment.NewLine
|
||
+ "This is the second line.",
|
||
_textView.Text
|
||
);
|
||
|
||
break;
|
||
case 3:
|
||
Assert.Equal (0, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
|
||
Assert.Equal (
|
||
"line."
|
||
+ Environment.NewLine
|
||
+ "This is the second line.",
|
||
_textView.Text
|
||
);
|
||
|
||
break;
|
||
case 4:
|
||
Assert.Equal (0, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
|
||
Assert.Equal (
|
||
"."
|
||
+ Environment.NewLine
|
||
+ "This is the second line.",
|
||
_textView.Text
|
||
);
|
||
|
||
break;
|
||
case 5:
|
||
Assert.Equal (0, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
|
||
Assert.Equal (
|
||
""
|
||
+ Environment.NewLine
|
||
+ "This is the second line.",
|
||
_textView.Text
|
||
);
|
||
|
||
break;
|
||
case 6:
|
||
Assert.Equal (0, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal ("This is the second line.", _textView.Text);
|
||
|
||
break;
|
||
case 7:
|
||
Assert.Equal (0, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal ("is the second line.", _textView.Text);
|
||
|
||
break;
|
||
case 8:
|
||
Assert.Equal (0, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal ("the second line.", _textView.Text);
|
||
|
||
break;
|
||
case 9:
|
||
Assert.Equal (0, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal ("second line.", _textView.Text);
|
||
|
||
break;
|
||
case 10:
|
||
Assert.Equal (0, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal ("line.", _textView.Text);
|
||
|
||
break;
|
||
case 11:
|
||
Assert.Equal (0, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (".", _textView.Text);
|
||
|
||
break;
|
||
case 12:
|
||
Assert.Equal (0, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal ("", _textView.Text);
|
||
|
||
break;
|
||
default:
|
||
iterationsFinished = true;
|
||
|
||
break;
|
||
}
|
||
|
||
iteration++;
|
||
}
|
||
}
|
||
|
||
[Fact (Skip = "Fake Clipboard is broken")]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void Kill_To_End_Delete_Forwards_Copy_To_The_Clipboard_And_Paste ()
|
||
{
|
||
_textView.Text = "This is the first line.\nThis is the second line.";
|
||
var iteration = 0;
|
||
var iterationsFinished = false;
|
||
|
||
while (!iterationsFinished)
|
||
{
|
||
switch (iteration)
|
||
{
|
||
case 0:
|
||
_textView.NewKeyDownEvent (Key.K.WithCtrl);
|
||
Assert.Equal (0, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal ($"{Environment.NewLine}This is the second line.", _textView.Text);
|
||
Assert.Equal ("This is the first line.", Clipboard.Contents);
|
||
|
||
break;
|
||
case 1:
|
||
_textView.NewKeyDownEvent (
|
||
new (
|
||
KeyCode.Delete | KeyCode.CtrlMask | KeyCode.ShiftMask
|
||
)
|
||
);
|
||
Assert.Equal (0, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal ("This is the second line.", _textView.Text);
|
||
Assert.Equal ($"This is the first line.{Environment.NewLine}", Clipboard.Contents);
|
||
|
||
break;
|
||
case 2:
|
||
_textView.NewKeyDownEvent (Key.K.WithCtrl);
|
||
Assert.Equal (0, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal ("", _textView.Text);
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.",
|
||
Clipboard.Contents
|
||
);
|
||
|
||
// Paste
|
||
_textView.NewKeyDownEvent (Key.Y.WithCtrl);
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.",
|
||
_textView.Text
|
||
);
|
||
|
||
break;
|
||
default:
|
||
iterationsFinished = true;
|
||
|
||
break;
|
||
}
|
||
|
||
iteration++;
|
||
}
|
||
}
|
||
|
||
[Fact (Skip = "FakeClipboard is broken in some way, causing this unit test to fail intermittently.")]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void Kill_To_Start_Delete_Backwards_Copy_To_The_Clipboard_And_Paste ()
|
||
{
|
||
_textView.Text = "This is the first line.\nThis is the second line.";
|
||
_textView.MoveEnd ();
|
||
var iteration = 0;
|
||
var iterationsFinished = false;
|
||
|
||
while (!iterationsFinished)
|
||
{
|
||
switch (iteration)
|
||
{
|
||
case 0:
|
||
_textView.NewKeyDownEvent (Key.Backspace.WithCtrl.WithShift);
|
||
Assert.Equal (0, _textView.CursorPosition.X);
|
||
Assert.Equal (1, _textView.CursorPosition.Y);
|
||
Assert.Equal ($"This is the first line.{Environment.NewLine}", _textView.Text);
|
||
Assert.Equal ("This is the second line.", Clipboard.Contents);
|
||
|
||
break;
|
||
case 1:
|
||
_textView.NewKeyDownEvent (
|
||
new (
|
||
KeyCode.Backspace | KeyCode.CtrlMask | KeyCode.ShiftMask
|
||
)
|
||
);
|
||
Assert.Equal (23, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal ("This is the first line.", _textView.Text);
|
||
Assert.Equal ($"This is the second line.{Environment.NewLine}", Clipboard.Contents);
|
||
|
||
break;
|
||
case 2:
|
||
_textView.NewKeyDownEvent (Key.Backspace.WithCtrl.WithShift);
|
||
Assert.Equal (0, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal ("", _textView.Text);
|
||
|
||
Assert.Equal (
|
||
$"This is the second line.{Environment.NewLine}This is the first line.",
|
||
Clipboard.Contents
|
||
);
|
||
|
||
// Paste inverted
|
||
_textView.NewKeyDownEvent (Key.Y.WithCtrl);
|
||
|
||
Assert.Equal (
|
||
$"This is the second line.{Environment.NewLine}This is the first line.",
|
||
_textView.Text
|
||
);
|
||
|
||
break;
|
||
default:
|
||
iterationsFinished = true;
|
||
|
||
break;
|
||
}
|
||
|
||
iteration++;
|
||
}
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void Mouse_Button_Shift_Preserves_Selection ()
|
||
{
|
||
Assert.Equal ("TAB to jump between text fields.", _textView.Text);
|
||
|
||
Assert.True (
|
||
_textView.NewMouseEvent (
|
||
new () { Position = new (12, 0), Flags = MouseFlags.Button1Pressed | MouseFlags.ButtonShift }
|
||
)
|
||
);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (new (12, 0), _textView.CursorPosition);
|
||
Assert.True (_textView.IsSelecting);
|
||
Assert.Equal ("TAB to jump ", _textView.SelectedText);
|
||
|
||
Assert.True (_textView.NewMouseEvent (new () { Position = new (12, 0), Flags = MouseFlags.Button1Clicked }));
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (new (12, 0), _textView.CursorPosition);
|
||
Assert.True (_textView.IsSelecting);
|
||
Assert.Equal ("TAB to jump ", _textView.SelectedText);
|
||
|
||
Assert.True (
|
||
_textView.NewMouseEvent (
|
||
new () { Position = new (19, 0), Flags = MouseFlags.Button1Pressed | MouseFlags.ButtonShift }
|
||
)
|
||
);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (new (19, 0), _textView.CursorPosition);
|
||
Assert.True (_textView.IsSelecting);
|
||
Assert.Equal ("TAB to jump between", _textView.SelectedText);
|
||
|
||
Assert.True (_textView.NewMouseEvent (new () { Position = new (19, 0), Flags = MouseFlags.Button1Clicked }));
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (new (19, 0), _textView.CursorPosition);
|
||
Assert.True (_textView.IsSelecting);
|
||
Assert.Equal ("TAB to jump between", _textView.SelectedText);
|
||
|
||
Assert.True (
|
||
_textView.NewMouseEvent (
|
||
new () { Position = new (24, 0), Flags = MouseFlags.Button1Pressed | MouseFlags.ButtonShift }
|
||
)
|
||
);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (new (24, 0), _textView.CursorPosition);
|
||
Assert.True (_textView.IsSelecting);
|
||
Assert.Equal ("TAB to jump between text", _textView.SelectedText);
|
||
|
||
Assert.True (_textView.NewMouseEvent (new () { Position = new (24, 0), Flags = MouseFlags.Button1Clicked }));
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (new (24, 0), _textView.CursorPosition);
|
||
Assert.True (_textView.IsSelecting);
|
||
Assert.Equal ("TAB to jump between text", _textView.SelectedText);
|
||
|
||
Assert.True (_textView.NewMouseEvent (new () { Position = new (24, 0), Flags = MouseFlags.Button1Pressed }));
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (new (24, 0), _textView.CursorPosition);
|
||
Assert.True (_textView.IsSelecting);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void MoveDown_By_Setting_CursorPosition ()
|
||
{
|
||
var tv = new TextView { Width = 10, Height = 5 };
|
||
|
||
// add 100 lines of wide text to view
|
||
for (var i = 0; i < 100; i++)
|
||
{
|
||
tv.Text += new string ('x', 100) + (i == 99 ? "" : Environment.NewLine);
|
||
}
|
||
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
tv.CursorPosition = new (5, 50);
|
||
Assert.Equal (new (5, 50), tv.CursorPosition);
|
||
|
||
tv.CursorPosition = new (200, 200);
|
||
Assert.Equal (new (100, 99), tv.CursorPosition);
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void Multiline_Setting_Changes_AllowsReturn_AllowsTab_Height_WordWrap ()
|
||
{
|
||
Assert.True (_textView.Multiline);
|
||
Assert.True (_textView.AllowsReturn);
|
||
Assert.Equal (4, _textView.TabWidth);
|
||
Assert.True (_textView.AllowsTab);
|
||
Assert.False (_textView.WordWrap);
|
||
|
||
_textView.WordWrap = true;
|
||
Assert.True (_textView.WordWrap);
|
||
_textView.Multiline = false;
|
||
Assert.False (_textView.Multiline);
|
||
Assert.False (_textView.AllowsReturn);
|
||
Assert.Equal (0, _textView.TabWidth);
|
||
Assert.False (_textView.AllowsTab);
|
||
Assert.False (_textView.WordWrap);
|
||
|
||
_textView.WordWrap = true;
|
||
Assert.False (_textView.WordWrap);
|
||
_textView.Multiline = true;
|
||
Assert.True (_textView.Multiline);
|
||
Assert.True (_textView.AllowsReturn);
|
||
Assert.Equal (4, _textView.TabWidth);
|
||
Assert.True (_textView.AllowsTab);
|
||
Assert.False (_textView.WordWrap);
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void Paste_Always_Clear_The_SelectedText ()
|
||
{
|
||
_textView.SelectionStartColumn = 20;
|
||
_textView.SelectionStartRow = 0;
|
||
_textView.CursorPosition = new (24, 0);
|
||
_textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy
|
||
Assert.Equal ("text", _textView.SelectedText);
|
||
_textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void ScrollDownTillCaretOffscreen_ThenType ()
|
||
{
|
||
var tv = new TextView { Width = 10, Height = 5 };
|
||
|
||
// add 100 lines of wide text to view
|
||
for (var i = 0; i < 100; i++)
|
||
{
|
||
tv.Text += new string ('x', 100) + Environment.NewLine;
|
||
}
|
||
|
||
Assert.Equal (0, tv.CursorPosition.Y);
|
||
tv.ScrollTo (50);
|
||
Assert.Equal (0, tv.CursorPosition.Y);
|
||
|
||
tv.NewKeyDownEvent (Key.P);
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void ScrollTo_CursorPosition ()
|
||
{
|
||
var tv = new TextView { Width = 10, Height = 5 };
|
||
|
||
// add 100 lines of wide text to view
|
||
for (var i = 0; i < 100; i++)
|
||
{
|
||
tv.Text += new string ('x', 100) + (i == 99 ? "" : Environment.NewLine);
|
||
}
|
||
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
tv.ScrollTo (50);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
tv.CursorPosition = new (tv.LeftColumn, tv.TopRow);
|
||
Assert.Equal (new (0, 50), tv.CursorPosition);
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void Selected_Text_Shows ()
|
||
{
|
||
// Proves #3022 is fixed (TextField selected text does not show in v2)
|
||
Toplevel top = new ();
|
||
top.Add (_textView);
|
||
SessionToken rs = Application.Begin (top);
|
||
|
||
_textView.CursorPosition = Point.Empty;
|
||
_textView.SelectionStartColumn = 0;
|
||
_textView.SelectionStartRow = 0;
|
||
|
||
Attribute [] attributes =
|
||
{
|
||
_textView.GetScheme ().Focus,
|
||
new (_textView.GetScheme ().Focus.Background, _textView.GetScheme ().Focus.Foreground)
|
||
};
|
||
|
||
// TAB to jump between text fields.
|
||
DriverAssert.AssertDriverAttributesAre ("0000000", _output, Application.Driver, attributes);
|
||
Assert.Empty (_textView.SelectedCellsList);
|
||
|
||
_textView.NewKeyDownEvent (Key.CursorRight.WithCtrl.WithShift);
|
||
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
Assert.Equal (new (4, 0), _textView.CursorPosition);
|
||
|
||
// TAB to jump between text fields.
|
||
DriverAssert.AssertDriverAttributesAre ("1111000", _output, Application.Driver, attributes);
|
||
Assert.Equal ("TAB ", Cell.ToString (_textView.SelectedCellsList [^1]));
|
||
top.Dispose ();
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void Selection_And_CursorPosition_With_Value_Greater_Than_Text_Length_Changes_Both_To_Text_Length ()
|
||
{
|
||
_textView.CursorPosition = new (33, 2);
|
||
_textView.SelectionStartColumn = 33;
|
||
_textView.SelectionStartRow = 33;
|
||
Assert.Equal (32, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (32, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void Selection_With_Empty_Text ()
|
||
{
|
||
_textView = new ();
|
||
_textView.CursorPosition = new (2, 0);
|
||
_textView.SelectionStartColumn = 33;
|
||
_textView.SelectionStartRow = 1;
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void Selection_With_Value_Greater_Than_Text_Length_Changes_To_Text_Length ()
|
||
{
|
||
_textView.CursorPosition = new (2, 0);
|
||
_textView.SelectionStartColumn = 33;
|
||
_textView.SelectionStartRow = 1;
|
||
Assert.Equal (32, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (30, _textView.SelectedLength);
|
||
Assert.Equal ("B to jump between text fields.", _textView.SelectedText);
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void Selection_With_Value_Less_Than_Zero_Changes_To_Zero ()
|
||
{
|
||
_textView.SelectionStartColumn = -2;
|
||
_textView.SelectionStartRow = -2;
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void Tab_Test_Follow_By_BackTab ()
|
||
{
|
||
var top = new Toplevel ();
|
||
top.Add (_textView);
|
||
|
||
Application.Iteration += OnApplicationOnIteration;
|
||
|
||
Application.Run (top);
|
||
Application.Iteration -= OnApplicationOnIteration;
|
||
top.Dispose ();
|
||
|
||
return;
|
||
|
||
void OnApplicationOnIteration (object s, EventArgs<IApplication> a)
|
||
{
|
||
int width = _textView.Viewport.Width - 1;
|
||
Assert.Equal (30, width + 1);
|
||
Assert.Equal (10, _textView.Height);
|
||
_textView.Text = "";
|
||
var col = 0;
|
||
var leftCol = 0;
|
||
int tabWidth = _textView.TabWidth;
|
||
|
||
while (col < 100)
|
||
{
|
||
col++;
|
||
_textView.NewKeyDownEvent (Key.Tab);
|
||
Assert.Equal (new (col, 0), _textView.CursorPosition);
|
||
leftCol = GetLeftCol (leftCol);
|
||
Assert.Equal (leftCol, _textView.LeftColumn);
|
||
}
|
||
|
||
while (col > 0)
|
||
{
|
||
col--;
|
||
_textView.NewKeyDownEvent (Key.Tab.WithShift);
|
||
Assert.Equal (new (col, 0), _textView.CursorPosition);
|
||
leftCol = GetLeftCol (leftCol);
|
||
Assert.Equal (leftCol, _textView.LeftColumn);
|
||
}
|
||
|
||
top.Remove (_textView);
|
||
Application.RequestStop ();
|
||
}
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void Tab_Test_Follow_By_BackTab_With_Text ()
|
||
{
|
||
var top = new Toplevel ();
|
||
top.Add (_textView);
|
||
|
||
Application.Iteration += OnApplicationOnIteration;
|
||
|
||
Application.Run (top);
|
||
Application.Iteration -= OnApplicationOnIteration;
|
||
top.Dispose ();
|
||
|
||
return;
|
||
|
||
void OnApplicationOnIteration (object s, EventArgs<IApplication> a)
|
||
{
|
||
int width = _textView.Viewport.Width - 1;
|
||
Assert.Equal (30, width + 1);
|
||
Assert.Equal (10, _textView.Height);
|
||
var col = 0;
|
||
var leftCol = 0;
|
||
Assert.Equal (new (col, 0), _textView.CursorPosition);
|
||
Assert.Equal (leftCol, _textView.LeftColumn);
|
||
|
||
while (col < 100)
|
||
{
|
||
col++;
|
||
_textView.NewKeyDownEvent (Key.Tab);
|
||
Assert.Equal (new (col, 0), _textView.CursorPosition);
|
||
leftCol = GetLeftCol (leftCol);
|
||
Assert.Equal (leftCol, _textView.LeftColumn);
|
||
}
|
||
|
||
while (col > 0)
|
||
{
|
||
col--;
|
||
_textView.NewKeyDownEvent (Key.Tab.WithShift);
|
||
Assert.Equal (new (col, 0), _textView.CursorPosition);
|
||
leftCol = GetLeftCol (leftCol);
|
||
Assert.Equal (leftCol, _textView.LeftColumn);
|
||
}
|
||
|
||
top.Remove (_textView);
|
||
Application.RequestStop ();
|
||
}
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void Tab_Test_Follow_By_CursorLeft_And_Then_Follow_By_CursorRight ()
|
||
{
|
||
var top = new Toplevel ();
|
||
top.Add (_textView);
|
||
|
||
Application.Iteration += OnApplicationOnIteration;
|
||
|
||
Application.Run (top);
|
||
Application.Iteration -= OnApplicationOnIteration;
|
||
top.Dispose ();
|
||
|
||
return;
|
||
|
||
void OnApplicationOnIteration (object s, EventArgs<IApplication> a)
|
||
{
|
||
int width = _textView.Viewport.Width - 1;
|
||
Assert.Equal (30, width + 1);
|
||
Assert.Equal (10, _textView.Height);
|
||
_textView.Text = "";
|
||
var col = 0;
|
||
var leftCol = 0;
|
||
int tabWidth = _textView.TabWidth;
|
||
|
||
while (col < 100)
|
||
{
|
||
col++;
|
||
_textView.NewKeyDownEvent (Key.Tab);
|
||
Assert.Equal (new (col, 0), _textView.CursorPosition);
|
||
leftCol = GetLeftCol (leftCol);
|
||
Assert.Equal (leftCol, _textView.LeftColumn);
|
||
}
|
||
|
||
while (col > 0)
|
||
{
|
||
col--;
|
||
_textView.NewKeyDownEvent (Key.CursorLeft);
|
||
Assert.Equal (new (col, 0), _textView.CursorPosition);
|
||
leftCol = GetLeftCol (leftCol);
|
||
Assert.Equal (leftCol, _textView.LeftColumn);
|
||
}
|
||
|
||
while (col < 100)
|
||
{
|
||
col++;
|
||
_textView.NewKeyDownEvent (Key.CursorRight);
|
||
Assert.Equal (new (col, 0), _textView.CursorPosition);
|
||
leftCol = GetLeftCol (leftCol);
|
||
Assert.Equal (leftCol, _textView.LeftColumn);
|
||
}
|
||
|
||
top.Remove (_textView);
|
||
Application.RequestStop ();
|
||
}
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void Tab_Test_Follow_By_CursorLeft_And_Then_Follow_By_CursorRight_With_Text ()
|
||
{
|
||
var top = new Toplevel ();
|
||
top.Add (_textView);
|
||
|
||
Application.Iteration += OnApplicationOnIteration;
|
||
|
||
Application.Run (top);
|
||
Application.Iteration -= OnApplicationOnIteration;
|
||
top.Dispose ();
|
||
|
||
return;
|
||
|
||
void OnApplicationOnIteration (object s, EventArgs<IApplication> a)
|
||
{
|
||
int width = _textView.Viewport.Width - 1;
|
||
Assert.Equal (30, width + 1);
|
||
Assert.Equal (10, _textView.Height);
|
||
Assert.Equal ("TAB to jump between text fields.", _textView.Text);
|
||
var col = 0;
|
||
var leftCol = 0;
|
||
int tabWidth = _textView.TabWidth;
|
||
|
||
while (col < 100)
|
||
{
|
||
col++;
|
||
_textView.NewKeyDownEvent (Key.Tab);
|
||
Assert.Equal (new (col, 0), _textView.CursorPosition);
|
||
leftCol = GetLeftCol (leftCol);
|
||
Assert.Equal (leftCol, _textView.LeftColumn);
|
||
}
|
||
|
||
Assert.Equal (132, _textView.Text.Length);
|
||
|
||
while (col > 0)
|
||
{
|
||
col--;
|
||
_textView.NewKeyDownEvent (Key.CursorLeft);
|
||
Assert.Equal (new (col, 0), _textView.CursorPosition);
|
||
leftCol = GetLeftCol (leftCol);
|
||
Assert.Equal (leftCol, _textView.LeftColumn);
|
||
}
|
||
|
||
while (col < 100)
|
||
{
|
||
col++;
|
||
_textView.NewKeyDownEvent (Key.CursorRight);
|
||
Assert.Equal (new (col, 0), _textView.CursorPosition);
|
||
leftCol = GetLeftCol (leftCol);
|
||
Assert.Equal (leftCol, _textView.LeftColumn);
|
||
}
|
||
|
||
top.Remove (_textView);
|
||
Application.RequestStop ();
|
||
}
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void Tab_Test_Follow_By_Home_And_Then_Follow_By_End_And_Then_Follow_By_BackTab_With_Text ()
|
||
{
|
||
var top = new Toplevel ();
|
||
top.Add (_textView);
|
||
|
||
Application.Iteration += OnApplicationOnIteration;
|
||
|
||
Application.Run (top);
|
||
Application.Iteration -= OnApplicationOnIteration;
|
||
top.Dispose ();
|
||
|
||
return;
|
||
|
||
void OnApplicationOnIteration (object s, EventArgs<IApplication> a)
|
||
{
|
||
int width = _textView.Viewport.Width - 1;
|
||
Assert.Equal (30, width + 1);
|
||
Assert.Equal (10, _textView.Height);
|
||
var col = 0;
|
||
var leftCol = 0;
|
||
Assert.Equal (new (col, 0), _textView.CursorPosition);
|
||
Assert.Equal (leftCol, _textView.LeftColumn);
|
||
Assert.Equal ("TAB to jump between text fields.", _textView.Text);
|
||
Assert.Equal (32, _textView.Text.Length);
|
||
|
||
while (col < 100)
|
||
{
|
||
col++;
|
||
_textView.NewKeyDownEvent (Key.Tab);
|
||
Assert.Equal (new (col, 0), _textView.CursorPosition);
|
||
leftCol = GetLeftCol (leftCol);
|
||
Assert.Equal (leftCol, _textView.LeftColumn);
|
||
}
|
||
|
||
_textView.NewKeyDownEvent (Key.Home);
|
||
col = 0;
|
||
Assert.Equal (new (col, 0), _textView.CursorPosition);
|
||
leftCol = 0;
|
||
Assert.Equal (leftCol, _textView.LeftColumn);
|
||
|
||
_textView.NewKeyDownEvent (Key.End);
|
||
col = _textView.Text.Length;
|
||
Assert.Equal (132, _textView.Text.Length);
|
||
Assert.Equal (new (col, 0), _textView.CursorPosition);
|
||
leftCol = GetLeftCol (leftCol);
|
||
Assert.Equal (leftCol, _textView.LeftColumn);
|
||
string txt = _textView.Text;
|
||
|
||
while (col - 1 > 0 && txt [col - 1] != '\t')
|
||
{
|
||
col--;
|
||
}
|
||
|
||
_textView.CursorPosition = new (col, 0);
|
||
leftCol = GetLeftCol (leftCol);
|
||
|
||
while (col > 0)
|
||
{
|
||
col--;
|
||
_textView.NewKeyDownEvent (Key.Tab.WithShift);
|
||
Assert.Equal (new (col, 0), _textView.CursorPosition);
|
||
leftCol = GetLeftCol (leftCol);
|
||
Assert.Equal (leftCol, _textView.LeftColumn);
|
||
}
|
||
|
||
Assert.Equal ("TAB to jump between text fields.", _textView.Text);
|
||
Assert.Equal (32, _textView.Text.Length);
|
||
|
||
top.Remove (_textView);
|
||
Application.RequestStop ();
|
||
}
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void TabWidth_Setting_To_Zero_Keeps_AllowsTab ()
|
||
{
|
||
var top = new Toplevel ();
|
||
top.Add (_textView);
|
||
Application.Begin (top);
|
||
|
||
Assert.Equal (4, _textView.TabWidth);
|
||
Assert.True (_textView.AllowsTab);
|
||
Assert.True (_textView.AllowsReturn);
|
||
Assert.True (_textView.Multiline);
|
||
_textView.TabWidth = -1;
|
||
Assert.Equal (0, _textView.TabWidth);
|
||
Assert.True (_textView.AllowsTab);
|
||
Assert.True (_textView.AllowsReturn);
|
||
Assert.True (_textView.Multiline);
|
||
_textView.NewKeyDownEvent (Key.Tab);
|
||
Assert.Equal ("\tTAB to jump between text fields.", _textView.Text);
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
|
||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||
@"
|
||
TAB to jump between text field",
|
||
_output
|
||
);
|
||
|
||
_textView.TabWidth = 4;
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
|
||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||
@"
|
||
TAB to jump between text f",
|
||
_output
|
||
);
|
||
|
||
_textView.NewKeyDownEvent (Key.Tab.WithShift);
|
||
Assert.Equal ("TAB to jump between text fields.", _textView.Text);
|
||
Assert.True (_textView.NeedsDraw);
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
|
||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||
@"
|
||
TAB to jump between text field",
|
||
_output
|
||
);
|
||
top.Dispose ();
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void TextChanged_Event ()
|
||
{
|
||
_textView.TextChanged += (s, e) =>
|
||
{
|
||
if (_textView.Text == "changing")
|
||
{
|
||
Assert.Equal ("changing", _textView.Text);
|
||
_textView.Text = "changed";
|
||
}
|
||
};
|
||
|
||
_textView.Text = "changing";
|
||
Assert.Equal ("changed", _textView.Text);
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void TextChanged_Event_NoFires_OnTyping ()
|
||
{
|
||
var eventcount = 0;
|
||
_textView.TextChanged += (s, e) => { eventcount++; };
|
||
|
||
_textView.Text = "ay";
|
||
Assert.Equal (1, eventcount);
|
||
_textView.NewKeyDownEvent (Key.Y.WithShift);
|
||
Assert.Equal (1, eventcount);
|
||
Assert.Equal ("Yay", _textView.Text);
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void TextView_InsertText_Newline_CRLF ()
|
||
{
|
||
var tv = new TextView { Width = 10, Height = 10 };
|
||
tv.InsertText ("\r\naaa\r\nbbb");
|
||
PlatformID p = Environment.OSVersion.Platform;
|
||
|
||
if (p == PlatformID.Win32NT || p == PlatformID.Win32S || p == PlatformID.Win32Windows)
|
||
{
|
||
Assert.Equal ("\r\naaa\r\nbbb", tv.Text);
|
||
}
|
||
else
|
||
{
|
||
Assert.Equal ("\naaa\nbbb", tv.Text);
|
||
}
|
||
|
||
Assert.Equal ($"{Environment.NewLine}aaa{Environment.NewLine}bbb", tv.Text);
|
||
|
||
var win = new Window ();
|
||
win.Add (tv);
|
||
var top = new Toplevel ();
|
||
top.Add (win);
|
||
Application.Begin (top);
|
||
Application.Driver!.SetScreenSize (15, 15);
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
|
||
//this passes
|
||
Rectangle pos = DriverAssert.AssertDriverContentsWithFrameAre (
|
||
@"
|
||
┌─────────────┐
|
||
│ │
|
||
│aaa │
|
||
│bbb │
|
||
│ │
|
||
│ │
|
||
│ │
|
||
│ │
|
||
│ │
|
||
│ │
|
||
│ │
|
||
│ │
|
||
│ │
|
||
│ │
|
||
└─────────────┘",
|
||
_output
|
||
);
|
||
|
||
Assert.Equal (new (0, 0, 15, 15), pos);
|
||
|
||
Assert.True (tv.Used);
|
||
tv.Used = false;
|
||
tv.CursorPosition = Point.Empty;
|
||
tv.InsertText ("\r\naaa\r\nbbb");
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
|
||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||
@"
|
||
┌─────────────┐
|
||
│ │
|
||
│aaa │
|
||
│bbb │
|
||
│aaa │
|
||
│bbb │
|
||
│ │
|
||
│ │
|
||
│ │
|
||
│ │
|
||
│ │
|
||
│ │
|
||
│ │
|
||
│ │
|
||
└─────────────┘",
|
||
_output
|
||
);
|
||
top.Dispose ();
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void TextView_InsertText_Newline_LF ()
|
||
{
|
||
var tv = new TextView { Width = 10, Height = 10 };
|
||
tv.InsertText ("\naaa\nbbb");
|
||
PlatformID p = Environment.OSVersion.Platform;
|
||
|
||
if (p == PlatformID.Win32NT || p == PlatformID.Win32S || p == PlatformID.Win32Windows)
|
||
{
|
||
Assert.Equal ("\r\naaa\r\nbbb", tv.Text);
|
||
}
|
||
else
|
||
{
|
||
Assert.Equal ("\naaa\nbbb", tv.Text);
|
||
}
|
||
|
||
Assert.Equal ($"{Environment.NewLine}aaa{Environment.NewLine}bbb", tv.Text);
|
||
|
||
var win = new Window ();
|
||
win.Add (tv);
|
||
var top = new Toplevel ();
|
||
top.Add (win);
|
||
Application.Begin (top);
|
||
Application.Driver!.SetScreenSize (15, 15);
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
|
||
//this passes
|
||
Rectangle pos = DriverAssert.AssertDriverContentsWithFrameAre (
|
||
@"
|
||
┌─────────────┐
|
||
│ │
|
||
│aaa │
|
||
│bbb │
|
||
│ │
|
||
│ │
|
||
│ │
|
||
│ │
|
||
│ │
|
||
│ │
|
||
│ │
|
||
│ │
|
||
│ │
|
||
│ │
|
||
└─────────────┘",
|
||
_output
|
||
);
|
||
|
||
Assert.Equal (new (0, 0, 15, 15), pos);
|
||
|
||
Assert.True (tv.Used);
|
||
tv.Used = false;
|
||
tv.CursorPosition = Point.Empty;
|
||
tv.InsertText ("\naaa\nbbb");
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
|
||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||
@"
|
||
┌─────────────┐
|
||
│ │
|
||
│aaa │
|
||
│bbb │
|
||
│aaa │
|
||
│bbb │
|
||
│ │
|
||
│ │
|
||
│ │
|
||
│ │
|
||
│ │
|
||
│ │
|
||
│ │
|
||
│ │
|
||
└─────────────┘",
|
||
_output
|
||
);
|
||
top.Dispose ();
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void TextView_SpaceHandling ()
|
||
{
|
||
var tv = new TextView { Width = 10, Text = " " };
|
||
|
||
var ev = new MouseEventArgs { Position = new (0, 0), Flags = MouseFlags.Button1DoubleClicked };
|
||
|
||
tv.NewMouseEvent (ev);
|
||
Assert.Equal (1, tv.SelectedLength);
|
||
|
||
ev = new () { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked };
|
||
|
||
tv.NewMouseEvent (ev);
|
||
Assert.Equal (1, tv.SelectedLength);
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void UnwrappedCursorPosition_Event ()
|
||
{
|
||
var cp = Point.Empty;
|
||
|
||
var tv = new TextView
|
||
{
|
||
Width = Dim.Fill (), Height = Dim.Fill (), Text = "This is the first line.\nThis is the second line.\n"
|
||
};
|
||
tv.UnwrappedCursorPosition += (s, e) => { cp = e; };
|
||
var top = new Toplevel ();
|
||
top.Add (tv);
|
||
Application.Begin (top);
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
|
||
Assert.False (tv.WordWrap);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.Equal (Point.Empty, cp);
|
||
|
||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||
@"
|
||
This is the first line.
|
||
This is the second line.
|
||
",
|
||
_output
|
||
);
|
||
|
||
tv.WordWrap = true;
|
||
tv.CursorPosition = new (12, 0);
|
||
tv.Draw ();
|
||
Assert.Equal (new (12, 0), tv.CursorPosition);
|
||
Assert.Equal (new (12, 0), cp);
|
||
|
||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||
@"
|
||
This is the first line.
|
||
This is the second line.
|
||
",
|
||
_output
|
||
);
|
||
|
||
Application.Driver!.SetScreenSize (6, 25);
|
||
tv.SetRelativeLayout (Application.Screen.Size);
|
||
tv.Draw ();
|
||
Assert.Equal (new (4, 2), tv.CursorPosition);
|
||
Assert.Equal (new (12, 0), cp);
|
||
|
||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||
@"
|
||
This
|
||
is
|
||
the
|
||
first
|
||
|
||
line.
|
||
This
|
||
is
|
||
the
|
||
secon
|
||
d
|
||
line.
|
||
",
|
||
_output
|
||
);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.CursorRight));
|
||
tv.Draw ();
|
||
Assert.Equal (new (0, 3), tv.CursorPosition);
|
||
Assert.Equal (new (12, 0), cp);
|
||
|
||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||
@"
|
||
This
|
||
is
|
||
the
|
||
first
|
||
|
||
line.
|
||
This
|
||
is
|
||
the
|
||
secon
|
||
d
|
||
line.
|
||
",
|
||
_output
|
||
);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.CursorRight));
|
||
tv.Draw ();
|
||
Assert.Equal (new (1, 3), tv.CursorPosition);
|
||
Assert.Equal (new (13, 0), cp);
|
||
|
||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||
@"
|
||
This
|
||
is
|
||
the
|
||
first
|
||
|
||
line.
|
||
This
|
||
is
|
||
the
|
||
secon
|
||
d
|
||
line.
|
||
",
|
||
_output
|
||
);
|
||
|
||
Assert.True (tv.NewMouseEvent (new () { Position = new (0, 3), Flags = MouseFlags.Button1Pressed }));
|
||
tv.Draw ();
|
||
Assert.Equal (new (0, 3), tv.CursorPosition);
|
||
Assert.Equal (new (12, 0), cp);
|
||
|
||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||
@"
|
||
This
|
||
is
|
||
the
|
||
first
|
||
|
||
line.
|
||
This
|
||
is
|
||
the
|
||
secon
|
||
d
|
||
line.
|
||
",
|
||
_output
|
||
);
|
||
top.Dispose ();
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void Used_Is_False ()
|
||
{
|
||
_textView.Used = false;
|
||
_textView.CursorPosition = new (10, 0);
|
||
Assert.Equal ("TAB to jump between text fields.", _textView.Text);
|
||
_textView.NewKeyDownEvent (Key.U); // u
|
||
Assert.Equal ("TAB to jumu between text fields.", _textView.Text);
|
||
_textView.NewKeyDownEvent (Key.S); // s
|
||
Assert.Equal ("TAB to jumusbetween text fields.", _textView.Text);
|
||
_textView.NewKeyDownEvent (Key.E); // e
|
||
Assert.Equal ("TAB to jumuseetween text fields.", _textView.Text);
|
||
_textView.NewKeyDownEvent (Key.D); // d
|
||
Assert.Equal ("TAB to jumusedtween text fields.", _textView.Text);
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void Used_Is_True_By_Default ()
|
||
{
|
||
_textView.CursorPosition = new (10, 0);
|
||
Assert.Equal ("TAB to jump between text fields.", _textView.Text);
|
||
_textView.NewKeyDownEvent (Key.U); // u
|
||
Assert.Equal ("TAB to jumup between text fields.", _textView.Text);
|
||
_textView.NewKeyDownEvent (Key.S); // s
|
||
Assert.Equal ("TAB to jumusp between text fields.", _textView.Text);
|
||
_textView.NewKeyDownEvent (Key.E); // e
|
||
Assert.Equal ("TAB to jumusep between text fields.", _textView.Text);
|
||
_textView.NewKeyDownEvent (Key.D); // d
|
||
Assert.Equal ("TAB to jumusedp between text fields.", _textView.Text);
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void WordBackward_Multiline_With_Selection ()
|
||
{
|
||
// 4 3 2 1
|
||
// 87654321098765432109876 54321098765432109876543210-Length
|
||
// 1 2 1 2
|
||
// 01234567890123456789012 0123456789012345678901234
|
||
_textView.Text = "This is the first line.\nThis is the second line.";
|
||
|
||
_textView.MoveEnd ();
|
||
_textView.SelectionStartColumn = _textView.CurrentColumn;
|
||
_textView.SelectionStartRow = _textView.CurrentRow;
|
||
var iteration = 0;
|
||
var iterationsFinished = false;
|
||
|
||
while (!iterationsFinished)
|
||
{
|
||
_textView.NewKeyDownEvent (Key.CursorLeft.WithCtrl.WithShift);
|
||
|
||
switch (iteration)
|
||
{
|
||
case 0:
|
||
Assert.Equal (23, _textView.CursorPosition.X);
|
||
Assert.Equal (1, _textView.CursorPosition.Y);
|
||
Assert.Equal (24, _textView.SelectionStartColumn);
|
||
Assert.Equal (1, _textView.SelectionStartRow);
|
||
Assert.Equal (1, _textView.SelectedLength);
|
||
Assert.Equal (".", _textView.SelectedText);
|
||
|
||
break;
|
||
case 1:
|
||
Assert.Equal (19, _textView.CursorPosition.X);
|
||
Assert.Equal (1, _textView.CursorPosition.Y);
|
||
Assert.Equal (24, _textView.SelectionStartColumn);
|
||
Assert.Equal (1, _textView.SelectionStartRow);
|
||
Assert.Equal (5, _textView.SelectedLength);
|
||
Assert.Equal ("line.", _textView.SelectedText);
|
||
|
||
break;
|
||
case 2:
|
||
Assert.Equal (12, _textView.CursorPosition.X);
|
||
Assert.Equal (1, _textView.CursorPosition.Y);
|
||
Assert.Equal (24, _textView.SelectionStartColumn);
|
||
Assert.Equal (1, _textView.SelectionStartRow);
|
||
Assert.Equal (12, _textView.SelectedLength);
|
||
Assert.Equal ("second line.", _textView.SelectedText);
|
||
|
||
break;
|
||
case 3:
|
||
Assert.Equal (8, _textView.CursorPosition.X);
|
||
Assert.Equal (1, _textView.CursorPosition.Y);
|
||
Assert.Equal (24, _textView.SelectionStartColumn);
|
||
Assert.Equal (1, _textView.SelectionStartRow);
|
||
Assert.Equal (16, _textView.SelectedLength);
|
||
Assert.Equal ("the second line.", _textView.SelectedText);
|
||
|
||
break;
|
||
case 4:
|
||
Assert.Equal (5, _textView.CursorPosition.X);
|
||
Assert.Equal (1, _textView.CursorPosition.Y);
|
||
Assert.Equal (24, _textView.SelectionStartColumn);
|
||
Assert.Equal (1, _textView.SelectionStartRow);
|
||
Assert.Equal (19, _textView.SelectedLength);
|
||
Assert.Equal ("is the second line.", _textView.SelectedText);
|
||
|
||
break;
|
||
case 5:
|
||
Assert.Equal (0, _textView.CursorPosition.X);
|
||
Assert.Equal (1, _textView.CursorPosition.Y);
|
||
Assert.Equal (24, _textView.SelectionStartColumn);
|
||
Assert.Equal (1, _textView.SelectionStartRow);
|
||
Assert.Equal (24, _textView.SelectedLength);
|
||
Assert.Equal ("This is the second line.", _textView.SelectedText);
|
||
|
||
break;
|
||
case 6:
|
||
Assert.Equal (23, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (24, _textView.SelectionStartColumn);
|
||
Assert.Equal (1, _textView.SelectionStartRow);
|
||
Assert.Equal (24 + Environment.NewLine.Length, _textView.SelectedLength);
|
||
Assert.Equal ($"{Environment.NewLine}This is the second line.", _textView.SelectedText);
|
||
|
||
break;
|
||
case 7:
|
||
Assert.Equal (22, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (24, _textView.SelectionStartColumn);
|
||
Assert.Equal (1, _textView.SelectionStartRow);
|
||
Assert.Equal (25 + Environment.NewLine.Length, _textView.SelectedLength);
|
||
|
||
Assert.Equal (
|
||
$".{Environment.NewLine}This is the second line.",
|
||
_textView.SelectedText
|
||
);
|
||
|
||
break;
|
||
case 8:
|
||
Assert.Equal (18, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (24, _textView.SelectionStartColumn);
|
||
Assert.Equal (1, _textView.SelectionStartRow);
|
||
Assert.Equal (29 + Environment.NewLine.Length, _textView.SelectedLength);
|
||
|
||
Assert.Equal (
|
||
$"line.{Environment.NewLine}This is the second line.",
|
||
_textView.SelectedText
|
||
);
|
||
|
||
break;
|
||
case 9:
|
||
Assert.Equal (12, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (24, _textView.SelectionStartColumn);
|
||
Assert.Equal (1, _textView.SelectionStartRow);
|
||
Assert.Equal (35 + Environment.NewLine.Length, _textView.SelectedLength);
|
||
|
||
Assert.Equal (
|
||
$"first line.{Environment.NewLine}This is the second line.",
|
||
_textView.SelectedText
|
||
);
|
||
|
||
break;
|
||
case 10:
|
||
Assert.Equal (8, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (24, _textView.SelectionStartColumn);
|
||
Assert.Equal (1, _textView.SelectionStartRow);
|
||
Assert.Equal (39 + Environment.NewLine.Length, _textView.SelectedLength);
|
||
|
||
Assert.Equal (
|
||
$"the first line.{Environment.NewLine}This is the second line.",
|
||
_textView.SelectedText
|
||
);
|
||
|
||
break;
|
||
case 11:
|
||
Assert.Equal (5, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (24, _textView.SelectionStartColumn);
|
||
Assert.Equal (1, _textView.SelectionStartRow);
|
||
Assert.Equal (42 + Environment.NewLine.Length, _textView.SelectedLength);
|
||
|
||
Assert.Equal (
|
||
$"is the first line.{Environment.NewLine}This is the second line.",
|
||
_textView.SelectedText
|
||
);
|
||
|
||
break;
|
||
case 12:
|
||
Assert.Equal (0, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (24, _textView.SelectionStartColumn);
|
||
Assert.Equal (1, _textView.SelectionStartRow);
|
||
Assert.Equal (47 + Environment.NewLine.Length, _textView.SelectedLength);
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.",
|
||
_textView.SelectedText
|
||
);
|
||
|
||
break;
|
||
default:
|
||
iterationsFinished = true;
|
||
|
||
break;
|
||
}
|
||
|
||
iteration++;
|
||
}
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void WordBackward_With_No_Selection ()
|
||
{
|
||
_textView.CursorPosition = new (_textView.Text.Length, 0);
|
||
var iteration = 0;
|
||
|
||
while (_textView.CursorPosition.X > 0)
|
||
{
|
||
_textView.NewKeyDownEvent (Key.CursorLeft.WithCtrl);
|
||
|
||
switch (iteration)
|
||
{
|
||
case 0:
|
||
Assert.Equal (31, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
|
||
break;
|
||
case 1:
|
||
Assert.Equal (25, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
|
||
break;
|
||
case 2:
|
||
Assert.Equal (20, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
|
||
break;
|
||
case 3:
|
||
Assert.Equal (12, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
|
||
break;
|
||
case 4:
|
||
Assert.Equal (7, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
|
||
break;
|
||
case 5:
|
||
Assert.Equal (4, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
|
||
break;
|
||
case 6:
|
||
Assert.Equal (0, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
|
||
break;
|
||
}
|
||
|
||
iteration++;
|
||
}
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void WordBackward_With_No_Selection_And_With_More_Than_Only_One_Whitespace_And_With_Only_One_Letter ()
|
||
{
|
||
// 1 2 3 4 5
|
||
// 0123456789012345678901234567890123456789012345678901234=55 (Length)
|
||
_textView.Text = "TAB t o jump b etween t ext f ields .";
|
||
_textView.CursorPosition = new (_textView.Text.Length, 0);
|
||
var iteration = 0;
|
||
|
||
while (_textView.CursorPosition.X > 0)
|
||
{
|
||
_textView.NewKeyDownEvent (Key.CursorLeft.WithCtrl);
|
||
|
||
switch (iteration)
|
||
{
|
||
case 0:
|
||
Assert.Equal (54, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
|
||
break;
|
||
case 1:
|
||
Assert.Equal (48, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
|
||
break;
|
||
case 2:
|
||
Assert.Equal (46, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
|
||
break;
|
||
case 3:
|
||
Assert.Equal (40, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
|
||
break;
|
||
case 4:
|
||
Assert.Equal (38, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
|
||
break;
|
||
case 5:
|
||
Assert.Equal (28, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
|
||
break;
|
||
case 6:
|
||
Assert.Equal (25, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
|
||
break;
|
||
case 7:
|
||
Assert.Equal (12, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
|
||
break;
|
||
case 8:
|
||
Assert.Equal (9, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
|
||
break;
|
||
case 9:
|
||
Assert.Equal (6, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
|
||
break;
|
||
case 10:
|
||
Assert.Equal (0, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
|
||
break;
|
||
}
|
||
|
||
iteration++;
|
||
}
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void WordBackward_With_Selection ()
|
||
{
|
||
_textView.CursorPosition = new (_textView.Text.Length, 0);
|
||
_textView.SelectionStartColumn = _textView.Text.Length;
|
||
_textView.SelectionStartRow = 0;
|
||
var iteration = 0;
|
||
|
||
while (_textView.CursorPosition.X > 0)
|
||
{
|
||
_textView.NewKeyDownEvent (Key.CursorLeft.WithCtrl.WithShift);
|
||
|
||
switch (iteration)
|
||
{
|
||
case 0:
|
||
Assert.Equal (31, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (32, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (1, _textView.SelectedLength);
|
||
Assert.Equal (".", _textView.SelectedText);
|
||
|
||
break;
|
||
case 1:
|
||
Assert.Equal (25, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (32, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (7, _textView.SelectedLength);
|
||
Assert.Equal ("fields.", _textView.SelectedText);
|
||
|
||
break;
|
||
case 2:
|
||
Assert.Equal (20, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (32, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (12, _textView.SelectedLength);
|
||
Assert.Equal ("text fields.", _textView.SelectedText);
|
||
|
||
break;
|
||
case 3:
|
||
Assert.Equal (12, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (32, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (20, _textView.SelectedLength);
|
||
Assert.Equal ("between text fields.", _textView.SelectedText);
|
||
|
||
break;
|
||
case 4:
|
||
Assert.Equal (7, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (32, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (25, _textView.SelectedLength);
|
||
Assert.Equal ("jump between text fields.", _textView.SelectedText);
|
||
|
||
break;
|
||
case 5:
|
||
Assert.Equal (4, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (32, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (28, _textView.SelectedLength);
|
||
Assert.Equal ("to jump between text fields.", _textView.SelectedText);
|
||
|
||
break;
|
||
case 6:
|
||
Assert.Equal (0, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (32, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (32, _textView.SelectedLength);
|
||
Assert.Equal ("TAB to jump between text fields.", _textView.SelectedText);
|
||
|
||
break;
|
||
}
|
||
|
||
iteration++;
|
||
}
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void
|
||
WordBackward_With_The_Same_Values_For_SelectedStart_And_CursorPosition_And_Not_Starting_At_Beginning_Of_The_Text ()
|
||
{
|
||
_textView.CursorPosition = new (10, 0);
|
||
_textView.SelectionStartColumn = 10;
|
||
_textView.SelectionStartRow = 0;
|
||
var iteration = 0;
|
||
|
||
while (_textView.CursorPosition.X > 0)
|
||
{
|
||
_textView.NewKeyDownEvent (Key.CursorLeft.WithCtrl.WithShift);
|
||
|
||
switch (iteration)
|
||
{
|
||
case 0:
|
||
Assert.Equal (7, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (10, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (3, _textView.SelectedLength);
|
||
Assert.Equal ("jum", _textView.SelectedText);
|
||
|
||
break;
|
||
case 1:
|
||
Assert.Equal (4, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (10, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (6, _textView.SelectedLength);
|
||
Assert.Equal ("to jum", _textView.SelectedText);
|
||
|
||
break;
|
||
case 2:
|
||
Assert.Equal (0, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (10, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (10, _textView.SelectedLength);
|
||
Assert.Equal ("TAB to jum", _textView.SelectedText);
|
||
|
||
break;
|
||
}
|
||
|
||
iteration++;
|
||
}
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void WordForward_Multiline_With_Selection ()
|
||
{
|
||
// 1 2 3 4
|
||
// 01234567890123456789012 34567890123456789012345678-Length
|
||
// 1 2 1 2
|
||
// 01234567890123456789012 0123456789012345678901234
|
||
_textView.Text = "This is the first line.\nThis is the second line.";
|
||
|
||
_textView.SelectionStartColumn = _textView.CurrentColumn;
|
||
_textView.SelectionStartRow = _textView.CurrentRow;
|
||
var iteration = 0;
|
||
var iterationsFinished = false;
|
||
|
||
while (!iterationsFinished)
|
||
{
|
||
_textView.NewKeyDownEvent (
|
||
Key.CursorRight.WithCtrl.WithShift
|
||
);
|
||
|
||
switch (iteration)
|
||
{
|
||
case 0:
|
||
Assert.Equal (5, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (5, _textView.SelectedLength);
|
||
Assert.Equal ("This ", _textView.SelectedText);
|
||
|
||
break;
|
||
case 1:
|
||
Assert.Equal (8, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (8, _textView.SelectedLength);
|
||
Assert.Equal ("This is ", _textView.SelectedText);
|
||
|
||
break;
|
||
case 2:
|
||
Assert.Equal (12, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (12, _textView.SelectedLength);
|
||
Assert.Equal ("This is the ", _textView.SelectedText);
|
||
|
||
break;
|
||
case 3:
|
||
Assert.Equal (18, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (18, _textView.SelectedLength);
|
||
Assert.Equal ("This is the first ", _textView.SelectedText);
|
||
|
||
break;
|
||
case 4:
|
||
Assert.Equal (22, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (22, _textView.SelectedLength);
|
||
Assert.Equal ("This is the first line", _textView.SelectedText);
|
||
|
||
break;
|
||
case 5:
|
||
Assert.Equal (23, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (23, _textView.SelectedLength);
|
||
Assert.Equal ("This is the first line.", _textView.SelectedText);
|
||
|
||
break;
|
||
case 6:
|
||
Assert.Equal (0, _textView.CursorPosition.X);
|
||
Assert.Equal (1, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (23 + Environment.NewLine.Length, _textView.SelectedLength);
|
||
Assert.Equal ($"This is the first line.{Environment.NewLine}", _textView.SelectedText);
|
||
|
||
break;
|
||
case 7:
|
||
Assert.Equal (5, _textView.CursorPosition.X);
|
||
Assert.Equal (1, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (28 + Environment.NewLine.Length, _textView.SelectedLength);
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This ",
|
||
_textView.SelectedText
|
||
);
|
||
|
||
break;
|
||
case 8:
|
||
Assert.Equal (8, _textView.CursorPosition.X);
|
||
Assert.Equal (1, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (31 + Environment.NewLine.Length, _textView.SelectedLength);
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is ",
|
||
_textView.SelectedText
|
||
);
|
||
|
||
break;
|
||
case 9:
|
||
Assert.Equal (12, _textView.CursorPosition.X);
|
||
Assert.Equal (1, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (35 + Environment.NewLine.Length, _textView.SelectedLength);
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the ",
|
||
_textView.SelectedText
|
||
);
|
||
|
||
break;
|
||
case 10:
|
||
Assert.Equal (19, _textView.CursorPosition.X);
|
||
Assert.Equal (1, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (42 + Environment.NewLine.Length, _textView.SelectedLength);
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second ",
|
||
_textView.SelectedText
|
||
);
|
||
|
||
break;
|
||
case 11:
|
||
Assert.Equal (23, _textView.CursorPosition.X);
|
||
Assert.Equal (1, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (46 + Environment.NewLine.Length, _textView.SelectedLength);
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line",
|
||
_textView.SelectedText
|
||
);
|
||
|
||
break;
|
||
case 12:
|
||
Assert.Equal (24, _textView.CursorPosition.X);
|
||
Assert.Equal (1, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (47 + Environment.NewLine.Length, _textView.SelectedLength);
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.",
|
||
_textView.SelectedText
|
||
);
|
||
|
||
break;
|
||
default:
|
||
iterationsFinished = true;
|
||
|
||
break;
|
||
}
|
||
|
||
iteration++;
|
||
}
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void WordForward_With_No_Selection ()
|
||
{
|
||
_textView.CursorPosition = Point.Empty;
|
||
var iteration = 0;
|
||
|
||
while (_textView.CursorPosition.X < _textView.Text.Length)
|
||
{
|
||
_textView.NewKeyDownEvent (Key.CursorRight.WithCtrl);
|
||
|
||
switch (iteration)
|
||
{
|
||
case 0:
|
||
Assert.Equal (4, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
|
||
break;
|
||
case 1:
|
||
Assert.Equal (7, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
|
||
break;
|
||
case 2:
|
||
Assert.Equal (12, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
|
||
break;
|
||
case 3:
|
||
Assert.Equal (20, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
|
||
break;
|
||
case 4:
|
||
Assert.Equal (25, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
|
||
break;
|
||
case 5:
|
||
Assert.Equal (31, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
|
||
break;
|
||
case 6:
|
||
Assert.Equal (32, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
|
||
break;
|
||
}
|
||
|
||
iteration++;
|
||
}
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void WordForward_With_No_Selection_And_With_More_Than_Only_One_Whitespace_And_With_Only_One_Letter ()
|
||
{
|
||
// 1 2 3 4 5
|
||
// 0123456789012345678901234567890123456789012345678901234=55 (Length)
|
||
_textView.Text = "TAB t o jump b etween t ext f ields .";
|
||
_textView.CursorPosition = Point.Empty;
|
||
var iteration = 0;
|
||
|
||
while (_textView.CursorPosition.X < _textView.Text.Length)
|
||
{
|
||
_textView.NewKeyDownEvent (Key.CursorRight.WithCtrl);
|
||
|
||
switch (iteration)
|
||
{
|
||
case 0:
|
||
Assert.Equal (6, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
|
||
break;
|
||
case 1:
|
||
Assert.Equal (9, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
|
||
break;
|
||
case 2:
|
||
Assert.Equal (12, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
|
||
break;
|
||
case 3:
|
||
Assert.Equal (25, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
|
||
break;
|
||
case 4:
|
||
Assert.Equal (28, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
|
||
break;
|
||
case 5:
|
||
Assert.Equal (38, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
|
||
break;
|
||
case 6:
|
||
Assert.Equal (40, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
|
||
break;
|
||
case 7:
|
||
Assert.Equal (46, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
|
||
break;
|
||
case 8:
|
||
Assert.Equal (48, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
|
||
break;
|
||
case 9:
|
||
Assert.Equal (54, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
|
||
break;
|
||
case 10:
|
||
Assert.Equal (55, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.Equal ("", _textView.SelectedText);
|
||
|
||
break;
|
||
}
|
||
|
||
iteration++;
|
||
}
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void WordForward_With_Selection ()
|
||
{
|
||
_textView.CursorPosition = Point.Empty;
|
||
_textView.SelectionStartColumn = 0;
|
||
_textView.SelectionStartRow = 0;
|
||
var iteration = 0;
|
||
|
||
while (_textView.CursorPosition.X < _textView.Text.Length)
|
||
{
|
||
_textView.NewKeyDownEvent (
|
||
Key.CursorRight.WithCtrl.WithShift
|
||
);
|
||
|
||
switch (iteration)
|
||
{
|
||
case 0:
|
||
Assert.Equal (4, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (4, _textView.SelectedLength);
|
||
Assert.Equal ("TAB ", _textView.SelectedText);
|
||
|
||
break;
|
||
case 1:
|
||
Assert.Equal (7, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (7, _textView.SelectedLength);
|
||
Assert.Equal ("TAB to ", _textView.SelectedText);
|
||
|
||
break;
|
||
case 2:
|
||
Assert.Equal (12, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (12, _textView.SelectedLength);
|
||
Assert.Equal ("TAB to jump ", _textView.SelectedText);
|
||
|
||
break;
|
||
case 3:
|
||
Assert.Equal (20, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (20, _textView.SelectedLength);
|
||
Assert.Equal ("TAB to jump between ", _textView.SelectedText);
|
||
|
||
break;
|
||
case 4:
|
||
Assert.Equal (25, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (25, _textView.SelectedLength);
|
||
Assert.Equal ("TAB to jump between text ", _textView.SelectedText);
|
||
|
||
break;
|
||
case 5:
|
||
Assert.Equal (31, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (31, _textView.SelectedLength);
|
||
Assert.Equal ("TAB to jump between text fields", _textView.SelectedText);
|
||
|
||
break;
|
||
case 6:
|
||
Assert.Equal (32, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (32, _textView.SelectedLength);
|
||
Assert.Equal ("TAB to jump between text fields.", _textView.SelectedText);
|
||
|
||
break;
|
||
}
|
||
|
||
iteration++;
|
||
}
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void
|
||
WordForward_With_The_Same_Values_For_SelectedStart_And_CursorPosition_And_Not_Starting_At_Beginning_Of_The_Text ()
|
||
{
|
||
_textView.CursorPosition = new (10, 0);
|
||
_textView.SelectionStartColumn = 10;
|
||
_textView.SelectionStartRow = 0;
|
||
var iteration = 0;
|
||
|
||
while (_textView.CursorPosition.X < _textView.Text.Length)
|
||
{
|
||
_textView.NewKeyDownEvent (
|
||
Key.CursorRight.WithCtrl.WithShift
|
||
);
|
||
|
||
switch (iteration)
|
||
{
|
||
case 0:
|
||
Assert.Equal (12, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (10, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (2, _textView.SelectedLength);
|
||
Assert.Equal ("p ", _textView.SelectedText);
|
||
|
||
break;
|
||
case 1:
|
||
Assert.Equal (20, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (10, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (10, _textView.SelectedLength);
|
||
Assert.Equal ("p between ", _textView.SelectedText);
|
||
|
||
break;
|
||
case 2:
|
||
Assert.Equal (25, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (10, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (15, _textView.SelectedLength);
|
||
Assert.Equal ("p between text ", _textView.SelectedText);
|
||
|
||
break;
|
||
case 3:
|
||
Assert.Equal (31, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (10, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (21, _textView.SelectedLength);
|
||
Assert.Equal ("p between text fields", _textView.SelectedText);
|
||
|
||
break;
|
||
case 4:
|
||
Assert.Equal (32, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (10, _textView.SelectionStartColumn);
|
||
Assert.Equal (0, _textView.SelectionStartRow);
|
||
Assert.Equal (22, _textView.SelectedLength);
|
||
Assert.Equal ("p between text fields.", _textView.SelectedText);
|
||
|
||
break;
|
||
}
|
||
|
||
iteration++;
|
||
}
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void WordWrap_Deleting_Backwards ()
|
||
{
|
||
var tv = new TextView { Width = 5, Height = 2, WordWrap = true, Text = "aaaa" };
|
||
var top = new Toplevel ();
|
||
top.Add (tv);
|
||
Application.Begin (top);
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.Equal (0, tv.LeftColumn);
|
||
|
||
DriverAssert.AssertDriverContentsAre (
|
||
@"
|
||
aaaa
|
||
",
|
||
_output
|
||
);
|
||
|
||
tv.CursorPosition = new (5, 0);
|
||
Assert.True (tv.NewKeyDownEvent (Key.Backspace));
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
Assert.Equal (0, tv.LeftColumn);
|
||
|
||
DriverAssert.AssertDriverContentsAre (
|
||
@"
|
||
aaa
|
||
",
|
||
_output
|
||
);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Backspace));
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
Assert.Equal (0, tv.LeftColumn);
|
||
|
||
DriverAssert.AssertDriverContentsAre (
|
||
@"
|
||
aa
|
||
",
|
||
_output
|
||
);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Backspace));
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
Assert.Equal (0, tv.LeftColumn);
|
||
|
||
DriverAssert.AssertDriverContentsAre (
|
||
@"
|
||
a
|
||
",
|
||
_output
|
||
);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Backspace));
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
Assert.Equal (0, tv.LeftColumn);
|
||
|
||
DriverAssert.AssertDriverContentsAre (
|
||
@"
|
||
|
||
",
|
||
_output
|
||
);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Backspace));
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
Assert.Equal (0, tv.LeftColumn);
|
||
|
||
DriverAssert.AssertDriverContentsAre (
|
||
@"
|
||
|
||
",
|
||
_output
|
||
);
|
||
top.Dispose ();
|
||
}
|
||
|
||
[Theory]
|
||
[TextViewTestsSetupFakeApplication]
|
||
[InlineData (KeyCode.Delete)]
|
||
public void WordWrap_Draw_Typed_Keys_After_Text_Is_Deleted (KeyCode del)
|
||
{
|
||
var top = new Toplevel ();
|
||
top.Add (_textView);
|
||
_textView.Text = "Line 1.\nLine 2.";
|
||
_textView.WordWrap = true;
|
||
Application.Begin (top);
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
|
||
Assert.True (_textView.WordWrap);
|
||
|
||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||
@"
|
||
Line 1.
|
||
Line 2.",
|
||
_output
|
||
);
|
||
|
||
Assert.True (_textView.NewKeyDownEvent (Key.End.WithShift));
|
||
Assert.Equal ("Line 1.", _textView.SelectedText);
|
||
|
||
Assert.True (_textView.NewKeyDownEvent (new (del)));
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
DriverAssert.AssertDriverContentsWithFrameAre ("Line 2.", _output);
|
||
|
||
Assert.True (_textView.NewKeyDownEvent (Key.H.WithShift));
|
||
Assert.NotEqual (Rectangle.Empty, _textView.NeedsDrawRect);
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
|
||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||
@"
|
||
H
|
||
Line 2.",
|
||
_output
|
||
);
|
||
top.Dispose ();
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void WordWrap_Not_Throw_If_Width_Is_Less_Than_Zero ()
|
||
{
|
||
Exception exception = Record.Exception (
|
||
() =>
|
||
{
|
||
var tv = new TextView
|
||
{
|
||
Width = Dim.Fill (),
|
||
Height = Dim.Fill (),
|
||
WordWrap = true,
|
||
Text = "これは、左右のクリップ境界をテストするための非常に長いテキストです。"
|
||
};
|
||
}
|
||
);
|
||
Assert.Null (exception);
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void WordWrap_ReadOnly_CursorPosition_SelectedText_Copy ()
|
||
{
|
||
// 0123456789
|
||
var text = "This is the first line.\nThis is the second line.\n";
|
||
var tv = new TextView
|
||
{
|
||
Width = 11,
|
||
Height = 9,
|
||
App = ApplicationImpl.Instance
|
||
};
|
||
tv.Text = text;
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}",
|
||
tv.Text
|
||
);
|
||
tv.WordWrap = true;
|
||
|
||
var top = new Toplevel ()
|
||
{
|
||
Driver = ApplicationImpl.Instance.Driver,
|
||
};
|
||
top.Add (tv);
|
||
top.Layout ();
|
||
tv.Draw ();
|
||
|
||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||
@"
|
||
This is
|
||
the first
|
||
line.
|
||
This is
|
||
the
|
||
second
|
||
line.
|
||
",
|
||
_output
|
||
);
|
||
|
||
tv.ReadOnly = true;
|
||
tv.CursorPosition = new (6, 2);
|
||
Assert.Equal (new (5, 2), tv.CursorPosition);
|
||
top.LayoutSubViews ();
|
||
top.SetClipToScreen ();
|
||
tv.Draw ();
|
||
|
||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||
@"
|
||
This is
|
||
the first
|
||
line.
|
||
This is
|
||
the second
|
||
line.
|
||
",
|
||
_output
|
||
);
|
||
|
||
tv.SelectionStartRow = 0;
|
||
tv.SelectionStartColumn = 0;
|
||
Assert.Equal ("This is the first line.", tv.SelectedText);
|
||
|
||
tv.Copy ();
|
||
Assert.Equal ("This is the first line.", Clipboard.Contents);
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void WordWrap_True_LoadStream_New_Text ()
|
||
{
|
||
Assert.Equal ("TAB to jump between text fields.", _textView.Text);
|
||
_textView.WordWrap = true;
|
||
Assert.Equal ("TAB to jump between text fields.", _textView.Text);
|
||
var text = "This is the first line.\nThis is the second line.\n";
|
||
|
||
using (var stream = new MemoryStream ())
|
||
{
|
||
var writer = new StreamWriter (stream);
|
||
writer.Write (text);
|
||
writer.Flush ();
|
||
stream.Position = 0;
|
||
|
||
_textView.Load (stream);
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}",
|
||
_textView.Text
|
||
);
|
||
Assert.True (_textView.WordWrap);
|
||
}
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void WordWrap_WrapModel_Output ()
|
||
{
|
||
// 0123456789
|
||
var text = "This is the first line.\nThis is the second line.\n";
|
||
var tv = new TextView { Width = 10, Height = 10 };
|
||
tv.Text = text;
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}",
|
||
tv.Text
|
||
);
|
||
tv.WordWrap = true;
|
||
|
||
var top = new Toplevel ()
|
||
{
|
||
Driver = ApplicationImpl.Instance.Driver,
|
||
};
|
||
top.Add (tv);
|
||
|
||
top.Layout ();
|
||
tv.Draw ();
|
||
|
||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||
@"
|
||
This is
|
||
the
|
||
first
|
||
line.
|
||
This is
|
||
the
|
||
second
|
||
line.
|
||
",
|
||
_output
|
||
);
|
||
}
|
||
|
||
private int GetLeftCol (int start)
|
||
{
|
||
string [] lines = _textView.Text.Split (Environment.NewLine);
|
||
|
||
if (lines is { Length: 0 })
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
if (start == _textView.LeftColumn)
|
||
{
|
||
return start;
|
||
}
|
||
|
||
if (_textView.LeftColumn == _textView.CurrentColumn)
|
||
{
|
||
return _textView.CurrentColumn;
|
||
}
|
||
|
||
int cCol = _textView.CurrentColumn;
|
||
string line = lines [_textView.CurrentRow];
|
||
int lCount = cCol > line.Length - 1 ? line.Length - 1 : cCol;
|
||
int width = _textView.Frame.Width;
|
||
int tabWidth = _textView.TabWidth;
|
||
var sumLength = 0;
|
||
var col = 0;
|
||
|
||
for (int i = lCount; i >= 0; i--)
|
||
{
|
||
char r = line [i];
|
||
sumLength += ((Rune)r).GetColumns ();
|
||
|
||
if (r == '\t')
|
||
{
|
||
sumLength += tabWidth + 1;
|
||
}
|
||
|
||
if (sumLength > width)
|
||
{
|
||
if (col + width == cCol)
|
||
{
|
||
col++;
|
||
}
|
||
|
||
break;
|
||
}
|
||
|
||
if ((cCol < line.Length && col > 0 && start < cCol && col == start) || cCol - col == width - 1)
|
||
{
|
||
break;
|
||
}
|
||
|
||
col = i;
|
||
}
|
||
|
||
return col;
|
||
}
|
||
|
||
// This class enables test functions annotated with the [InitShutdown] attribute
|
||
// to have a function called before the test function is called and after.
|
||
//
|
||
// This is necessary because a) Application is a singleton and Init/Shutdown must be called
|
||
// as a pair, and b) all unit test functions should be atomic.
|
||
[AttributeUsage (AttributeTargets.Class | AttributeTargets.Method)]
|
||
public class TextViewTestsSetupFakeApplication : SetupFakeApplicationAttribute
|
||
{
|
||
public static string Txt = "TAB to jump between text fields.";
|
||
|
||
public TextViewTestsSetupFakeApplication () : base () { }
|
||
|
||
public override void After (MethodInfo methodUnderTest)
|
||
{
|
||
_textView = null;
|
||
base.After (methodUnderTest);
|
||
}
|
||
|
||
public override void Before (MethodInfo methodUnderTest)
|
||
{
|
||
base.Before (methodUnderTest);
|
||
|
||
// 1 2 3
|
||
// 01234567890123456789012345678901=32 (Length)
|
||
byte [] buff = Encoding.Unicode.GetBytes (Txt);
|
||
byte [] ms = new MemoryStream (buff).ToArray ();
|
||
_textView = new ()
|
||
{
|
||
App = ApplicationImpl.Instance,
|
||
Width = 30, Height = 10, SchemeName = "Base"
|
||
};
|
||
_textView.Text = Encoding.Unicode.GetString (ms);
|
||
}
|
||
}
|
||
|
||
[Fact]
|
||
[SetupFakeApplication]
|
||
public void Draw_Esc_Rune ()
|
||
{
|
||
var tv = new TextView
|
||
{
|
||
Driver = ApplicationImpl.Instance.Driver,
|
||
Width = 5, Height = 1, Text = "\u001b"
|
||
};
|
||
tv.BeginInit ();
|
||
tv.EndInit ();
|
||
tv.Draw ();
|
||
|
||
DriverAssert.AssertDriverContentsWithFrameAre ("\u241b", _output);
|
||
|
||
tv.Dispose ();
|
||
}
|
||
|
||
[Fact (Skip = "v2 fake driver broke. TextView still works; disabling tests.")]
|
||
[SetupFakeApplication]
|
||
public void CellEventArgs_WordWrap_True ()
|
||
{
|
||
var eventCount = 0;
|
||
|
||
List<List<Cell>> text =
|
||
[
|
||
Cell.ToCells (
|
||
"This is the first line.".ToStringList ()
|
||
),
|
||
|
||
Cell.ToCells (
|
||
"This is the second line.".ToStringList ()
|
||
)
|
||
];
|
||
TextView tv = CreateTextView ();
|
||
tv.DrawNormalColor += TextView_DrawColor;
|
||
tv.DrawReadOnlyColor += TextView_DrawColor;
|
||
tv.DrawSelectionColor += TextView_DrawColor;
|
||
tv.DrawUsedColor += TextView_DrawColor;
|
||
|
||
void TextView_DrawColor (object sender, CellEventArgs e)
|
||
{
|
||
Assert.Equal (e.Line [e.Col], text [e.UnwrappedPosition.Row] [e.UnwrappedPosition.Col]);
|
||
eventCount++;
|
||
}
|
||
|
||
tv.Text = $"{Cell.ToString (text [0])}\n{Cell.ToString (text [1])}\n";
|
||
Assert.False (tv.WordWrap);
|
||
var top = new Toplevel ();
|
||
top.Add (tv);
|
||
Application.Begin (top);
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
|
||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||
@"
|
||
This is the first line.
|
||
This is the second line.",
|
||
_output
|
||
);
|
||
|
||
tv.Width = 10;
|
||
tv.Height = 25;
|
||
tv.WordWrap = true;
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
|
||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||
@"
|
||
This is
|
||
the
|
||
first
|
||
line.
|
||
This is
|
||
the
|
||
second
|
||
line. ",
|
||
_output
|
||
);
|
||
|
||
Assert.Equal (eventCount, (text [0].Count + text [1].Count) * 2);
|
||
top.Dispose ();
|
||
}
|
||
|
||
// BUGBUG: This test depends on the order of the schemes in SchemeManager.Schemes.
|
||
// BUGBUG: Breaks on Mac/Linux?
|
||
[Fact (Skip = "This test depends on the order of the schemes in SchemeManager.Schemes.")]
|
||
[SetupFakeApplication]
|
||
public void Cell_LoadCells_InheritsPreviousAttribute ()
|
||
{
|
||
List<Cell> cells = [];
|
||
|
||
foreach (KeyValuePair<string, Scheme> color in SchemeManager.GetSchemes ())
|
||
{
|
||
string csName = color.Key;
|
||
|
||
cells.AddRange (Cell.ToCellList (csName, color.Value.Normal));
|
||
|
||
cells.Add (new () { Grapheme = "\n", Attribute = color.Value.Focus });
|
||
}
|
||
|
||
TextView tv = CreateTextView ();
|
||
tv.Load (cells);
|
||
var top = new Toplevel ();
|
||
top.Add (tv);
|
||
SessionToken rs = Application.Begin (top);
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
|
||
Assert.True (tv.InheritsPreviousAttribute);
|
||
|
||
var expectedText = @"
|
||
TopLevel
|
||
Base
|
||
Dialog
|
||
Menu
|
||
Error ";
|
||
DriverAssert.AssertDriverContentsWithFrameAre (expectedText, _output);
|
||
|
||
Attribute [] attributes =
|
||
{
|
||
// 0
|
||
SchemeManager.GetSchemes () ["TopLevel"].Normal,
|
||
|
||
// 1
|
||
SchemeManager.GetSchemes () ["Base"].Normal,
|
||
|
||
// 2
|
||
SchemeManager.GetSchemes () ["Dialog"].Normal,
|
||
|
||
// 3
|
||
SchemeManager.GetSchemes () ["Menu"].Normal,
|
||
|
||
// 4
|
||
SchemeManager.GetSchemes () ["Error"].Normal,
|
||
|
||
// 5
|
||
tv.GetScheme ()!.Focus
|
||
};
|
||
|
||
var expectedColor = @"
|
||
0000000055
|
||
1111555555
|
||
2222225555
|
||
3333555555
|
||
4444455555";
|
||
DriverAssert.AssertDriverAttributesAre (expectedColor, _output, Application.Driver, attributes);
|
||
|
||
tv.WordWrap = true;
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
DriverAssert.AssertDriverContentsWithFrameAre (expectedText, _output);
|
||
DriverAssert.AssertDriverAttributesAre (expectedColor, _output, Application.Driver, attributes);
|
||
|
||
tv.CursorPosition = new (6, 2);
|
||
tv.SelectionStartColumn = 0;
|
||
tv.SelectionStartRow = 0;
|
||
Assert.Equal ($"TopLevel{Environment.NewLine}Base{Environment.NewLine}Dialog", tv.SelectedText);
|
||
tv.Copy ();
|
||
tv.IsSelecting = false;
|
||
tv.CursorPosition = new (2, 4);
|
||
tv.Paste ();
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
|
||
expectedText = @"
|
||
TopLevel
|
||
Base
|
||
Dialog
|
||
Menu
|
||
ErTopLevel
|
||
Base
|
||
Dialogror ";
|
||
DriverAssert.AssertDriverContentsWithFrameAre (expectedText, _output);
|
||
|
||
expectedColor = @"
|
||
0000000055
|
||
1111555555
|
||
2222225555
|
||
3333555555
|
||
4400000000
|
||
1111555555
|
||
2222224445";
|
||
DriverAssert.AssertDriverAttributesAre (expectedColor, _output, Application.Driver, attributes);
|
||
|
||
tv.Undo ();
|
||
tv.CursorPosition = new (0, 3);
|
||
tv.SelectionStartColumn = 0;
|
||
tv.SelectionStartRow = 0;
|
||
|
||
Assert.Equal (
|
||
$"TopLevel{Environment.NewLine}Base{Environment.NewLine}Dialog{Environment.NewLine}",
|
||
tv.SelectedText
|
||
);
|
||
tv.Copy ();
|
||
tv.IsSelecting = false;
|
||
tv.CursorPosition = new (2, 4);
|
||
tv.Paste ();
|
||
SetupFakeApplicationAttribute.RunIteration ();
|
||
|
||
expectedText = @"
|
||
TopLevel
|
||
Base
|
||
Dialog
|
||
Menu
|
||
ErTopLevel
|
||
Base
|
||
Dialog
|
||
ror ";
|
||
DriverAssert.AssertDriverContentsWithFrameAre (expectedText, _output);
|
||
|
||
expectedColor = @"
|
||
0000000055
|
||
1111555555
|
||
2222225555
|
||
3333555555
|
||
4400000000
|
||
1111555555
|
||
2222225555
|
||
4445555555";
|
||
DriverAssert.AssertDriverAttributesAre (expectedColor, _output, Application.Driver, attributes);
|
||
|
||
Application.End (rs);
|
||
top.Dispose ();
|
||
}
|
||
|
||
[Fact]
|
||
[TextViewTestsSetupFakeApplication]
|
||
public void IsSelecting_False_If_SelectedLength_Is_Zero_On_Mouse_Click ()
|
||
{
|
||
_textView.Text = "This is the first line.";
|
||
var top = new Toplevel ();
|
||
top.Add (_textView);
|
||
Application.Begin (top);
|
||
|
||
Application.RaiseMouseEvent (new () { ScreenPosition = new (22, 0), Flags = MouseFlags.Button1Pressed });
|
||
Assert.Equal (22, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.True (_textView.IsSelecting);
|
||
|
||
Application.RaiseMouseEvent (new () { ScreenPosition = new (22, 0), Flags = MouseFlags.Button1Released });
|
||
Assert.Equal (22, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.True (_textView.IsSelecting);
|
||
|
||
Application.RaiseMouseEvent (new () { ScreenPosition = new (22, 0), Flags = MouseFlags.Button1Clicked });
|
||
Assert.Equal (22, _textView.CursorPosition.X);
|
||
Assert.Equal (0, _textView.CursorPosition.Y);
|
||
Assert.Equal (0, _textView.SelectedLength);
|
||
Assert.False (_textView.IsSelecting);
|
||
|
||
top.Dispose ();
|
||
Application.Shutdown ();
|
||
}
|
||
|
||
private TextView CreateTextView () { return new () { Width = 30, Height = 10 }; }
|
||
}
|