Changeset 14481


Ignore:
Timestamp:
Dec 11, 2010, 9:27:28 AM (9 years ago)
Author:
gb
Message:

Pasting clipboard content from other applications doesn't work under
Cocotron, because of confusion about the format and endianness of that
data. (What actually gets pasted is a string with byte-reversed character
codes, which may not be visible even though it make take up space in the
buffer.)

Try to work around that: if more than half of the (16-bit) characters
in the string obtained from the clipboard have 0s in their low bytes,
assume that the string is byte-reversed 8-bit text and reverse those
characters again. This can be fooled, so this workaround should be
removed when the underlying Cocotron bug is fixed.

For the sake of argument, this fixes ticket:740, though we should
report the underlying Cocotron confusion and try to render the workaround
unnecessary.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/cocoa-ide/cocoa-editor.lisp

    r14429 r14481  
    33683368     *nsapp* (@selector #/stringToPasteBoard:) (%make-nsstring string) t)))
    33693369
     3370#+cocotron
     3371;;; Work around a byte-order bug that affects #/paste.
     3372(defun maybe-byte-reverse-string (nsstring)
     3373  (let* ((len (#/length nsstring))
     3374         (maybe-reversed-count  0))
     3375    (dotimes (i len)
     3376      (when (not (logtest #xff (#/characterAtIndex: nsstring i)))
     3377        (incf maybe-reversed-count)))
     3378    (if (> maybe-reversed-count (ash len -1))
     3379      (%stack-block ((chars (* 2 len)))
     3380        (ns:with-ns-range (r 0 len)
     3381          (#/getCharacters:range: nsstring chars r)
     3382          (dotimes (i len)
     3383            (declare (fixnum i))
     3384            (let* ((j (+ i i)))
     3385              (declare (fixnum j))
     3386              (let* ((w (%get-unsigned-word chars j)))
     3387                (setf (%get-unsigned-word chars j)
     3388                      (dpb (ldb (byte 8 0) w)
     3389                           (byte 8 8)
     3390                           (ldb (byte 8 8) w))))))
     3391
     3392           
     3393          (#/autorelease
     3394           (make-instance ns:ns-string
     3395                          :with-characters chars
     3396                          :length len))))
     3397      nsstring)))
     3398                       
     3399                   
     3400                                                           
    33703401;;; The default #/paste method seems to want to set the font to
    33713402;;; something ... inappropriate.  If we can figure out why it
     
    33833414    #+debug (log-debug "   string = ~s" string)
    33843415    (unless (%null-ptr-p string)
     3416      #+cocotron (setq string (maybe-byte-reverse-string string))
    33853417      (unless (zerop (ns:ns-range-length (#/rangeOfString: string *ns-cr-string*)))
    33863418        (setq string (make-instance 'ns:ns-mutable-string :with-string string))
Note: See TracChangeset for help on using the changeset viewer.