 					
 					comment.op.p = Math.min(comment_start, op_start)
 					comment.op.c = remaining_before + remaining_after
-					@emit "comment:moved", comment
+					@_markAsDirty comment, "comment", "moved"
 
 		applyInsertToChanges: (op, metadata) ->
 			op_start = op.p
 			op_length = op.i.length
 			op_end = op.p + op_length
+			undoing = !!op.u
 
 
 			already_merged = false

					# Only merge inserts if they are from the same user
					is_same_user = metadata.user_id == change.metadata.user_id
					
					# If this is an insert op at the end of an existing insert with a delete following, and it cancels out the following
					# delete then we shouldn't append it to this insert, but instead only cancel the following delete.
					# E.g.
					#                   foo|<--- about to insert 'b' here
					#  inserted 'foo'  --^ ^-- deleted 'bar'
					# should become just 'foo' not 'foob' (with the delete marker becoming just 'ar'), .
					next_change = @changes[i+1]
					is_op_adjacent_to_next_delete = next_change? and next_change.op.d? and op.p == change_end and next_change.op.p == op.p
					will_op_cancel_next_delete = is_op_adjacent_to_next_delete and next_change.op.d.slice(0, op.i.length) == op.i
					
					# If there is a delete at the start of the insert, and we're inserting
					# at the start, we SHOULDN'T merge since the delete acts as a partition.

					t: op.t
				metadata
			}
			@_markAsDirty comment, "comment", "added"
			return comment
		
		applyInsertToComments: (op) ->
			for comment in @comments
				if op.p <= comment.op.p
					comment.op.p += op.i.length
					@_markAsDirty comment, "comment", "moved"
				else if op.p < comment.op.p + comment.op.c.length
					offset = op.p - comment.op.p
					comment.op.c = comment.op.c[0..(offset-1)] + op.i + comment.op.c[offset...]
					@_markAsDirty comment, "comment", "moved"

		applyDeleteToComments: (op) ->
			op_start = op.p
