selection and cocoa clipboard fixes

This commit is contained in:
Matthew Flatt 2010-09-14 08:55:16 -06:00
parent b69b97c113
commit f51345b512
3 changed files with 31 additions and 26 deletions

View File

@ -5,7 +5,8 @@
"utils.rkt"
"types.rkt"
"../common/bstr.rkt"
"../../syntax.rkt")
"../../syntax.rkt"
"../../lock.rkt")
(provide clipboard-driver%
has-x-selection?)
@ -49,20 +50,22 @@
#f)))))
(define/public (set-client c types)
(let ([pb (tell NSPasteboard generalPasteboard)]
[a (tell NSArray arrayWithObjects:
#:type (_list i _NSString) (map map-type types)
count: #:type _NSUInteger (length types))])
(set! counter (tell #:type _NSInteger pb clearContents))
(set! client c)
(for ([type (in-list types)])
(let* ([bstr (send c get-data type)]
[data (tell NSData
dataWithBytes: #:type _bytes bstr
length: #:type _NSUInteger (bytes-length bstr))])
(tellv (tell NSPasteboard generalPasteboard)
setData: data
forType: #:type _NSString (map-type type))))))
(atomically
(with-autorelease
(let ([pb (tell NSPasteboard generalPasteboard)]
[a (tell NSArray arrayWithObjects:
#:type (_list i _NSString) (map map-type types)
count: #:type _NSUInteger (length types))])
(set! counter (tell #:type _NSInteger pb clearContents))
(set! client c)
(for ([type (in-list types)])
(let* ([bstr (send c get-data type)]
[data (tell NSData
dataWithBytes: #:type _bytes bstr
length: #:type _NSUInteger (bytes-length bstr))])
(tellv (tell NSPasteboard generalPasteboard)
setData: data
forType: #:type _NSString (map-type type))))))))
(define/public (get-data-for-type type)
(log-error "didn't expect clipboard data request"))
@ -73,9 +76,11 @@
(bytes->string/utf-8 bstr #\?))))
(define/public (get-data type)
(let* ([pb (tell NSPasteboard generalPasteboard)]
[data (tell pb dataForType: #:type _NSString (map-type type))])
(and data
(let ([len (tell #:type _NSUInteger data length)]
[bstr (tell #:type _pointer data bytes)])
(scheme_make_sized_byte_string bstr len 1))))))
(atomically
(with-autorelease
(let* ([pb (tell NSPasteboard generalPasteboard)]
[data (tell pb dataForType: #:type _NSString (map-type type))])
(and data
(let ([len (tell #:type _NSUInteger data length)]
[bstr (tell #:type _pointer data bytes)])
(scheme_make_sized_byte_string bstr len 1))))))))

View File

@ -68,7 +68,7 @@
(and (pair? v)
(exact-nonnegative-integer? (car v))
(exact-nonnegative-integer? (cdr v))
((car v) . < . (cdr v)))))
((car v) . <= . (cdr v)))))
(define selected-text-color (get-highlight-text-color))

View File

@ -5188,10 +5188,10 @@
(if (eq? snip s-caret-snip)
show-caret
(if (and maybe-hilite?
(endpos . > . p)
(startpos . < . (+ p (snip->count snip))))
(cons (max 0 (- startpos p))
(min (snip->count snip) (- endpos p)))
(-endpos . > . p)
(-startpos . < . (+ p (snip->count snip))))
(cons (max 0 (- -startpos p))
(min (snip->count snip) (- -endpos p)))
'no-caret))))))
;; the rules for hiliting are surprisingly complicated: