fix text% `get-paragraph-{start,end}-position' bug and doc bugs

Merge to 5.2
This commit is contained in:
Matthew Flatt 2011-10-08 08:37:09 -06:00
parent d362bda6d3
commit 379991c5bb
5 changed files with 63 additions and 44 deletions

View File

@ -3343,25 +3343,27 @@
[any? [visible-only? #t]])
(if (not (check-recalc #f #f #t))
0
(let* ([i (max 0 i)]
[l (mline-find-paragraph (unbox line-root-box) i)]
[l (if l
(let loop ([l l])
(if (and (mline-next l)
(zero? (mline-starts-paragraph (mline-next l))))
(loop (mline-next l))
l))
(if extra-line?
len
last-line))])
(if (mline? l)
(let ([p (+ (mline-get-position l) (mline-len l))])
(if visible-only?
(let-boxes ([p p])
(find-last-visible-position l p)
p)
p))
l))))
(if (i . > . (+ (last-paragraph) (if extra-line? -1 0)))
len
(let* ([i (max 0 i)]
[l (mline-find-paragraph (unbox line-root-box) i)]
[l (if l
(let loop ([l l])
(if (and (mline-next l)
(zero? (mline-starts-paragraph (mline-next l))))
(loop (mline-next l))
l))
(if extra-line?
len
last-line))])
(if (mline? l)
(let ([p (+ (mline-get-position l) (mline-len l))])
(if visible-only?
(let-boxes ([p p])
(find-last-visible-position l p)
p)
p))
l)))))
(def/public (line-paragraph [exact-nonnegative-integer? i])
(cond

View File

@ -537,10 +537,10 @@ See also @method[editor<%> write-headers-to-file] and
@section[#:tag "editoreol"]{End of Line Ambiguity}
Because an editor can force a line break even when there is no
carriage return item, a @techlink{position} alone does not always
newline item, a @techlink{position} alone does not always
specify a @techlink{location} for the caret. Consider the last
@techlink{position} of a line that is soft-broken (i.e., no carriage
return is present): there is no @techlink{item} between the last
@techlink{position} of a line that is soft-broken (i.e., no newline
is present): there is no @techlink{item} between the last
@techlink{item} of the line and the first @techlink{item} of the next
line, so two @techlink{location}s (one end-of-line and one
start-of-line) map to the same @techlink{position}.
@ -570,8 +570,8 @@ Text can be extracted from an editor in either of two forms:
@item{@deftech{Simple text}, where there is one character per
@techlink{item}. @techlink{Item}s that are characters are mapped to
themselves, and all other @techlink{item}s are mapped to a
period. Line breaks are represented by carriage-return characters
(ASCII 13).}
period. Line breaks are represented by newline characters
(ASCII 10).}
@item{@deftech{Flattened text}, where each @techlink{item} can map to
an arbitrary string. @techlink{Item}s that are characters are still

View File

@ -362,8 +362,8 @@ following symbols:
@item{@indexed-racket['can-append] --- this snip can be merged with
another snip of the same type}
@item{@indexed-racket['invisible] --- the user doesn't ``see'' this snip;
e.g.: a carriage return}
@item{@indexed-racket['invisible] --- an @deftech{invisible} snip
that the user doesn't see, such as a newline}
@item{@indexed-racket['hard-newline] --- a newline must follow the snip}

View File

@ -163,7 +163,7 @@ Called after the editor's maximum or minimum height or width is
after-set-size-constraint] modifies the editor).
(This callback method is provided because setting an editor's maximum
width may cause lines to be re-flowed with soft carriage returns.)
width may cause lines to be re-flowed with soft newlines.)
See also @method[text% can-set-size-constraint?] and @method[editor<%>
on-edit-sequence].
@ -299,7 +299,7 @@ is changed. If the return value is @racket[#f], then the
change will be aborted.
(This callback method is provided because setting an editor's maximum
width may cause lines to be re-flowed with soft carriage returns.)
width may cause lines to be re-flowed with soft newlines.)
See also @method[text% on-set-size-constraint], @method[text%
after-set-size-constraint], and @method[editor<%> on-edit-sequence].
@ -996,8 +996,8 @@ If @racket[flattened?] is not @racket[#f], then flattened text is returned.
text.
If @racket[force-cr?] is not @racket[#f] and @racket[flattened?] is not
@racket[#f], then automatic carriage returns (from word-wrapping) are
written into the return string as real carriage returns.
@racket[#f], then automatic newlines (from word-wrapping) are
written into the return string as real newlines.
}
@ -1214,9 +1214,9 @@ If there are fewer than @math{@racket[line]-1} lines, the end of the
last line is returned. If @racket[line] is less than 0, then the end
of the first line is returned.
If the line ends with invisible @techlink{item}s (such as a carriage
return) and @racket[visible?] is not @racket[#f], the first
@techlink{position} before the invisible @techlink{item}s is
If the line ends with @tech{invisible} @techlink{item}s (such as a
newline) and @racket[visible?] is not @racket[#f], the first
@techlink{position} before the @tech{invisible} @techlink{item}s is
returned.
@LineToPara[@racket[paragraph-end-position]]
@ -1273,8 +1273,8 @@ If there are fewer than @math{@racket[line]-1} lines, the start of the
last line is returned. If @racket[line] is less than 0, then
the start of the first line is returned.
If the line starts with invisible @techlink{item}s and @racket[visible?] is not
@racket[#f], the first @techlink{position} past the invisible @techlink{item}s is
If the line starts with @tech{invisible} @techlink{item}s and @racket[visible?] is not
@racket[#f], the first @techlink{position} past the @tech{invisible} @techlink{item}s is
returned.
@LineToPara[@racket[paragraph-start-position]]
@ -1537,7 +1537,7 @@ Called before the editor's maximum or minimum height or width is
the change has completed.
(This callback method is provided because setting an editor's maximum
width may cause lines to be re-flowed with soft carriage returns.)
width may cause lines to be re-flowed with soft newlines.)
See also @method[editor<%> on-edit-sequence].
@ -1560,7 +1560,7 @@ Returns the ending line of a given paragraph. @|ParagraphNumbering| @|LineNumber
@defmethod[(paragraph-end-position [paragraph exact-nonnegative-integer?]
[visible? any/c #f])
[visible? any/c #t])
exact-nonnegative-integer?]{
Returns the ending @techlink{position} of a given paragraph. @|ParagraphNumbering|
@ -1569,9 +1569,9 @@ If there are fewer than @math{@racket[paragraph]-1} paragraphs, the
end of the last paragraph is returned. If @racket[paragraph] is less
than 0, then the end of the first paragraph is returned.
If the paragraph ends with invisible @techlink{item}s (such as a carriage
return) and @racket[visible?] is not @racket[#f], the first @techlink{position}
before the invisible @techlink{item}s is returned.
If the paragraph ends with @tech{invisible} @techlink{item}s (such as a newline)
and @racket[visible?] is not @racket[#f], the first @techlink{position}
before the @tech{invisible} @techlink{item}s is returned.
}
@ -1589,7 +1589,7 @@ is greater than the highest-numbered paragraph, then the editor's end
@defmethod[(paragraph-start-position [paragraph exact-nonnegative-integer?]
[visible? any/c #f])
[visible? any/c #t])
exact-nonnegative-integer?]{
Returns the starting @techlink{position} of a given paragraph. @|ParagraphNumbering|
@ -1597,8 +1597,8 @@ Returns the starting @techlink{position} of a given paragraph. @|ParagraphNumber
If there are fewer than @math{@racket[paragraph]-1} paragraphs, the
start of the last paragraph is returned.
If the paragraph starts with invisible @techlink{item}s and @racket[visible?] is
not @racket[#f], the first @techlink{position} past the invisible @techlink{item}s is
If the paragraph starts with @tech{invisible} @techlink{item}s and @racket[visible?] is
not @racket[#f], the first @techlink{position} past the @tech{invisible} @techlink{item}s is
returned.
}
@ -1887,7 +1887,8 @@ The legal formats are:
@itemize[
@item{@racket['standard] --- a standard editor file}
@item{@racket['text] --- a text file}
@item{@racket['text-force-cr] --- a text file; when writing, change automatic newlines (from word-wrapping) into real carriage returns}
@item{@racket['text-force-cr] --- a text file; when writing, change
automatic newlines (from word-wrapping) into real newlines}
]
@MonitorMethod[@elem{The file format of an editor} @elem{the

View File

@ -1400,4 +1400,20 @@
;; ----------------------------------------
(let ()
(define t (new text%))
(send t insert "1\n12\n123\n")
(expect (send t paragraph-start-position 3) 9)
(expect (send t paragraph-end-position 3) 9)
(expect (send t line-end-position 3) 9))
(let ()
(define t (new text%))
(send t insert "1\n12\n123\n\n")
(expect (send t paragraph-start-position 3) 9)
(expect (send t paragraph-end-position 3) 9)
(expect (send t line-end-position 3) 9))
;; ----------------------------------------
(done)