mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 04:36:39 +00:00
Merge pull request #1388 from PowerShell/andschwa/default-editmode
Use Emacs as DefaultEditMode on Linux / OS X
This commit is contained in:
commit
5a1432e234
5 files changed
+37
-15
No files matched your search
@@ -92,7 +92,12 @@ namespace Microsoft.PowerShell
|
||||
public const ConsoleColor DefaultEmphasisForegroundColor = ConsoleColor.Cyan;
|
||||
public const ConsoleColor DefaultErrorForegroundColor = ConsoleColor.Red;
|
||||
|
||||
public const EditMode DefaultEditMode = EditMode.Windows;
|
||||
public const EditMode DefaultEditMode =
|
||||
#if LINUX
|
||||
EditMode.Emacs;
|
||||
#else
|
||||
EditMode.Windows;
|
||||
#endif
|
||||
|
||||
public const string DefaultContinuationPrompt = ">> ";
|
||||
|
||||
|
||||
@@ -114,6 +114,25 @@ namespace Microsoft.PowerShell
|
||||
private Dictionary<ConsoleKeyInfo, KeyHandler> _dispatchTable;
|
||||
private Dictionary<ConsoleKeyInfo, Dictionary<ConsoleKeyInfo, KeyHandler>> _chordDispatchTable;
|
||||
|
||||
/// <summary>
|
||||
/// Helper to set bindings based on EditMode
|
||||
/// </summary>
|
||||
void SetDefaultBindings(EditMode editMode)
|
||||
{
|
||||
switch (editMode)
|
||||
{
|
||||
case EditMode.Emacs:
|
||||
SetDefaultEmacsBindings();
|
||||
break;
|
||||
case EditMode.Vi:
|
||||
SetDefaultViBindings();
|
||||
break;
|
||||
case EditMode.Windows:
|
||||
SetDefaultWindowsBindings();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void SetDefaultWindowsBindings()
|
||||
{
|
||||
_dispatchTable = new Dictionary<ConsoleKeyInfo, KeyHandler>(new ConsoleKeyInfoComparer())
|
||||
|
||||
@@ -96,18 +96,7 @@ namespace Microsoft.PowerShell
|
||||
// Switching/resetting modes - clear out chord dispatch table
|
||||
_chordDispatchTable.Clear();
|
||||
|
||||
switch (options._editMode)
|
||||
{
|
||||
case EditMode.Emacs:
|
||||
SetDefaultEmacsBindings();
|
||||
break;
|
||||
case EditMode.Vi:
|
||||
SetDefaultViBindings();
|
||||
break;
|
||||
case EditMode.Windows:
|
||||
SetDefaultWindowsBindings();
|
||||
break;
|
||||
}
|
||||
SetDefaultBindings(Options.EditMode);
|
||||
}
|
||||
if (options._showToolTips.HasValue)
|
||||
{
|
||||
|
||||
@@ -485,8 +485,6 @@ namespace Microsoft.PowerShell
|
||||
_console = new ConhostConsole();
|
||||
#endif
|
||||
|
||||
SetDefaultWindowsBindings();
|
||||
|
||||
_buffer = new StringBuilder(8 * 1024);
|
||||
_statusBuffer = new StringBuilder(256);
|
||||
_savedCurrentLine = new HistoryItem();
|
||||
@@ -516,6 +514,7 @@ namespace Microsoft.PowerShell
|
||||
hostName = "PSReadline";
|
||||
}
|
||||
_options = new PSConsoleReadlineOptions(hostName);
|
||||
SetDefaultBindings(_options.EditMode);
|
||||
}
|
||||
|
||||
private void Initialize(Runspace runspace, EngineIntrinsics engineIntrinsics)
|
||||
|
||||
@@ -13,6 +13,16 @@ Describe "PSReadLine" {
|
||||
$module.Version | Should Be "1.2"
|
||||
}
|
||||
|
||||
It "Should use Emacs Bindings on Linux and OS X" -skip:$IsWindows {
|
||||
(Get-PSReadLineOption).EditMode | Should Be Emacs
|
||||
(Get-PSReadlineKeyHandler | where { $_.Key -eq "Ctrl+A" }).Function | Should Be BeginningOfLine
|
||||
}
|
||||
|
||||
It "Should use Windows Bindings on Windows" -skip:(-not $IsWindows) {
|
||||
(Get-PSReadLineOption).EditMode | Should Be Windows
|
||||
(Get-PSReadlineKeyHandler | where { $_.Key -eq "Ctrl+A" }).Function | Should Be SelectAll
|
||||
}
|
||||
|
||||
It "Should set the edit mode" {
|
||||
Set-PSReadlineOption -EditMode Windows
|
||||
(Get-PSReadlineKeyHandler | where { $_.Key -eq "Ctrl+A" }).Function | Should Be SelectAll
|
||||
|
||||
Reference in new issue
Block a user