redcar 0.9.2 → 0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (234) hide show
  1. data/CHANGES +34 -4
  2. data/Rakefile +2 -1
  3. data/lib/redcar.rb +3 -3
  4. data/lib/redcar/installer.rb +2 -3
  5. data/plugins/application/features/step_definitions/dialog_steps.rb +7 -0
  6. data/plugins/application/features/step_definitions/key_steps.rb +18 -0
  7. data/plugins/application/features/step_definitions/menu_steps.rb +5 -6
  8. data/plugins/application/features/step_definitions/speedbar_steps.rb +29 -9
  9. data/plugins/application/features/step_definitions/tree_steps.rb +13 -0
  10. data/plugins/application/features/support/env.rb +39 -5
  11. data/plugins/application/features/support/fake_event.rb +12 -0
  12. data/plugins/application/lib/application.rb +5 -6
  13. data/plugins/application/lib/application/dialog.rb +53 -10
  14. data/plugins/application/lib/application/dialogs/modeless_list_dialog.rb +85 -0
  15. data/plugins/application/lib/application/keymap.rb +10 -8
  16. data/plugins/application/lib/application/menu.rb +38 -16
  17. data/plugins/application/lib/application/treebook.rb +30 -0
  18. data/plugins/application/lib/application/window.rb +20 -2
  19. data/plugins/application/spec/application/command/executor_spec.rb +1 -0
  20. data/plugins/application/spec/application/menu_spec.rb +26 -26
  21. data/plugins/application/spec/application/treebook_spec.rb +6 -6
  22. data/plugins/application/spec/spec_helper.rb +10 -1
  23. data/plugins/application_swt/lib/application_swt.rb +25 -3
  24. data/plugins/application_swt/lib/application_swt/dialog_adapter.rb +48 -27
  25. data/plugins/application_swt/lib/application_swt/dialogs/filter_list_dialog_controller.rb +22 -11
  26. data/plugins/application_swt/lib/application_swt/dialogs/modeless_dialog.rb +113 -0
  27. data/plugins/application_swt/lib/application_swt/dialogs/modeless_html_dialog.rb +85 -0
  28. data/plugins/application_swt/lib/application_swt/dialogs/modeless_list_dialog_controller.rb +143 -0
  29. data/plugins/application_swt/lib/application_swt/gradient.rb +61 -0
  30. data/plugins/application_swt/lib/application_swt/menu/binding_translator.rb +4 -4
  31. data/plugins/application_swt/lib/application_swt/notebook.rb +5 -8
  32. data/plugins/application_swt/lib/application_swt/speedbar.rb +1 -0
  33. data/plugins/application_swt/lib/application_swt/treebook.rb +6 -8
  34. data/plugins/application_swt/lib/application_swt/window.rb +85 -57
  35. data/plugins/application_swt/lib/swt/graphics_utils.rb +23 -0
  36. data/plugins/application_swt/lib/swt/vtab_folder.rb +7 -0
  37. data/plugins/application_swt/lib/swt/vtab_label.rb +1 -1
  38. data/plugins/application_swt/spec/application_swt/gradient_spec.rb +142 -0
  39. data/plugins/auto_completer/lib/auto_completer.rb +10 -42
  40. data/plugins/auto_completer/lib/auto_completer/list_dialog.rb +21 -0
  41. data/plugins/clojure/lib/clojure.rb +33 -0
  42. data/plugins/{repl/lib/repl/clojure_mirror.rb → clojure/lib/clojure/repl_mirror.rb} +16 -20
  43. data/plugins/clojure/plugin.rb +9 -0
  44. data/plugins/{repl/spec/repl/clojure_mirror_spec.rb → clojure/spec/clojure/repl_mirror_spec.rb} +12 -13
  45. data/plugins/clojure/spec/spec_helper.rb +5 -0
  46. data/plugins/{repl → clojure}/vendor/Wrapper.clj +0 -0
  47. data/plugins/{repl → clojure}/vendor/dummy +0 -0
  48. data/plugins/{repl → clojure}/vendor/enclojure-wrapper.jar +0 -0
  49. data/plugins/connection_manager/lib/connection_manager.rb +13 -13
  50. data/plugins/declarations/lib/declarations.rb +17 -6
  51. data/plugins/document_search/features/find.feature +389 -0
  52. data/plugins/document_search/features/find_and_replace.feature +723 -0
  53. data/plugins/document_search/features/replace.feature +69 -62
  54. data/plugins/document_search/lib/document_search.rb +81 -64
  55. data/plugins/document_search/lib/document_search/commands.rb +258 -0
  56. data/plugins/document_search/lib/document_search/find_and_replace_speedbar.rb +142 -0
  57. data/plugins/document_search/lib/document_search/find_speedbar.rb +102 -0
  58. data/plugins/document_search/lib/document_search/query_options.rb +45 -0
  59. data/plugins/edit_view/features/case_change.feature +9 -5
  60. data/plugins/edit_view/features/step_definitions/editing_steps.rb +19 -0
  61. data/plugins/edit_view/lib/edit_view.rb +15 -12
  62. data/plugins/edit_view/lib/edit_view/actions/arrow_keys.rb +12 -2
  63. data/plugins/edit_view/lib/edit_view/commands/text_conversion_commands.rb +1 -1
  64. data/plugins/edit_view/lib/edit_view/document.rb +129 -99
  65. data/plugins/edit_view_swt/lib/edit_view_swt.rb +33 -15
  66. data/plugins/encryption/encryption.rb +2 -0
  67. data/plugins/find-in-project/lib/find_in_project.rb +3 -5
  68. data/plugins/find-in-project/lib/find_in_project/views/index.html.erb +2 -0
  69. data/plugins/groovy/features/step_definitions/groovy_steps.rb +2 -2
  70. data/plugins/groovy/features/syntax_check_groovy.feature +3 -3
  71. data/plugins/groovy/lib/groovy.rb +38 -0
  72. data/plugins/groovy/lib/groovy/commands.rb +10 -0
  73. data/plugins/{repl/lib/repl/groovy_mirror.rb → groovy/lib/groovy/repl_mirror.rb} +33 -13
  74. data/plugins/groovy/lib/{syntax_check/groovy.rb → groovy/syntax_checker.rb} +13 -8
  75. data/plugins/groovy/plugin.rb +5 -4
  76. data/plugins/{repl/spec/repl/groovy_mirror_spec.rb → groovy/spec/groovy/repl_mirror_spec.rb} +14 -13
  77. data/plugins/groovy/spec/spec_helper.rb +5 -0
  78. data/plugins/html_view/assets/json2.js +476 -0
  79. data/plugins/html_view/lib/html_view.rb +1 -0
  80. data/plugins/java/features/fixtures/test.java +0 -0
  81. data/plugins/java/features/support/env.rb +27 -0
  82. data/plugins/java/features/syntax_check_java.feature +86 -0
  83. data/plugins/java/lib/syntax_check/java.rb +86 -0
  84. data/plugins/java/plugin.rb +7 -0
  85. data/plugins/javascript/features/fixtures/test2.js +5 -0
  86. data/plugins/javascript/features/step_definitions/javascript_steps.rb +16 -0
  87. data/plugins/javascript/features/support/env.rb +14 -0
  88. data/plugins/javascript/features/syntax_check_javascript.feature +46 -3
  89. data/plugins/javascript/lib/syntax_check/javascript.rb +15 -9
  90. data/plugins/line_tools/features/trim_line.feature +49 -0
  91. data/plugins/line_tools/lib/line_tools.rb +5 -1
  92. data/plugins/mirah/README +7 -0
  93. data/plugins/mirah/features/fixtures/test.mirah +2 -0
  94. data/plugins/mirah/features/syntax_check_mirah.feature +46 -0
  95. data/plugins/mirah/lib/mirah.rb +43 -0
  96. data/plugins/mirah/lib/mirah/my_error_handler.rb +22 -0
  97. data/plugins/mirah/lib/mirah/repl_mirror.rb +50 -0
  98. data/plugins/mirah/lib/mirah/syntax_checker.rb +38 -0
  99. data/plugins/mirah/plugin.rb +8 -0
  100. data/plugins/mirah/spec/mirah/repl_mirror_spec.rb +188 -0
  101. data/plugins/mirah/spec/spec_helper.rb +5 -0
  102. data/plugins/mirah/vendor/mirah-parser.jar +0 -0
  103. data/plugins/pair_highlighter/lib/pair_highlighter/document_controller.rb +24 -23
  104. data/plugins/plugin_manager_ui/lib/plugin_manager_ui.rb +10 -1
  105. data/plugins/plugin_manager_ui/views/index.html.erb +2 -0
  106. data/plugins/project/features/find_file.feature +40 -16
  107. data/plugins/project/features/highlight_focussed_tab.feature +16 -10
  108. data/plugins/project/features/step_definitions/find_file_steps.rb +11 -0
  109. data/plugins/project/features/step_definitions/project_tree_steps.rb +5 -1
  110. data/plugins/project/features/support/env.rb +5 -0
  111. data/plugins/project/lib/project/commands.rb +8 -1
  112. data/plugins/project/lib/project/dir_controller.rb +4 -1
  113. data/plugins/project/lib/project/find_file_dialog.rb +16 -12
  114. data/plugins/project/lib/project/manager.rb +30 -1
  115. data/plugins/project_search/vendor/lucene/CHANGELOG +147 -0
  116. data/plugins/project_search/vendor/lucene/CONTRIBUTORS +17 -0
  117. data/plugins/project_search/vendor/lucene/Gemfile +9 -0
  118. data/plugins/project_search/vendor/lucene/Gemfile.lock +33 -0
  119. data/plugins/project_search/vendor/lucene/LICENSE +19 -0
  120. data/plugins/project_search/vendor/lucene/README.rdoc +283 -0
  121. data/plugins/project_search/vendor/lucene/Rakefile +35 -0
  122. data/plugins/project_search/vendor/lucene/examples/active_model/serializers.rb +25 -0
  123. data/plugins/project_search/vendor/lucene/examples/active_model/validation.rb +26 -0
  124. data/plugins/project_search/vendor/lucene/examples/admin/Rakefile +4 -0
  125. data/plugins/project_search/vendor/lucene/examples/admin/admin.rb +29 -0
  126. data/plugins/project_search/vendor/lucene/examples/admin/public/jquery.js +4376 -0
  127. data/plugins/project_search/vendor/lucene/examples/admin/public/neo4j.css +153 -0
  128. data/plugins/project_search/vendor/lucene/examples/admin/public/neo_admin.js +18 -0
  129. data/plugins/project_search/vendor/lucene/examples/admin/spec/admin_spec.rb +26 -0
  130. data/plugins/project_search/vendor/lucene/examples/admin/views/index.erb +21 -0
  131. data/plugins/project_search/vendor/lucene/examples/filetree/README.rdoc +9 -0
  132. data/plugins/project_search/vendor/lucene/examples/filetree/app.rb +7 -0
  133. data/plugins/project_search/vendor/lucene/examples/filetree/batch.props +5 -0
  134. data/plugins/project_search/vendor/lucene/examples/filetree/features/step_definitions/add_steps.rb +121 -0
  135. data/plugins/project_search/vendor/lucene/examples/filetree/features/support/env.rb +30 -0
  136. data/plugins/project_search/vendor/lucene/examples/filetree/features/support/rspec_helper.rb +50 -0
  137. data/plugins/project_search/vendor/lucene/examples/filetree/features/treesizes.feature +19 -0
  138. data/plugins/project_search/vendor/lucene/examples/imdb/1_create_neo_db.rb +66 -0
  139. data/plugins/project_search/vendor/lucene/examples/imdb/2_index_db.rb +23 -0
  140. data/plugins/project_search/vendor/lucene/examples/imdb/README +12 -0
  141. data/plugins/project_search/vendor/lucene/examples/imdb/find_actors.rb +56 -0
  142. data/plugins/project_search/vendor/lucene/examples/imdb/install.sh +12 -0
  143. data/plugins/project_search/vendor/lucene/examples/imdb/model.rb +37 -0
  144. data/plugins/project_search/vendor/lucene/examples/railway/README +111 -0
  145. data/plugins/project_search/vendor/lucene/examples/railway/railnet-app.rb +31 -0
  146. data/plugins/project_search/vendor/lucene/examples/railway/railnet-data.rb +42 -0
  147. data/plugins/project_search/vendor/lucene/examples/rest/example.rb +41 -0
  148. data/plugins/project_search/vendor/lucene/examples/you_might_know/YouMightKnow.java +60 -0
  149. data/plugins/project_search/vendor/lucene/examples/you_might_know/all_simple_paths.rb +34 -0
  150. data/plugins/project_search/vendor/lucene/examples/you_might_know/nodes.rb +34 -0
  151. data/plugins/project_search/vendor/lucene/examples/you_might_know/you_might_know.rb +50 -0
  152. data/plugins/project_search/vendor/lucene/lib/lucene.rb +15 -0
  153. data/plugins/project_search/vendor/lucene/lib/lucene/config.rb +145 -0
  154. data/plugins/project_search/vendor/lucene/lib/lucene/document.rb +96 -0
  155. data/plugins/project_search/vendor/lucene/lib/lucene/field_info.rb +144 -0
  156. data/plugins/project_search/vendor/lucene/lib/lucene/hits.rb +54 -0
  157. data/plugins/project_search/vendor/lucene/lib/lucene/index.rb +267 -0
  158. data/plugins/project_search/vendor/lucene/lib/lucene/index_info.rb +146 -0
  159. data/plugins/project_search/vendor/lucene/lib/lucene/index_searcher.rb +157 -0
  160. data/plugins/project_search/vendor/lucene/lib/lucene/jars.rb +5 -0
  161. data/plugins/project_search/vendor/lucene/lib/lucene/query_dsl.rb +135 -0
  162. data/plugins/project_search/vendor/lucene/lib/lucene/transaction.rb +117 -0
  163. data/plugins/project_search/vendor/lucene/lib/lucene/version.rb +3 -0
  164. data/plugins/project_search/vendor/lucene/lucene.gemspec +23 -0
  165. data/plugins/project_search/vendor/lucene/spec/lucene/document_spec.rb +32 -0
  166. data/plugins/project_search/vendor/lucene/spec/lucene/field_info_spec.rb +70 -0
  167. data/plugins/project_search/vendor/lucene/spec/lucene/index_info_spec.rb +76 -0
  168. data/plugins/project_search/vendor/lucene/spec/lucene/index_spec.rb +643 -0
  169. data/plugins/project_search/vendor/lucene/spec/lucene/query_dsl_spec.rb +142 -0
  170. data/plugins/project_search/vendor/lucene/spec/lucene/sort_spec.rb +101 -0
  171. data/plugins/project_search/vendor/lucene/spec/lucene/spec_helper.rb +10 -0
  172. data/plugins/project_search/vendor/lucene/spec/lucene/transaction_spec.rb +118 -0
  173. data/plugins/redcar/features/alter_font_size.feature +25 -0
  174. data/plugins/redcar/features/step_definitions/font_steps.rb +34 -0
  175. data/plugins/redcar/redcar.rb +256 -43
  176. data/plugins/repl/features/command_editing.feature +55 -0
  177. data/plugins/repl/features/command_history.feature +75 -0
  178. data/plugins/repl/features/step_definitions/repl_steps.rb +17 -1
  179. data/plugins/repl/features/support/env.rb +24 -0
  180. data/plugins/repl/features/support/fake_repl.rb +16 -0
  181. data/plugins/repl/lib/repl.rb +17 -74
  182. data/plugins/repl/lib/repl/repl_command.rb +20 -0
  183. data/plugins/repl/lib/repl/repl_mirror.rb +168 -22
  184. data/plugins/repl/lib/repl/repl_tab.rb +131 -6
  185. data/plugins/repl/plugin.rb +1 -1
  186. data/plugins/repl/spec/repl/repl_mirror_spec.rb +72 -0
  187. data/plugins/repl/spec/spec_helper.rb +1 -1
  188. data/plugins/repl_swt/lib/repl_swt.rb +7 -0
  189. data/plugins/repl_swt/lib/repl_swt/key_listener.rb +43 -0
  190. data/plugins/repl_swt/plugin.rb +8 -0
  191. data/plugins/ruby/lib/ruby.rb +35 -0
  192. data/plugins/{repl/lib/repl/ruby_mirror.rb → ruby/lib/ruby/repl_mirror.rb} +12 -12
  193. data/plugins/ruby/lib/{syntax_check/ruby.rb → ruby/syntax_checker.rb} +3 -3
  194. data/plugins/ruby/plugin.rb +5 -4
  195. data/plugins/{repl/spec/repl/ruby_mirror_spec.rb → ruby/spec/ruby/repl_mirror_spec.rb} +38 -29
  196. data/plugins/ruby/spec/spec_helper.rb +5 -0
  197. data/plugins/runnables/lib/runnables.rb +2 -0
  198. data/plugins/runnables/lib/runnables/command_output_controller.rb +5 -0
  199. data/plugins/runnables/lib/runnables/output_processor.rb +14 -3
  200. data/plugins/runnables/views/command_output.html.erb +3 -2
  201. data/plugins/scm/lib/scm.rb +4 -2
  202. data/plugins/scm/lib/scm/diff_mirror.rb +6 -6
  203. data/plugins/scm_git/lib/scm_git.rb +136 -107
  204. data/plugins/scm_git/lib/scm_git/change.rb +28 -19
  205. data/plugins/snippets/lib/snippets/explorer.rb +2 -2
  206. data/plugins/swt/lib/swt/full_swt.rb +1 -0
  207. data/plugins/syntax_check/features/step_definitions/syntax_check_steps.rb +4 -0
  208. data/plugins/syntax_check/features/support/env.rb +3 -0
  209. data/plugins/syntax_check/lib/syntax_check.rb +71 -5
  210. data/plugins/syntax_check/lib/syntax_check/annotation.rb +61 -0
  211. data/plugins/test_runner/lib/test_runner.rb +39 -0
  212. data/plugins/test_runner/lib/test_runner/rspec_runner.rb +20 -0
  213. data/plugins/test_runner/lib/test_runner/run_test_command.rb +63 -0
  214. data/plugins/test_runner/lib/test_runner/runnable_test_runner.rb +26 -0
  215. data/plugins/test_runner/plugin.rb +8 -0
  216. data/plugins/test_runner/spec/run_test_command_spec.rb +51 -0
  217. data/plugins/test_runner/spec/spec_helper.rb +5 -0
  218. data/plugins/textmate/lib/textmate.rb +12 -2
  219. data/plugins/textmate/vendor/redcar-bundles/Bundles/HTML.tmbundle/Syntaxes/HTML.plist +0 -2
  220. data/plugins/textmate/vendor/redcar-bundles/Bundles/Mirah.tmbundle/Syntaxes/Mirah.plist +22 -0
  221. data/plugins/textmate/vendor/redcar-bundles/Bundles/Mirah.tmbundle/info.plist +12 -0
  222. data/plugins/textmate/vendor/redcar-bundles/Bundles/Ruby.tmbundle/Syntaxes/Ruby.plist +2 -0
  223. data/plugins/todo_list/lib/todo_list.rb +7 -0
  224. data/plugins/todo_list/lib/todo_list/todo_controller.rb +3 -1
  225. data/plugins/tree/lib/tree.rb +4 -0
  226. data/plugins/tree_view_swt/lib/tree_view_swt.rb +5 -0
  227. data/plugins/web_bookmarks/lib/web_bookmarks.rb +10 -0
  228. metadata +137 -22
  229. data/plugins/document_search/features/search.feature +0 -163
  230. data/plugins/document_search/lib/document_search/replace_all_command.rb +0 -27
  231. data/plugins/document_search/lib/document_search/replace_command.rb +0 -38
  232. data/plugins/document_search/lib/document_search/replace_next_command.rb +0 -27
  233. data/plugins/document_search/lib/document_search/search_and_replace.rb +0 -81
  234. data/plugins/ruby/README +0 -6
