             return
         current_value = @getValue()
         if value == current_value
-            # Nothing to do
+            # Special case: nothing to do
             return
 
         r = @getOption('readOnly')

        pos = {line:0, ch:0}  # start at the beginning
        last_pos = undefined
        for chunk in diff
            #console.log(chunk)
            op  = chunk[0]  # 0 = stay same; -1 = delete; +1 = add
            val = chunk[1]  # the actual text to leave same, delete, or add
            pos1 = next_pos(val, pos)

        b      = @setBookmark(line:@lineAtHeight(t, 'local'))
        before = @heightAtLine(@lineAtHeight(t, 'local'))

        # Compute patch that transforms current_value to new value:
        diff = dmp.diff_main(current_value, value)
        if diff.length >= 500
            # special case -- a really weird change that will take
            # an enormous amount of time to apply using diffApply.
            # For example, something that changes every line in a file
            # slightly could do this.  In this case, instead of blocking
            # the user browser for several seconds, we just take the
            # hit and possibly unset the cursor.  Most diffs involve
            # a much smaller number of patches.
            scroll = @getScrollInfo().top - (before - @heightAtLine(b.find().line))
            @setValue(value)
            @scrollTo(undefined, scroll)  # make some attempt to fix scroll.
        else
            # Change the buffer in place by applying the diffs as we go; this avoids replacing the entire buffer,
            # which would cause total chaos.
            last_pos = @diffApply(diff)

        # Now, if possible, restore the exact scroll position.
        n = b.find()?.line
