summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMaciejDym <[email protected]>2021-01-09 08:51:34 +0100
committerAmir Rajan <[email protected]>2021-01-11 04:26:28 -0600
commit4aac5a65acfd4f989c1af416bd70cc368ee0fff3 (patch)
treedf07d7886b1ed2eb8b229fcf5ae25ded412982e4
parentb6e6b9187ef88f4900b8b29bbce56ec1631ce099 (diff)
downloaddragonruby-game-toolkit-contrib-4aac5a65acfd4f989c1af416bd70cc368ee0fff3.tar.gz
dragonruby-game-toolkit-contrib-4aac5a65acfd4f989c1af416bd70cc368ee0fff3.zip
Fixes to the code according to @kfischer-okarin 's suggestions. Some minor deletions of code that isn't needed
-rw-r--r--dragon/console_prompt.rb18
-rw-r--r--dragon/inputs.rb1
2 files changed, 12 insertions, 7 deletions
diff --git a/dragon/console_prompt.rb b/dragon/console_prompt.rb
index 9fb1b95..1eddf98 100644
--- a/dragon/console_prompt.rb
+++ b/dragon/console_prompt.rb
@@ -8,6 +8,9 @@
module GTK
class Console
class Prompt
+ # ? Can be changed, it was just taken from my editor settings :>
+ WORD_LIMITER_CHARS = "`~!@#$%^&*-=+()[]{}\|;:'\",.<>/?_ \t\n\0".chars
+
attr_accessor :current_input_str, :font_style, :console_text_width, :last_input_str, :last_input_str_changed
def initialize(font_style:, text_color:, console_text_width:)
@@ -69,11 +72,11 @@ module GTK
# TODO: (requires re-writing a lot of the code most likely)
# ?? how can we put in regex? the code would be cleaner that way \ amir please fix :P \\ abolish consoles :>
def move_cursor_left_word
- str = @current_input_str[0..[@cursor_position - 1, 0].sort[1]]
- # ? Can be changed, it was just taken from my editor settings :>
- @cursor_position = ("`~!@#$%^&*-=+()[]{}\|;:'\",.<>/?_ \t\n\0".chars.map { |char|
+ str = @current_input_str[0..[@cursor_position - 1, 0].max]
+ cand = WORD_LIMITER_CHARS.map { |char|
(val = str.rindex char) ? (val + 1 == @cursor_position ? val : val + 1) : 0
- }.sort.reverse[0])
+ }
+ @cursor_position = cand.max
update_cursor_position_px
end
@@ -82,13 +85,14 @@ module GTK
update_cursor_position_px
end
+ # ? Not sure if this is the most efficient solution
+ # ? but it does sure work
def move_cursor_right_word
str = @current_input_str[@cursor_position..@current_input_str.length]
- # ? Can be changed, it was just taken from my editor settings :>
- cand = ("`~!@#$%^&*-=+()[]{}\|;:'\",.<>/?_ \t\n\0".chars.map { |char|
+ cand = (WORD_LIMITER_CHARS.map { |char|
(val = str.index char) ? val : 0
}.sort - [0])
- (cand == []) ? @cursor_position = @current_input_str.length : @cursor_position += (cand[0]+0)
+ (cand == []) ? @cursor_position = @current_input_str.length : @cursor_position += (cand[0])
update_cursor_position_px
end
diff --git a/dragon/inputs.rb b/dragon/inputs.rb
index 6e6439d..13cfe06 100644
--- a/dragon/inputs.rb
+++ b/dragon/inputs.rb
@@ -275,6 +275,7 @@ module GTK
if m.end_with_bang?
clear_after_return = true
end
+
value = self.instance_variable_get("@#{m.without_ending_bang}".to_sym)
clear_key m if clear_after_return
[m.without_ending_bang, value]