@@ -46,7 +46,12 @@ module Redcar
46
46
  def self.column_previous(edit_view)
47
47
  return false if edit_view.document.block_selection_mode?
48
48
  doc = edit_view.document
49
- doc.cursor_offset = move_left_offset(edit_view)
49
+ if doc.selection?
50
+ doc.cursor_offset = doc.selection_range.first
51
+ doc.set_selection_range(doc.selection_range.first, doc.selection_range.first)
52
+ else
53
+ doc.cursor_offset = move_left_offset(edit_view)
54
+ end
50
55
  ArrowHandler.ensure_cursor_in_view(edit_view)
51
56
  true
52
57
  end
@@ -104,7 +109,12 @@ module Redcar
104
109
  def self.column_next(edit_view)
105
110
  return false if edit_view.document.block_selection_mode?
106
111
  doc = edit_view.document
107
- doc.cursor_offset = move_right_offset(edit_view)
112
+ if doc.selection?
113
+ doc.cursor_offset = doc.selection_range.last
114
+ doc.set_selection_range(doc.selection_range.last, doc.selection_range.last)
115
+ else
116
+ doc.cursor_offset = move_right_offset(edit_view)
117
+ end
108
118
  ArrowHandler.ensure_cursor_in_view(edit_view)
109
119
  true
