lib/textbringer/commands.rb in textbringer-0.1.1 vs lib/textbringer/commands.rb in textbringer-0.1.2
- old
+ new
@@ -77,25 +77,24 @@
Buffer.current.goto_line(n.to_i)
Window.current.recenter_if_needed
end
define_command(:self_insert) do |n = number_prefix_arg|
- c = Controller.current.last_key.chr(Encoding::UTF_8)
+ c = Controller.current.last_key
merge_undo = Controller.current.last_command == :self_insert
n.times do
Buffer.current.insert(c, merge_undo)
end
end
define_command(:quoted_insert) do |n = number_prefix_arg|
c = Controller.current.read_char
- if !c.is_a?(Integer)
+ if !c.is_a?(String)
raise "Invalid key"
end
- ch = c.chr(Encoding::UTF_8)
n.times do
- Buffer.current.insert(ch)
+ Buffer.current.insert(c)
end
end
define_command(:kill_line) do
Buffer.current.kill_line(Controller.current.last_command == :kill_region)
@@ -234,11 +233,11 @@
end
exit(status)
end
define_command(:suspend_textbringer) do
- Ncurses.endwin
+ Curses.close_screen
Process.kill(:STOP, $$)
end
define_command(:pwd) do
message(Dir.pwd)
@@ -437,11 +436,11 @@
end
end
define_command(:digit_argument) do
|arg = current_prefix_arg|
- n = last_key.chr.to_i
+ n = last_key.to_i
Controller.current.prefix_arg =
case arg
when Integer
arg * 10 + (arg < 0 ? -n : n)
when :-
@@ -489,22 +488,17 @@
define_command(:recursive_edit) do
Controller.current.recursive_edit
end
ISEARCH_MODE_MAP = Keymap.new
- (0x20..0x7e).each do |c|
+ (?\x20..?\x7e).each do |c|
ISEARCH_MODE_MAP.define_key(c, :isearch_printing_char)
end
ISEARCH_MODE_MAP.define_key(?\t, :isearch_printing_char)
ISEARCH_MODE_MAP.handle_undefined_key do |key|
- if key.is_a?(Integer) && key > 0x80
- begin
- key.chr(Encoding::UTF_8)
- :isearch_printing_char
- rescue RangeError
- nil
- end
+ if key.is_a?(String) && /[\0-\x7f]/ !~ key
+ :isearch_printing_char
else
nil
end
end
ISEARCH_MODE_MAP.define_key(:backspace, :isearch_delete_char)
@@ -572,10 +566,10 @@
isearch_done
raise Quit
end
define_command(:isearch_printing_char) do
- c = Controller.current.last_key.chr(Encoding::UTF_8)
+ c = Controller.current.last_key
ISEARCH_STATUS[:string].concat(c)
isearch_search
end
define_command(:isearch_delete_char) do