fix text% `get-paragraph-{start,end}-position' bug and doc bugs
Merge to 5.2
This commit is contained in:
parent
d362bda6d3
commit
379991c5bb
|
@ -3343,25 +3343,27 @@
|
||||||
[any? [visible-only? #t]])
|
[any? [visible-only? #t]])
|
||||||
(if (not (check-recalc #f #f #t))
|
(if (not (check-recalc #f #f #t))
|
||||||
0
|
0
|
||||||
(let* ([i (max 0 i)]
|
(if (i . > . (+ (last-paragraph) (if extra-line? -1 0)))
|
||||||
[l (mline-find-paragraph (unbox line-root-box) i)]
|
len
|
||||||
[l (if l
|
(let* ([i (max 0 i)]
|
||||||
(let loop ([l l])
|
[l (mline-find-paragraph (unbox line-root-box) i)]
|
||||||
(if (and (mline-next l)
|
[l (if l
|
||||||
(zero? (mline-starts-paragraph (mline-next l))))
|
(let loop ([l l])
|
||||||
(loop (mline-next l))
|
(if (and (mline-next l)
|
||||||
l))
|
(zero? (mline-starts-paragraph (mline-next l))))
|
||||||
(if extra-line?
|
(loop (mline-next l))
|
||||||
len
|
l))
|
||||||
last-line))])
|
(if extra-line?
|
||||||
(if (mline? l)
|
len
|
||||||
(let ([p (+ (mline-get-position l) (mline-len l))])
|
last-line))])
|
||||||
(if visible-only?
|
(if (mline? l)
|
||||||
(let-boxes ([p p])
|
(let ([p (+ (mline-get-position l) (mline-len l))])
|
||||||
(find-last-visible-position l p)
|
(if visible-only?
|
||||||
p)
|
(let-boxes ([p p])
|
||||||
p))
|
(find-last-visible-position l p)
|
||||||
l))))
|
p)
|
||||||
|
p))
|
||||||
|
l)))))
|
||||||
|
|
||||||
(def/public (line-paragraph [exact-nonnegative-integer? i])
|
(def/public (line-paragraph [exact-nonnegative-integer? i])
|
||||||
(cond
|
(cond
|
||||||
|
|
|
@ -537,10 +537,10 @@ See also @method[editor<%> write-headers-to-file] and
|
||||||
@section[#:tag "editoreol"]{End of Line Ambiguity}
|
@section[#:tag "editoreol"]{End of Line Ambiguity}
|
||||||
|
|
||||||
Because an editor can force a line break even when there is no
|
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
|
specify a @techlink{location} for the caret. Consider the last
|
||||||
@techlink{position} of a line that is soft-broken (i.e., no carriage
|
@techlink{position} of a line that is soft-broken (i.e., no newline
|
||||||
return is present): there is no @techlink{item} between the last
|
is present): there is no @techlink{item} between the last
|
||||||
@techlink{item} of the line and the first @techlink{item} of the next
|
@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
|
line, so two @techlink{location}s (one end-of-line and one
|
||||||
start-of-line) map to the same @techlink{position}.
|
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
|
@item{@deftech{Simple text}, where there is one character per
|
||||||
@techlink{item}. @techlink{Item}s that are characters are mapped to
|
@techlink{item}. @techlink{Item}s that are characters are mapped to
|
||||||
themselves, and all other @techlink{item}s are mapped to a
|
themselves, and all other @techlink{item}s are mapped to a
|
||||||
period. Line breaks are represented by carriage-return characters
|
period. Line breaks are represented by newline characters
|
||||||
(ASCII 13).}
|
(ASCII 10).}
|
||||||
|
|
||||||
@item{@deftech{Flattened text}, where each @techlink{item} can map to
|
@item{@deftech{Flattened text}, where each @techlink{item} can map to
|
||||||
an arbitrary string. @techlink{Item}s that are characters are still
|
an arbitrary string. @techlink{Item}s that are characters are still
|
||||||
|
|
|
@ -362,8 +362,8 @@ following symbols:
|
||||||
@item{@indexed-racket['can-append] --- this snip can be merged with
|
@item{@indexed-racket['can-append] --- this snip can be merged with
|
||||||
another snip of the same type}
|
another snip of the same type}
|
||||||
|
|
||||||
@item{@indexed-racket['invisible] --- the user doesn't ``see'' this snip;
|
@item{@indexed-racket['invisible] --- an @deftech{invisible} snip
|
||||||
e.g.: a carriage return}
|
that the user doesn't see, such as a newline}
|
||||||
|
|
||||||
@item{@indexed-racket['hard-newline] --- a newline must follow the snip}
|
@item{@indexed-racket['hard-newline] --- a newline must follow the snip}
|
||||||
|
|
||||||
|
|
|
@ -163,7 +163,7 @@ Called after the editor's maximum or minimum height or width is
|
||||||
after-set-size-constraint] modifies the editor).
|
after-set-size-constraint] modifies the editor).
|
||||||
|
|
||||||
(This callback method is provided because setting an editor's maximum
|
(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<%>
|
See also @method[text% can-set-size-constraint?] and @method[editor<%>
|
||||||
on-edit-sequence].
|
on-edit-sequence].
|
||||||
|
@ -299,7 +299,7 @@ is changed. If the return value is @racket[#f], then the
|
||||||
change will be aborted.
|
change will be aborted.
|
||||||
|
|
||||||
(This callback method is provided because setting an editor's maximum
|
(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%
|
See also @method[text% on-set-size-constraint], @method[text%
|
||||||
after-set-size-constraint], and @method[editor<%> on-edit-sequence].
|
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.
|
text.
|
||||||
|
|
||||||
If @racket[force-cr?] is not @racket[#f] and @racket[flattened?] is not
|
If @racket[force-cr?] is not @racket[#f] and @racket[flattened?] is not
|
||||||
@racket[#f], then automatic carriage returns (from word-wrapping) are
|
@racket[#f], then automatic newlines (from word-wrapping) are
|
||||||
written into the return string as real carriage returns.
|
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
|
last line is returned. If @racket[line] is less than 0, then the end
|
||||||
of the first line is returned.
|
of the first line is returned.
|
||||||
|
|
||||||
If the line ends with invisible @techlink{item}s (such as a carriage
|
If the line ends with @tech{invisible} @techlink{item}s (such as a
|
||||||
return) and @racket[visible?] is not @racket[#f], the first
|
newline) and @racket[visible?] is not @racket[#f], the first
|
||||||
@techlink{position} before the invisible @techlink{item}s is
|
@techlink{position} before the @tech{invisible} @techlink{item}s is
|
||||||
returned.
|
returned.
|
||||||
|
|
||||||
@LineToPara[@racket[paragraph-end-position]]
|
@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
|
last line is returned. If @racket[line] is less than 0, then
|
||||||
the start of the first line is returned.
|
the start of the first line is returned.
|
||||||
|
|
||||||
If the line starts with invisible @techlink{item}s and @racket[visible?] is not
|
If the line starts with @tech{invisible} @techlink{item}s and @racket[visible?] is not
|
||||||
@racket[#f], the first @techlink{position} past the invisible @techlink{item}s is
|
@racket[#f], the first @techlink{position} past the @tech{invisible} @techlink{item}s is
|
||||||
returned.
|
returned.
|
||||||
|
|
||||||
@LineToPara[@racket[paragraph-start-position]]
|
@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.
|
the change has completed.
|
||||||
|
|
||||||
(This callback method is provided because setting an editor's maximum
|
(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].
|
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?]
|
@defmethod[(paragraph-end-position [paragraph exact-nonnegative-integer?]
|
||||||
[visible? any/c #f])
|
[visible? any/c #t])
|
||||||
exact-nonnegative-integer?]{
|
exact-nonnegative-integer?]{
|
||||||
|
|
||||||
Returns the ending @techlink{position} of a given paragraph. @|ParagraphNumbering|
|
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
|
end of the last paragraph is returned. If @racket[paragraph] is less
|
||||||
than 0, then the end of the first paragraph is returned.
|
than 0, then the end of the first paragraph is returned.
|
||||||
|
|
||||||
If the paragraph ends with invisible @techlink{item}s (such as a carriage
|
If the paragraph ends with @tech{invisible} @techlink{item}s (such as a newline)
|
||||||
return) and @racket[visible?] is not @racket[#f], the first @techlink{position}
|
and @racket[visible?] is not @racket[#f], the first @techlink{position}
|
||||||
before the invisible @techlink{item}s is returned.
|
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?]
|
@defmethod[(paragraph-start-position [paragraph exact-nonnegative-integer?]
|
||||||
[visible? any/c #f])
|
[visible? any/c #t])
|
||||||
exact-nonnegative-integer?]{
|
exact-nonnegative-integer?]{
|
||||||
|
|
||||||
Returns the starting @techlink{position} of a given paragraph. @|ParagraphNumbering|
|
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
|
If there are fewer than @math{@racket[paragraph]-1} paragraphs, the
|
||||||
start of the last paragraph is returned.
|
start of the last paragraph is returned.
|
||||||
|
|
||||||
If the paragraph starts with invisible @techlink{item}s and @racket[visible?] is
|
If the paragraph starts with @tech{invisible} @techlink{item}s and @racket[visible?] is
|
||||||
not @racket[#f], the first @techlink{position} past the invisible @techlink{item}s is
|
not @racket[#f], the first @techlink{position} past the @tech{invisible} @techlink{item}s is
|
||||||
returned.
|
returned.
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1887,7 +1887,8 @@ The legal formats are:
|
||||||
@itemize[
|
@itemize[
|
||||||
@item{@racket['standard] --- a standard editor file}
|
@item{@racket['standard] --- a standard editor file}
|
||||||
@item{@racket['text] --- a text 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
|
@MonitorMethod[@elem{The file format of an editor} @elem{the
|
||||||
|
|
|
@ -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)
|
(done)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user