110
120
  end
@@ -28,7 +28,7 @@ module Redcar
28
28
 
29
29
  class TitlizeTextCommand < TextConversionCommand
30
30
  def convert(text)
31
- text.gsub(/\b('?[a-z])/) { $1.capitalize }
31
+ text.downcase.gsub(/\b('?[a-z])/) { $1.capitalize }
32
32
  end
33
33
  end
34
34
 
@@ -6,7 +6,7 @@ module Redcar
6
6
  include Redcar::Model
7
7
  include Redcar::Observable
8
8
  extend Forwardable
9
-
9
+
10
10
  def self.all_document_controller_types
11
11
  result = []
12
12
  Redcar.plugin_manager.objects_implementing(:document_controller_types).each do |object|
@@ -14,19 +14,19 @@ module Redcar
14
14
  end
15
15
  result
16
16
  end
17
-
17
+
18
18
  class << self
19
19
  attr_accessor :default_mirror
20
20
  end
21
-
21
+
22
22
  attr_reader :mirror, :edit_view
23
-
23
+
24
24
  def initialize(edit_view)
25
25
  @edit_view = edit_view
26
26
  @grammar = Redcar::Grammar.new(self)
27
27
  get_controllers
28
28
  end
29
-
29
+
30
30
  def get_controllers
31
31
  @controllers = {
32
32
  Controller::ModificationCallbacks => [],
@@ -54,7 +54,7 @@ module Redcar
54
54
  end
55
55
 
56
56
  end
57
-
57
+
58
58
  def controllers(klass=nil)
59
59
  if klass
60
60
  @controllers.values.flatten.uniq.select {|c| c.is_a?(klass) }
@@ -90,11 +90,11 @@ module Redcar
90
90
  def modified?
91
91
  @modified
92
92
  end
93
-
93
+
94
94
  def title
95
95
  @mirror ? @mirror.title : nil
96
96
  end
97
-
97
+
98
98
  # helper method to get the mirror's path if it has one
99
99
  def path
100
100
  if @mirror and @mirror.respond_to?(:path) and @mirror.path
@@ -103,11 +103,11 @@ module Redcar
103
103
  nil
104
104
  end
105
105
  end
106
-
106
+
107
107
  def exists?
108
108
  edit_view.exists?
109
109
  end
110
-
110
+
111
111
  def mirror=(new_mirror)
112
112
  notify_listeners(:new_mirror, new_mirror) do
113
113
  @mirror = new_mirror
@@ -117,13 +117,13 @@ module Redcar
117
117
  update_from_mirror
118
118
  end
119
119
  end
120
-
120
+
121
121
  def mirror_changed?
122
122
  mirror and mirror.changed?
123
123
  end
124
124
 
125
125
  def verify_text(start_offset, end_offset, text)
126
- @change = [start_offset, end_offset, text]
126
+ @change = [start_offset, end_offset, text]
127
127
  @controllers[Controller::ModificationCallbacks].each do |controller|
128
128
  rescue_document_controller_error(controller) do
129
129
  controller.before_modify(start_offset, end_offset, text)
@@ -146,33 +146,33 @@ module Redcar
146
146
  end
147
147
  end
148
148
  end
149
- @change = nil
149
+ @change = nil
150
150
  notify_listeners(:changed)
151
151
  end
152
-
152
+
153
153
  def cursor_moved(new_offset)
154
154
  @controllers[Controller::CursorCallbacks].each do |controller|
155
155
  rescue_document_controller_error(controller) do
156
156
  controller.cursor_moved(new_offset)
157
157
  end
158
158
  end
159
- end
160
-
159
+ end
160
+
161
161
  def about_to_be_changed(start_offset, length, text)
162
162
  end
163
-
163
+
164
164
  def changed(start_offset, length, text)
165
165
  notify_listeners(:changed)
166
166
  end
167
-
167
+
168
168
  def selection_range_changed(start_offset, end_offset)
169
169
  notify_listeners(:selection_range_changed, start_offset..end_offset)
170
170
  end
171
-
171
+
172
172
  def single_line?
173
173
  controller.single_line?
174
174
  end
175
-
175
+
176
176
  # Returns the line delimiter for this document. Either
177
177
  # \n or \r\n. It will attempt to detect the delimiter from the document
178
178
  # or it will default to the platform delimiter.
@@ -182,8 +182,8 @@ module Redcar
182
182
  controller.get_line_delimiter
183
183
  end
184
184
 
185
- alias :delim :line_delimiter
186
-
185
+ alias :delim :line_delimiter
186
+
187
187
  # Is there any text selected? (Or equivalently, is the length
188
188
  # of the selection equal to 0)
189
189
  #
@@ -191,7 +191,7 @@ module Redcar
191
191
  def selection?
192
192
  selection_range.count > 0
193
193
  end
194
-
194
+
195
195
  # Insert text
196
196
  #
197
197
  # @param [Integer] offset character offset from the start of the document
@@ -201,14 +201,14 @@ module Redcar
201
201
  text = text.gsub(delim, "") if single_line?
202
202
  replace(offset, 0, text)
203
203
  end
204
-
204
+
205
205
  # Insert text at the cursor offset
206
206
  #
207
207
  # @param [String] text text to insert
208
208
  def insert_at_cursor(text)
209
209
  insert(cursor_offset, text)
210
210
  end
211
-
211
+
212
212
  # Delete text
213
213
  #
214
214
  # @param [Integer] offset character offset from the start of the document
@@ -226,39 +226,39 @@ module Redcar
226
226
  text = text.gsub(delim, "") if single_line?
227
227
  controller.replace(offset, length, text)
228
228
  end
229
-
229
+
230
230
  # Length of the document in characters
231
231
  #
232
232
  # @return [Integer]
233
233
  def length
234
234
  controller.length
235
235
  end
236
-
236
+
237
237
  # Number of lines.
238
238
  #
239
239
  # @return [Integer]
240
240
  def line_count
241
241
  controller.line_count
242
242
  end
243
-
243
+
244
244
  # The entire contents of the document
245
245
  #
246
246
  # @return [String]
247
247
  def to_s
248
248
  controller.to_s
249
249
  end
250
-
250
+
251
251
  # Set the contents of the document
252
252
  #
253
253
  # @param [String] text new text
254
254
  def text=(text)
255
255
  controller.text = text
256
- end
257
-
256
+ end
257
+
258
258
  def controller_text
259
259
  controller.text
260
260
  end
261
-
261
+
262
262
  # Get the line index of the given offset
263
263
  #
264
264
  # @param [Integer] offset zero-based character offset
@@ -266,7 +266,7 @@ module Redcar
266
266
  def line_at_offset(offset)
267
267
  controller.line_at_offset(offset)
268
268
  end
269
-
269
+
270
270
  # Get the character offset at the start of the given line
271
271
  #
272
272
  # @param [Integer] line zero-based line index
@@ -274,40 +274,40 @@ module Redcar
274
274
  def offset_at_line(line)
275
275
  controller.offset_at_line(line)
276
276
  end
277
-
277
+
278
278
  # Get the position of the cursor.
279
279
  #
280
280
  # @return [Integer] zero-based character offset
281
281
  def cursor_offset
282
282
  controller.cursor_offset
283
283
  end
284
-
284
+
285
285
  def cursor_line_offset
286
286
  cursor_offset - offset_at_line(cursor_line)
287
287
  end
288
-
288
+
289
289
  # Set the position of the cursor.
290
290
  #
291
291
  # @param [Integer] offset zero-based character offset
292
292
  def cursor_offset=(offset)
293
293
  controller.cursor_offset = offset
294
294
  end
295
-
295
+
296
296
  # The line index the cursor is on (zero-based)
297
297
  #
298
298
  # @return [Integer]
299
299
  def cursor_line
300
300
  line_at_offset(cursor_offset)
301
301
  end
302
-
302
+
303
303
  def cursor_line_start_offset
304
304
  offset_at_line(cursor_line)
305
305
  end
306
-
306
+
307
307
  def cursor_line_end_offset
308
308
  offset_at_line_end(cursor_line)
309
309
  end
310
-
310
+
311
311
  def offset_at_line_end(line_ix)
312
312
  if line_ix == line_count - 1
313
313
  end_offset = length
@@ -315,7 +315,7 @@ module Redcar
315
315
  end_offset = offset_at_line(line_ix + 1)
316
316
  end
317
317
  end
318
-
318
+
319
319
  def word
320
320
  @grammar.word
321
321
  end
@@ -328,20 +328,20 @@ module Redcar
328
328
  range = word_range_at_offset(offset)
329
329
  get_range(range.first, range.last - range.first)
330
330
  end
331
-
331
+
332
332
  # The word found at the current cursor offset.
333
333
  #
334
334
  # @return [String] the text of the word
335
335
  def current_word
336
336
  word_at_offset(cursor_offset)
337
337
  end
338
-
338
+
339
339
  # The range of the word at an offset.
340
340
  #
341
341
  # @param [Integer] an offset
342
342
  # @return [Range<Integer>] a range between two character offsets
343
343
  def word_range_at_offset(offset)
344
- line_ix = line_at_offset(offset)
344
+ line_ix = line_at_offset(offset)
345
345
  match_left = offset == 0 ? false : !/\s/.match(get_slice(offset - 1, offset))
346
346
  match_right = offset == length ? false : !/\s/.match(get_slice(offset, offset + 1))
347
347
  if match_left && match_right
@@ -354,7 +354,7 @@ module Redcar
354
354
  offset..offset
355
355
  end
356
356
  end
357
-
357
+
358
358
  # Returns the range of the word located around an offset.
359
359
  # Before using this method, it's best to make sure there actually
360
360
  # might be a word around the offset. This means we are not at the beginning
@@ -379,7 +379,7 @@ module Redcar
379
379
  end
380
380
  matched_offsets
381
381
  end
382
-
382
+
383
383
  # Returns the range of the word located left of an offset.
384
384
  # Before using this method, it's best to make sure there actually
385
385
  # might be a word left of the offset. This means we are not at the beginning
@@ -405,10 +405,10 @@ module Redcar
405
405
  end
406
406
  matched_offsets
407
407
  end
408
-
408
+
409
409
  # Returns the range of the word located right of an offset.
410
410
  # Before using this method, it's best to make sure there actually
411
- # might be a word right of the offset. This means we are not at the end of
411
+ # might be a word right of the offset. This means we are not at the end of
412
412
  # the file and there are no spaces right of the offset.
413
413
  #
414
414
  # @param [Integer] an offset
@@ -426,14 +426,14 @@ module Redcar
426
426
  end
427
427
  matched_offsets
428
428
  end
429
-
429
+
430
430
  # The range of the word at the current cursor position.
431
431
  #
432
432
  # @return [Range<Integer>] a range between two character offsets
433
433
  def current_word_range
434
434
  word_range_at_offset(cursor_offset)
435
435
  end
436
-
436
+
437
437
  # The range of text selected by the user.
438
438
  #
439
439
  # @return [Range<Integer>] a range between two character offsets
@@ -447,36 +447,36 @@ module Redcar
447
447
  def selection_ranges
448
448
  controller.selection_ranges
449
449
  end
450
-
450
+
451
451
  def selection_offset
452
452
  controller.selection_offset
453
453
  end
454
-
454
+
455
455
  def selection_offset=(value)
456
456
  set_selection_range(cursor_offset, value)
457
457
  end
458
-
458
+
459
459
  def selection_line
460
460
  line_at_offset(selection_offset)
461
461
  end
462
-
462
+
463
463
  def selection_line_offset
464
464
  selection_offset - offset_at_line(selection_line)
465
465
  end
466
-
467
- # Set the range of text selected by the user.
466
+
467
+ # Set the range of text selected by the user.
468
468
  #
469
469
  # @param [Integer] cursor_offset
470
470
  # @param [Integer] selection_offset
471
471
  def set_selection_range(cursor_offset, selection_offset)
472
472
  controller.set_selection_range(cursor_offset, selection_offset)
473
473
  end
474
-
474
+
475
475
  # Select all text in the document.
476
476
  def select_all
477
477
  set_selection_range(length, 0)
478
478
  end
479
-
479
+
480
480
  # Get the text selected by the user. If no text is selected
481
481
  # returns "".
482
482
  #
@@ -484,17 +484,17 @@ module Redcar
484
484
  def selected_text
485
485
  get_range(selection_range.begin, selection_range.count)
486
486
  end
487
-
487
+
488
488
  # Is the document in block selection mode.
489
489
  def block_selection_mode?
490
490
  controller.block_selection_mode?
491
491
  end
492
-
492
+
493
493
  # Turn the block selection mode on or off.
494
494
  def block_selection_mode=(boolean)
495
495
  controller.block_selection_mode = !!boolean
496
496
  end
497
-
497
+
498
498
  # Get a range of text from the document.
499
499
  #
500
500
  # @param [Integer] start the character offset of the start of the range
@@ -503,7 +503,7 @@ module Redcar
503
503
  def get_range(start, length)
504
504
  controller.get_range(start, length)
505
505
  end
506
-
506
+
507
507
  # Get a slice of text from the document.
508
508
  #
509
509
  # @param [Integer] start_offset the character offset of the start of the slice
@@ -513,7 +513,7 @@ module Redcar
513
513
  get_range(start_offset, end_offset - start_offset)
514
514
  end
515
515
 
516
- # Get the text of a line by index. (Includes a trailing "\n",
516
+ # Get the text of a line by index. (Includes a trailing "\n",
517
517
  # unless it is the last line in the document.)
518
518
  #
519
519
  # @param [Integer] line_ix the zero-based line number
@@ -524,7 +524,7 @@ module Redcar
524
524
  offset_at_line_end(line_ix) - offset_at_line(line_ix)
525
525
  )
526
526
  end
527
-
527
+
528
528
  # Get the text of a line by index.
529
529
  #
530
530
  # @param [Integer] line_ix the zero-based line number
@@ -535,19 +535,19 @@ module Redcar
535
535
  offset_at_inner_end_of_line(line_ix) - offset_at_line(line_ix)
536
536
  )
537
537
  end
538
-
538
+
539
539
  # Get all text
540
540
  def get_all_text
541
541
  get_range(0, length)
542
542
  end
543
-
544
- # Replace a line in the document. This has two modes. In the first,
543
+
544
+ # Replace a line in the document. This has two modes. In the first,
545
545
  # you supply the replacement text as an argument:
546
546
  #
547
547
  # replace_line(10, "new line text")
548
548
  #
549
549
  # In the second, you supply a block. The block argument is the current
550
- # text of the line, and the return value of the block is the
550
+ # text of the line, and the return value of the block is the
551
551
  # replacement text:
552
552
  #
553
553
  # replace_line(10) {|current_text| current_text.upcase }
@@ -557,20 +557,20 @@ module Redcar
557
557
  end_offset = offset_at_inner_end_of_line(line_ix)
558
558
  replace(start_offset, end_offset - start_offset, text)
559
559
  end
560
-
561
- # Replace the currently selected text. This has two modes. In the first,
560
+
561
+ # Replace the currently selected text. This has two modes. In the first,
562
562
  # you supply the replacement text as an argument:
563
563
  #
564
564
  # replace_selection("new text")
565
565
  #
566
566
  # In the second, you supply a block. The block argument is the current
567
- # selected text, and the return value of the block is the
567
+ # selected text, and the return value of the block is the
568
568
  # replacement text:
569
569
  #
570
570
  # replace_selection {|current_text| current_text.upcase }
571
571
  def replace_selection(new_text=nil)
572
572
  previous_cursor_offset = cursor_offset
573
-
573
+
574
574
  sr = selection_range
575
575
  start_offset = sr.first
576
576
  end_offset = sr.last
@@ -579,36 +579,36 @@ module Redcar
579
579
  replace(start_offset, end_offset - start_offset, new_text)
580
580
 
581
581
  new_end_offset = start_offset + new_text.length
582
-
582
+
583
583
  if previous_cursor_offset == end_offset
584
584
  self.set_selection_range(new_end_offset, start_offset)
585
585
  else
586
586
  self.set_selection_range(start_offset, new_end_offset)
587
587
  end
588
588
  end
589
-
590
- # Replace the current word. This has two modes. In the first,
589
+
590
+ # Replace the current word. This has two modes. In the first,
591
591
  # you supply the replacement text as an argument:
592
592
  #
593
593
  # replace_word_at_offset(offset, "new text")
594
594
  #
595
595
  # In the second, you supply a block. The block argument is the current
596
- # word, and the return value of the block is the
596
+ # word, and the return value of the block is the
597
597
  # replacement text:
598
598
  #
599
599
  # replace_word_at_offset(offset) {|current_text| current_text.upcase }
600
600
  def replace_word_at_offset(offset, new_text=nil)
601
601
  previous_offset = cursor_offset
602
-
602
+
603
603
  wr = word_range_at_offset(offset)
604
604
  start_offset = wr.first
605
605
  end_offset = wr.last
606
606
  new_text = new_text || yield(word_at_offset(offset))
607
607
  replace(start_offset, end_offset - start_offset, new_text)
608
-
608
+
609
609
  self.cursor_offset = [previous_offset, start_offset + new_text.length].min
610
610
  end
611
-
611
+
612
612
  # Get the offset at the end of a given line, *before* the line delimiter.
613
613
  #
614
614
  # @param [Integer] line_ix a zero-based line index
@@ -619,8 +619,8 @@ module Redcar
619
619
  offset_at_line(line_ix + 1) - delim.length
620
620
  end
621
621
  end
622
-
623
- # Does the minimum amount of scrolling that brings the given line
622
+
623
+ # Does the minimum amount of scrolling that brings the given line
624
624
  # into the viewport. Which may be none at all.
625
625
  #
626
626
  # @param [Integer] line_ix a zero-based line index
@@ -635,7 +635,29 @@ module Redcar
635
635
  scroll_to_line_at_top(bottom_line_ix)
636
636
  end
637
637
  end
638
-
638
+
639
+ # Does the minimum amount of scrolling that brings the given horizontal
640
+ # offset into the viewport. Which may be none at all.
641
+ #
642
+ # @param [Integer] offset a zero-based horizontal offset
643
+ def scroll_to_horizontal_offset(offset)
644
+ line = cursor_line
645
+ start = offset_at_line(line)
646
+ lend = offset_at_inner_end_of_line(line)
647
+ dist = largest_visible_horizontal_index - smallest_visible_horizontal_index
648
+ if offset > 0 and offset <= lend - start # if offset exists at line
649
+ if offset < dist
650
+ @edit_view.controller.scroll_to_horizontal_offset(0)
651
+ else
652
+ if offset > largest_visible_horizontal_index
653
+ @edit_view.controller.scroll_to_horizontal_offset(offset-dist)
654
+ elsif offset < smallest_visible_horizontal_index
655
+ @edit_view.controller.scroll_to_horizontal_offset(offset)
656
+ end
657
+ end
658
+ end
659
+ end
660
+
639
661
  # Tries to scroll so the given line is at the top of the viewport.
640
662
  #
641
663
  # @param [Integer] line_ix a zero-based line index
@@ -645,18 +667,26 @@ module Redcar
645
667
 
646
668
  # The line_ix of the line at the top of the viewport.
647
669
  #
648
- # @return [Integer] a zero-based line index
670
+ # @return [Integer] a zero-based line index
649
671
  def smallest_visible_line
650
672
  @edit_view.controller.smallest_visible_line
651
673
  end
652
-
674
+
653
675
  # The line_ix of the line at the bottom of the viewport.
654
676
  #
655
- # @return [Integer] a zero-based line index
677
+ # @return [Integer] a zero-based line index
656
678
  def biggest_visible_line
657
679
  @edit_view.controller.biggest_visible_line
658
680
  end
659
681
 
682
+ def largest_visible_horizontal_index
683
+ @edit_view.controller.largest_visible_horizontal_index
684
+ end
685
+
686
+ def smallest_visible_horizontal_index
687
+ @edit_view.controller.smallest_visible_horizontal_index
688
+ end
689
+
660
690
  def ensure_visible(offset)
661
691
  @edit_view.controller.ensure_visible(offset)
662
692
  end
@@ -664,22 +694,22 @@ module Redcar
664
694
  def num_lines_visible
665
695
  biggest_visible_line - smallest_visible_line
666
696
  end
667
-
697
+
668
698
  # The scope hierarchy at this point
669
699
  #
670
700
  # @param [String]
671
701
  def cursor_scope
672
702
  controller.scope_at(cursor_line, cursor_line_offset)
673
703
  end
674
-
704
+
675
705
  def create_mark(offset, gravity=:right)
676
706
  controller.create_mark(offset, gravity)
677
707
  end
678
-
708
+
679
709
  def delete_mark(mark)
680
710
  controller.delete_mark(mark)
681
711
  end
682
-
712
+
683
713
  # Everything within the block will be treated as a single action
684
714
  # for the purposes of Undo.
685
715
  #
@@ -687,13 +717,13 @@ module Redcar
687
717
  def compound
688
718
  @edit_view.controller.compound { yield }
689
719
  end
690
-
720
+
691
721
  def update_from_mirror
692
722
  previous_line = cursor_line
693
723
  top_line = smallest_visible_line
694
-
724
+
695
725
  self.text = mirror.read
696
-
726
+
697
727
  @modified = false
698
728
  @edit_view.title = title_with_star
699
729
  if line_count > previous_line
@@ -701,18 +731,18 @@ module Redcar
701
731
  scroll_to_line_at_top(top_line)
702
732
  end
703
733
  end
704
-
734
+
705
735
  def set_modified(boolean)
706
736
  @modified = boolean
707
737
  @edit_view.title = title_with_star
708
738
  end
709
-
739
+
710
740
  def indentation
711
741
  Document::Indentation.new(self, @edit_view.tab_width, @edit_view.soft_tabs?)
712
742
  end
713
-
714
- private
715
-
743
+
744
+ private
745
+
716
746
  def title_with_star
717
747
  if mirror
718
748
  if @modified
@@ -724,7 +754,7 @@ module Redcar
724
754
  "untitled"
725
755
  end
726
756
  end
727
-
757
+
728
758
  def rescue_document_controller_error(controller)
729
759
  begin
730
760
  yield
@@ -732,7 +762,7 @@ module Redcar
732
762
  puts "*** ERROR in Document controller: #{controller.inspect}"
733
763
  puts e.class.name + ": " + e.message
734
764
  puts e.backtrace
735
- end
765
+ end
736
766
  end
737
767
  end
738
768
  end