Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
nosami committed Nov 6, 2019
1 parent 5dc0acd commit 2ea976c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 70 deletions.
77 changes: 11 additions & 66 deletions Src/VimMac/AlternateKeyUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,19 @@ internal static VimKeyModifiers ConvertToKeyModifiers(NSEventModifierMask keys)
var res = VimKeyModifiers.None;
if (keys.HasFlag(NSEventModifierMask.ShiftKeyMask))
{
res = res | VimKeyModifiers.Shift;
res |= VimKeyModifiers.Shift;
}
if (keys.HasFlag(NSEventModifierMask.AlternateKeyMask))
{
res = res | VimKeyModifiers.Alt;
res |= VimKeyModifiers.Alt;
}
if (keys.HasFlag(NSEventModifierMask.ControlKeyMask))
{
res = res | VimKeyModifiers.Control;
res |= VimKeyModifiers.Control;
}
if (keys.HasFlag(NSEventModifierMask.CommandKeyMask))
{
res = res | VimKeyModifiers.Command;
res |= VimKeyModifiers.Command;
}
return res;
}
Expand All @@ -138,19 +138,19 @@ internal static NSEventModifierMask ConvertToModifierKeys(VimKeyModifiers keys)
NSEventModifierMask res = 0;
if (0 != (keys & VimKeyModifiers.Shift))
{
res = res | NSEventModifierMask.ShiftKeyMask;
res |= NSEventModifierMask.ShiftKeyMask;
}
if (0 != (keys & VimKeyModifiers.Alt))
{
res = res | NSEventModifierMask.AlternateKeyMask;
res |= NSEventModifierMask.AlternateKeyMask;
}
if (0 != (keys & VimKeyModifiers.Control))
{
res = res | NSEventModifierMask.ControlKeyMask;
res |= NSEventModifierMask.ControlKeyMask;
}
if (0 != (keys & VimKeyModifiers.Command))
{
res = res | NSEventModifierMask.CommandKeyMask;
res |= NSEventModifierMask.CommandKeyMask;
}
return res;
}
Expand Down Expand Up @@ -196,7 +196,7 @@ bool IKeyUtil.TryConvertSpecialToKeyInput(NSEvent theEvent, out KeyInput keyInpu
// correspond to an ASCII control key (like <C-^>), we need to convert it here.
// This is needed because key combinations like <C-;> won't be passed to
// TextInput, because they can't be represented as system or control text.
// We just haijsshhhyuusdgdfve to be careful not to shadow any keys that produce text when
// We just have to be careful not to shadow any keys that produce text when
// combined with the AltGr key.
if (modifierKeys != 0
&& modifierKeys != NSEventModifierMask.AlternateKeyMask
Expand Down Expand Up @@ -249,63 +249,8 @@ private bool GetKeyInputFromKey(NSEvent theEvent, NSEventModifierMask modifierKe
}
keyInput = null;
return false;
}

private bool GetCharFromKey(NSKey key, NSEventModifierMask modifierKeys, out char unicodeChar)
{

//// From the documentation for GetKeyboardState:
//// - If the high-order bit is 1, the key is down; otherwise, it is up.
//const byte keyIsDown = 0x80;
//const byte keyIsUp = 0x00;

//// Use interop and pinvoke to get the scan code and keyboard layout.
//var virtualKey = (uint)KeyInterop.VirtualKeyFromKey(key);
//var scanCode = NativeMethods.MapVirtualKey(virtualKey, NativeMethods.MAPVK_VK_TO_VSC);
//StringBuilder stringBuilder = new StringBuilder(1);
//var keyboardLayout = NativeMethods.GetKeyboardLayout(0);

//// Fail if the AltGr modifier is set and the key produces a character
//// when AltGr is pressed. We want to disambiguate Ctrl+Alt from AltGr.
//if (IsAltGr(modifierKeys))
//{
// // Mark control and alt (and their merged virtual keys) as pressed.
// // This is conceptually equivalent to passing in the modifier
// // keys control and alt.
// _keyboardState[NativeMethods.VK_LCONTROL] = keyIsDown;
// _keyboardState[NativeMethods.VK_LMENU] = keyIsDown;
// _keyboardState[NativeMethods.VK_CONTROL] = keyIsDown;
// _keyboardState[NativeMethods.VK_MENU] = keyIsDown;
// int altGrResult = NativeMethods.ToUnicodeEx(virtualKey, scanCode,
// _keyboardState, stringBuilder, stringBuilder.Capacity, 0, keyboardLayout);
// if (altGrResult == 1)
// {
// VimTrace.TraceInfo("AlternateKeyUtil::GetCharFromKey AltGr {0} -> {1}",
// key, stringBuilder[0]);
// unicodeChar = default(char);
// return false;
// }
//}

//// Return the "base" key (or AltGr level 1) for the scan code.
//// This is the unicode character that would be produced if the
//// the key were pressed with no modifiers.
//// This is conceptually equivalent to passing in modifier keys none.
//_keyboardState[NativeMethods.VK_LCONTROL] = keyIsUp;
//_keyboardState[NativeMethods.VK_LMENU] = keyIsUp;
//_keyboardState[NativeMethods.VK_CONTROL] = keyIsUp;
//_keyboardState[NativeMethods.VK_MENU] = keyIsUp;
//int result = NativeMethods.ToUnicodeEx(virtualKey, scanCode,
// _keyboardState, stringBuilder, stringBuilder.Capacity, 0, keyboardLayout);
//if (result == 1)
//{
// unicodeChar = stringBuilder[0];
// return true;
//}
unicodeChar = default(char);
return false;
}

}

#endregion
}
}
3 changes: 1 addition & 2 deletions Src/VimMac/VimHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ public void CloseAllOtherWindows(ITextView textView)
Dispatch(FileTabCommands.CloseAllButThis);
}

//TODO: Same as WPF version (_except_ _textEditorFactoryService is an instance of ICocoaTextEditorFactoryService)
/// <summary>
/// Create a hidden ITextView. It will have no roles in order to keep it out of
/// most plugins
Expand Down Expand Up @@ -149,7 +148,7 @@ public void EnsureVisible(ITextView textView, SnapshotPoint point)
}
catch (Exception)
{
// The ITextViewLine implementation canq throw if this code runs in the middle of
// The ITextViewLine implementation can throw if this code runs in the middle of
// a layout or if the line believes itself to be invalid. Hard to completely guard
// against this
}
Expand Down
7 changes: 5 additions & 2 deletions Src/VimMac/WindowManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using MonoDevelop.Ide;
using System.Reflection;
using MonoDevelop.Ide;

namespace Vim.Mac
{
Expand Down Expand Up @@ -37,22 +37,25 @@ private static Notebook ToNotebook(object obj)
var children = (object[])childrenProperty.GetValue(obj);
bool isActiveNotebook = false;
int currentTab = 0;

if (children.Length > 0)
{
var tabstrip = children[0];
var tabstripType = tabstrip.GetType();
isActiveNotebook = (bool)tabstripType.GetProperty("IsActiveNotebook").GetValue(tabstrip);

}

currentTab = (int)notebookType.GetProperty("CurrentTabIndex", instanceFlags).GetValue(obj);

var tabs = (IEnumerable<object>)notebookType.GetProperty("Tabs", instanceFlags).GetValue(obj);

var files = tabs.Select(tab =>
{
var tabType = tab.GetType();
var fileName = (string)tabType.GetProperty("Tooltip", instanceFlags).GetValue(tab);
return fileName;
}).ToImmutableArray();

return new Notebook(isActiveNotebook, currentTab, files);
}

Expand Down

0 comments on commit 2ea976c

Please sign in to comment.