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" "utils.rkt"
"types.rkt" "types.rkt"
"../common/bstr.rkt" "../common/bstr.rkt"
"../../syntax.rkt") "../../syntax.rkt"
"../../lock.rkt")
(provide clipboard-driver% (provide clipboard-driver%
has-x-selection?) has-x-selection?)
@ -49,6 +50,8 @@
#f))))) #f)))))
(define/public (set-client c types) (define/public (set-client c types)
(atomically
(with-autorelease
(let ([pb (tell NSPasteboard generalPasteboard)] (let ([pb (tell NSPasteboard generalPasteboard)]
[a (tell NSArray arrayWithObjects: [a (tell NSArray arrayWithObjects:
#:type (_list i _NSString) (map map-type types) #:type (_list i _NSString) (map map-type types)
@ -62,7 +65,7 @@
length: #:type _NSUInteger (bytes-length bstr))]) length: #:type _NSUInteger (bytes-length bstr))])
(tellv (tell NSPasteboard generalPasteboard) (tellv (tell NSPasteboard generalPasteboard)
setData: data setData: data
forType: #:type _NSString (map-type type)))))) forType: #:type _NSString (map-type type))))))))
(define/public (get-data-for-type type) (define/public (get-data-for-type type)
(log-error "didn't expect clipboard data request")) (log-error "didn't expect clipboard data request"))
@ -73,9 +76,11 @@
(bytes->string/utf-8 bstr #\?)))) (bytes->string/utf-8 bstr #\?))))
(define/public (get-data type) (define/public (get-data type)
(atomically
(with-autorelease
(let* ([pb (tell NSPasteboard generalPasteboard)] (let* ([pb (tell NSPasteboard generalPasteboard)]
[data (tell pb dataForType: #:type _NSString (map-type type))]) [data (tell pb dataForType: #:type _NSString (map-type type))])
(and data (and data
(let ([len (tell #:type _NSUInteger data length)] (let ([len (tell #:type _NSUInteger data length)]
[bstr (tell #:type _pointer data bytes)]) [bstr (tell #:type _pointer data bytes)])
(scheme_make_sized_byte_string bstr len 1)))))) (scheme_make_sized_byte_string bstr len 1))))))))

View File

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

View File

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