30 Text
Classes matching this interface are expected to implement the basic
functionality needed by the framework.
This function highlights a region of text in the buffer.
The range between start and end will be highlighted with
the given color, if the style is 'rectangle (the default). If
the style is 'ellipse, then an ellipse is drawn around the range
in the editor, using the color. If the style is 'hollow-ellipse,
then the outline of an ellipse is drawn around the range in the editor,
using the color.
If the style is 'dot, then start and end must be
the same, and a dot is drawn at the bottom of that position in the editor.
If caret-space? is not #f, the left edge of the range
will be one pixel short, to leave space for the caret. The caret does not
interfere with the right hand side of the range. Note that under some
platforms, the caret is drawn with XOR, which means almost anything can
happen. So if the caret is in the middle of the range it may be hard to
see, or if it is on the left of the range and caret-space? is
#f it may also be hard to see.
The priority argument indicates the relative priority for drawing
overlapping regions. If two regions overlap and have different priorities,
the region with 'high priority will be drawn second and only it
will be visible in the overlapping region.
If adjust-on-insert/delete? is #t, then insertions
and deletions to the text will adjust the start and end
of the range. Insertions and deletions before the range move the range forward
and backward; insertions and deletions after the range will be ignored. An insertion
in the middle of the range will enlarge the range and a deletion that overlaps
the range adjusts the range to reflect the deleted portion of the range and its
new position.
The key argument can be used with
unhighlight-ranges/key
and
unhighlight-ranges
to identify ranges whose start and end positions may have changed.
Symbols whose names begin with plt: are reserved
for internal use.
If this method returns a thunk, invoking the thunk will turn off the
highlighting from this range.
Note that if adjust-on-insert/delete is a true value, then
the result is not a thunk and instead
unhighlight-range,
unhighlight-ranges/key, or
unhighlight-ranges
must be called directly to remove the highlighting.
This method removes the highlight from a region of text in the buffer.
The region must match up to a region specified from an earlier call to
highlight-range.
This method does a linear scan over all of the regions currently set.
If you expect to call this method many times (when there are many
ranges set)
consider instead calling unhighlight-ranges.
This method removes the highlight from regions in the buffer
that have the key
key
(as passed to
highlight-range).
This method removes the highlight from regions in the buffer as
selected by
pred?. The arguments to
pred? are the
same as the arguments to
highlight-range when it was originally called,
unless the
adjust-on-insert/delete argument was a true value, in which case the
first two arguments to the predicate will reflect the current state
of the bubble, if it is changed.
Returns a list of (opaque) values representing the active ranges in the
editor.
If the result of this function is
#t, the styles in this
text:basic<%> will be fixed. This means that any text inserted to
this editor has its style set to this editor’s
style-list%’s
"Standard" style.
See also set-styles-fixed.
This moves or copies text and snips to another edit.
Moves or copies from the edit starting at start and ending at
end. It puts the copied text and snips in dest-text
starting at location dest-pos.
If try-to-move is #t, then the snips are removed;
and if it is #f, then they are copied.
If a snip refused to be moved, it will be copied and deleted from the editor,
otherwise it will be moved. A snip may refuse to be moved by returning
#f from release-from-owner.
The result of this method is used as the initial autowrap bitmap. Override
this method to change the initial
bitmap%. See also
set-autowrap-bitmapReturns the result of icon:get-autowrap-bitmap by default.
The result of this method is a symbol that identifies this editor and that
is used as the port-name of a port that is read from this editor if this
editor is used in DrRacket. See also
port-name-matches?.
Indicates if
id matches the port name of this file. If the file is
saved, the port name matches when the save file is the path as
id. If the file has not been saved, the port name matches if the
symbol is the same as the result of
get-port-name.
This method calls normalize-path and thus can be very expensive on
some filesystems. If it is called many times in a loop, cache the results
to avoid calling it too often.
When
get-port-name returns a symbol, the printed
representation of the symbol will be the same as
name.
Returns a number that increments every time something in the editor
changes.
The number is updated in after-insert in text% and
after-delete in text%.
This method is used by
keymap:setup-global to implement a
keybinding for the
"home" key and for
"c:a".
This mixin implements the basic functionality needed for
text%
objects in the framework.
The class that this mixin produces uses the same initialization arguments as
its input.
Objects implementing this interface adjust their
spacing based on the 'framework:line-spacing-add-gap?
preference.
Calls
set-line-spacing to either
0 or
1
when an object is created, based
on the
'framework:line-spacing-add-gap?
preference.
Call this method to enable special treatment of the first line in the editor.
Returns
#t if
is-special-first-line?
returned
#t for the current first line and if the buffer is
scrolled down so that the first line would not (ordinarily) be visible.
Returns the height, in pixels, of the first line.
Override this method to control when the first line is always visible. The
argument is the first line, as a string.
Provides the implementation of
text:first-line<%>. Does so by just
painting the text of the first line over top of what is already there and
overriding
scroll-editor-to to patch up
scrolling and
on-event to patch up mouse
handling.
Based on the various return values of the methods in
text:first-line, draws the first actual line of the editor over
top of the first visible line in the editor.
Clicks in the first line cause the editor to scroll to the actual first
line.
Scrolls a little bit more, when a scroll would be requested that scrolls
something so that it is line underneath the first line.
This class hides the caret, except when the selection is active.
Instances of this class are useful for editors that used for displaying
purposes, but still allow users to copy their text.
Calls
hide-caret to hide the caret when there is only a
caret and no selection.
Classes that implement this interface silently change non-breaking spaces, ie
the character
(integer->char 160), to regular spaces when inserted
into the editor.
Replaces all non-breaking space characters
(integer->char 160) by
#\space characters.
Classes that implement this interface show a vertical line
at a specified column width (when the content in the
text has any lines wider than that column width).
The column width is determined by the 'framework:column-guide-width
preference; that preference is a list of length two where the
first element is a boolean indicating if the line should be
visible at all, and the second is the width where the line
would be visible (if the first is #t).
The position of the line is determined by taking the
width of the x character in the "Standard"
style (or, if there is no "Standard" style, then
the "Basic" style) and multiplying that by the
preference value.
Checks to see if any of the state that would cause the line to draw
in a different place has changed (via calls to
get-extent and
get-padding; if so makes (up to) two calls to
invalidate-bitmap-cache with rectangles that cover the
old and new locations of the line.
Prompts the user if the pasted text should be normalized (and updates
various preferences based on the response).
Override this method in the mixin to avoid all GUI and preferences
interactions.
Normalizes s. Defaults to:
Overridden to detect when insertions are due to pasting. Sets some internal
state and calls the super.
This method usually returns quickly, tracking changes to the editor
to update internal state. But if a non-
string-snip% is deleted,
then the next call to
all-string-snips?
traverses the entire content to search to see if there are other
non-
string-snip%s.
Checks to see if there were any non-
string-snip%s inserted
in the given range and, if so, updates the internal state.
Checks to see if there were any non-
string-snip%s deleted
in the given range and, if so, updates the internal state.
Any object matching this interface can be searched.
If str is not #f, then this method initiates a search for
every occurrence of str in the editor. If str is #f,
then it clears all of the search highlighting in the buffer.
If cs? is #f, the search is case-insensitive, and otherwise
it is case-sensitive.
The replace-mode? boolean determines if the resulting search should
be tracking the next-to-replace search hit as the insertion point moves
around in the editor. Also, when replace-mode? is #f, then
the bubbles are are uniform medium purple color ("plum" in
the-color-database) and otherwise they are either a lighter
purple or a darker purple, with every bubble except the one just following
the insertion the lighter color.
The search does not complete before set-searching-state
returns. Accordingly, get-search-hit-count may
have out-of-date results for a while, until the search process is finished.
If notify-frame? is #t then
search-hits-changed
is called when the search completes.
Sets the anchor’s position in the editor. Only takes effect if the
'framework:anchored-search preference is on.
Returns the number of hits for the search in the buffer before the
insertion point and the total number of hits. Both are based on the count
found last time that a search completed.
Returns the position of the nearest search hit that comes after the
insertion point.
This method is ignored. (The next replacement start is now
tracked via the
after-set-position method.)
Finishes any pending work in computing and
drawing the search bubbles.
Returns information about the search bubbles in the editor. Each item in
the outermost list corresponds to a single bubble. The pair of numbers is
the range of the bubble and the symbol is the color of the
bubble.
This method is intended for use in test suites.
This
text% can be searched.
The result of this mixin uses the same initialization arguments as the
mixin’s argument.
This returns a list containing the super-class’s keymaps, plus the result
of
keymap:get-search.
Re-does any search now that the contents of the window have changed.
Re-does any search now that the contents of the window have changed.
Tells the frame containing the editor to search based on this editor via
the
set-text-to-search method.
Use this buffer to perform some special action when return is typed.
If key is either return or newline, only invoke the
return thunk (initialization argument) and do nothing else.
Registers a snip in this editor to be resized when its viewing area
changes. Ensures the snip is as wide as the viewing area.
This method should only be called by
add-wide-snip in canvas:wide-snip<%>.
Registers a snip in this editor. It is resized when the viewing area of the
editor changes.
The contents of the two editor are kept in sync, as modifications to this
object happen.
The result of this method is the
text% object that the contents of
this editor are being delegated to, or
#f, if there is none.
This method sets the current delegate.
When it is set, all of the snips are copied from this object to
delegate. Additionally, if this object implements
racket:text<%> the tab settings of
delegate are updated
to match this objects.
This class re-uses the implementation of
string-snip% to implement a
string snip that just draws a single pixel for each character in the string.
Sets the descent, space, lspace, and rspace to zero. Sets the height to
1. Sets the width to the number of characters in the string.
Draws black pixels for non-whitespace characters and draws nothing for
whitespace characters.
This class re-uses the implementation of
tab-snip% to implement a
string snip that is always one pixel high.
Sets the descent, space, lspace, and rspace to zero. Sets the height to
1. Sets the width to the width of tabs as returned in the
tab-width parameter of the
get-tabs method.
Draws nothing.
In addition to calling the super method,
highlight-range, this method forwards the highlighting to the delegatee.
This method propagates the call to the delegate and calls the super method.
Draws a blue region in the delegatee editor that shows where the visible
region of the delegate editor is.
starts an edit sequence in the delegate.
ends an edit sequence in the delegate.
Sends a message to the delegate to update the size of the copied snip, if
there is one.
forwards the change to the delegate
forwards the change to the delegate.
forwards the changed style to the delegate.
updates the delegate with the new contents of the text.
Objects supporting this interface are expected to send information about
themselves to the frame that is displaying them.
Objects supporting this interface are expected to support a clever
file format when saving.
The result of this mixin uses the same initialization arguments as the
mixin’s argument.
When files are saved from this
text%, a check is made to see if
there are any non-
string-snip% objects in the
text%. If so,
it is saved using the file format
'std. (see
set-file-format for more information. If not, the file format passed to
save-file is used.
|
filename : path? |
| format | | : | | (or/c 'guess 'standard 'text | 'text-force-cr 'same 'copy) |
|
|
If the method get-file-format returns 'text and the
text has some non string-snip%s, the file format is set to
'standard.
Depending on the user’s preferences, the user may also be queried.
Also, the changes to the file format only happen if the argument
file-format is 'copy or 'same.
Checks to see if the newly loaded file has any lines terminated with
"\n" (i.e., not
"\r\n") or if the file is empty.
If so, and if the
system-type returns
'windows, then
this method calls
use-file-text-mode, passing
#f.
Mixins that implement this interface lock themselves when the file they are
editing is read only.
Indicates whether or not this editor is in read-write mode.
Unlocks the editor, calls the thunk, and then relocks the editor, all using
a
dynamic-wind.
Returns false if the result of
get-read-write? is
true, otherwise returns the result of calling
inner.
Returns false if the result of
get-read-write? is
true, otherwise returns the result of calling
inner.
Checks if the newly saved file is write-only in the filesystem. If so,
locks the editor with the
lock method. Otherwise unlocks
the buffer
For each canvas returned from get-canvases it checks to
see if the canvas%’s get-top-level-window matches
the frame:editor<%> interface. If so, it calls
set-label with the last part of the filename
(ie, the name of the file, not the directory the file is in).
Checks if the newly loaded file is write-only in the filesystem. If so,
locks the editor with the
lock method. Otherwise unlocks
the buffer
Classes implementing this interface (via the associated mixin) support input
and output ports that read from and to the editor.
There are two input ports: the normal input port just reads from the editor’s
contents directly and the box input port inserts an editor snip into this
text and uses input typed into the box as input into the port.
There are three output ports, designed to match stdout, stderr, and a special
port for printing values. The only difference between them is the output is
rendered in different colors when it comes in via the different ports.
They create three threads to mediate access to the input and output ports
(one for each input port and one for all of the output ports).
Deletes the text between start and end without changing
the behavior of the ports (otherwise, deleting the text would break
internal invariants of the port).
Both start and end must be less than
get-insertion-point (or else it is safe to delete
them via delete, so you don’t need this method).
Inserts str at the position start without changing
the behavior of the ports (otherwise, inserting the text would break
internal invariants of the port).
The pos argument must be less than
get-insertion-point (or else it is safe to insert
the string via insert, so you don’t need this method).
Added in version 1.2 of package gui-lib.
Triggers a submission to the input port with what is currently pending
in the editor.
Returns the position where characters put into the output port will appear.
Returns the position where input will be taken into the input port (after
the next time return is typed).
Sets the position where input will be taken into the input port (after the
next time return is typed).
See also get-unread-start-point.
Indicates if editing is allowed in the buffer at this point.
Inserts some text between the unread start point and the insertion point
(and updates them properly). To insert before the two points, see
insert-before.
See also set-unread-start-point and
set-insertion-point.
Inserts some text before the unread start point and updates it and the
insertion point properly. To insert between the two points, see
insert-between.
See also set-unread-start-point and
set-insertion-point.
Augment this method to help control when characters should be submitted to
the input port.
Return #t or the result of calling inner.
This method is called when text is sent into the input port.
Does nothing.
This method puts an eof into the input port.
This method puts an eof into the box input port.
This method removes the current input box from the editor (and all input in
it is lost).
Flushes all of the data in all of the output ports that hasn’t appeared in
the editor yet.
Flushes all of the data in the input port that hasn’t yet been
read. Reading will now block.
Flushes all of the data in the box input port that hasn’t yet been
read. Reading will now block.
The result of this method is the style that is used to color text submitted
to the result of
get-out-port.
If the result is a string that is not mapped in the editor’s style list,
the style named "Standard" is used and if that isn’t mapped, the
style named "Basic" is used.
This method is called during the initialization of the class.
By default, returns "text:ports out" which is mapped to a blue
style in the style list returned by editor:get-standard-style-list.
The result of this method is the style that is used to color text submitted
to the result of
get-err-port.
If the result is a string that is not mapped in the editor’s style list,
the style named "Standard" is used and if that isn’t mapped, the
style named "Basic" is used.
This method is called during the initialization of the class.
By default, returns "text:ports err" which is mapped to a red
italic style in the style list returned by
editor:get-standard-style-list.
The result of this method is the style (or the name of the style) that is
used to color text submitted to the result of
get-value-port.
If the result is a string that is not mapped in the editor’s style list,
the style named "Standard" is used and if that isn’t mapped, the
style named "Basic" is used.
This method is called during the initialization of the class.
By default, returns "text:ports value" which is mapped to a blue
style in the style list returned by
editor:get-standard-style-list.
Returns the input port that data in this editor is sent to.
Returns the box input port that data in this editor is sent to.
Returns an output port that writes into this editor. The only difference
between this port and the ports returned by
get-err-port and
get-value-port is the font style
and color.
Returns an output port that writes into this editor. The only difference
between this port and the ports returned by
get-err-port and
get-out-port is the font style and
color.
Returns an output port that writes into this editor. The only difference
between this port and the ports returned by
get-err-port and
get-out-port is the font style and
color.
This method is called after an insertion due to IO occurs.
The result of this method is used as the class of editor snips that is
inserted by the box port in this editor.
Also calls on-submit.
Adjusts the embedded editor-snip (used for reading input to the
get-in-box-port) to match the width of the editor.
Classes that implement this interface are used as the editors for the box
input port in text:ports%.
Notifies the
text:ports<%> enclosing this editor that a new line
of input has been provided.
The mixin implementing this interface provides an unintrusive autocompletion
menu when a particular (configurable) keystroke is pressed.
Starts a completion.
The border color for the autocomplete menu. Defaults to "black".
The background color for the non-selected menu items. Defaults to
"lavender".
The background color for the selected menu item. Defaults to
(make-object color% 204 153 255).
Returns true when the key event passed to it should initiate the
completions menu.
Returns the list of the words that autocompletion should
choose from.
Given an editor location, returns the prefix ending at that location
that autocompletion should try to complete.
Draws the completion menu (when it is popped up).
Takes over the handling of key events when the completions menu is
visible. Also, when the completions menu is not visible, it calls the
completion-mode-key-event? method to see if it
should start completing.
This method is overridden to allow mouse access of the completions menu. It
only handles events when there is a menu open and the mouse is in the menu,
in which case it makes the menu trace the mouse.
The only time it does not call the super method is when the mouse is button
is pushed.
Classes implementing this interface disable overwrite mode when
the overwrite mode keybindings are turned off.
Enables or disables line number drawing.
Returns whether or not line drawing is enabled.
Sets the color of the line numbers.
Draws the line numbers.
Enables or disables line number drawing.
Returns whether or not line drawing is enabled.
Sets the color of the line numbers.
Determines if arg is an instance of the range struct.
Returns the start position of the range.
Returns the end position of the range.
Returns a boolean indicating where the caret-space in the range goes.
See also
highlight-range.
Returns the color of the highlighted range.
A string that is inserted after a completion is inserted by a
text:autocomplete instance.
Defaults to "".
Controls the number of completions visible at a time in the menu produced
by text:autocomplete instances.
Defaults to 15.
Returns the list of keywords for the manuals from
manuals by
extracting all of the documented exports of the manuals. The symbols are
meant to be module paths, e.g., the quoted form of the argument to
require.
If manuals is false, then all of the documented names are used.
Returns the editor instance whose port-name matches the given symbol.
If no editor can be found, then returns false.
When a snip is sent as a special, if it has a
snip-class%
from a different
eventspace,
it may not work properly
in the
text% object connected to the ports in a
text:port<%>
object. This function, when it is called, constructs the bytes
corresponding to the result of using the
snip’s
write method and saves them in its result. Then,
when the result is used as a special, the snip will rebuild from
the bytes, but now using the
snip-class% from the
eventspace
where the
text:ports<%> operates.
Sends
snip to
port by using
text:make-snip-special,
handling a few special cases for performance and backwards compatibility
reasons.