mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
* WIP: Broken
* Got working. Mostly.
* Parllel tests pass
* More progres
* Fixed app tests.
* Mouse
* more progress.
* working on shortcut
* Shortcut accept on ENTER is broken.
* One left...
* More test progress.
* All unit tests pass. Still some issues though.
* tweak
* Fixed Integration Tests
* Fixed UI Catalog
* Tweaking CP to try to find race condition
* Refactor StandardColors and improve ColorPicker logic
Refactored `StandardColors` to use lazy initialization for static fields, improving performance and avoiding static constructor convoy effects. Introduced `NamesValueFactory` and `MapValueFactory` methods for encapsulated initialization logic.
Simplified `GetColorNames` to directly return `_names.Value`. Improved `TryParseColor` by clarifying default value usage and adopting object initializer syntax. Updated `TryNameColor` to use `_argbNameMap.Value`.
Refactored `GetArgb` for better readability. Replaced `MultiStandardColorNameResolver` with `StandardColorsNameResolver` in `ColorPicker`. Commented out `app.Init("Fake")` in `ColorPickerTests` for testing purposes.
Made minor formatting improvements, including updated comments and XML documentation for consistency.
* revert
* Throttle input loop to prevent CPU spinning
Introduce a 20ms delay in the input loop of `InputImpl<TInputRecord>`
to prevent excessive CPU usage when no input is available. Removed
the `DateTime dt = Now();` line and the `while (Peek())` block, which
previously enqueued input records.
This change improves resource management, especially in scenarios
where multiple `ApplicationImpl` instances are created in parallel
tests without calling `Shutdown()`. It prevents thread pool
exhaustion and ensures better performance in such cases.
* Refactor ApplicationImpl to use IDisposable pattern
Implemented the IDisposable pattern in ApplicationImpl to improve resource management. Added `Dispose` and `DisposeCore` methods, and marked the `Shutdown` method as obsolete, encouraging the use of `Dispose` or `using` statements instead. Updated the `IApplication` interface to inherit from IDisposable and added `GetResult` methods for retrieving run session results.
Refactored unit tests to adopt the new lifecycle management approach, replacing legacy `Shutdown` calls with `Dispose` or `using`. Removed fragile and obsolete tests, and re-enabled previously skipped tests after addressing underlying issues.
Updated `FakeApplicationLifecycle` and `SetupFakeApplicationAttribute` to align with the new disposal pattern. Improved documentation and examples to guide users toward modern usage patterns. Maintained backward compatibility for legacy singleton usage.
* Add IDisposable pattern with input loop throttling
- Add IDisposable to IApplication for proper resource cleanup
- Add 20ms throttle to input loop (prevents CPU spinning)
- Add Lazy<T> to StandardColors (eliminates convoy effect)
- Add MainLoopCoordinatorTests suite (5 new tests)
- Add Dispose() calls to all 16 ColorPickerTests
- Mark Application.Shutdown() as [Obsolete]
IApplication now requires Dispose() for cleanup
Performance: 100x CPU reduction, 15x faster disposal, tests complete in <5s
Fixes: Thread leaks, CPU saturation, test hangs in parallel execution
Docs: Updated application.md and newinv2.md with disposal patterns
* Refactor test for input loop throttling clarity
Updated `InputLoop_Throttle_Limits_Poll_Rate` test to improve clarity, reliability, and efficiency:
- Rewrote summary comment to clarify purpose and emphasize the 20ms throttle's role in preventing CPU spinning.
- Replaced `var` with explicit types for better readability.
- Reduced test duration from 1s to 500ms to improve test speed.
- Revised assertions:
- Replaced range-based assertion with upper-bound check to ensure poll count is below 500, avoiding timing sensitivity issues.
- Added assertion to verify the thread ran and was not immediately canceled.
- Added a 2-second timeout to `inputTask.Wait` and verified task completion.
- Improved comments to explain test behavior and reasoning behind changes.
* tweaks
* Fix nullabiltiy stuff.
* runnable fixes
* more nullabe
* More nullability
* warnings gone
* Fixed fluent test failure.
* Refactor ApplicationImpl and update Runnable layout logic
Refactored `ApplicationImpl.Run.cs` for improved readability and
atomicity:
- Combined `if (wasModal)` with `SessionStack?.TryPop` to streamline
logic.
- Simplified restoration of `previousRunnable` by reducing nesting.
- Updated comments for clarity and retained `SetIsModal` call.
Simplified focus-setting logic in `ApplicationImpl.Run.cs` using
pattern matching for `TopRunnableView`.
In `Runnable<TResult>`, added `SetNeedsLayout` after `IsModalChanged`
to ensure layout updates. Removed an unused empty line for cleanup.
Corrected namespace in `GetViewsUnderLocationForRootTests.cs` to
align with test structure.
* Update layout on modal state change
A call to `SetNeedsLayout()` was added to the `OnIsModalChanged`
method in the `Runnable` class. This ensures that the layout
is updated whenever the modal state changes.
* Increase test timeout for inputTask.Wait to 10 seconds
Extended the timeout duration for the `inputTask.Wait` method
from 4 seconds to 10 seconds in `MainLoopCoordinatorTests`.
This change ensures the test has a longer window to complete
under conditions of increased load or slower execution
environments, reducing the likelihood of false test failures.
* Refactor project files and simplify test logic
Removed `<LangVersion>` and `<ImplicitUsings>` properties from
`UnitTests.csproj` and `UnitTests.Parallelizable.csproj` to rely
on default SDK settings and disable implicit global usings.
Simplified the `SizeChanged_Event_Still_Fires_For_Compatibility`
test in `FakeDriverTests` by removing the `screenChangedFired`
variable, its associated event handler, and related assertions.
Also removed obsolete warning suppression directives as they
are no longer needed.
* Reduce UnitTestsParallelizable iterations from 10 to 3
Reduced the number of iterations for the UnitTestsParallelizable
test suite from 10 to 3 to save time and resources while still
exposing concurrency issues. Updated the loop and log messages
to reflect the new iteration count.
* disabled InputLoop_Throttle_Limits_Poll_Rate
* Refactor app lifecycle and improve Runnable API
Refactored `Program.cs` to simplify application lifecycle:
- Modularized app creation, initialization, and disposal.
- Improved result handling and ensured proper resource cleanup.
Re-implemented `Runnable<TResult>` with a cleaner design:
- Retained functionality while improving readability and structure.
- Added XML documentation and followed the Cancellable Work Pattern.
Re-implemented `RunnableWrapper<TView, TResult>`:
- Enabled wrapping any `View` to make it runnable with typed results.
- Added examples and remarks for better developer guidance.
Re-implemented `ViewRunnableExtensions`:
- Provided fluent API for making views runnable with or without results.
- Enhanced documentation with examples for common use cases.
General improvements:
- Enhanced code readability, maintainability, and error handling.
- Replaced redundant code with cleaner, more maintainable versions.
* Modernize codebase for Terminal.Gui and MVVM updates
Refactored `LoginView` to remove redundant `Application.LayoutAndDraw()`
call. Enhanced `LoginViewModel` with new observable properties for
automatic property change notifications. Updated `Message` class to use
nullable generics for improved type safety.
Replaced legacy `Application.Init()` and `Application.Run()` calls with
the modern `IApplication` API across `Program.cs`, `Example.cs`, and
`ReactiveExample`. Ensured proper disposal of `IApplication` instances
to prevent resource leaks.
Updated `TerminalScheduler` to integrate with `IApplication` for
invoking actions and managing timeouts. Added null checks and improved
timeout disposal logic for robustness.
Refactored `ExampleWindow` for better readability and alignment with
modern `Terminal.Gui` conventions. Cleaned up unused imports and
improved code clarity across the codebase.
Updated README.md to reflect the latest `Terminal.Gui` practices,
including examples of the `IApplication` API and automatic UI refresh
handling. Renamed `LoginAction` to `LoginActions` for consistency.
* Refactor: Transition to IRunnable-based architecture
Replaced `Toplevel` with `Window` as the primary top-level UI element. Introduced the `IRunnable` interface to modernize the architecture, enabling greater flexibility and testability. Deprecated the static `Application` class in favor of the instance-based `IApplication` model, which supports multiple application contexts.
Updated methods like `Application.Run()` and `Application.RequestStop()` to use `IRunnable`. Removed or replaced legacy `Modal` properties with `IsModal`. Enhanced the `IApplication` interface with a fluent API, including methods like `Run<TRunnable>()` and `GetResult<T>()`.
Refactored tests and examples to align with the new architecture. Updated documentation to reflect the instance-based model. Deprecated obsolete members and methods, including `Application.Current` and `Application.TopRunnable`.
Improved event handling by replacing the `Accept` event with `Accepting` and using `e.Handled` for event processing. Updated threading examples to use `App?.Invoke()` or `app.Invoke()` for UI updates. Cleaned up redundant code and redefined modal behavior for better consistency.
These changes modernize the `Terminal.Gui` library, improving clarity, usability, and maintainability while ensuring backward compatibility where possible.
* Refactor: Replace Toplevel with Runnable class
This commit introduces a major architectural update to the `Terminal.Gui` library, replacing the legacy `Toplevel` class with the new `Runnable` class. The changes span the entire codebase, including core functionality, tests, documentation, and configuration files.
- **Core Class Replacement**:
- Replaced `Toplevel` with `Runnable` as the base class for modal views and session management.
- Updated all references to `Toplevel` in the codebase, including constructors, methods, and properties.
- **Configuration Updates**:
- Updated `tui-config-schema.json` to reflect the new `Runnable` scheme.
- **New Classes**:
- Added `UICatalogRunnable` for managing the UI Catalog application.
- Introduced `Runnable<TResult>` as a generic base class for blocking sessions with result handling.
- **Documentation and Tests**:
- Updated documentation to emphasize `Runnable` and mark `Toplevel` as obsolete.
- Refactored test cases to use `Runnable` and ensure compatibility.
- **Behavioral Improvements**:
- Enhanced lifecycle management and alignment with the `IRunnable` interface.
- Improved clarity and consistency in naming conventions.
These changes modernize the library, improve flexibility, and provide a clearer architecture for developers.
* Refactor: Consolidate Runnable classes and decouple View from ApplicationImpl
- Made Runnable<TResult> inherit from Runnable (eliminating ~180 LOC duplication)
- Moved View init/layout/cursor logic from ApplicationImpl to Runnable lifecycle events
- ApplicationImpl.Begin now operates purely on IRunnable interface
Related to #4419
* Simplified the disposal logic in `ApplicationImpl.Run.cs` by replacing
the type-specific check for `View` with a more general check for
`IDisposable`. This ensures proper disposal of any `IDisposable`
object, improving robustness.
Removed the `FrameworkOwnedRunnable` property from the `ApplicationImpl`
class in `ApplicationImpl.cs` and the `IApplication` interface in
`IApplication.cs`. This eliminates the need to manage this property,
reducing complexity and improving maintainability.
Updated `application.md` to reflect the removal of the
`FrameworkOwnedRunnable` property, ensuring the documentation aligns
with the updated codebase.
* Replaces the legacy `Shutdown()` method with `Dispose()` to align
with the `IDisposable` pattern, ensuring proper resource cleanup
and simplifying the API. The `Dispose()` method is now the
recommended way to release resources, with `using` statements
encouraged for automatic disposal.
Key changes:
- Marked `Shutdown()` as obsolete; it now internally calls `Dispose()`.
- Updated the fluent API to remove `Shutdown()` from chaining.
- Enhanced session lifecycle management for thread safety.
- Updated tests to validate proper disposal and state reset.
- Improved `IRunnable` integration with automatic disposal for
framework-created runnables.
- Maintained backward compatibility for the legacy static
`Application` singleton.
- Refactored documentation and examples to reflect modern practices
and emphasize `Dispose()` usage.
These changes modernize the `Terminal.Gui` lifecycle, improve
testability, and encourage alignment with .NET conventions.
* Refactor runnable app context handling in ApplicationImpl
Refactor how the application context is set for `runnable` objects
by introducing a new `SetApp` method in the `IRunnable` interface.
This replaces the previous logic of directly setting the `App`
property for `View` objects, making the process more generic and
encapsulated within `IRunnable` implementations.
Simplify `Mouse.UngrabMouse()` by removing the conditional check
and calling it unconditionally.
Make a minor formatting adjustment in the generic constraint of
`Run<TRunnable>` in `ApplicationImpl`.
Add `SetApp(IApplication app)` to the `IRunnable` interface and
implement it in the `Runnable` class to set the `App` property
to the provided application instance.
* Improve docs, tests, and modularity across the codebase
Reorganized and updated `CONTRIBUTING.md`:
- Added **Key Architecture Concepts** section and reordered the table of contents.
- Updated testing requirements to discourage legacy patterns.
- Added instructions for replicating CI workflows locally.
- Clarified PR guidelines and coding style expectations.
Enhanced `README.md` with detailed CI/CD workflow documentation.
Refactored `ColorPicker.Prompt` to use `IApplication` for improved modularity and testability.
Introduced `IApplicationScreenChangedTests` for comprehensive testing of `ScreenChanged` events and `Screen` property.
Refactored `ApplicationScreenTests` and `TextView.PromptForColors` to align with modern patterns.
Updated `Terminal.sln` to include `.github/workflows/README.md`.
Performed general cleanup:
- Removed outdated documentation links.
- Improved XML documentation and coding consistency.
* readme tweaks
* Improve thread safety, layout, and test coverage
Refactored `OutputBufferImpl.cs` to enhance thread safety by locking shared resources and adding bounds checks for columns and rows. Improved handling of wide characters and removed outdated TODO comments.
Updated `Runnable.cs` to call `SetNeedsDraw()` on modal state changes, ensuring proper layout and drawing updates. Simplified layout handling in `ApplicationImpl.Run.cs` by replacing redundant comments with a `LayoutAndDraw()` call.
Added a check in `AllViewsTester.cs` to skip creating instances of `RunnableWrapper` types with unsatisfiable generic constraints, logging a warning when encountered.
Enhanced `ListViewTests.cs` by adding explicit `app.LayoutAndDraw()` calls to validate visual output and ensure tests reflect the updated application state.
These changes improve robustness, prevent race conditions, and ensure consistent behavior across the application.
* Refactor: Rename Toplevel to Runnable and update logic
Updated the `Border` class to use `Command.Quit` instead of
`Command.QuitToplevel` in the `CloseButton.Accept` handler.
Renamed test methods in `GetViewsAtLocationTests.cs` to replace
"Toplevel" with "Runnable" for consistency. Updated `Runnable<bool>`
instances to use "topRunnable" as the `Id` property.
These changes align the codebase with updated naming conventions
and improve clarity.
* Removed `ToplevelTests` and migrated relevant test cases to
`MouseDragTests` with improved structure and coverage. Updated
tests to use `Application.Create`, `app.Begin`, and `app.End`
for better resource management and lifecycle handling.
Replaced direct event handling with `app.Mouse.RaiseMouseEvent`
to align with the application's event-handling mechanism. Added
`Runnable` objects to ensure views are properly initialized and
disposed of within the application context.
Enhanced tests to include assertions for minimum width and
height constraints during resize operations. Removed redundant
tests and streamlined logic to reduce duplication and improve
maintainability.
* Reorged Unit Test namespaces.
* more
* Refactor tests and update namespaces for consistency
Updated namespaces in `ArrangementTests.cs` and `MouseDragTests.cs` for better organization. Enhanced `ArrangementTests.cs` with additional checks for arrangement flags. Reformatted and re-added `MouseDragTests.cs` and `SchemeTests.cs` with modern C# features like nullable annotations and object initializers. Ensured no functional changes while improving code clarity and consistency.
* Fix nullability warnings in MouseDragTests.cs
Updated `app.End` calls to use the null-forgiving operator (`!`)
on `app.SessionStack` to ensure it is treated as non-null.
This change addresses potential nullability warnings and
improves code safety and clarity. Applied consistently across
all relevant test cases in the `MouseDragTests` class.
2410 lines
90 KiB
C#
2410 lines
90 KiB
C#
#nullable disable
|
||
using System.Text;
|
||
|
||
namespace ViewsTests;
|
||
|
||
public class TextViewTests
|
||
{
|
||
[Fact]
|
||
public void CloseFile_Throws_If_FilePath_Is_Null ()
|
||
{
|
||
var tv = new TextView ();
|
||
Assert.Throws<ArgumentNullException> (() => tv.CloseFile ());
|
||
}
|
||
|
||
[Fact]
|
||
public void ContentsChanged_Event_Fires_ClearHistoryChanges ()
|
||
{
|
||
var eventcount = 0;
|
||
|
||
var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
|
||
var tv = new TextView { Width = 50, Height = 10, Text = text };
|
||
tv.ContentsChanged += (s, e) => { eventcount++; };
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Enter));
|
||
|
||
Assert.Equal (
|
||
$"{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);
|
||
|
||
var expectedEventCount = 1; // for ENTER key
|
||
Assert.Equal (expectedEventCount, eventcount);
|
||
|
||
tv.ClearHistoryChanges ();
|
||
expectedEventCount = 2;
|
||
Assert.Equal (expectedEventCount, eventcount);
|
||
}
|
||
|
||
[Fact]
|
||
public void ContentsChanged_Event_Fires_LoadStream_By_Calling_HistoryText_Clear ()
|
||
{
|
||
var eventcount = 0;
|
||
|
||
var tv = new TextView { Width = 50, Height = 10 };
|
||
tv.ContentsChanged += (s, e) => { eventcount++; };
|
||
|
||
var text = "This is the first line.\r\nThis is the second line.\r\n";
|
||
tv.Load (new MemoryStream (Encoding.ASCII.GetBytes (text)));
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}",
|
||
tv.Text
|
||
);
|
||
|
||
Assert.Equal (1, eventcount);
|
||
}
|
||
|
||
[Fact]
|
||
public void ContentsChanged_Event_Fires_On_LoadFile_By_Calling_HistoryText_Clear ()
|
||
{
|
||
var eventcount = 0;
|
||
|
||
var tv = new TextView { Width = 50, Height = 10 };
|
||
tv.BeginInit ();
|
||
tv.EndInit ();
|
||
|
||
tv.ContentsChanged += (s, e) => { eventcount++; };
|
||
|
||
var fileName = "textview.txt";
|
||
File.WriteAllText (fileName, "This is the first line.\r\nThis is the second line.\r\n");
|
||
|
||
tv.Load (fileName);
|
||
Assert.Equal (1, eventcount);
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}",
|
||
tv.Text
|
||
);
|
||
}
|
||
|
||
[Fact]
|
||
public void GetRegion_StringFromRunes_Environment_NewLine ()
|
||
{
|
||
var tv = new TextView { Text = $"1{Environment.NewLine}2" };
|
||
|
||
Assert.Equal ($"1{Environment.NewLine}2", tv.Text);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
|
||
tv.SelectAll ();
|
||
Assert.Equal ($"1{Environment.NewLine}2", tv.Text);
|
||
Assert.Equal ($"1{Environment.NewLine}2", tv.SelectedText);
|
||
}
|
||
|
||
[Fact]
|
||
public void HistoryText_ClearHistoryChanges ()
|
||
{
|
||
var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
|
||
var tv = new TextView { Text = text };
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Enter));
|
||
|
||
Assert.Equal (
|
||
$"{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 (0, 1), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
Assert.True (tv.HasHistoryChanges);
|
||
|
||
tv.ClearHistoryChanges ();
|
||
|
||
Assert.Equal (
|
||
$"{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 (0, 1), tv.CursorPosition);
|
||
Assert.False (tv.IsDirty);
|
||
Assert.False (tv.HasHistoryChanges);
|
||
}
|
||
|
||
[Fact]
|
||
public void HistoryText_Exceptions ()
|
||
{
|
||
var ht = new HistoryText ();
|
||
|
||
foreach (object ls in Enum.GetValues (typeof (TextEditingLineStatus)))
|
||
{
|
||
if ((TextEditingLineStatus)ls != TextEditingLineStatus.Original)
|
||
{
|
||
Assert.Throws<ArgumentException> (
|
||
() => ht.Add (
|
||
new List<List<Cell>> (),
|
||
Point.Empty,
|
||
(TextEditingLineStatus)ls
|
||
)
|
||
);
|
||
}
|
||
}
|
||
|
||
Assert.Null (Record.Exception (() => ht.Add (new () { new () }, Point.Empty)));
|
||
}
|
||
|
||
[Fact]
|
||
public void HistoryText_IsDirty_HasHistoryChanges ()
|
||
{
|
||
var tv = new TextView ();
|
||
|
||
Assert.Equal ("", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.False (tv.IsDirty);
|
||
Assert.False (tv.HasHistoryChanges);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.D1));
|
||
Assert.Equal ("1", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (1, 0), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
Assert.True (tv.HasHistoryChanges);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Enter));
|
||
Assert.Equal ($"1{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
Assert.True (tv.HasHistoryChanges);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.D2));
|
||
Assert.Equal ($"1{Environment.NewLine}2", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (1, 1), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
Assert.True (tv.HasHistoryChanges);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Backspace));
|
||
Assert.Equal ($"1{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
Assert.True (tv.HasHistoryChanges);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Backspace));
|
||
Assert.Equal ("1", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (1, 0), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
Assert.True (tv.HasHistoryChanges);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Backspace));
|
||
Assert.Equal ("", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
// IsDirty cannot be based on HasHistoryChanges because HasHistoryChanges is greater than 0
|
||
// The only way is comparing from the original text
|
||
Assert.False (tv.IsDirty);
|
||
|
||
// Still true because HasHistoryChanges is greater than 0
|
||
Assert.True (tv.HasHistoryChanges);
|
||
}
|
||
|
||
[Fact]
|
||
public void HistoryText_Undo_Redo_Changing_On_Middle_Clear_History_Forwards ()
|
||
{
|
||
var tv = new TextView ();
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.D1));
|
||
Assert.Equal ("1", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (1, 0), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.D2));
|
||
Assert.Equal ("12", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (2, 0), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.D3));
|
||
Assert.Equal ("123", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (3, 0), tv.CursorPosition);
|
||
|
||
// Undo
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ("12", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (2, 0), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.D4));
|
||
Assert.Equal ("124", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (3, 0), tv.CursorPosition);
|
||
|
||
// Redo
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ("124", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (3, 0), tv.CursorPosition);
|
||
}
|
||
|
||
[Fact]
|
||
public void HistoryText_Undo_Redo_Disabled_On_WordWrap ()
|
||
{
|
||
var text = "This is the first line.\nThis is the second line.\nThis is the third line.\n";
|
||
var tv = new TextView { Width = 80, Height = 5, Text = text };
|
||
|
||
Assert.False (tv.WordWrap);
|
||
tv.WordWrap = true;
|
||
|
||
tv.SelectionStartColumn = 12;
|
||
tv.CursorPosition = new (12, 2);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Enter));
|
||
Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.A));
|
||
Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (1, 1), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (1, 1), tv.CursorPosition);
|
||
}
|
||
|
||
[Fact]
|
||
public void HistoryText_Undo_Redo_Ending_With_Newline_Multi_Line_Selected_Almost_All_Return_And_InsertText ()
|
||
{
|
||
var text = "This is the first line.\nThis is the second line.\nThis is the third line.\n";
|
||
var tv = new TextView { Text = text };
|
||
|
||
tv.SelectionStartColumn = 12;
|
||
tv.CursorPosition = new (12, 2);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Enter));
|
||
Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.A));
|
||
Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (1, 1), tv.CursorPosition);
|
||
|
||
// Undo
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
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.{Environment.NewLine}",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (4, tv.Lines);
|
||
Assert.Equal (new (12, 2), tv.CursorPosition);
|
||
Assert.False (tv.IsDirty);
|
||
|
||
// Redo
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (1, 1), tv.CursorPosition);
|
||
|
||
// Undo
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
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.{Environment.NewLine}",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (4, tv.Lines);
|
||
Assert.Equal (new (12, 2), tv.CursorPosition);
|
||
Assert.False (tv.IsDirty);
|
||
|
||
// Redo
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (1, 1), tv.CursorPosition);
|
||
}
|
||
|
||
[Fact]
|
||
public void HistoryText_Undo_Redo_First_Line_Selected_Return_And_InsertText ()
|
||
{
|
||
var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
|
||
var tv = new TextView { Text = text };
|
||
|
||
tv.SelectionStartColumn = 12;
|
||
tv.CursorPosition = new (17, 0);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Enter));
|
||
|
||
Assert.Equal (
|
||
$"This is the {Environment.NewLine} 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 (0, 1), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.A));
|
||
|
||
Assert.Equal (
|
||
$"This is the {Environment.NewLine}a 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 (1, 1), tv.CursorPosition);
|
||
|
||
// Undo
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the {Environment.NewLine} 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 (0, 1), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
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, 0), tv.CursorPosition);
|
||
Assert.False (tv.IsDirty);
|
||
|
||
// Redo
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the {Environment.NewLine} 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 (0, 1), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the {Environment.NewLine}a 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 (1, 1), tv.CursorPosition);
|
||
|
||
// Undo
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the {Environment.NewLine} 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 (0, 1), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
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, 0), tv.CursorPosition);
|
||
Assert.False (tv.IsDirty);
|
||
|
||
// Redo
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the {Environment.NewLine} 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 (0, 1), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the {Environment.NewLine}a 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 (1, 1), tv.CursorPosition);
|
||
}
|
||
|
||
[Fact]
|
||
public void HistoryText_Undo_Redo_KillWordBackward ()
|
||
{
|
||
var text = "First line.\nSecond line.";
|
||
var tv = new TextView { 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));
|
||
Assert.Equal ($"First line.{Environment.NewLine}Second line", tv.Text);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (11, 1), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl));
|
||
Assert.Equal ($"First line.{Environment.NewLine}Second ", tv.Text);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (7, 1), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl));
|
||
Assert.Equal ($"First line.{Environment.NewLine}", tv.Text);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl));
|
||
Assert.Equal ("First line.", tv.Text);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (11, 0), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl));
|
||
Assert.Equal ("First line", tv.Text);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (10, 0), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl));
|
||
Assert.Equal ("First ", tv.Text);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (6, 0), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl));
|
||
Assert.Equal ("", tv.Text);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
// Undo
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ("First ", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (6, 0), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ("First line", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (10, 0), tv.CursorPosition);
|
||
|
||
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 ", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (7, 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 (11, 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}Second line", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (11, 1), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"First line.{Environment.NewLine}Second ", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (7, 1), tv.CursorPosition);
|
||
|
||
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 ("First line", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (10, 0), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ("First ", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (6, 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]
|
||
public void HistoryText_Undo_Redo_KillWordForward ()
|
||
{
|
||
var text = "First line.\nSecond line.";
|
||
var tv = new TextView { Text = text };
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Delete.WithCtrl));
|
||
Assert.Equal ($"line.{Environment.NewLine}Second line.", tv.Text);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Delete.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.Delete.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.Delete.WithCtrl));
|
||
Assert.Equal ("Second line.", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Delete.WithCtrl));
|
||
Assert.Equal ("line.", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Delete.WithCtrl));
|
||
Assert.Equal (".", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Delete.WithCtrl));
|
||
Assert.Equal ("", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
// Undo
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal (".", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ("line.", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
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 ($".{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 ($"line.{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 ($"line.{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 ($".{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 ($"{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 ("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);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ("", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
}
|
||
|
||
[Fact]
|
||
public void HistoryText_Undo_Redo_Multi_Line_Selected_All_Return_And_InsertText ()
|
||
{
|
||
var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
|
||
var tv = new TextView { Text = text };
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.End.WithCtrl.WithShift));
|
||
|
||
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, 2), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Enter));
|
||
Assert.Equal ($"{Environment.NewLine}", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.A));
|
||
Assert.Equal ($"{Environment.NewLine}a", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (1, 1), tv.CursorPosition);
|
||
|
||
// Undo
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"{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 (
|
||
$"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, 2), tv.CursorPosition);
|
||
Assert.False (tv.IsDirty);
|
||
|
||
// Redo
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"{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 ($"{Environment.NewLine}a", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (1, 1), tv.CursorPosition);
|
||
|
||
// Undo
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"{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 (
|
||
$"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, 2), tv.CursorPosition);
|
||
Assert.False (tv.IsDirty);
|
||
|
||
// Redo
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"{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 ($"{Environment.NewLine}a", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (1, 1), tv.CursorPosition);
|
||
}
|
||
|
||
[Fact]
|
||
public void HistoryText_Undo_Redo_Multi_Line_Selected_DeleteCharLeft_All ()
|
||
{
|
||
var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
|
||
var tv = new TextView { Text = text };
|
||
|
||
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.IsDirty);
|
||
Assert.False (tv.HasHistoryChanges);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.End.WithCtrl.WithShift));
|
||
|
||
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 (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.SelectedText
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (23, 2), tv.CursorPosition);
|
||
Assert.Equal (70 + Environment.NewLine.Length * 2, tv.SelectedLength);
|
||
Assert.False (tv.IsDirty);
|
||
Assert.False (tv.HasHistoryChanges);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Backspace));
|
||
Assert.Equal ("", tv.Text);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
Assert.True (tv.HasHistoryChanges);
|
||
|
||
// 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 ("", tv.SelectedText);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (23, 2), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.False (tv.IsDirty);
|
||
Assert.True (tv.HasHistoryChanges);
|
||
|
||
// Redo
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ("", tv.Text);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
Assert.True (tv.HasHistoryChanges);
|
||
}
|
||
|
||
[Fact]
|
||
public void HistoryText_Undo_Redo_Multi_Line_Selected_DeleteCharRight_All ()
|
||
{
|
||
var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
|
||
var tv = new TextView { Text = text };
|
||
|
||
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.IsDirty);
|
||
Assert.False (tv.HasHistoryChanges);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.End.WithCtrl.WithShift));
|
||
|
||
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 (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.",
|
||
tv.SelectedText
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (23, 2), tv.CursorPosition);
|
||
Assert.Equal (70 + Environment.NewLine.Length * 2, tv.SelectedLength);
|
||
Assert.False (tv.IsDirty);
|
||
Assert.False (tv.HasHistoryChanges);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Delete));
|
||
Assert.Equal ("", tv.Text);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
Assert.True (tv.HasHistoryChanges);
|
||
|
||
// 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 ("", tv.SelectedText);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (23, 2), tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.False (tv.IsDirty);
|
||
Assert.True (tv.HasHistoryChanges);
|
||
|
||
// Redo
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ("", tv.Text);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.True (tv.IsDirty);
|
||
Assert.True (tv.HasHistoryChanges);
|
||
}
|
||
|
||
[Fact]
|
||
public void HistoryText_Undo_Redo_Multiline_Selected_Tab_BackTab ()
|
||
{
|
||
var text = "First line.\nSecond line.\nThird line.";
|
||
var tv = new TextView { Width = 80, Height = 5, Text = text };
|
||
|
||
tv.SelectionStartColumn = 6;
|
||
tv.CursorPosition = new (6, 2);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Tab));
|
||
Assert.Equal ("First \tline.", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (7, 0), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Tab.WithShift));
|
||
Assert.Equal ("First line.", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (6, 0), tv.CursorPosition);
|
||
|
||
// Undo
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ("First \tline.", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (7, 0), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (6, 2), tv.CursorPosition);
|
||
Assert.False (tv.IsDirty);
|
||
|
||
// Redo
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ("First \tline.", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (7, 0), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ("First line.", tv.Text);
|
||
Assert.Equal (1, tv.Lines);
|
||
Assert.Equal (new (6, 0), tv.CursorPosition);
|
||
}
|
||
|
||
[Fact]
|
||
public void HistoryText_Undo_Redo_Multiline_Simples_Tab_BackTab ()
|
||
{
|
||
var text = "First line.\nSecond line.\nThird line.";
|
||
var tv = new TextView { Width = 80, Height = 5, Text = text };
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Tab));
|
||
|
||
Assert.Equal (
|
||
$"\tFirst line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (1, 0), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Tab.WithShift));
|
||
Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
|
||
// Undo
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"\tFirst line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (1, 0), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.False (tv.IsDirty);
|
||
|
||
// Redo
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"\tFirst line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (1, 0), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
}
|
||
|
||
[Fact]
|
||
public void HistoryText_Undo_Redo_Single_Line_Selected_Return ()
|
||
{
|
||
var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
|
||
var tv = new TextView { Text = text };
|
||
|
||
tv.SelectionStartColumn = 12;
|
||
tv.CursorPosition = new (17, 0);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Enter));
|
||
|
||
Assert.Equal (
|
||
$"This is the {Environment.NewLine} 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 (0, 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 (17, 0), tv.CursorPosition);
|
||
Assert.False (tv.IsDirty);
|
||
|
||
// Redo
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the {Environment.NewLine} 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 (0, 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 (17, 0), tv.CursorPosition);
|
||
Assert.False (tv.IsDirty);
|
||
|
||
// Redo
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the {Environment.NewLine} 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 (0, 1), tv.CursorPosition);
|
||
}
|
||
|
||
[Fact]
|
||
public void HistoryText_Undo_Redo_Single_Second_Line_Selected_Return ()
|
||
{
|
||
var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
|
||
var tv = new TextView { Text = text };
|
||
|
||
tv.SelectionStartColumn = 12;
|
||
tv.SelectionStartRow = 1;
|
||
tv.CursorPosition = new (18, 1);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Enter));
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (4, tv.Lines);
|
||
Assert.Equal (new (0, 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);
|
||
Assert.False (tv.IsDirty);
|
||
|
||
// Redo
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (4, tv.Lines);
|
||
Assert.Equal (new (0, 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);
|
||
Assert.False (tv.IsDirty);
|
||
|
||
// Redo
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (4, tv.Lines);
|
||
Assert.Equal (new (0, 2), tv.CursorPosition);
|
||
}
|
||
|
||
[Fact]
|
||
public void HistoryText_Undo_Redo_Single_Second_Line_Selected_Return_And_InsertText ()
|
||
{
|
||
var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
|
||
var tv = new TextView { Text = text };
|
||
|
||
tv.SelectionStartColumn = 12;
|
||
tv.SelectionStartRow = 1;
|
||
tv.CursorPosition = new (18, 1);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Enter));
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (4, tv.Lines);
|
||
Assert.Equal (new (0, 2), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.A));
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the {Environment.NewLine}a line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (4, tv.Lines);
|
||
Assert.Equal (new (1, 2), tv.CursorPosition);
|
||
|
||
// Undo
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (4, tv.Lines);
|
||
Assert.Equal (new (0, 2), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
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);
|
||
Assert.False (tv.IsDirty);
|
||
|
||
// Redo
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (4, tv.Lines);
|
||
Assert.Equal (new (0, 2), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the {Environment.NewLine}a line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (4, tv.Lines);
|
||
Assert.Equal (new (1, 2), tv.CursorPosition);
|
||
|
||
// Undo
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (4, tv.Lines);
|
||
Assert.Equal (new (0, 2), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
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);
|
||
Assert.False (tv.IsDirty);
|
||
|
||
// Redo
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (4, tv.Lines);
|
||
Assert.Equal (new (0, 2), tv.CursorPosition);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the {Environment.NewLine}a line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (4, tv.Lines);
|
||
Assert.Equal (new (1, 2), tv.CursorPosition);
|
||
}
|
||
|
||
[Fact]
|
||
public void HistoryText_Undo_Redo_Three_Line_Selected_Return ()
|
||
{
|
||
var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
|
||
var tv = new TextView { Text = text };
|
||
|
||
tv.SelectionStartColumn = 12;
|
||
tv.CursorPosition = new (17, 2);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Enter));
|
||
Assert.Equal ($"This is the {Environment.NewLine} line.", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (0, 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 (17, 2), tv.CursorPosition);
|
||
Assert.False (tv.IsDirty);
|
||
|
||
// Redo
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"This is the {Environment.NewLine} line.", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (0, 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 (17, 2), tv.CursorPosition);
|
||
Assert.False (tv.IsDirty);
|
||
|
||
// Redo
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
Assert.Equal ($"This is the {Environment.NewLine} line.", tv.Text);
|
||
Assert.Equal (2, tv.Lines);
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
}
|
||
|
||
[Fact]
|
||
public void HistoryText_Undo_Redo_Two_Line_Selected_Return ()
|
||
{
|
||
var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
|
||
var tv = new TextView { Text = text };
|
||
|
||
tv.SelectionStartColumn = 12;
|
||
tv.CursorPosition = new (18, 1);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.Enter));
|
||
|
||
Assert.Equal (
|
||
$"This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (0, 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 (18, 1), tv.CursorPosition);
|
||
Assert.False (tv.IsDirty);
|
||
|
||
// Redo
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (0, 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 (18, 1), tv.CursorPosition);
|
||
Assert.False (tv.IsDirty);
|
||
|
||
// Redo
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
|
||
Assert.Equal (
|
||
$"This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.",
|
||
tv.Text
|
||
);
|
||
Assert.Equal (3, tv.Lines);
|
||
Assert.Equal (new (0, 1), tv.CursorPosition);
|
||
}
|
||
|
||
[Fact]
|
||
public void HistoryText_Undo_Redo_ApplyCellsAttribute ()
|
||
{
|
||
var text = "This is the first line.\nThis is the second line.\nThis is the third line.";
|
||
var tv = new TextView { Text = text };
|
||
|
||
tv.SelectionStartColumn = 12;
|
||
tv.CursorPosition = new (18, 1);
|
||
|
||
if (Environment.NewLine.Length == 2)
|
||
{
|
||
Assert.Equal (31, tv.SelectedLength);
|
||
}
|
||
else
|
||
{
|
||
Assert.Equal (30, tv.SelectedLength);
|
||
}
|
||
|
||
Assert.Equal ($"first line.{Environment.NewLine}This is the second", tv.SelectedText);
|
||
Assert.Equal ($"first line.{Environment.NewLine}This is the second", Cell.ToString (tv.SelectedCellsList));
|
||
Assert.Equal (new (18, 1), tv.CursorPosition);
|
||
Assert.False (tv.IsDirty);
|
||
|
||
AssertNullAttribute ();
|
||
|
||
tv.ApplyCellsAttribute (new (Color.Red, Color.Green));
|
||
|
||
AssertRedGreenAttribute ();
|
||
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.Equal ($"first line.{Environment.NewLine}This is the second", Cell.ToString (tv.SelectedCellsList));
|
||
Assert.Equal (new (18, 1), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
// Undo
|
||
Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl));
|
||
|
||
AssertNullAttribute ();
|
||
|
||
Assert.Equal (12, tv.SelectionStartColumn);
|
||
Assert.Equal (0, tv.SelectionStartRow);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.Empty (tv.SelectedCellsList);
|
||
Assert.Equal (new (12, 0), tv.CursorPosition);
|
||
Assert.False (tv.IsDirty);
|
||
|
||
// Redo
|
||
Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl));
|
||
|
||
AssertRedGreenAttribute ();
|
||
|
||
Assert.Equal (12, tv.SelectionStartColumn);
|
||
Assert.Equal (0, tv.SelectionStartRow);
|
||
Assert.Equal (0, tv.SelectedLength);
|
||
Assert.Equal ("", tv.SelectedText);
|
||
Assert.Empty (tv.SelectedCellsList);
|
||
Assert.Equal (new (12, 0), tv.CursorPosition);
|
||
Assert.True (tv.IsDirty);
|
||
|
||
void AssertNullAttribute ()
|
||
{
|
||
tv.GetRegion (out List<List<Cell>> region, 0, 12, 1, 18);
|
||
|
||
foreach (List<Cell> cells in region)
|
||
{
|
||
foreach (Cell cell in cells)
|
||
{
|
||
Assert.Null (cell.Attribute);
|
||
}
|
||
}
|
||
}
|
||
|
||
void AssertRedGreenAttribute ()
|
||
{
|
||
tv.GetRegion (out List<List<Cell>> region, 0, 12, 1, 18);
|
||
|
||
foreach (List<Cell> cells in region)
|
||
{
|
||
foreach (Cell cell in cells)
|
||
{
|
||
Assert.Equal ("[Red,Green,None]", cell.Attribute.ToString ());
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
[Fact]
|
||
public void Internal_Tests ()
|
||
{
|
||
var txt = "This is a text.";
|
||
List<Cell> txtStrings = Cell.StringToCells (txt);
|
||
Assert.Equal (txt.Length, txtStrings.Count);
|
||
Assert.Equal ("T", txtStrings [0].Grapheme);
|
||
Assert.Equal ("h", txtStrings [1].Grapheme);
|
||
Assert.Equal ("i", txtStrings [2].Grapheme);
|
||
Assert.Equal ("s", txtStrings [3].Grapheme);
|
||
Assert.Equal (" ", txtStrings [4].Grapheme);
|
||
Assert.Equal ("i", txtStrings [5].Grapheme);
|
||
Assert.Equal ("s", txtStrings [6].Grapheme);
|
||
Assert.Equal (" ", txtStrings [7].Grapheme);
|
||
Assert.Equal ("a", txtStrings [8].Grapheme);
|
||
Assert.Equal (" ", txtStrings [9].Grapheme);
|
||
Assert.Equal ("t", txtStrings [10].Grapheme);
|
||
Assert.Equal ("e", txtStrings [11].Grapheme);
|
||
Assert.Equal ("x", txtStrings [12].Grapheme);
|
||
Assert.Equal ("t", txtStrings [13].Grapheme);
|
||
Assert.Equal (".", txtStrings [^1].Grapheme);
|
||
|
||
var col = 0;
|
||
Assert.True (TextModel.SetCol (ref col, 80, 79));
|
||
Assert.False (TextModel.SetCol (ref col, 80, 80));
|
||
Assert.Equal (79, col);
|
||
|
||
var start = 0;
|
||
var x = 8;
|
||
Assert.Equal (8, TextModel.GetColFromX (txtStrings, start, x));
|
||
Assert.Equal ("a", txtStrings [start + x].Grapheme);
|
||
start = 1;
|
||
x = 7;
|
||
Assert.Equal (7, TextModel.GetColFromX (txtStrings, start, x));
|
||
Assert.Equal ("a", txtStrings [start + x].Grapheme);
|
||
|
||
Assert.Equal ((15, 15), TextModel.DisplaySize (txtStrings));
|
||
Assert.Equal ((6, 6), TextModel.DisplaySize (txtStrings, 1, 7));
|
||
|
||
Assert.Equal (0, TextModel.CalculateLeftColumn (txtStrings, 0, 7, 8));
|
||
Assert.Equal (1, TextModel.CalculateLeftColumn (txtStrings, 0, 8, 8));
|
||
Assert.Equal (2, TextModel.CalculateLeftColumn (txtStrings, 0, 9, 8));
|
||
|
||
var tm = new TextModel ();
|
||
tm.AddLine (0, Cell.StringToCells ("This is first line."));
|
||
tm.AddLine (1, Cell.StringToCells ("This is last line."));
|
||
Assert.Equal ((new Point (2, 0), true), tm.FindNextText ("is", out bool gaveFullTurn));
|
||
Assert.False (gaveFullTurn);
|
||
Assert.Equal ((new Point (5, 0), true), tm.FindNextText ("is", out gaveFullTurn));
|
||
Assert.False (gaveFullTurn);
|
||
Assert.Equal ((new Point (2, 1), true), tm.FindNextText ("is", out gaveFullTurn));
|
||
Assert.False (gaveFullTurn);
|
||
Assert.Equal ((new Point (5, 1), true), tm.FindNextText ("is", out gaveFullTurn));
|
||
Assert.False (gaveFullTurn);
|
||
Assert.Equal ((new Point (2, 0), true), tm.FindNextText ("is", out gaveFullTurn));
|
||
Assert.True (gaveFullTurn);
|
||
tm.ResetContinuousFind (Point.Empty);
|
||
Assert.Equal ((new Point (5, 1), true), tm.FindPreviousText ("is", out gaveFullTurn));
|
||
Assert.False (gaveFullTurn);
|
||
Assert.Equal ((new Point (2, 1), true), tm.FindPreviousText ("is", out gaveFullTurn));
|
||
Assert.False (gaveFullTurn);
|
||
Assert.Equal ((new Point (5, 0), true), tm.FindPreviousText ("is", out gaveFullTurn));
|
||
Assert.False (gaveFullTurn);
|
||
Assert.Equal ((new Point (2, 0), true), tm.FindPreviousText ("is", out gaveFullTurn));
|
||
Assert.False (gaveFullTurn);
|
||
Assert.Equal ((new Point (5, 1), true), tm.FindPreviousText ("is", out gaveFullTurn));
|
||
Assert.True (gaveFullTurn);
|
||
|
||
Assert.Equal ((new Point (9, 1), true), tm.ReplaceAllText ("is", false, false, "really"));
|
||
Assert.Equal (Cell.StringToCells ("Threally really first line."), tm.GetLine (0));
|
||
Assert.Equal (Cell.StringToCells ("Threally really last line."), tm.GetLine (1));
|
||
tm = new ();
|
||
tm.AddLine (0, Cell.StringToCells ("This is first line."));
|
||
tm.AddLine (1, Cell.StringToCells ("This is last line."));
|
||
Assert.Equal ((new Point (5, 1), true), tm.ReplaceAllText ("is", false, true, "really"));
|
||
Assert.Equal (Cell.StringToCells ("This really first line."), tm.GetLine (0));
|
||
Assert.Equal (Cell.StringToCells ("This really last line."), tm.GetLine (1));
|
||
}
|
||
|
||
[Fact]
|
||
public void LeftColumn_Add_One_If_Text_Length_Is_Equal_To_Width ()
|
||
{
|
||
var tv = new TextView { Width = 10, Text = "1234567890" };
|
||
|
||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||
Assert.Equal (0, tv.LeftColumn);
|
||
|
||
tv.CursorPosition = new (9, 0);
|
||
Assert.Equal (new (9, 0), tv.CursorPosition);
|
||
Assert.Equal (0, tv.LeftColumn);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.CursorRight));
|
||
tv.CursorPosition = new (10, 0);
|
||
Assert.Equal (new (10, 0), tv.CursorPosition);
|
||
Assert.Equal (1, tv.LeftColumn);
|
||
}
|
||
|
||
[Fact]
|
||
public void LoadFile_Throws_If_File_Is_Empty ()
|
||
{
|
||
var result = false;
|
||
var tv = new TextView ();
|
||
Assert.Throws<ArgumentException> (() => result = tv.Load (""));
|
||
Assert.False (result);
|
||
}
|
||
|
||
[Fact]
|
||
public void LoadFile_Throws_If_File_Is_Null ()
|
||
{
|
||
var result = false;
|
||
var tv = new TextView ();
|
||
Assert.Throws<ArgumentNullException> (() => result = tv.Load ((string)null));
|
||
Assert.False (result);
|
||
}
|
||
|
||
[Fact]
|
||
public void LoadFile_Throws_If_File_Not_Exist ()
|
||
{
|
||
var result = false;
|
||
var tv = new TextView ();
|
||
Assert.Throws<FileNotFoundException> (() => result = tv.Load ("blabla"));
|
||
Assert.False (result);
|
||
}
|
||
|
||
[Fact]
|
||
public void LoadStream_CRLF ()
|
||
{
|
||
var text = "This is the first line.\r\nThis is the second line.\r\n";
|
||
var tv = new TextView ();
|
||
tv.Load (new MemoryStream (Encoding.ASCII.GetBytes (text)));
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}",
|
||
tv.Text
|
||
);
|
||
}
|
||
|
||
[Fact]
|
||
public void LoadStream_IsDirty ()
|
||
{
|
||
var text = "Testing";
|
||
|
||
using (var stream = new MemoryStream ())
|
||
{
|
||
var writer = new StreamWriter (stream);
|
||
writer.Write (text);
|
||
writer.Flush ();
|
||
stream.Position = 0;
|
||
|
||
var tv = new TextView ();
|
||
tv.Load (stream);
|
||
|
||
Assert.Equal (7, text.Length);
|
||
Assert.Equal (text.Length, tv.Text.Length);
|
||
Assert.Equal (text, tv.Text);
|
||
Assert.False (tv.IsDirty);
|
||
}
|
||
}
|
||
|
||
[Fact]
|
||
public void LoadStream_IsDirty_With_Null_On_The_Text ()
|
||
{
|
||
var text = "Test\0ing";
|
||
|
||
using (var stream = new MemoryStream ())
|
||
{
|
||
var writer = new StreamWriter (stream);
|
||
writer.Write (text);
|
||
writer.Flush ();
|
||
stream.Position = 0;
|
||
|
||
var tv = new TextView ();
|
||
tv.Load (stream);
|
||
|
||
Assert.Equal (8, text.Length);
|
||
Assert.Equal (text.Length, tv.Text.Length);
|
||
Assert.Equal (8, text.Length);
|
||
Assert.Equal (8, tv.Text.Length);
|
||
Assert.Equal (text, tv.Text);
|
||
Assert.False (tv.IsDirty);
|
||
Assert.Equal ((Rune)'\u2400', ((Rune)tv.Text [4]).MakePrintable ());
|
||
}
|
||
}
|
||
|
||
[Fact]
|
||
public void LoadStream_LF ()
|
||
{
|
||
var text = "This is the first line.\nThis is the second line.\n";
|
||
var tv = new TextView ();
|
||
tv.Load (new MemoryStream (Encoding.ASCII.GetBytes (text)));
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}",
|
||
tv.Text
|
||
);
|
||
}
|
||
|
||
[Fact]
|
||
public void LoadStream_Stream_Is_Empty ()
|
||
{
|
||
var tv = new TextView ();
|
||
tv.Load (new MemoryStream ());
|
||
Assert.Equal ("", tv.Text);
|
||
}
|
||
|
||
[Fact]
|
||
public void LoadStream_Throws_If_Stream_Is_Null ()
|
||
{
|
||
var tv = new TextView ();
|
||
Assert.Throws<ArgumentNullException> (() => tv.Load ((Stream)null));
|
||
}
|
||
|
||
[Fact]
|
||
public void ReplaceAllText_Does_Not_Throw_Exception ()
|
||
{
|
||
var textToFind = "hello! hello!";
|
||
var textToReplace = "hello!";
|
||
var tv = new TextView { Width = 20, Height = 3, Text = textToFind };
|
||
|
||
Exception exception = Record.Exception (() => tv.ReplaceAllText (textToFind, false, false, textToReplace));
|
||
Assert.Null (exception);
|
||
Assert.Equal (textToReplace, tv.Text);
|
||
}
|
||
|
||
[Fact]
|
||
public void StringToRunes_Slipts_CRLF ()
|
||
{
|
||
var text = "This is the first line.\r\nThis is the second line.\r\n";
|
||
var tv = new TextView ();
|
||
tv.Text = text;
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}",
|
||
tv.Text
|
||
);
|
||
}
|
||
|
||
[Fact]
|
||
public void StringToRunes_Slipts_LF ()
|
||
{
|
||
var text = "This is the first line.\nThis is the second line.\n";
|
||
var tv = new TextView ();
|
||
tv.Text = text;
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}",
|
||
tv.Text
|
||
);
|
||
}
|
||
|
||
[Fact]
|
||
public void TextView_MultiLine_But_Without_Tabs ()
|
||
{
|
||
var view = new TextView ();
|
||
|
||
// the default for TextView
|
||
Assert.True (view.Multiline);
|
||
|
||
view.AllowsTab = false;
|
||
Assert.False (view.AllowsTab);
|
||
|
||
Assert.True (view.Multiline);
|
||
}
|
||
|
||
[Fact]
|
||
public void WordBackward_WordForward_Limits_Return_Null ()
|
||
{
|
||
var model = new TextModel ();
|
||
model.LoadString ("Test");
|
||
(int col, int row)? newPos = model.WordBackward (0, 0, false);
|
||
Assert.Null (newPos);
|
||
newPos = model.WordForward (4, 0, false);
|
||
Assert.Null (newPos);
|
||
}
|
||
|
||
[Fact]
|
||
public void WordWrap_Gets_Sets ()
|
||
{
|
||
var tv = new TextView { WordWrap = true };
|
||
Assert.True (tv.WordWrap);
|
||
tv.WordWrap = false;
|
||
Assert.False (tv.WordWrap);
|
||
}
|
||
|
||
[Fact]
|
||
public void WordWrap_True_Text_Always_Returns_Unwrapped ()
|
||
{
|
||
var text = "This is the first line.\nThis is the second line.\n";
|
||
var tv = new TextView { Width = 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;
|
||
|
||
Assert.Equal (
|
||
$"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}",
|
||
tv.Text
|
||
);
|
||
}
|
||
|
||
[Fact]
|
||
public void HotKey_Command_SetsFocus ()
|
||
{
|
||
var view = new TextView ();
|
||
|
||
view.CanFocus = true;
|
||
Assert.False (view.HasFocus);
|
||
view.InvokeCommand (Command.HotKey);
|
||
Assert.True (view.HasFocus);
|
||
}
|
||
|
||
[Fact]
|
||
public void HotKey_Command_Does_Not_Accept ()
|
||
{
|
||
var view = new TextView ();
|
||
var accepted = false;
|
||
view.Accepting += OnAccept;
|
||
view.InvokeCommand (Command.HotKey);
|
||
|
||
Assert.False (accepted);
|
||
|
||
return;
|
||
|
||
void OnAccept (object sender, CommandEventArgs e) { accepted = true; }
|
||
}
|
||
|
||
[Theory]
|
||
[InlineData (false, 1)]
|
||
[InlineData (true, 1)]
|
||
public void Accepted_Command_Raises_Accepted_Regardles_Of_AllowsReturn (bool allowsReturn, int expectedAcceptEvents)
|
||
{
|
||
var view = new TextView
|
||
{
|
||
AllowsReturn = allowsReturn
|
||
};
|
||
|
||
var acceptedEvents = 0;
|
||
view.Accepting += Accept;
|
||
view.InvokeCommand (Command.Accept);
|
||
Assert.Equal (expectedAcceptEvents, acceptedEvents);
|
||
|
||
return;
|
||
|
||
void Accept (object sender, CommandEventArgs e) { acceptedEvents++; }
|
||
}
|
||
|
||
[Theory]
|
||
[InlineData (false, 1)]
|
||
[InlineData (true, 0)]
|
||
public void Enter_Key_Fires_Accepted_BasedOn_AllowsReturn (bool allowsReturn, int expectedAccepts)
|
||
{
|
||
var view = new TextView
|
||
{
|
||
Multiline = allowsReturn
|
||
};
|
||
|
||
var accepted = 0;
|
||
view.Accepting += Accept;
|
||
view.NewKeyDownEvent (Key.Enter);
|
||
Assert.Equal (expectedAccepts, accepted);
|
||
|
||
return;
|
||
|
||
void Accept (object sender, CommandEventArgs e) { accepted++; }
|
||
}
|
||
|
||
[Theory]
|
||
[InlineData (false, 1)]
|
||
[InlineData (true, 0)]
|
||
public void Enter_Key_Fires_Accepted_BasedOn_Multiline (bool multiline, int expectedAccepts)
|
||
{
|
||
var view = new TextView
|
||
{
|
||
Multiline = multiline
|
||
};
|
||
|
||
var accepted = 0;
|
||
view.Accepting += Accept;
|
||
view.NewKeyDownEvent (Key.Enter);
|
||
Assert.Equal (expectedAccepts, accepted);
|
||
|
||
return;
|
||
|
||
void Accept (object sender, CommandEventArgs e) { accepted++; }
|
||
}
|
||
|
||
[Fact]
|
||
public void Space_Key_Types_Space ()
|
||
{
|
||
var view = new TextView ();
|
||
|
||
view.NewKeyDownEvent (Key.Space);
|
||
|
||
Assert.Equal (" ", view.Text);
|
||
}
|
||
|
||
[Theory]
|
||
[InlineData (false, false, 1, 1)]
|
||
[InlineData (false, true, 1, 0)]
|
||
[InlineData (true, false, 0, 0)]
|
||
[InlineData (true, true, 0, 0)]
|
||
public void Accepted_Event_Handled_Prevents_Default_Button_Accept (bool multiline, bool handleAccept, int expectedAccepts, int expectedButtonAccepts)
|
||
{
|
||
var superView = new Window ();
|
||
|
||
var tv = new TextView
|
||
{
|
||
Multiline = multiline
|
||
};
|
||
|
||
var button = new Button
|
||
{
|
||
IsDefault = true
|
||
};
|
||
|
||
superView.Add (tv, button);
|
||
|
||
var buttonAccept = 0;
|
||
button.Accepting += ButtonAccept;
|
||
|
||
var textViewAccept = 0;
|
||
tv.Accepting += TextViewAccept;
|
||
|
||
tv.SetFocus ();
|
||
Assert.True (tv.HasFocus);
|
||
|
||
superView.NewKeyDownEvent (Key.Enter);
|
||
Assert.Equal (expectedAccepts, textViewAccept);
|
||
Assert.Equal (expectedButtonAccepts, buttonAccept);
|
||
|
||
button.SetFocus ();
|
||
superView.NewKeyDownEvent (Key.Enter);
|
||
Assert.Equal (expectedAccepts, textViewAccept);
|
||
Assert.Equal (expectedButtonAccepts + 1, buttonAccept);
|
||
|
||
return;
|
||
|
||
void TextViewAccept (object sender, CommandEventArgs e)
|
||
{
|
||
textViewAccept++;
|
||
e.Handled = handleAccept;
|
||
}
|
||
|
||
void ButtonAccept (object sender, CommandEventArgs e) { buttonAccept++; }
|
||
}
|
||
|
||
[Theory]
|
||
[InlineData (true, 0)]
|
||
[InlineData (false, 1)]
|
||
public void Accepted_No_Handler_Enables_Default_Button_Accept (bool multiline, int expectedButtonAccept)
|
||
{
|
||
var superView = new Window ();
|
||
|
||
var tv = new TextView
|
||
{
|
||
Multiline = multiline
|
||
};
|
||
|
||
var button = new Button
|
||
{
|
||
IsDefault = true
|
||
};
|
||
|
||
superView.Add (tv, button);
|
||
|
||
var buttonAccept = 0;
|
||
button.Accepting += ButtonAccept;
|
||
|
||
tv.SetFocus ();
|
||
Assert.True (tv.HasFocus);
|
||
|
||
superView.NewKeyDownEvent (Key.Enter);
|
||
Assert.Equal (expectedButtonAccept, buttonAccept);
|
||
|
||
button.SetFocus ();
|
||
superView.NewKeyDownEvent (Key.Enter);
|
||
Assert.Equal (expectedButtonAccept + 1, buttonAccept);
|
||
|
||
return;
|
||
|
||
void ButtonAccept (object sender, CommandEventArgs e) { buttonAccept++; }
|
||
}
|
||
|
||
[Fact]
|
||
public void Autocomplete_Popup_Added_To_SuperView_On_Init ()
|
||
{
|
||
View superView = new ()
|
||
{
|
||
CanFocus = true
|
||
};
|
||
|
||
TextView t = new ();
|
||
|
||
superView.Add (t);
|
||
Assert.Single (superView.SubViews);
|
||
|
||
superView.BeginInit ();
|
||
superView.EndInit ();
|
||
|
||
Assert.Equal (2, superView.SubViews.Count);
|
||
}
|
||
|
||
[Fact]
|
||
public void Autocomplete__Added_To_SuperView_On_Add ()
|
||
{
|
||
View superView = new ()
|
||
{
|
||
CanFocus = true,
|
||
Id = "superView"
|
||
};
|
||
|
||
superView.BeginInit ();
|
||
superView.EndInit ();
|
||
Assert.Empty (superView.SubViews);
|
||
|
||
TextView t = new ()
|
||
{
|
||
Id = "t"
|
||
};
|
||
|
||
superView.Add (t);
|
||
|
||
Assert.Equal (2, superView.SubViews.Count);
|
||
}
|
||
|
||
[Fact]
|
||
public void Autocomplete_Visible_False_By_Default ()
|
||
{
|
||
View superView = new ()
|
||
{
|
||
CanFocus = true
|
||
};
|
||
|
||
TextView t = new ();
|
||
|
||
superView.Add (t);
|
||
superView.BeginInit ();
|
||
superView.EndInit ();
|
||
|
||
Assert.Equal (2, superView.SubViews.Count);
|
||
|
||
Assert.True (t.Visible);
|
||
Assert.False (t.Autocomplete.Visible);
|
||
}
|
||
|
||
[Fact]
|
||
public void Right_CursorAtEnd_WithSelection_ShouldClearSelection ()
|
||
{
|
||
var tv = new TextView
|
||
{
|
||
Text = "Hello"
|
||
};
|
||
tv.SetFocus ();
|
||
|
||
tv.NewKeyDownEvent (Key.End.WithShift);
|
||
Assert.Equal (5, tv.CursorPosition.X);
|
||
|
||
// When there is selected text and the cursor is at the end of the text field
|
||
Assert.Equal ("Hello", tv.SelectedText);
|
||
|
||
// Pressing right should not move focus, instead it should clear selection
|
||
Assert.True (tv.NewKeyDownEvent (Key.CursorRight));
|
||
Assert.Empty (tv.SelectedText);
|
||
|
||
// Now that the selection is cleared another right keypress should move focus
|
||
Assert.False (tv.NewKeyDownEvent (Key.CursorRight));
|
||
}
|
||
|
||
[Fact]
|
||
public void Left_CursorAtStart_WithSelection_ShouldClearSelection ()
|
||
{
|
||
var tv = new TextView
|
||
{
|
||
Text = "Hello"
|
||
};
|
||
tv.SetFocus ();
|
||
|
||
tv.NewKeyDownEvent (Key.CursorRight);
|
||
tv.NewKeyDownEvent (Key.CursorRight);
|
||
|
||
Assert.Equal (2, tv.CursorPosition.X);
|
||
|
||
Assert.True (tv.NewKeyDownEvent (Key.CursorLeft.WithShift));
|
||
Assert.True (tv.NewKeyDownEvent (Key.CursorLeft.WithShift));
|
||
|
||
// When there is selected text and the cursor is at the start of the text field
|
||
Assert.Equal ("He", tv.SelectedText);
|
||
|
||
// Pressing left should not move focus, instead it should clear selection
|
||
Assert.True (tv.NewKeyDownEvent (Key.CursorLeft));
|
||
Assert.Empty (tv.SelectedText);
|
||
|
||
// When clearing selected text with left the cursor should be at the start of the selection
|
||
Assert.Equal (0, tv.CursorPosition.X);
|
||
|
||
// Now that the selection is cleared another left keypress should move focus
|
||
Assert.False (tv.NewKeyDownEvent (Key.CursorLeft));
|
||
}
|
||
|
||
[Fact]
|
||
public void Equals_True ()
|
||
{
|
||
var c1 = new Cell ();
|
||
var c2 = new Cell ();
|
||
Assert.True (c1.Equals (c2));
|
||
Assert.True (c2.Equals (c1));
|
||
|
||
c1.Grapheme = new ("a");
|
||
c1.Attribute = new ();
|
||
c2.Grapheme = new ("a");
|
||
c2.Attribute = new ();
|
||
Assert.True (c1.Equals (c2));
|
||
Assert.True (c2.Equals (c1));
|
||
}
|
||
|
||
[Fact]
|
||
public void Cell_LoadCells_Without_Scheme_Is_Never_Null ()
|
||
{
|
||
List<Cell> cells = new ()
|
||
{
|
||
new () { Grapheme = new ("T") },
|
||
new () { Grapheme = new ("e") },
|
||
new () { Grapheme = new ("s") },
|
||
new () { Grapheme = new ("t") }
|
||
};
|
||
TextView tv = CreateTextView ();
|
||
var top = new Runnable ();
|
||
top.Add (tv);
|
||
tv.Load (cells);
|
||
|
||
for (var i = 0; i < tv.Lines; i++)
|
||
{
|
||
List<Cell> line = tv.GetLine (i);
|
||
|
||
foreach (Cell c in line)
|
||
{
|
||
Assert.NotNull (c.Attribute);
|
||
}
|
||
}
|
||
}
|
||
|
||
[Theory]
|
||
[InlineData ("", false, "")]
|
||
[InlineData ("", true, "")]
|
||
[InlineData (" ", false, "")]
|
||
[InlineData (" ", true, "")]
|
||
[InlineData (" ", false, "")]
|
||
[InlineData (" ", true, "")]
|
||
[InlineData ("a", false, "")]
|
||
[InlineData ("a", true, "")]
|
||
[InlineData ("a ", false, "")]
|
||
[InlineData ("a ", true, "")]
|
||
[InlineData (" a ", false, "a ", "")]
|
||
[InlineData (" a ", true, "a ", "")]
|
||
[InlineData (" H1 ", false, "H1 ", "")]
|
||
[InlineData (" H1 ", true, "H1 ", "")]
|
||
[InlineData ("a$", false, "$", "")]
|
||
[InlineData ("a$", true, "$", "")]
|
||
[InlineData ("a$#", false, "$#", "")]
|
||
[InlineData ("a$#", true, "$#", "#", "")]
|
||
[InlineData (" a$# ", false, "a$# ", "$# ", "")]
|
||
[InlineData (" a$# ", true, "a$# ", "$# ", "# ", "")]
|
||
[InlineData ("\"$schema\"", false, "schema\"", "\"", "")]
|
||
[InlineData ("\"$schema\"", true, "$schema\"", "schema\"", "\"", "")]
|
||
[InlineData ("\": \"", false, "\"", "")]
|
||
[InlineData ("\": \"", true, "\"", "")]
|
||
[InlineData ("\"$schema\": \"", false, "schema\": \"", "\": \"", "\"", "")]
|
||
[InlineData ("\"$schema\": \"", true, "$schema\": \"", "schema\": \"", "\": \"", "\"", "")]
|
||
[InlineData ("1ºªA", false, "")]
|
||
[InlineData ("1ºªA", true, "")]
|
||
[InlineData (
|
||
"ºª\\!\"#%&/()?'«»*;,:._-@{[]}]|$=+´`~^<>£€¨",
|
||
false,
|
||
"\\!\"#%&/()?'«»*;,:._-@{[]}]|$=+´`~^<>£€¨",
|
||
"")]
|
||
[InlineData (
|
||
"ºª\\!\"#%&/()?'«»*;,:._-@{[]}]|$=+´`~^<>£€¨",
|
||
true,
|
||
"\\!\"#%&/()?'«»*;,:._-@{[]}]|$=+´`~^<>£€¨",
|
||
"|$=+´`~^<>£€¨",
|
||
"")]
|
||
[InlineData (
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
false,
|
||
"\r\n \"$schema\": \"https://gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
" \"$schema\": \"https://gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
"\"$schema\": \"https://gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
"schema\": \"https://gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
"\": \"https://gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
"\"https://gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
"https://gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
"://gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
"gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
"-cs.github.io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
"cs.github.io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
".github.io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
"github.io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
".io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
"io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
"/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
"Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
".Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
"Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
"/schemas/tui-config-schema.json\"\r\n}",
|
||
"schemas/tui-config-schema.json\"\r\n}",
|
||
"/tui-config-schema.json\"\r\n}",
|
||
"tui-config-schema.json\"\r\n}",
|
||
"-config-schema.json\"\r\n}",
|
||
"config-schema.json\"\r\n}",
|
||
"-schema.json\"\r\n}",
|
||
"schema.json\"\r\n}",
|
||
".json\"\r\n}",
|
||
"json\"\r\n}",
|
||
"\"\r\n}",
|
||
"\r\n}",
|
||
"}",
|
||
"")]
|
||
[InlineData (
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
true,
|
||
"\r\n \"$schema\": \"https://gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
" \"$schema\": \"https://gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
"\"$schema\": \"https://gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
"$schema\": \"https://gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
"schema\": \"https://gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
"\": \"https://gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
"\"https://gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
"https://gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
"://gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
"gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
"-cs.github.io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
"cs.github.io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
".github.io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
"github.io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
".io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
"io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
"/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
"Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
".Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
"Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
"/schemas/tui-config-schema.json\"\r\n}",
|
||
"schemas/tui-config-schema.json\"\r\n}",
|
||
"/tui-config-schema.json\"\r\n}",
|
||
"tui-config-schema.json\"\r\n}",
|
||
"-config-schema.json\"\r\n}",
|
||
"config-schema.json\"\r\n}",
|
||
"-schema.json\"\r\n}",
|
||
"schema.json\"\r\n}",
|
||
".json\"\r\n}",
|
||
"json\"\r\n}",
|
||
"\"\r\n}",
|
||
"\r\n}",
|
||
"}",
|
||
"")]
|
||
public void WordForward_WordWrap_False_True (string text, bool useSameRuneType, params string [] expectedText)
|
||
{
|
||
TextView tv = CreateTextView ();
|
||
tv.UseSameRuneTypeForWords = useSameRuneType;
|
||
|
||
ProcessDeleteWithCtrl ();
|
||
|
||
tv.WordWrap = true;
|
||
ProcessDeleteWithCtrl ();
|
||
|
||
void ProcessDeleteWithCtrl ()
|
||
{
|
||
tv.Text = text;
|
||
var idx = 0;
|
||
|
||
while (!string.IsNullOrEmpty (tv.Text))
|
||
{
|
||
tv.NewKeyDownEvent (Key.Delete.WithCtrl);
|
||
Assert.Equal (expectedText [idx].Replace ("\r\n", Environment.NewLine), tv.Text);
|
||
idx++;
|
||
}
|
||
}
|
||
}
|
||
|
||
[Theory]
|
||
[InlineData ("", false, "")]
|
||
[InlineData ("", true, "")]
|
||
[InlineData (" ", false, "")]
|
||
[InlineData (" ", true, "")]
|
||
[InlineData (" ", false, "")]
|
||
[InlineData (" ", true, "")]
|
||
[InlineData ("a", false, "")]
|
||
[InlineData ("a", true, "")]
|
||
[InlineData ("a ", false, "")]
|
||
[InlineData ("a ", true, "")]
|
||
[InlineData (" a ", false, " ", "")]
|
||
[InlineData (" a ", true, " ", "")]
|
||
[InlineData (" H1 ", false, " ", "")]
|
||
[InlineData (" H1 ", true, " ", "")]
|
||
[InlineData ("a$", false, "a", "")]
|
||
[InlineData ("a$", true, "a", "")]
|
||
[InlineData ("a$#", false, "a", "")]
|
||
[InlineData ("a$#", true, "a$", "a", "")]
|
||
[InlineData (" a$# ", false, " a", " ", "")]
|
||
[InlineData (" a$# ", true, " a$", " a", " ", "")]
|
||
[InlineData ("\"$schema\"", false, "\"$schema", "\"$", "")]
|
||
[InlineData ("\"$schema\"", true, "\"$schema", "\"$", "\"", "")]
|
||
[InlineData ("\"$schema\": \"", false, "\"$schema\": ", "\"$schema", "\"$", "")]
|
||
[InlineData ("\"$schema\": \"", true, "\"$schema\": ", "\"$schema", "\"$", "\"", "")]
|
||
[InlineData ("1ºªA", false, "")]
|
||
[InlineData ("1ºªA", true, "")]
|
||
[InlineData (
|
||
"ºª\\!\"#%&/()?'«»*;,:._-@{[]}]|$=+´`~^<>£€¨",
|
||
false,
|
||
"ºª",
|
||
"")]
|
||
[InlineData (
|
||
"ºª\\!\"#%&/()?'«»*;,:._-@{[]}]|$=+´`~^<>£€¨",
|
||
true,
|
||
"ºª\\!\"#%&/()?'«»*;,:._-@{[]}]",
|
||
"ºª",
|
||
"")]
|
||
[InlineData (
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
false,
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n",
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema.json\"",
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema.json",
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema.",
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema",
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io/Terminal.Gui/schemas/tui-config-",
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io/Terminal.Gui/schemas/tui-config",
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io/Terminal.Gui/schemas/tui-",
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io/Terminal.Gui/schemas/tui",
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io/Terminal.Gui/schemas/",
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io/Terminal.Gui/schemas",
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io/Terminal.Gui/",
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io/Terminal.Gui",
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io/Terminal.",
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io/Terminal",
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io/",
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io",
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.",
|
||
"{\r\n \"$schema\": \"https://gui-cs.github",
|
||
"{\r\n \"$schema\": \"https://gui-cs.",
|
||
"{\r\n \"$schema\": \"https://gui-cs",
|
||
"{\r\n \"$schema\": \"https://gui-",
|
||
"{\r\n \"$schema\": \"https://gui",
|
||
"{\r\n \"$schema\": \"https://",
|
||
"{\r\n \"$schema\": \"https",
|
||
"{\r\n \"$schema\": \"",
|
||
"{\r\n \"$schema\": ",
|
||
"{\r\n \"$schema",
|
||
"{\r\n \"$",
|
||
"{\r\n ",
|
||
"{\r\n",
|
||
"{",
|
||
"")]
|
||
[InlineData (
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n}",
|
||
true,
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema.json\"\r\n",
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema.json\"",
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema.json",
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema.",
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema",
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io/Terminal.Gui/schemas/tui-config-",
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io/Terminal.Gui/schemas/tui-config",
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io/Terminal.Gui/schemas/tui-",
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io/Terminal.Gui/schemas/tui",
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io/Terminal.Gui/schemas/",
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io/Terminal.Gui/schemas",
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io/Terminal.Gui/",
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io/Terminal.Gui",
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io/Terminal.",
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io/Terminal",
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io/",
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.io",
|
||
"{\r\n \"$schema\": \"https://gui-cs.github.",
|
||
"{\r\n \"$schema\": \"https://gui-cs.github",
|
||
"{\r\n \"$schema\": \"https://gui-cs.",
|
||
"{\r\n \"$schema\": \"https://gui-cs",
|
||
"{\r\n \"$schema\": \"https://gui-",
|
||
"{\r\n \"$schema\": \"https://gui",
|
||
"{\r\n \"$schema\": \"https://",
|
||
"{\r\n \"$schema\": \"https",
|
||
"{\r\n \"$schema\": \"",
|
||
"{\r\n \"$schema\": ",
|
||
"{\r\n \"$schema",
|
||
"{\r\n \"$",
|
||
"{\r\n \"",
|
||
"{\r\n ",
|
||
"{\r\n",
|
||
"{",
|
||
"")]
|
||
public void WordBackward_WordWrap_False_True (string text, bool useSameRuneType, params string [] expectedText)
|
||
{
|
||
TextView tv = CreateTextView ();
|
||
tv.UseSameRuneTypeForWords = useSameRuneType;
|
||
|
||
ProcessBackspaceWithCtrl ();
|
||
|
||
tv.WordWrap = true;
|
||
ProcessBackspaceWithCtrl ();
|
||
|
||
void ProcessBackspaceWithCtrl ()
|
||
{
|
||
tv.Text = text;
|
||
tv.MoveEnd ();
|
||
var idx = 0;
|
||
|
||
while (!string.IsNullOrEmpty (tv.Text))
|
||
{
|
||
tv.NewKeyDownEvent (Key.Backspace.WithCtrl);
|
||
Assert.Equal (expectedText [idx].Replace ("\r\n", Environment.NewLine), tv.Text);
|
||
idx++;
|
||
}
|
||
}
|
||
}
|
||
|
||
[Theory]
|
||
[InlineData ("", 0, false, "")]
|
||
[InlineData ("", 0, true, "")]
|
||
[InlineData ("a", 0, false, "a")]
|
||
[InlineData ("a", 0, true, "a")]
|
||
[InlineData ("a:", 0, false, "a")]
|
||
[InlineData ("a:", 0, true, "a")]
|
||
[InlineData ("a:", 1, false, ":")]
|
||
[InlineData ("a:", 1, true, ":")]
|
||
[InlineData ("a ", 0, false, "a ")]
|
||
[InlineData ("a ", 0, true, "a")]
|
||
[InlineData ("a ", 1, false, "a ")]
|
||
[InlineData ("a ", 1, true, "a")]
|
||
[InlineData ("a b", 0, false, "a ")]
|
||
[InlineData ("a b", 0, true, "a")]
|
||
[InlineData ("a b", 1, false, "a ")]
|
||
[InlineData ("a b", 1, true, "a")]
|
||
[InlineData ("a b ", 2, false, "b ")]
|
||
[InlineData ("a b ", 2, true, "b")]
|
||
[InlineData ("a b ", 3, false, "b ")]
|
||
[InlineData ("a b ", 3, true, "b")]
|
||
[InlineData (" a b ", 0, false, " ")]
|
||
[InlineData (" a b ", 0, true, " ")]
|
||
[InlineData (" a b ", 2, false, " ")]
|
||
[InlineData (" a b ", 2, true, " ")]
|
||
[InlineData (" a b ", 3, false, " ")]
|
||
[InlineData (" a b ", 3, true, " ")]
|
||
[InlineData (" H1$you ", 2, false, "H1")]
|
||
[InlineData (" H1$you ", 2, true, "H1")]
|
||
[InlineData (" H1$you ", 3, false, "$&#")]
|
||
[InlineData (" H1$you ", 3, true, "$&#")]
|
||
[InlineData (" H1$you ", 4, false, "$&#")]
|
||
[InlineData (" H1$you ", 4, true, "$&#")]
|
||
[InlineData (" H1$you ", 5, false, "$&#")]
|
||
[InlineData (" H1$you ", 5, true, "$&#")]
|
||
[InlineData (" H1$you ", 6, false, "2you ")]
|
||
[InlineData (" H1$you ", 6, true, "2you")]
|
||
public void ProcessDoubleClickSelection_False_True (string text, int col, bool selectWordOnly, string expectedText)
|
||
{
|
||
TextView tv = CreateTextView ();
|
||
tv.Text = text;
|
||
tv.SelectWordOnlyOnDoubleClick = selectWordOnly;
|
||
|
||
Assert.True (tv.NewMouseEvent (new () { Position = new (col, 0), Flags = MouseFlags.Button1DoubleClicked }));
|
||
Assert.Equal (expectedText, tv.SelectedText);
|
||
}
|
||
|
||
private TextView CreateTextView () { return new () { Width = 30, Height = 10 }; }
|
||
}
|