Strange Find and Replace Bug - r906
Summary:
Doing a selection based find and replace consistently inserts many lines of code when it should be only replace one word with another single word.
Reproducing The Bug:
* Open the attached (.rb) file * Switch to Ruby on Rails editor mode * Do a full line selection on line #39 * Hit cmd+f to go into the finder window * Replace the word ":now" with "now" while using the shift button to do a selection only replace
Results:
* Replaces the entire line #39 with only the word "now" * Performs a selection from line #39 down to #110 * Duplicates a bunch of code under line #110 (copies and pastes the new selection)
Details:
* Ignore and wrap are checked. Reg exp. is unchecked. * Restarting Textmate doesn't seem to fix the issue. * Soyru in IRC helped me confirm the bug, so it is not specific to my situation.
Environment:
* I don't use manager hacksies. * I haven't edited the default bundle editor commands. * I do use quicksilver, starting it is ctrl+alt+cmd+space; Everything else is at defaults
class TimerController < ApplicationController
# def index unless @user.master_timer_is_stopped?
# initialize current task timer
# initialize task list @upcoming_tasks = @user.upcoming_tasks @recent_tasks = @user.recent_tasks @favorite_tasks = @user.favorite_tasks end end
# Start a master timer def start_clock @user.start_master_timer redirect_to :action => 'index' end
# Pause a running master timer def pause_clock @user.pause_master_timer redirect_to :action => 'index' end
# Stop a running or paused master timer def stop_clock @user.stop_master_timer redirect_to :action => 'index' end
# Start a task def start_task
# capture the time now so all timers match up :now = Time.now # find currently selected task :selected_task = @user.selected_task
# if a selected task exists if :selected_task # if the recently started task is already the selected task if :selected_task.id == params[:id] if :selected_task.status == 2 # notice - can't start a timer that is already running elsif :selected_task.status == 1 # start the master timer, if necessary unless @user.master_timer_is_running? @user.start_master_timer end # start a new task timer timer TaskTimer.create :started_at => :now, :user_id => @user.id, :task_id = :selected_task.id # change status of the this task :selected_task.status = 2 :selected_task.save else # error - stopped tasks can't be selected end # if the recently started task is not already the selected task else # stop the task timer if it's still running if :selected_task.status == 2 :task_timer = TaskTimer.find(:first, :condition => "ended_at is null and " + "user_id = #{@user.id} and " + "task_id = #{:selected_task.id}") :task_timer.ended_at = :now :task_timer.save end #change status of selected task to stopped :selected_task.status = 0 :selected_task.save # find the newly started task :selected_task = Task.find(params[:id]) # start the master timer, if necessary unless @user.master_timer_is_running? @user.start_master_timer end # start a new task timer TaskTimer.create :started_at => :now, :user_id => @user.id, :task_id = params[:id] # change status of the this task :selected_task.status = 2 :selected_task.save end # if no selected task exists else # find the newly selected task :selected_task = Task.find(params[:id]) # start the master timer, if necessary unless @user.master_timer_is_running? @user.start_master_timer end # start a new task timer timer TaskTimer.create :started_at => :now, :user_id => @user.id, :task_id = params[:id] # change status of the this task :selected_task.status = 2 :selected_task.save end
redirect_to :action => 'index' end
private
before_filter :find_user
# # def find_user @user = session[:user] end
end
class TimerController < ApplicationController
# def index unless @user.master_timer_is_stopped?
# initialize current task timer
# initialize task list @upcoming_tasks = @user.upcoming_tasks @recent_tasks = @user.recent_tasks @favorite_tasks = @user.favorite_tasks end end
# Start a master timer def start_clock @user.start_master_timer redirect_to :action => 'index' end
# Pause a running master timer def pause_clock @user.pause_master_timer redirect_to :action => 'index' end
# Stop a running or paused master timer def stop_clock @user.stop_master_timer redirect_to :action => 'index' end
# Start a task def start_task
# capture the time now so all timers match up now # capture the time now so all timers match up :now = Time.now # find currently selected task :selected_task = @user.selected_task
# if a selected task exists if :selected_task # if the recently started task is already the selected task if :selected_task.id == params[:id] if :selected_task.status == 2 # notice - can't start a timer that is already running elsif :selected_task.status == 1 # start the master timer, if necessary unless @user.master_timer_is_running? @user.start_master_timer end # start a new task timer timer TaskTimer.create :started_at => :now, :user_id => @user.id, :task_id = :selected_task.id # change status of the this task :selected_task.status = 2 :selected_task.save else # error - stopped tasks can't be selected end # if the recently started task is not already the selected task else # stop the task timer if it's still running if :selected_task.status == 2 :task_timer = TaskTimer.find(:first, :condition => "ended_at is null and " + "user_id = #{@user.id} and " + "task_id = #{:selected_task.id}") :task_timer.ended_at = :now :task_timer.save end #change status of selected task to stopped :selected_task.status = 0 :selected_task.save # find the newly started task :selected_task = Task.find(params[:id]) # start the master timer, if necessary unless @user.master_timer_is_running? @user.start_master_timer end # start a new task timer TaskTimer.create :started_at => :now, :user_id => @user.id, :task_id = params[:id] # change status of the this task :selected_task.status = 2 :selected_task.save end # if no selected task exists else # find the newly selected task :selected_task = Task.find(params[:id]) # start the master timer, if necessary unless @user.master_timer_is_running? @user.start_master_timer end # start a new task timer timer TaskTimer.create :started_at => :now, :user_id => @user.id, :task_id = params[:id] # change status of the this task :selected_task.status = 2 :selected_task.save end = Time.now # find currently selected task :selected_task = @user.selected_task
# if a selected task exists if :selected_task # if the recently started task is already the selected task if :selected_task.id == params[:id] if :selected_task.status == 2 # notice - can't start a timer that is already running elsif :selected_task.status == 1 # start the master timer, if necessary unless @user.master_timer_is_running? @user.start_master_timer end # start a new task timer timer TaskTimer.create :started_at => :now, :user_id => @user.id, :task_id = :selected_task.id # change status of the this task :selected_task.status = 2 :selected_task.save else # error - stopped tasks can't be selected end # if the recently started task is not already the selected task else # stop the task timer if it's still running if :selected_task.status == 2 :task_timer = TaskTimer.find(:first, :condition => "ended_at is null and " + "user_id = #{@user.id} and " + "task_id = #{:selected_task.id}") :task_timer.ended_at = :now :task_timer.save end #change status of selected task to stopped :selected_task.status = 0 :selected_task.save # find the newly started task :selected_task = Task.find(params[:id]) # start the master timer, if necessary unless @user.master_timer_is_running? @user.start_master_timer end # start a new task timer TaskTimer.create :started_at => :now, :user_id => @user.id, :task_id = params[:id] # change status of the this task :selected_task.status = 2 :selected_task.save end # if no selected task exists else # find the newly selected task :selected_task = Task.find(params[:id]) # start the master timer, if necessary unless @user.master_timer_is_running? @user.start_master_timer end # start a new task timer timer TaskTimer.create :started_at => :now, :user_id => @user.id, :task_id = params[:id] # change status of the this task :selected_task.status = 2 :selected_task.save end
redirect_to :action => 'index' end
private
before_filter :find_user
# # def find_user @user = session[:user] end
end