Class: PWKeep::Editor
- Inherits:
-
Object
- Object
- PWKeep::Editor
- Defined in:
- lib/pwkeep/editor.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#history ⇒ Object
readonly
Returns the value of attribute history.
-
#saved_content ⇒ Object
readonly
Returns the value of attribute saved_content.
Instance Method Summary collapse
- #content ⇒ Object
- #find(text) ⇒ Object
-
#initialize(data, options) ⇒ Editor
constructor
A new instance of Editor.
- #modified? ⇒ Boolean
- #save ⇒ Object
- #store_session ⇒ Object
Constructor Details
#initialize(data, options) ⇒ Editor
Returns a new instance of Editor.
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
# File 'lib/pwkeep/editor.rb', line 357 def initialize(data, ) @options = content = data @options[:language] ||= LanguageSniffer.detect(@file, :content => content).language content.tabs_to_spaces! if @options[:convert_tabs] # cleanup newline formats @newline = content.match("\r\n|\r|\n") @newline = (@newline ? @newline[0] : "\n") content.gsub!(/\r\n?/,"\n") @saved_content = content @text_area = Ruco::EditorArea.new(content, @options) @history = @text_area.history restore_session end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
344 345 346 |
# File 'lib/pwkeep/editor.rb', line 344 def file @file end |
#history ⇒ Object (readonly)
Returns the value of attribute history.
346 347 348 |
# File 'lib/pwkeep/editor.rb', line 346 def history @history end |
#saved_content ⇒ Object (readonly)
Returns the value of attribute saved_content.
347 348 349 |
# File 'lib/pwkeep/editor.rb', line 347 def saved_content @saved_content end |
Instance Method Details
#content ⇒ Object
408 409 410 |
# File 'lib/pwkeep/editor.rb', line 408 def content text_area.content.freeze # no modifications allowed end |
#find(text) ⇒ Object
375 376 377 378 379 380 381 382 383 384 385 386 |
# File 'lib/pwkeep/editor.rb', line 375 def find(text) move(:relative, 0,0) # reset selection start = text_area.content.index(text, text_area.index_for_position+1) return unless start # select the found word finish = start + text.size move(:to_index, finish) selecting{ move(:to_index, start) } true end |
#modified? ⇒ Boolean
388 389 390 |
# File 'lib/pwkeep/editor.rb', line 388 def modified? @saved_content != text_area.content end |
#save ⇒ Object
392 393 394 395 396 397 398 399 400 401 402 403 |
# File 'lib/pwkeep/editor.rb', line 392 def save lines = text_area.send(:lines) lines.each(&:rstrip!) if @options[:remove_trailing_whitespace_on_save] lines << '' if @options[:blank_line_before_eof_on_save] and lines.last.to_s !~ /^\s*$/ content = lines * @newline @saved_content = content.gsub(/\r?\n/, "\n") true rescue Object => e e. end |
#store_session ⇒ Object
405 406 |
# File 'lib/pwkeep/editor.rb', line 405 def store_session end |