Skip to content

Commit 1eb21b3

Browse files
committed
in string number replacement
1 parent b02c331 commit 1eb21b3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+67
-2166
lines changed

main/string_object.rb

Lines changed: 61 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -6,104 +6,106 @@ class StringObject
66

77
def initialize(s)
88
@content = s
9-
@object_list = [methode, arguments || [] ]
10-
@position = [0..0]
11-
end
9+
end
1210

1311
def append(key)
1412
@content += key.to_s
15-
@object_list = [methode, arguments]
1613
end
1714

1815
def delete #last Char
1916
@content.chop!
20-
@object_list = [methode, arguments]
2117
end
2218

2319
def methode
2420
@content.split.to_a[0]
2521
end
2622

27-
def arguments
28-
array = @content.split.to_a
29-
#splits the string after the methode into arguments array
30-
if (array.count > 2)
31-
update(array)
32-
else
33-
[]
23+
def update_param(x_mouse, y_mouse)
24+
#Try to find beginn of param and set this as the char_position to prevent unintendet param change!!!
25+
char_position = find_char($app.pressed[0])
26+
found_number = find_number(char_position) unless char_position.nil?
27+
if found_number and found_number != [0..0]
28+
new_param_value = -$app.width/2+x_mouse-length($app.initial_param[:string])+$app.initial_param[:value]
29+
begin_of_param = found_number[0].first
30+
current_param_length = @content[found_number[0]].to_s.length
31+
@content[begin_of_param, current_param_length] = new_param_value.to_s
3432
end
3533
end
3634

37-
def update_argument(x_mouse, y_mouse)
38-
update_argument_position
39-
arg = find_argument($app.pressed[0])
40-
if arg
41-
new_arg_value = -$app.width/2+x_mouse+$app.editor_left_margin-length((methode+ " ").to_s)-length(@object_list[1][0..arg].join(" ").to_s)+$app.initial_arg_value
42-
@object_list[1][arg] = new_arg_value
43-
@content = @object_list.first + " " + @object_list[1].join(", ") + "\n" if @object_list.first
44-
end
45-
end
46-
47-
def get_param_value(x,y)
35+
def get_param_values
4836
#get the rigth param of x position and give the value back
49-
arg = find_argument(x)
50-
if arg
51-
value = @object_list[1][arg]
52-
else
53-
value = 0
37+
char_position = find_char($app.pressed[0])
38+
if char_position
39+
found_number = find_number(char_position)[0]
40+
unless found_number == [0..0]
41+
number = @content[found_number].to_i
42+
#return string without begin of number (because it will change):
43+
string = @content[0..found_number.first-1]
44+
return { :value => number, :string => string }
45+
end
5446
end
55-
return value
5647
end
5748

5849
def set_position=(range)
50+
#of the string in the editor
5951
@position = range
6052
end
6153

6254
def get_position
63-
#get the first nuber of an range x..y
55+
#get the first number of an range x..y
6456
@position.to_a.first
6557
end
6658

6759
private
6860

69-
def update(array)
70-
a = array.map do |e|
71-
if /[[:alpha:]]/.match(e)
72-
e
73-
else
74-
e.to_i
75-
end
76-
end
77-
a[1..-1]
78-
end
79-
8061
def length(s)
8162
text_width(s.to_s).to_i unless s.nil?
8263
end
8364

84-
def update_argument_position
85-
start_position = $app.width/2+$app.editor_left_margin+length((methode).to_s)
86-
arg_length_new = 0
87-
space = length(" ")
88-
@argument_position = Hash.new {|this_hash,missing_key| #set always a new hash to keep track of growing numbers
65+
def update_char_position
66+
start_position = $app.width/2
67+
char_length_new = 0
68+
@char_position = Hash.new {|this_hash,missing_key| #set always a new hash to keep track of growing numbers
8969
found_key = this_hash.keys.find {|this_key| this_key.class == Range && this_key.include?(missing_key) }
9070
found_key ? this_hash[missing_key] = this_hash[found_key] : :undefined
9171
} #source: http://www.developwithpurpose.com/ruby-hash-awesomeness-part-2/
92-
arguments.each_with_index do |value, k|
93-
arg_length = length(value)
94-
arg_range = [
95-
start_position+arg_length_new..
96-
start_position+arg_length_new+arg_length
72+
@content.chars.each_with_index do |value, k|
73+
char_length = length(value)
74+
char_range = [
75+
start_position+char_length_new..
76+
start_position+char_length_new+char_length
9777
]
98-
@argument_position[arg_range[0]] = k
99-
arg_length_new = arg_length_new + arg_length + space
100-
end
78+
@char_position[char_range[0]] = k
79+
char_length_new = char_length_new + char_length
80+
end
10181
end
10282

103-
def find_argument(x_position)
104-
#return argument on rigth position
105-
update_argument_position # first initialisation on mouse down
106-
arg = @argument_position[x_position]
107-
arg unless arg == :undefined
83+
def find_char(x_position)
84+
update_char_position
85+
char_position = @char_position[x_position]
86+
char_position unless char_position == :undefined
87+
end
88+
89+
def find_number(start_position)
90+
#returns the range position of the selected number of the String (refr. to recursion--)
91+
left_position, right_position = start_position, start_position
92+
left_search, right_search = true, true
93+
while (left_search) or (right_search) and left_position > 0
94+
if @content[left_position].match(/^-?[0-9]?(\.[0-9]+)?$+/)
95+
left_position -=1
96+
else
97+
left_search = false
98+
end
99+
if !@content[right_position].nil? and @content[right_position].match(/^-?[0-9]?(\.[0-9]+)?$+/)
100+
right_position +=1
101+
else
102+
right_search = false
103+
end
104+
end
105+
if start_position == left_position and right_position
106+
[0..0]
107+
else
108+
[left_position+1..right_position-1]
109+
end
108110
end
109111
end

main/watch.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ def check_param(x,y)
2020
y_position = @cursor.y_position
2121
string_object = @lines.positiontable(y_position)
2222
if (string_object.position[0]).include?($app.pressed[1])
23-
string_object.update_argument(x,y) unless string_object == :undefined
23+
string_object.update_param(x,y) unless string_object == :undefined
2424
end
2525
end
2626

2727
def get_param(x,y)
2828
y_position = @cursor.y_position
2929
string_object = @lines.positiontable(y_position)
30-
string_object.get_param_value(x,y_position) unless string_object == :undefined
30+
string_object.get_param_values unless string_object == :undefined
3131
end
32-
3332
end

simple_live_coding.app/Contents/Info.plist

Lines changed: 0 additions & 58 deletions
This file was deleted.
-46.6 KB
Binary file not shown.

simple_live_coding.app/Contents/PkgInfo

Lines changed: 0 additions & 1 deletion
This file was deleted.

simple_live_coding.app/Contents/Resources/Java

Lines changed: 0 additions & 1 deletion
This file was deleted.
-98.5 KB
Binary file not shown.

simple_live_coding.app/lib/MANIFEST.MF

Lines changed: 0 additions & 3 deletions
This file was deleted.

simple_live_coding.app/lib/args.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.
-179 KB
Binary file not shown.

0 commit comments

Comments
 (0)