about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2011-05-19 16:08:04 +0200
committerhut <hut@lavabit.com>2011-05-19 16:08:04 +0200
commit71569b7201925274f3a97dd24e8e735f50bc9a53 (patch)
tree6f68a937963aebab37aeb88960952479b6fe6bac
parente690d4e989cb52a73cfd3c141a6388aded4b4a8c (diff)
downloadranger-71569b7201925274f3a97dd24e8e735f50bc9a53.tar.gz
ranger/gui/ui: Fixed issues with ALT key
<A-x> was treated equal to <ESC>x internally, which is clearly wrong.
As a result, the mapping <A-x> will override previous <ESC> mappings.
This was fixed by translating <A-x> to <ALT_KEY>x with <ALT_KEY> being
a special token for the keyparser. I hope this doesn't cause any
trouble.
Also, ALT+letter keys were fixed when using xterm-compatibility mode.
(Option xterm_alt_key = True)
-rw-r--r--ranger/ext/keybinding_parser.py5
-rw-r--r--ranger/gui/ui.py8
2 files changed, 10 insertions, 3 deletions
diff --git a/ranger/ext/keybinding_parser.py b/ranger/ext/keybinding_parser.py
index 93119bce..bfd1b6d4 100644
--- a/ranger/ext/keybinding_parser.py
+++ b/ranger/ext/keybinding_parser.py
@@ -67,6 +67,7 @@ def parse_keybinding(obj):
 DIRKEY = 9001
 ANYKEY = 9002
 PASSIVE_ACTION = 9003
+ALT_KEY = 9004
 
 very_special_keys = {
 	'dir': DIRKEY,
@@ -98,10 +99,10 @@ special_keys = {
 }
 
 for key, val in tuple(special_keys.items()):
-	special_keys['a-' + key] = (27, val)
+	special_keys['a-' + key] = (ALT_KEY, val)
 
 for char in ascii_lowercase + '0123456789':
-	special_keys['a-' + char] = (27, ord(char))
+	special_keys['a-' + char] = (ALT_KEY, ord(char))
 
 for char in ascii_lowercase:
 	special_keys['c-' + char] = ord(char) - 96
diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py
index a2babed8..cc2871af 100644
--- a/ranger/gui/ui.py
+++ b/ranger/gui/ui.py
@@ -22,6 +22,7 @@ from .displayable import DisplayableContainer
 from ranger.gui.curses_shortcuts import ascii_only
 from ranger.container.keymap import CommandArgs
 from .mouse_event import MouseEvent
+from ranger.ext.keybinding_parser import ALT_KEY
 
 TERMINALS_WITH_TITLE = ("xterm", "xterm-256color", "rxvt",
 		"rxvt-256color", "rxvt-unicode", "aterm", "Eterm",
@@ -183,9 +184,14 @@ class UI(DisplayableContainer):
 					keys.append(getkey)
 			if len(keys) == 1:
 				keys.append(-1)
+			elif keys[0] == 27:
+				keys[0] = ALT_KEY
 			if self.settings.xterm_alt_key:
 				if len(keys) == 2 and keys[1] in range(127, 256):
-					keys = [27, keys[1] - 128]
+					if keys[0] == 195:
+						keys = [ALT_KEY, keys[1] - 64]
+					elif keys[0] == 194:
+						keys = [ALT_KEY, keys[1] - 128]
 			self.handle_keys(*keys)
 			self.set_load_mode(previous_load_mode)
 			if self.settings.flushinput and not self.console.visible: